[ARM] Add support for ARMv8.1 PAN extension
[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 =
823d2571
TG
204 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M);
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);
e74cfd16
PB
211
212static const arm_feature_set arm_arch_any = ARM_ANY;
823d2571 213static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
214static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
215static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
251665fc 216static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
e74cfd16 217
2d447fca 218static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 219 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 220static const arm_feature_set arm_cext_iwmmxt =
823d2571 221 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 222static const arm_feature_set arm_cext_xscale =
823d2571 223 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 224static const arm_feature_set arm_cext_maverick =
823d2571
TG
225 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
226static const arm_feature_set fpu_fpa_ext_v1 =
227 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
228static const arm_feature_set fpu_fpa_ext_v2 =
229 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 230static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
231 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
232static const arm_feature_set fpu_vfp_ext_v1 =
233 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
234static const arm_feature_set fpu_vfp_ext_v2 =
235 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
236static const arm_feature_set fpu_vfp_ext_v3xd =
237 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
238static const arm_feature_set fpu_vfp_ext_v3 =
239 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 240static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
241 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
242static const arm_feature_set fpu_neon_ext_v1 =
243 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 244static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571
TG
245 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
246static const arm_feature_set fpu_vfp_fp16 =
247 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
248static const arm_feature_set fpu_neon_ext_fma =
249 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
250static const arm_feature_set fpu_vfp_ext_fma =
251 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 252static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 253 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 254static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 255 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 256static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 257 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 258static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 259 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 260static const arm_feature_set crc_ext_armv8 =
823d2571 261 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
e74cfd16 262
33a392fb 263static int mfloat_abi_opt = -1;
e74cfd16
PB
264/* Record user cpu selection for object attributes. */
265static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
266/* Must be long enough to hold any of the names in arm_cpus. */
267static char selected_cpu_name[16];
8d67f500 268
aacf0b33
KT
269extern FLONUM_TYPE generic_floating_point_number;
270
8d67f500
NC
271/* Return if no cpu was selected on command-line. */
272static bfd_boolean
273no_cpu_selected (void)
274{
823d2571 275 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
276}
277
7cc69913 278#ifdef OBJ_ELF
deeaaff8
DJ
279# ifdef EABI_DEFAULT
280static int meabi_flags = EABI_DEFAULT;
281# else
d507cf36 282static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 283# endif
e1da3f5b 284
ee3c0378
AS
285static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
286
e1da3f5b 287bfd_boolean
5f4273c7 288arm_is_eabi (void)
e1da3f5b
PB
289{
290 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
291}
7cc69913 292#endif
b99bd4ef 293
b99bd4ef 294#ifdef OBJ_ELF
c19d1205 295/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
296symbolS * GOT_symbol;
297#endif
298
b99bd4ef
NC
299/* 0: assemble for ARM,
300 1: assemble for Thumb,
301 2: assemble for Thumb even though target CPU does not support thumb
302 instructions. */
303static int thumb_mode = 0;
8dc2430f
NC
304/* A value distinct from the possible values for thumb_mode that we
305 can use to record whether thumb_mode has been copied into the
306 tc_frag_data field of a frag. */
307#define MODE_RECORDED (1 << 4)
b99bd4ef 308
e07e6e58
NC
309/* Specifies the intrinsic IT insn behavior mode. */
310enum implicit_it_mode
311{
312 IMPLICIT_IT_MODE_NEVER = 0x00,
313 IMPLICIT_IT_MODE_ARM = 0x01,
314 IMPLICIT_IT_MODE_THUMB = 0x02,
315 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
316};
317static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
318
c19d1205
ZW
319/* If unified_syntax is true, we are processing the new unified
320 ARM/Thumb syntax. Important differences from the old ARM mode:
321
322 - Immediate operands do not require a # prefix.
323 - Conditional affixes always appear at the end of the
324 instruction. (For backward compatibility, those instructions
325 that formerly had them in the middle, continue to accept them
326 there.)
327 - The IT instruction may appear, and if it does is validated
328 against subsequent conditional affixes. It does not generate
329 machine code.
330
331 Important differences from the old Thumb mode:
332
333 - Immediate operands do not require a # prefix.
334 - Most of the V6T2 instructions are only available in unified mode.
335 - The .N and .W suffixes are recognized and honored (it is an error
336 if they cannot be honored).
337 - All instructions set the flags if and only if they have an 's' affix.
338 - Conditional affixes may be used. They are validated against
339 preceding IT instructions. Unlike ARM mode, you cannot use a
340 conditional affix except in the scope of an IT instruction. */
341
342static bfd_boolean unified_syntax = FALSE;
b99bd4ef 343
bacebabc
RM
344/* An immediate operand can start with #, and ld*, st*, pld operands
345 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
346 before a [, which can appear as the first operand for pld.
347 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
348const char arm_symbol_chars[] = "#[]{}";
bacebabc 349
5287ad62
JB
350enum neon_el_type
351{
dcbf9037 352 NT_invtype,
5287ad62
JB
353 NT_untyped,
354 NT_integer,
355 NT_float,
356 NT_poly,
357 NT_signed,
dcbf9037 358 NT_unsigned
5287ad62
JB
359};
360
361struct neon_type_el
362{
363 enum neon_el_type type;
364 unsigned size;
365};
366
367#define NEON_MAX_TYPE_ELS 4
368
369struct neon_type
370{
371 struct neon_type_el el[NEON_MAX_TYPE_ELS];
372 unsigned elems;
373};
374
e07e6e58
NC
375enum it_instruction_type
376{
377 OUTSIDE_IT_INSN,
378 INSIDE_IT_INSN,
379 INSIDE_IT_LAST_INSN,
380 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 381 if inside, should be the last one. */
e07e6e58 382 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 383 i.e. BKPT and NOP. */
e07e6e58
NC
384 IT_INSN /* The IT insn has been parsed. */
385};
386
ad6cec43
MGD
387/* The maximum number of operands we need. */
388#define ARM_IT_MAX_OPERANDS 6
389
b99bd4ef
NC
390struct arm_it
391{
c19d1205 392 const char * error;
b99bd4ef 393 unsigned long instruction;
c19d1205
ZW
394 int size;
395 int size_req;
396 int cond;
037e8744
JB
397 /* "uncond_value" is set to the value in place of the conditional field in
398 unconditional versions of the instruction, or -1 if nothing is
399 appropriate. */
400 int uncond_value;
5287ad62 401 struct neon_type vectype;
88714cb8
DG
402 /* This does not indicate an actual NEON instruction, only that
403 the mnemonic accepts neon-style type suffixes. */
404 int is_neon;
0110f2b8
PB
405 /* Set to the opcode if the instruction needs relaxation.
406 Zero if the instruction is not relaxed. */
407 unsigned long relax;
b99bd4ef
NC
408 struct
409 {
410 bfd_reloc_code_real_type type;
c19d1205
ZW
411 expressionS exp;
412 int pc_rel;
b99bd4ef 413 } reloc;
b99bd4ef 414
e07e6e58
NC
415 enum it_instruction_type it_insn_type;
416
c19d1205
ZW
417 struct
418 {
419 unsigned reg;
ca3f61f7 420 signed int imm;
dcbf9037 421 struct neon_type_el vectype;
ca3f61f7
NC
422 unsigned present : 1; /* Operand present. */
423 unsigned isreg : 1; /* Operand was a register. */
424 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
425 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
426 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 427 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
428 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
429 instructions. This allows us to disambiguate ARM <-> vector insns. */
430 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 431 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 432 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 433 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
434 unsigned hasreloc : 1; /* Operand has relocation suffix. */
435 unsigned writeback : 1; /* Operand has trailing ! */
436 unsigned preind : 1; /* Preindexed address. */
437 unsigned postind : 1; /* Postindexed address. */
438 unsigned negative : 1; /* Index register was negated. */
439 unsigned shifted : 1; /* Shift applied to operation. */
440 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 441 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
442};
443
c19d1205 444static struct arm_it inst;
b99bd4ef
NC
445
446#define NUM_FLOAT_VALS 8
447
05d2d07e 448const char * fp_const[] =
b99bd4ef
NC
449{
450 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
451};
452
c19d1205 453/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
454#define MAX_LITTLENUMS 6
455
456LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
457
458#define FAIL (-1)
459#define SUCCESS (0)
460
461#define SUFF_S 1
462#define SUFF_D 2
463#define SUFF_E 3
464#define SUFF_P 4
465
c19d1205
ZW
466#define CP_T_X 0x00008000
467#define CP_T_Y 0x00400000
b99bd4ef 468
c19d1205
ZW
469#define CONDS_BIT 0x00100000
470#define LOAD_BIT 0x00100000
b99bd4ef
NC
471
472#define DOUBLE_LOAD_FLAG 0x00000001
473
474struct asm_cond
475{
d3ce72d0 476 const char * template_name;
c921be7d 477 unsigned long value;
b99bd4ef
NC
478};
479
c19d1205 480#define COND_ALWAYS 0xE
b99bd4ef 481
b99bd4ef
NC
482struct asm_psr
483{
d3ce72d0 484 const char * template_name;
c921be7d 485 unsigned long field;
b99bd4ef
NC
486};
487
62b3e311
PB
488struct asm_barrier_opt
489{
e797f7e0
MGD
490 const char * template_name;
491 unsigned long value;
492 const arm_feature_set arch;
62b3e311
PB
493};
494
2d2255b5 495/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
496#define SPSR_BIT (1 << 22)
497
c19d1205
ZW
498/* The individual PSR flag bits. */
499#define PSR_c (1 << 16)
500#define PSR_x (1 << 17)
501#define PSR_s (1 << 18)
502#define PSR_f (1 << 19)
b99bd4ef 503
c19d1205 504struct reloc_entry
bfae80f2 505{
c921be7d
NC
506 char * name;
507 bfd_reloc_code_real_type reloc;
bfae80f2
RE
508};
509
5287ad62 510enum vfp_reg_pos
bfae80f2 511{
5287ad62
JB
512 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
513 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
514};
515
516enum vfp_ldstm_type
517{
518 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
519};
520
dcbf9037
JB
521/* Bits for DEFINED field in neon_typed_alias. */
522#define NTA_HASTYPE 1
523#define NTA_HASINDEX 2
524
525struct neon_typed_alias
526{
c921be7d
NC
527 unsigned char defined;
528 unsigned char index;
529 struct neon_type_el eltype;
dcbf9037
JB
530};
531
c19d1205
ZW
532/* ARM register categories. This includes coprocessor numbers and various
533 architecture extensions' registers. */
534enum arm_reg_type
bfae80f2 535{
c19d1205
ZW
536 REG_TYPE_RN,
537 REG_TYPE_CP,
538 REG_TYPE_CN,
539 REG_TYPE_FN,
540 REG_TYPE_VFS,
541 REG_TYPE_VFD,
5287ad62 542 REG_TYPE_NQ,
037e8744 543 REG_TYPE_VFSD,
5287ad62 544 REG_TYPE_NDQ,
037e8744 545 REG_TYPE_NSDQ,
c19d1205
ZW
546 REG_TYPE_VFC,
547 REG_TYPE_MVF,
548 REG_TYPE_MVD,
549 REG_TYPE_MVFX,
550 REG_TYPE_MVDX,
551 REG_TYPE_MVAX,
552 REG_TYPE_DSPSC,
553 REG_TYPE_MMXWR,
554 REG_TYPE_MMXWC,
555 REG_TYPE_MMXWCG,
556 REG_TYPE_XSCALE,
90ec0d68 557 REG_TYPE_RNB
bfae80f2
RE
558};
559
dcbf9037
JB
560/* Structure for a hash table entry for a register.
561 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
562 information which states whether a vector type or index is specified (for a
563 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
564struct reg_entry
565{
c921be7d 566 const char * name;
90ec0d68 567 unsigned int number;
c921be7d
NC
568 unsigned char type;
569 unsigned char builtin;
570 struct neon_typed_alias * neon;
6c43fab6
RE
571};
572
c19d1205 573/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 574const char * const reg_expected_msgs[] =
c19d1205
ZW
575{
576 N_("ARM register expected"),
577 N_("bad or missing co-processor number"),
578 N_("co-processor register expected"),
579 N_("FPA register expected"),
580 N_("VFP single precision register expected"),
5287ad62
JB
581 N_("VFP/Neon double precision register expected"),
582 N_("Neon quad precision register expected"),
037e8744 583 N_("VFP single or double precision register expected"),
5287ad62 584 N_("Neon double or quad precision register expected"),
037e8744 585 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
586 N_("VFP system register expected"),
587 N_("Maverick MVF register expected"),
588 N_("Maverick MVD register expected"),
589 N_("Maverick MVFX register expected"),
590 N_("Maverick MVDX register expected"),
591 N_("Maverick MVAX register expected"),
592 N_("Maverick DSPSC register expected"),
593 N_("iWMMXt data register expected"),
594 N_("iWMMXt control register expected"),
595 N_("iWMMXt scalar register expected"),
596 N_("XScale accumulator register expected"),
6c43fab6
RE
597};
598
c19d1205 599/* Some well known registers that we refer to directly elsewhere. */
bd340a04 600#define REG_R12 12
c19d1205
ZW
601#define REG_SP 13
602#define REG_LR 14
603#define REG_PC 15
404ff6b5 604
b99bd4ef
NC
605/* ARM instructions take 4bytes in the object file, Thumb instructions
606 take 2: */
c19d1205 607#define INSN_SIZE 4
b99bd4ef
NC
608
609struct asm_opcode
610{
611 /* Basic string to match. */
d3ce72d0 612 const char * template_name;
c19d1205
ZW
613
614 /* Parameters to instruction. */
5be8be5d 615 unsigned int operands[8];
c19d1205
ZW
616
617 /* Conditional tag - see opcode_lookup. */
618 unsigned int tag : 4;
b99bd4ef
NC
619
620 /* Basic instruction code. */
c19d1205 621 unsigned int avalue : 28;
b99bd4ef 622
c19d1205
ZW
623 /* Thumb-format instruction code. */
624 unsigned int tvalue;
b99bd4ef 625
90e4755a 626 /* Which architecture variant provides this instruction. */
c921be7d
NC
627 const arm_feature_set * avariant;
628 const arm_feature_set * tvariant;
c19d1205
ZW
629
630 /* Function to call to encode instruction in ARM format. */
631 void (* aencode) (void);
b99bd4ef 632
c19d1205
ZW
633 /* Function to call to encode instruction in Thumb format. */
634 void (* tencode) (void);
b99bd4ef
NC
635};
636
a737bd4d
NC
637/* Defines for various bits that we will want to toggle. */
638#define INST_IMMEDIATE 0x02000000
639#define OFFSET_REG 0x02000000
c19d1205 640#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
641#define SHIFT_BY_REG 0x00000010
642#define PRE_INDEX 0x01000000
643#define INDEX_UP 0x00800000
644#define WRITE_BACK 0x00200000
645#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 646#define CPSI_MMOD 0x00020000
90e4755a 647
a737bd4d
NC
648#define LITERAL_MASK 0xf000f000
649#define OPCODE_MASK 0xfe1fffff
650#define V4_STR_BIT 0x00000020
8335d6aa 651#define VLDR_VMOV_SAME 0x0040f000
90e4755a 652
efd81785
PB
653#define T2_SUBS_PC_LR 0xf3de8f00
654
a737bd4d 655#define DATA_OP_SHIFT 21
90e4755a 656
ef8d22e6
PB
657#define T2_OPCODE_MASK 0xfe1fffff
658#define T2_DATA_OP_SHIFT 21
659
6530b175
NC
660#define A_COND_MASK 0xf0000000
661#define A_PUSH_POP_OP_MASK 0x0fff0000
662
663/* Opcodes for pushing/poping registers to/from the stack. */
664#define A1_OPCODE_PUSH 0x092d0000
665#define A2_OPCODE_PUSH 0x052d0004
666#define A2_OPCODE_POP 0x049d0004
667
a737bd4d
NC
668/* Codes to distinguish the arithmetic instructions. */
669#define OPCODE_AND 0
670#define OPCODE_EOR 1
671#define OPCODE_SUB 2
672#define OPCODE_RSB 3
673#define OPCODE_ADD 4
674#define OPCODE_ADC 5
675#define OPCODE_SBC 6
676#define OPCODE_RSC 7
677#define OPCODE_TST 8
678#define OPCODE_TEQ 9
679#define OPCODE_CMP 10
680#define OPCODE_CMN 11
681#define OPCODE_ORR 12
682#define OPCODE_MOV 13
683#define OPCODE_BIC 14
684#define OPCODE_MVN 15
90e4755a 685
ef8d22e6
PB
686#define T2_OPCODE_AND 0
687#define T2_OPCODE_BIC 1
688#define T2_OPCODE_ORR 2
689#define T2_OPCODE_ORN 3
690#define T2_OPCODE_EOR 4
691#define T2_OPCODE_ADD 8
692#define T2_OPCODE_ADC 10
693#define T2_OPCODE_SBC 11
694#define T2_OPCODE_SUB 13
695#define T2_OPCODE_RSB 14
696
a737bd4d
NC
697#define T_OPCODE_MUL 0x4340
698#define T_OPCODE_TST 0x4200
699#define T_OPCODE_CMN 0x42c0
700#define T_OPCODE_NEG 0x4240
701#define T_OPCODE_MVN 0x43c0
90e4755a 702
a737bd4d
NC
703#define T_OPCODE_ADD_R3 0x1800
704#define T_OPCODE_SUB_R3 0x1a00
705#define T_OPCODE_ADD_HI 0x4400
706#define T_OPCODE_ADD_ST 0xb000
707#define T_OPCODE_SUB_ST 0xb080
708#define T_OPCODE_ADD_SP 0xa800
709#define T_OPCODE_ADD_PC 0xa000
710#define T_OPCODE_ADD_I8 0x3000
711#define T_OPCODE_SUB_I8 0x3800
712#define T_OPCODE_ADD_I3 0x1c00
713#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 714
a737bd4d
NC
715#define T_OPCODE_ASR_R 0x4100
716#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
717#define T_OPCODE_LSR_R 0x40c0
718#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
719#define T_OPCODE_ASR_I 0x1000
720#define T_OPCODE_LSL_I 0x0000
721#define T_OPCODE_LSR_I 0x0800
b99bd4ef 722
a737bd4d
NC
723#define T_OPCODE_MOV_I8 0x2000
724#define T_OPCODE_CMP_I8 0x2800
725#define T_OPCODE_CMP_LR 0x4280
726#define T_OPCODE_MOV_HR 0x4600
727#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 728
a737bd4d
NC
729#define T_OPCODE_LDR_PC 0x4800
730#define T_OPCODE_LDR_SP 0x9800
731#define T_OPCODE_STR_SP 0x9000
732#define T_OPCODE_LDR_IW 0x6800
733#define T_OPCODE_STR_IW 0x6000
734#define T_OPCODE_LDR_IH 0x8800
735#define T_OPCODE_STR_IH 0x8000
736#define T_OPCODE_LDR_IB 0x7800
737#define T_OPCODE_STR_IB 0x7000
738#define T_OPCODE_LDR_RW 0x5800
739#define T_OPCODE_STR_RW 0x5000
740#define T_OPCODE_LDR_RH 0x5a00
741#define T_OPCODE_STR_RH 0x5200
742#define T_OPCODE_LDR_RB 0x5c00
743#define T_OPCODE_STR_RB 0x5400
c9b604bd 744
a737bd4d
NC
745#define T_OPCODE_PUSH 0xb400
746#define T_OPCODE_POP 0xbc00
b99bd4ef 747
2fc8bdac 748#define T_OPCODE_BRANCH 0xe000
b99bd4ef 749
a737bd4d 750#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 751#define THUMB_PP_PC_LR 0x0100
c19d1205 752#define THUMB_LOAD_BIT 0x0800
53365c0d 753#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
754
755#define BAD_ARGS _("bad arguments to instruction")
fdfde340 756#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
757#define BAD_PC _("r15 not allowed here")
758#define BAD_COND _("instruction cannot be conditional")
759#define BAD_OVERLAP _("registers may not be the same")
760#define BAD_HIREG _("lo register required")
761#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 762#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
763#define BAD_BRANCH _("branch must be last instruction in IT block")
764#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 765#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
766#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
767#define BAD_IT_COND _("incorrect condition in IT block")
768#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 769#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
770#define BAD_PC_ADDRESSING \
771 _("cannot use register index with PC-relative addressing")
772#define BAD_PC_WRITEBACK \
773 _("cannot use writeback with PC-relative addressing")
08f10d51 774#define BAD_RANGE _("branch out of range")
dd5181d5 775#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
c19d1205 776
c921be7d
NC
777static struct hash_control * arm_ops_hsh;
778static struct hash_control * arm_cond_hsh;
779static struct hash_control * arm_shift_hsh;
780static struct hash_control * arm_psr_hsh;
781static struct hash_control * arm_v7m_psr_hsh;
782static struct hash_control * arm_reg_hsh;
783static struct hash_control * arm_reloc_hsh;
784static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 785
b99bd4ef
NC
786/* Stuff needed to resolve the label ambiguity
787 As:
788 ...
789 label: <insn>
790 may differ from:
791 ...
792 label:
5f4273c7 793 <insn> */
b99bd4ef
NC
794
795symbolS * last_label_seen;
b34976b6 796static int label_is_thumb_function_name = FALSE;
e07e6e58 797
3d0c9500
NC
798/* Literal pool structure. Held on a per-section
799 and per-sub-section basis. */
a737bd4d 800
c19d1205 801#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 802typedef struct literal_pool
b99bd4ef 803{
c921be7d
NC
804 expressionS literals [MAX_LITERAL_POOL_SIZE];
805 unsigned int next_free_entry;
806 unsigned int id;
807 symbolS * symbol;
808 segT section;
809 subsegT sub_section;
a8040cf2
NC
810#ifdef OBJ_ELF
811 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
812#endif
c921be7d 813 struct literal_pool * next;
8335d6aa 814 unsigned int alignment;
3d0c9500 815} literal_pool;
b99bd4ef 816
3d0c9500
NC
817/* Pointer to a linked list of literal pools. */
818literal_pool * list_of_pools = NULL;
e27ec89e 819
2e6976a8
DG
820typedef enum asmfunc_states
821{
822 OUTSIDE_ASMFUNC,
823 WAITING_ASMFUNC_NAME,
824 WAITING_ENDASMFUNC
825} asmfunc_states;
826
827static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
828
e07e6e58
NC
829#ifdef OBJ_ELF
830# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
831#else
832static struct current_it now_it;
833#endif
834
835static inline int
836now_it_compatible (int cond)
837{
838 return (cond & ~1) == (now_it.cc & ~1);
839}
840
841static inline int
842conditional_insn (void)
843{
844 return inst.cond != COND_ALWAYS;
845}
846
847static int in_it_block (void);
848
849static int handle_it_state (void);
850
851static void force_automatic_it_block_close (void);
852
c921be7d
NC
853static void it_fsm_post_encode (void);
854
e07e6e58
NC
855#define set_it_insn_type(type) \
856 do \
857 { \
858 inst.it_insn_type = type; \
859 if (handle_it_state () == FAIL) \
477330fc 860 return; \
e07e6e58
NC
861 } \
862 while (0)
863
c921be7d
NC
864#define set_it_insn_type_nonvoid(type, failret) \
865 do \
866 { \
867 inst.it_insn_type = type; \
868 if (handle_it_state () == FAIL) \
477330fc 869 return failret; \
c921be7d
NC
870 } \
871 while(0)
872
e07e6e58
NC
873#define set_it_insn_type_last() \
874 do \
875 { \
876 if (inst.cond == COND_ALWAYS) \
477330fc 877 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 878 else \
477330fc 879 set_it_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
880 } \
881 while (0)
882
c19d1205 883/* Pure syntax. */
b99bd4ef 884
c19d1205
ZW
885/* This array holds the chars that always start a comment. If the
886 pre-processor is disabled, these aren't very useful. */
2e6976a8 887char arm_comment_chars[] = "@";
3d0c9500 888
c19d1205
ZW
889/* This array holds the chars that only start a comment at the beginning of
890 a line. If the line seems to have the form '# 123 filename'
891 .line and .file directives will appear in the pre-processed output. */
892/* Note that input_file.c hand checks for '#' at the beginning of the
893 first line of the input file. This is because the compiler outputs
894 #NO_APP at the beginning of its output. */
895/* Also note that comments like this one will always work. */
896const char line_comment_chars[] = "#";
3d0c9500 897
2e6976a8 898char arm_line_separator_chars[] = ";";
b99bd4ef 899
c19d1205
ZW
900/* Chars that can be used to separate mant
901 from exp in floating point numbers. */
902const char EXP_CHARS[] = "eE";
3d0c9500 903
c19d1205
ZW
904/* Chars that mean this number is a floating point constant. */
905/* As in 0f12.456 */
906/* or 0d1.2345e12 */
b99bd4ef 907
c19d1205 908const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 909
c19d1205
ZW
910/* Prefix characters that indicate the start of an immediate
911 value. */
912#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 913
c19d1205
ZW
914/* Separator character handling. */
915
916#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
917
918static inline int
919skip_past_char (char ** str, char c)
920{
8ab8155f
NC
921 /* PR gas/14987: Allow for whitespace before the expected character. */
922 skip_whitespace (*str);
427d0db6 923
c19d1205
ZW
924 if (**str == c)
925 {
926 (*str)++;
927 return SUCCESS;
3d0c9500 928 }
c19d1205
ZW
929 else
930 return FAIL;
931}
c921be7d 932
c19d1205 933#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 934
c19d1205
ZW
935/* Arithmetic expressions (possibly involving symbols). */
936
937/* Return TRUE if anything in the expression is a bignum. */
938
939static int
940walk_no_bignums (symbolS * sp)
941{
942 if (symbol_get_value_expression (sp)->X_op == O_big)
943 return 1;
944
945 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 946 {
c19d1205
ZW
947 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
948 || (symbol_get_value_expression (sp)->X_op_symbol
949 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
950 }
951
c19d1205 952 return 0;
3d0c9500
NC
953}
954
c19d1205
ZW
955static int in_my_get_expression = 0;
956
957/* Third argument to my_get_expression. */
958#define GE_NO_PREFIX 0
959#define GE_IMM_PREFIX 1
960#define GE_OPT_PREFIX 2
5287ad62
JB
961/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
962 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
963#define GE_OPT_PREFIX_BIG 3
a737bd4d 964
b99bd4ef 965static int
c19d1205 966my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 967{
c19d1205
ZW
968 char * save_in;
969 segT seg;
b99bd4ef 970
c19d1205
ZW
971 /* In unified syntax, all prefixes are optional. */
972 if (unified_syntax)
5287ad62 973 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 974 : GE_OPT_PREFIX;
b99bd4ef 975
c19d1205 976 switch (prefix_mode)
b99bd4ef 977 {
c19d1205
ZW
978 case GE_NO_PREFIX: break;
979 case GE_IMM_PREFIX:
980 if (!is_immediate_prefix (**str))
981 {
982 inst.error = _("immediate expression requires a # prefix");
983 return FAIL;
984 }
985 (*str)++;
986 break;
987 case GE_OPT_PREFIX:
5287ad62 988 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
989 if (is_immediate_prefix (**str))
990 (*str)++;
991 break;
992 default: abort ();
993 }
b99bd4ef 994
c19d1205 995 memset (ep, 0, sizeof (expressionS));
b99bd4ef 996
c19d1205
ZW
997 save_in = input_line_pointer;
998 input_line_pointer = *str;
999 in_my_get_expression = 1;
1000 seg = expression (ep);
1001 in_my_get_expression = 0;
1002
f86adc07 1003 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1004 {
f86adc07 1005 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1006 *str = input_line_pointer;
1007 input_line_pointer = save_in;
1008 if (inst.error == NULL)
f86adc07
NS
1009 inst.error = (ep->X_op == O_absent
1010 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1011 return 1;
1012 }
b99bd4ef 1013
c19d1205
ZW
1014#ifdef OBJ_AOUT
1015 if (seg != absolute_section
1016 && seg != text_section
1017 && seg != data_section
1018 && seg != bss_section
1019 && seg != undefined_section)
1020 {
1021 inst.error = _("bad segment");
1022 *str = input_line_pointer;
1023 input_line_pointer = save_in;
1024 return 1;
b99bd4ef 1025 }
87975d2a
AM
1026#else
1027 (void) seg;
c19d1205 1028#endif
b99bd4ef 1029
c19d1205
ZW
1030 /* Get rid of any bignums now, so that we don't generate an error for which
1031 we can't establish a line number later on. Big numbers are never valid
1032 in instructions, which is where this routine is always called. */
5287ad62
JB
1033 if (prefix_mode != GE_OPT_PREFIX_BIG
1034 && (ep->X_op == O_big
477330fc 1035 || (ep->X_add_symbol
5287ad62 1036 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1037 || (ep->X_op_symbol
5287ad62 1038 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1039 {
1040 inst.error = _("invalid constant");
1041 *str = input_line_pointer;
1042 input_line_pointer = save_in;
1043 return 1;
1044 }
b99bd4ef 1045
c19d1205
ZW
1046 *str = input_line_pointer;
1047 input_line_pointer = save_in;
1048 return 0;
b99bd4ef
NC
1049}
1050
c19d1205
ZW
1051/* Turn a string in input_line_pointer into a floating point constant
1052 of type TYPE, and store the appropriate bytes in *LITP. The number
1053 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1054 returned, or NULL on OK.
b99bd4ef 1055
c19d1205
ZW
1056 Note that fp constants aren't represent in the normal way on the ARM.
1057 In big endian mode, things are as expected. However, in little endian
1058 mode fp constants are big-endian word-wise, and little-endian byte-wise
1059 within the words. For example, (double) 1.1 in big endian mode is
1060 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1061 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1062
c19d1205 1063 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1064
c19d1205
ZW
1065char *
1066md_atof (int type, char * litP, int * sizeP)
1067{
1068 int prec;
1069 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1070 char *t;
1071 int i;
b99bd4ef 1072
c19d1205
ZW
1073 switch (type)
1074 {
1075 case 'f':
1076 case 'F':
1077 case 's':
1078 case 'S':
1079 prec = 2;
1080 break;
b99bd4ef 1081
c19d1205
ZW
1082 case 'd':
1083 case 'D':
1084 case 'r':
1085 case 'R':
1086 prec = 4;
1087 break;
b99bd4ef 1088
c19d1205
ZW
1089 case 'x':
1090 case 'X':
499ac353 1091 prec = 5;
c19d1205 1092 break;
b99bd4ef 1093
c19d1205
ZW
1094 case 'p':
1095 case 'P':
499ac353 1096 prec = 5;
c19d1205 1097 break;
a737bd4d 1098
c19d1205
ZW
1099 default:
1100 *sizeP = 0;
499ac353 1101 return _("Unrecognized or unsupported floating point constant");
c19d1205 1102 }
b99bd4ef 1103
c19d1205
ZW
1104 t = atof_ieee (input_line_pointer, type, words);
1105 if (t)
1106 input_line_pointer = t;
499ac353 1107 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1108
c19d1205
ZW
1109 if (target_big_endian)
1110 {
1111 for (i = 0; i < prec; i++)
1112 {
499ac353
NC
1113 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1114 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1115 }
1116 }
1117 else
1118 {
e74cfd16 1119 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1120 for (i = prec - 1; i >= 0; i--)
1121 {
499ac353
NC
1122 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1123 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1124 }
1125 else
1126 /* For a 4 byte float the order of elements in `words' is 1 0.
1127 For an 8 byte float the order is 1 0 3 2. */
1128 for (i = 0; i < prec; i += 2)
1129 {
499ac353
NC
1130 md_number_to_chars (litP, (valueT) words[i + 1],
1131 sizeof (LITTLENUM_TYPE));
1132 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1133 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1134 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1135 }
1136 }
b99bd4ef 1137
499ac353 1138 return NULL;
c19d1205 1139}
b99bd4ef 1140
c19d1205
ZW
1141/* We handle all bad expressions here, so that we can report the faulty
1142 instruction in the error message. */
1143void
91d6fa6a 1144md_operand (expressionS * exp)
c19d1205
ZW
1145{
1146 if (in_my_get_expression)
91d6fa6a 1147 exp->X_op = O_illegal;
b99bd4ef
NC
1148}
1149
c19d1205 1150/* Immediate values. */
b99bd4ef 1151
c19d1205
ZW
1152/* Generic immediate-value read function for use in directives.
1153 Accepts anything that 'expression' can fold to a constant.
1154 *val receives the number. */
1155#ifdef OBJ_ELF
1156static int
1157immediate_for_directive (int *val)
b99bd4ef 1158{
c19d1205
ZW
1159 expressionS exp;
1160 exp.X_op = O_illegal;
b99bd4ef 1161
c19d1205
ZW
1162 if (is_immediate_prefix (*input_line_pointer))
1163 {
1164 input_line_pointer++;
1165 expression (&exp);
1166 }
b99bd4ef 1167
c19d1205
ZW
1168 if (exp.X_op != O_constant)
1169 {
1170 as_bad (_("expected #constant"));
1171 ignore_rest_of_line ();
1172 return FAIL;
1173 }
1174 *val = exp.X_add_number;
1175 return SUCCESS;
b99bd4ef 1176}
c19d1205 1177#endif
b99bd4ef 1178
c19d1205 1179/* Register parsing. */
b99bd4ef 1180
c19d1205
ZW
1181/* Generic register parser. CCP points to what should be the
1182 beginning of a register name. If it is indeed a valid register
1183 name, advance CCP over it and return the reg_entry structure;
1184 otherwise return NULL. Does not issue diagnostics. */
1185
1186static struct reg_entry *
1187arm_reg_parse_multi (char **ccp)
b99bd4ef 1188{
c19d1205
ZW
1189 char *start = *ccp;
1190 char *p;
1191 struct reg_entry *reg;
b99bd4ef 1192
477330fc
RM
1193 skip_whitespace (start);
1194
c19d1205
ZW
1195#ifdef REGISTER_PREFIX
1196 if (*start != REGISTER_PREFIX)
01cfc07f 1197 return NULL;
c19d1205
ZW
1198 start++;
1199#endif
1200#ifdef OPTIONAL_REGISTER_PREFIX
1201 if (*start == OPTIONAL_REGISTER_PREFIX)
1202 start++;
1203#endif
b99bd4ef 1204
c19d1205
ZW
1205 p = start;
1206 if (!ISALPHA (*p) || !is_name_beginner (*p))
1207 return NULL;
b99bd4ef 1208
c19d1205
ZW
1209 do
1210 p++;
1211 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1212
1213 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1214
1215 if (!reg)
1216 return NULL;
1217
1218 *ccp = p;
1219 return reg;
b99bd4ef
NC
1220}
1221
1222static int
dcbf9037 1223arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1224 enum arm_reg_type type)
b99bd4ef 1225{
c19d1205
ZW
1226 /* Alternative syntaxes are accepted for a few register classes. */
1227 switch (type)
1228 {
1229 case REG_TYPE_MVF:
1230 case REG_TYPE_MVD:
1231 case REG_TYPE_MVFX:
1232 case REG_TYPE_MVDX:
1233 /* Generic coprocessor register names are allowed for these. */
79134647 1234 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1235 return reg->number;
1236 break;
69b97547 1237
c19d1205
ZW
1238 case REG_TYPE_CP:
1239 /* For backward compatibility, a bare number is valid here. */
1240 {
1241 unsigned long processor = strtoul (start, ccp, 10);
1242 if (*ccp != start && processor <= 15)
1243 return processor;
1244 }
6057a28f 1245
c19d1205
ZW
1246 case REG_TYPE_MMXWC:
1247 /* WC includes WCG. ??? I'm not sure this is true for all
1248 instructions that take WC registers. */
79134647 1249 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1250 return reg->number;
6057a28f 1251 break;
c19d1205 1252
6057a28f 1253 default:
c19d1205 1254 break;
6057a28f
NC
1255 }
1256
dcbf9037
JB
1257 return FAIL;
1258}
1259
1260/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1261 return value is the register number or FAIL. */
1262
1263static int
1264arm_reg_parse (char **ccp, enum arm_reg_type type)
1265{
1266 char *start = *ccp;
1267 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1268 int ret;
1269
1270 /* Do not allow a scalar (reg+index) to parse as a register. */
1271 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1272 return FAIL;
1273
1274 if (reg && reg->type == type)
1275 return reg->number;
1276
1277 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1278 return ret;
1279
c19d1205
ZW
1280 *ccp = start;
1281 return FAIL;
1282}
69b97547 1283
dcbf9037
JB
1284/* Parse a Neon type specifier. *STR should point at the leading '.'
1285 character. Does no verification at this stage that the type fits the opcode
1286 properly. E.g.,
1287
1288 .i32.i32.s16
1289 .s32.f32
1290 .u16
1291
1292 Can all be legally parsed by this function.
1293
1294 Fills in neon_type struct pointer with parsed information, and updates STR
1295 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1296 type, FAIL if not. */
1297
1298static int
1299parse_neon_type (struct neon_type *type, char **str)
1300{
1301 char *ptr = *str;
1302
1303 if (type)
1304 type->elems = 0;
1305
1306 while (type->elems < NEON_MAX_TYPE_ELS)
1307 {
1308 enum neon_el_type thistype = NT_untyped;
1309 unsigned thissize = -1u;
1310
1311 if (*ptr != '.')
1312 break;
1313
1314 ptr++;
1315
1316 /* Just a size without an explicit type. */
1317 if (ISDIGIT (*ptr))
1318 goto parsesize;
1319
1320 switch (TOLOWER (*ptr))
1321 {
1322 case 'i': thistype = NT_integer; break;
1323 case 'f': thistype = NT_float; break;
1324 case 'p': thistype = NT_poly; break;
1325 case 's': thistype = NT_signed; break;
1326 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1327 case 'd':
1328 thistype = NT_float;
1329 thissize = 64;
1330 ptr++;
1331 goto done;
dcbf9037
JB
1332 default:
1333 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1334 return FAIL;
1335 }
1336
1337 ptr++;
1338
1339 /* .f is an abbreviation for .f32. */
1340 if (thistype == NT_float && !ISDIGIT (*ptr))
1341 thissize = 32;
1342 else
1343 {
1344 parsesize:
1345 thissize = strtoul (ptr, &ptr, 10);
1346
1347 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1348 && thissize != 64)
1349 {
1350 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1351 return FAIL;
1352 }
1353 }
1354
037e8744 1355 done:
dcbf9037 1356 if (type)
477330fc
RM
1357 {
1358 type->el[type->elems].type = thistype;
dcbf9037
JB
1359 type->el[type->elems].size = thissize;
1360 type->elems++;
1361 }
1362 }
1363
1364 /* Empty/missing type is not a successful parse. */
1365 if (type->elems == 0)
1366 return FAIL;
1367
1368 *str = ptr;
1369
1370 return SUCCESS;
1371}
1372
1373/* Errors may be set multiple times during parsing or bit encoding
1374 (particularly in the Neon bits), but usually the earliest error which is set
1375 will be the most meaningful. Avoid overwriting it with later (cascading)
1376 errors by calling this function. */
1377
1378static void
1379first_error (const char *err)
1380{
1381 if (!inst.error)
1382 inst.error = err;
1383}
1384
1385/* Parse a single type, e.g. ".s32", leading period included. */
1386static int
1387parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1388{
1389 char *str = *ccp;
1390 struct neon_type optype;
1391
1392 if (*str == '.')
1393 {
1394 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1395 {
1396 if (optype.elems == 1)
1397 *vectype = optype.el[0];
1398 else
1399 {
1400 first_error (_("only one type should be specified for operand"));
1401 return FAIL;
1402 }
1403 }
dcbf9037 1404 else
477330fc
RM
1405 {
1406 first_error (_("vector type expected"));
1407 return FAIL;
1408 }
dcbf9037
JB
1409 }
1410 else
1411 return FAIL;
5f4273c7 1412
dcbf9037 1413 *ccp = str;
5f4273c7 1414
dcbf9037
JB
1415 return SUCCESS;
1416}
1417
1418/* Special meanings for indices (which have a range of 0-7), which will fit into
1419 a 4-bit integer. */
1420
1421#define NEON_ALL_LANES 15
1422#define NEON_INTERLEAVE_LANES 14
1423
1424/* Parse either a register or a scalar, with an optional type. Return the
1425 register number, and optionally fill in the actual type of the register
1426 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1427 type/index information in *TYPEINFO. */
1428
1429static int
1430parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1431 enum arm_reg_type *rtype,
1432 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1433{
1434 char *str = *ccp;
1435 struct reg_entry *reg = arm_reg_parse_multi (&str);
1436 struct neon_typed_alias atype;
1437 struct neon_type_el parsetype;
1438
1439 atype.defined = 0;
1440 atype.index = -1;
1441 atype.eltype.type = NT_invtype;
1442 atype.eltype.size = -1;
1443
1444 /* Try alternate syntax for some types of register. Note these are mutually
1445 exclusive with the Neon syntax extensions. */
1446 if (reg == NULL)
1447 {
1448 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1449 if (altreg != FAIL)
477330fc 1450 *ccp = str;
dcbf9037 1451 if (typeinfo)
477330fc 1452 *typeinfo = atype;
dcbf9037
JB
1453 return altreg;
1454 }
1455
037e8744
JB
1456 /* Undo polymorphism when a set of register types may be accepted. */
1457 if ((type == REG_TYPE_NDQ
1458 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1459 || (type == REG_TYPE_VFSD
477330fc 1460 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1461 || (type == REG_TYPE_NSDQ
477330fc
RM
1462 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1463 || reg->type == REG_TYPE_NQ))
f512f76f
NC
1464 || (type == REG_TYPE_MMXWC
1465 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1466 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1467
1468 if (type != reg->type)
1469 return FAIL;
1470
1471 if (reg->neon)
1472 atype = *reg->neon;
5f4273c7 1473
dcbf9037
JB
1474 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1475 {
1476 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1477 {
1478 first_error (_("can't redefine type for operand"));
1479 return FAIL;
1480 }
dcbf9037
JB
1481 atype.defined |= NTA_HASTYPE;
1482 atype.eltype = parsetype;
1483 }
5f4273c7 1484
dcbf9037
JB
1485 if (skip_past_char (&str, '[') == SUCCESS)
1486 {
1487 if (type != REG_TYPE_VFD)
477330fc
RM
1488 {
1489 first_error (_("only D registers may be indexed"));
1490 return FAIL;
1491 }
5f4273c7 1492
dcbf9037 1493 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1494 {
1495 first_error (_("can't change index for operand"));
1496 return FAIL;
1497 }
dcbf9037
JB
1498
1499 atype.defined |= NTA_HASINDEX;
1500
1501 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1502 atype.index = NEON_ALL_LANES;
dcbf9037 1503 else
477330fc
RM
1504 {
1505 expressionS exp;
dcbf9037 1506
477330fc 1507 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1508
477330fc
RM
1509 if (exp.X_op != O_constant)
1510 {
1511 first_error (_("constant expression required"));
1512 return FAIL;
1513 }
dcbf9037 1514
477330fc
RM
1515 if (skip_past_char (&str, ']') == FAIL)
1516 return FAIL;
dcbf9037 1517
477330fc
RM
1518 atype.index = exp.X_add_number;
1519 }
dcbf9037 1520 }
5f4273c7 1521
dcbf9037
JB
1522 if (typeinfo)
1523 *typeinfo = atype;
5f4273c7 1524
dcbf9037
JB
1525 if (rtype)
1526 *rtype = type;
5f4273c7 1527
dcbf9037 1528 *ccp = str;
5f4273c7 1529
dcbf9037
JB
1530 return reg->number;
1531}
1532
1533/* Like arm_reg_parse, but allow allow the following extra features:
1534 - If RTYPE is non-zero, return the (possibly restricted) type of the
1535 register (e.g. Neon double or quad reg when either has been requested).
1536 - If this is a Neon vector type with additional type information, fill
1537 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1538 This function will fault on encountering a scalar. */
dcbf9037
JB
1539
1540static int
1541arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1542 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1543{
1544 struct neon_typed_alias atype;
1545 char *str = *ccp;
1546 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1547
1548 if (reg == FAIL)
1549 return FAIL;
1550
0855e32b
NS
1551 /* Do not allow regname(... to parse as a register. */
1552 if (*str == '(')
1553 return FAIL;
1554
dcbf9037
JB
1555 /* Do not allow a scalar (reg+index) to parse as a register. */
1556 if ((atype.defined & NTA_HASINDEX) != 0)
1557 {
1558 first_error (_("register operand expected, but got scalar"));
1559 return FAIL;
1560 }
1561
1562 if (vectype)
1563 *vectype = atype.eltype;
1564
1565 *ccp = str;
1566
1567 return reg;
1568}
1569
1570#define NEON_SCALAR_REG(X) ((X) >> 4)
1571#define NEON_SCALAR_INDEX(X) ((X) & 15)
1572
5287ad62
JB
1573/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1574 have enough information to be able to do a good job bounds-checking. So, we
1575 just do easy checks here, and do further checks later. */
1576
1577static int
dcbf9037 1578parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1579{
dcbf9037 1580 int reg;
5287ad62 1581 char *str = *ccp;
dcbf9037 1582 struct neon_typed_alias atype;
5f4273c7 1583
dcbf9037 1584 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1585
dcbf9037 1586 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1587 return FAIL;
5f4273c7 1588
dcbf9037 1589 if (atype.index == NEON_ALL_LANES)
5287ad62 1590 {
dcbf9037 1591 first_error (_("scalar must have an index"));
5287ad62
JB
1592 return FAIL;
1593 }
dcbf9037 1594 else if (atype.index >= 64 / elsize)
5287ad62 1595 {
dcbf9037 1596 first_error (_("scalar index out of range"));
5287ad62
JB
1597 return FAIL;
1598 }
5f4273c7 1599
dcbf9037
JB
1600 if (type)
1601 *type = atype.eltype;
5f4273c7 1602
5287ad62 1603 *ccp = str;
5f4273c7 1604
dcbf9037 1605 return reg * 16 + atype.index;
5287ad62
JB
1606}
1607
c19d1205 1608/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1609
c19d1205
ZW
1610static long
1611parse_reg_list (char ** strp)
1612{
1613 char * str = * strp;
1614 long range = 0;
1615 int another_range;
a737bd4d 1616
c19d1205
ZW
1617 /* We come back here if we get ranges concatenated by '+' or '|'. */
1618 do
6057a28f 1619 {
477330fc
RM
1620 skip_whitespace (str);
1621
c19d1205 1622 another_range = 0;
a737bd4d 1623
c19d1205
ZW
1624 if (*str == '{')
1625 {
1626 int in_range = 0;
1627 int cur_reg = -1;
a737bd4d 1628
c19d1205
ZW
1629 str++;
1630 do
1631 {
1632 int reg;
6057a28f 1633
dcbf9037 1634 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1635 {
dcbf9037 1636 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1637 return FAIL;
1638 }
a737bd4d 1639
c19d1205
ZW
1640 if (in_range)
1641 {
1642 int i;
a737bd4d 1643
c19d1205
ZW
1644 if (reg <= cur_reg)
1645 {
dcbf9037 1646 first_error (_("bad range in register list"));
c19d1205
ZW
1647 return FAIL;
1648 }
40a18ebd 1649
c19d1205
ZW
1650 for (i = cur_reg + 1; i < reg; i++)
1651 {
1652 if (range & (1 << i))
1653 as_tsktsk
1654 (_("Warning: duplicated register (r%d) in register list"),
1655 i);
1656 else
1657 range |= 1 << i;
1658 }
1659 in_range = 0;
1660 }
a737bd4d 1661
c19d1205
ZW
1662 if (range & (1 << reg))
1663 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1664 reg);
1665 else if (reg <= cur_reg)
1666 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1667
c19d1205
ZW
1668 range |= 1 << reg;
1669 cur_reg = reg;
1670 }
1671 while (skip_past_comma (&str) != FAIL
1672 || (in_range = 1, *str++ == '-'));
1673 str--;
a737bd4d 1674
d996d970 1675 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1676 {
dcbf9037 1677 first_error (_("missing `}'"));
c19d1205
ZW
1678 return FAIL;
1679 }
1680 }
1681 else
1682 {
91d6fa6a 1683 expressionS exp;
40a18ebd 1684
91d6fa6a 1685 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1686 return FAIL;
40a18ebd 1687
91d6fa6a 1688 if (exp.X_op == O_constant)
c19d1205 1689 {
91d6fa6a
NC
1690 if (exp.X_add_number
1691 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1692 {
1693 inst.error = _("invalid register mask");
1694 return FAIL;
1695 }
a737bd4d 1696
91d6fa6a 1697 if ((range & exp.X_add_number) != 0)
c19d1205 1698 {
91d6fa6a 1699 int regno = range & exp.X_add_number;
a737bd4d 1700
c19d1205
ZW
1701 regno &= -regno;
1702 regno = (1 << regno) - 1;
1703 as_tsktsk
1704 (_("Warning: duplicated register (r%d) in register list"),
1705 regno);
1706 }
a737bd4d 1707
91d6fa6a 1708 range |= exp.X_add_number;
c19d1205
ZW
1709 }
1710 else
1711 {
1712 if (inst.reloc.type != 0)
1713 {
1714 inst.error = _("expression too complex");
1715 return FAIL;
1716 }
a737bd4d 1717
91d6fa6a 1718 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1719 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1720 inst.reloc.pc_rel = 0;
1721 }
1722 }
a737bd4d 1723
c19d1205
ZW
1724 if (*str == '|' || *str == '+')
1725 {
1726 str++;
1727 another_range = 1;
1728 }
a737bd4d 1729 }
c19d1205 1730 while (another_range);
a737bd4d 1731
c19d1205
ZW
1732 *strp = str;
1733 return range;
a737bd4d
NC
1734}
1735
5287ad62
JB
1736/* Types of registers in a list. */
1737
1738enum reg_list_els
1739{
1740 REGLIST_VFP_S,
1741 REGLIST_VFP_D,
1742 REGLIST_NEON_D
1743};
1744
c19d1205
ZW
1745/* Parse a VFP register list. If the string is invalid return FAIL.
1746 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1747 register. Parses registers of type ETYPE.
1748 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1749 - Q registers can be used to specify pairs of D registers
1750 - { } can be omitted from around a singleton register list
477330fc
RM
1751 FIXME: This is not implemented, as it would require backtracking in
1752 some cases, e.g.:
1753 vtbl.8 d3,d4,d5
1754 This could be done (the meaning isn't really ambiguous), but doesn't
1755 fit in well with the current parsing framework.
dcbf9037
JB
1756 - 32 D registers may be used (also true for VFPv3).
1757 FIXME: Types are ignored in these register lists, which is probably a
1758 bug. */
6057a28f 1759
c19d1205 1760static int
037e8744 1761parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1762{
037e8744 1763 char *str = *ccp;
c19d1205
ZW
1764 int base_reg;
1765 int new_base;
21d799b5 1766 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1767 int max_regs = 0;
c19d1205
ZW
1768 int count = 0;
1769 int warned = 0;
1770 unsigned long mask = 0;
a737bd4d 1771 int i;
6057a28f 1772
477330fc 1773 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1774 {
1775 inst.error = _("expecting {");
1776 return FAIL;
1777 }
6057a28f 1778
5287ad62 1779 switch (etype)
c19d1205 1780 {
5287ad62 1781 case REGLIST_VFP_S:
c19d1205
ZW
1782 regtype = REG_TYPE_VFS;
1783 max_regs = 32;
5287ad62 1784 break;
5f4273c7 1785
5287ad62
JB
1786 case REGLIST_VFP_D:
1787 regtype = REG_TYPE_VFD;
b7fc2769 1788 break;
5f4273c7 1789
b7fc2769
JB
1790 case REGLIST_NEON_D:
1791 regtype = REG_TYPE_NDQ;
1792 break;
1793 }
1794
1795 if (etype != REGLIST_VFP_S)
1796 {
b1cc4aeb
PB
1797 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1798 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1799 {
1800 max_regs = 32;
1801 if (thumb_mode)
1802 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1803 fpu_vfp_ext_d32);
1804 else
1805 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1806 fpu_vfp_ext_d32);
1807 }
5287ad62 1808 else
477330fc 1809 max_regs = 16;
c19d1205 1810 }
6057a28f 1811
c19d1205 1812 base_reg = max_regs;
a737bd4d 1813
c19d1205
ZW
1814 do
1815 {
5287ad62 1816 int setmask = 1, addregs = 1;
dcbf9037 1817
037e8744 1818 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1819
c19d1205 1820 if (new_base == FAIL)
a737bd4d 1821 {
dcbf9037 1822 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1823 return FAIL;
1824 }
5f4273c7 1825
b7fc2769 1826 if (new_base >= max_regs)
477330fc
RM
1827 {
1828 first_error (_("register out of range in list"));
1829 return FAIL;
1830 }
5f4273c7 1831
5287ad62
JB
1832 /* Note: a value of 2 * n is returned for the register Q<n>. */
1833 if (regtype == REG_TYPE_NQ)
477330fc
RM
1834 {
1835 setmask = 3;
1836 addregs = 2;
1837 }
5287ad62 1838
c19d1205
ZW
1839 if (new_base < base_reg)
1840 base_reg = new_base;
a737bd4d 1841
5287ad62 1842 if (mask & (setmask << new_base))
c19d1205 1843 {
dcbf9037 1844 first_error (_("invalid register list"));
c19d1205 1845 return FAIL;
a737bd4d 1846 }
a737bd4d 1847
c19d1205
ZW
1848 if ((mask >> new_base) != 0 && ! warned)
1849 {
1850 as_tsktsk (_("register list not in ascending order"));
1851 warned = 1;
1852 }
0bbf2aa4 1853
5287ad62
JB
1854 mask |= setmask << new_base;
1855 count += addregs;
0bbf2aa4 1856
037e8744 1857 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1858 {
1859 int high_range;
0bbf2aa4 1860
037e8744 1861 str++;
0bbf2aa4 1862
037e8744 1863 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1864 == FAIL)
c19d1205
ZW
1865 {
1866 inst.error = gettext (reg_expected_msgs[regtype]);
1867 return FAIL;
1868 }
0bbf2aa4 1869
477330fc
RM
1870 if (high_range >= max_regs)
1871 {
1872 first_error (_("register out of range in list"));
1873 return FAIL;
1874 }
b7fc2769 1875
477330fc
RM
1876 if (regtype == REG_TYPE_NQ)
1877 high_range = high_range + 1;
5287ad62 1878
c19d1205
ZW
1879 if (high_range <= new_base)
1880 {
1881 inst.error = _("register range not in ascending order");
1882 return FAIL;
1883 }
0bbf2aa4 1884
5287ad62 1885 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1886 {
5287ad62 1887 if (mask & (setmask << new_base))
0bbf2aa4 1888 {
c19d1205
ZW
1889 inst.error = _("invalid register list");
1890 return FAIL;
0bbf2aa4 1891 }
c19d1205 1892
5287ad62
JB
1893 mask |= setmask << new_base;
1894 count += addregs;
0bbf2aa4 1895 }
0bbf2aa4 1896 }
0bbf2aa4 1897 }
037e8744 1898 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1899
037e8744 1900 str++;
0bbf2aa4 1901
c19d1205
ZW
1902 /* Sanity check -- should have raised a parse error above. */
1903 if (count == 0 || count > max_regs)
1904 abort ();
1905
1906 *pbase = base_reg;
1907
1908 /* Final test -- the registers must be consecutive. */
1909 mask >>= base_reg;
1910 for (i = 0; i < count; i++)
1911 {
1912 if ((mask & (1u << i)) == 0)
1913 {
1914 inst.error = _("non-contiguous register range");
1915 return FAIL;
1916 }
1917 }
1918
037e8744
JB
1919 *ccp = str;
1920
c19d1205 1921 return count;
b99bd4ef
NC
1922}
1923
dcbf9037
JB
1924/* True if two alias types are the same. */
1925
c921be7d 1926static bfd_boolean
dcbf9037
JB
1927neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1928{
1929 if (!a && !b)
c921be7d 1930 return TRUE;
5f4273c7 1931
dcbf9037 1932 if (!a || !b)
c921be7d 1933 return FALSE;
dcbf9037
JB
1934
1935 if (a->defined != b->defined)
c921be7d 1936 return FALSE;
5f4273c7 1937
dcbf9037
JB
1938 if ((a->defined & NTA_HASTYPE) != 0
1939 && (a->eltype.type != b->eltype.type
477330fc 1940 || a->eltype.size != b->eltype.size))
c921be7d 1941 return FALSE;
dcbf9037
JB
1942
1943 if ((a->defined & NTA_HASINDEX) != 0
1944 && (a->index != b->index))
c921be7d 1945 return FALSE;
5f4273c7 1946
c921be7d 1947 return TRUE;
dcbf9037
JB
1948}
1949
5287ad62
JB
1950/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1951 The base register is put in *PBASE.
dcbf9037 1952 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1953 the return value.
1954 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1955 Bits [6:5] encode the list length (minus one).
1956 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1957
5287ad62 1958#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1959#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1960#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1961
1962static int
dcbf9037 1963parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 1964 struct neon_type_el *eltype)
5287ad62
JB
1965{
1966 char *ptr = *str;
1967 int base_reg = -1;
1968 int reg_incr = -1;
1969 int count = 0;
1970 int lane = -1;
1971 int leading_brace = 0;
1972 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
1973 const char *const incr_error = _("register stride must be 1 or 2");
1974 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1975 struct neon_typed_alias firsttype;
5f4273c7 1976
5287ad62
JB
1977 if (skip_past_char (&ptr, '{') == SUCCESS)
1978 leading_brace = 1;
5f4273c7 1979
5287ad62
JB
1980 do
1981 {
dcbf9037
JB
1982 struct neon_typed_alias atype;
1983 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1984
5287ad62 1985 if (getreg == FAIL)
477330fc
RM
1986 {
1987 first_error (_(reg_expected_msgs[rtype]));
1988 return FAIL;
1989 }
5f4273c7 1990
5287ad62 1991 if (base_reg == -1)
477330fc
RM
1992 {
1993 base_reg = getreg;
1994 if (rtype == REG_TYPE_NQ)
1995 {
1996 reg_incr = 1;
1997 }
1998 firsttype = atype;
1999 }
5287ad62 2000 else if (reg_incr == -1)
477330fc
RM
2001 {
2002 reg_incr = getreg - base_reg;
2003 if (reg_incr < 1 || reg_incr > 2)
2004 {
2005 first_error (_(incr_error));
2006 return FAIL;
2007 }
2008 }
5287ad62 2009 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2010 {
2011 first_error (_(incr_error));
2012 return FAIL;
2013 }
dcbf9037 2014
c921be7d 2015 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2016 {
2017 first_error (_(type_error));
2018 return FAIL;
2019 }
5f4273c7 2020
5287ad62 2021 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2022 modes. */
5287ad62 2023 if (ptr[0] == '-')
477330fc
RM
2024 {
2025 struct neon_typed_alias htype;
2026 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2027 if (lane == -1)
2028 lane = NEON_INTERLEAVE_LANES;
2029 else if (lane != NEON_INTERLEAVE_LANES)
2030 {
2031 first_error (_(type_error));
2032 return FAIL;
2033 }
2034 if (reg_incr == -1)
2035 reg_incr = 1;
2036 else if (reg_incr != 1)
2037 {
2038 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2039 return FAIL;
2040 }
2041 ptr++;
2042 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2043 if (hireg == FAIL)
2044 {
2045 first_error (_(reg_expected_msgs[rtype]));
2046 return FAIL;
2047 }
2048 if (! neon_alias_types_same (&htype, &firsttype))
2049 {
2050 first_error (_(type_error));
2051 return FAIL;
2052 }
2053 count += hireg + dregs - getreg;
2054 continue;
2055 }
5f4273c7 2056
5287ad62
JB
2057 /* If we're using Q registers, we can't use [] or [n] syntax. */
2058 if (rtype == REG_TYPE_NQ)
477330fc
RM
2059 {
2060 count += 2;
2061 continue;
2062 }
5f4273c7 2063
dcbf9037 2064 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2065 {
2066 if (lane == -1)
2067 lane = atype.index;
2068 else if (lane != atype.index)
2069 {
2070 first_error (_(type_error));
2071 return FAIL;
2072 }
2073 }
5287ad62 2074 else if (lane == -1)
477330fc 2075 lane = NEON_INTERLEAVE_LANES;
5287ad62 2076 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2077 {
2078 first_error (_(type_error));
2079 return FAIL;
2080 }
5287ad62
JB
2081 count++;
2082 }
2083 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2084
5287ad62
JB
2085 /* No lane set by [x]. We must be interleaving structures. */
2086 if (lane == -1)
2087 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2088
5287ad62
JB
2089 /* Sanity check. */
2090 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2091 || (count > 1 && reg_incr == -1))
2092 {
dcbf9037 2093 first_error (_("error parsing element/structure list"));
5287ad62
JB
2094 return FAIL;
2095 }
2096
2097 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2098 {
dcbf9037 2099 first_error (_("expected }"));
5287ad62
JB
2100 return FAIL;
2101 }
5f4273c7 2102
5287ad62
JB
2103 if (reg_incr == -1)
2104 reg_incr = 1;
2105
dcbf9037
JB
2106 if (eltype)
2107 *eltype = firsttype.eltype;
2108
5287ad62
JB
2109 *pbase = base_reg;
2110 *str = ptr;
5f4273c7 2111
5287ad62
JB
2112 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2113}
2114
c19d1205
ZW
2115/* Parse an explicit relocation suffix on an expression. This is
2116 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2117 arm_reloc_hsh contains no entries, so this function can only
2118 succeed if there is no () after the word. Returns -1 on error,
2119 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2120
c19d1205
ZW
2121static int
2122parse_reloc (char **str)
b99bd4ef 2123{
c19d1205
ZW
2124 struct reloc_entry *r;
2125 char *p, *q;
b99bd4ef 2126
c19d1205
ZW
2127 if (**str != '(')
2128 return BFD_RELOC_UNUSED;
b99bd4ef 2129
c19d1205
ZW
2130 p = *str + 1;
2131 q = p;
2132
2133 while (*q && *q != ')' && *q != ',')
2134 q++;
2135 if (*q != ')')
2136 return -1;
2137
21d799b5
NC
2138 if ((r = (struct reloc_entry *)
2139 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2140 return -1;
2141
2142 *str = q + 1;
2143 return r->reloc;
b99bd4ef
NC
2144}
2145
c19d1205
ZW
2146/* Directives: register aliases. */
2147
dcbf9037 2148static struct reg_entry *
90ec0d68 2149insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2150{
d3ce72d0 2151 struct reg_entry *new_reg;
c19d1205 2152 const char *name;
b99bd4ef 2153
d3ce72d0 2154 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2155 {
d3ce72d0 2156 if (new_reg->builtin)
c19d1205 2157 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2158
c19d1205
ZW
2159 /* Only warn about a redefinition if it's not defined as the
2160 same register. */
d3ce72d0 2161 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2162 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2163
d929913e 2164 return NULL;
c19d1205 2165 }
b99bd4ef 2166
c19d1205 2167 name = xstrdup (str);
d3ce72d0 2168 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
b99bd4ef 2169
d3ce72d0
NC
2170 new_reg->name = name;
2171 new_reg->number = number;
2172 new_reg->type = type;
2173 new_reg->builtin = FALSE;
2174 new_reg->neon = NULL;
b99bd4ef 2175
d3ce72d0 2176 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2177 abort ();
5f4273c7 2178
d3ce72d0 2179 return new_reg;
dcbf9037
JB
2180}
2181
2182static void
2183insert_neon_reg_alias (char *str, int number, int type,
477330fc 2184 struct neon_typed_alias *atype)
dcbf9037
JB
2185{
2186 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2187
dcbf9037
JB
2188 if (!reg)
2189 {
2190 first_error (_("attempt to redefine typed alias"));
2191 return;
2192 }
5f4273c7 2193
dcbf9037
JB
2194 if (atype)
2195 {
21d799b5 2196 reg->neon = (struct neon_typed_alias *)
477330fc 2197 xmalloc (sizeof (struct neon_typed_alias));
dcbf9037
JB
2198 *reg->neon = *atype;
2199 }
c19d1205 2200}
b99bd4ef 2201
c19d1205 2202/* Look for the .req directive. This is of the form:
b99bd4ef 2203
c19d1205 2204 new_register_name .req existing_register_name
b99bd4ef 2205
c19d1205 2206 If we find one, or if it looks sufficiently like one that we want to
d929913e 2207 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2208
d929913e 2209static bfd_boolean
c19d1205
ZW
2210create_register_alias (char * newname, char *p)
2211{
2212 struct reg_entry *old;
2213 char *oldname, *nbuf;
2214 size_t nlen;
b99bd4ef 2215
c19d1205
ZW
2216 /* The input scrubber ensures that whitespace after the mnemonic is
2217 collapsed to single spaces. */
2218 oldname = p;
2219 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2220 return FALSE;
b99bd4ef 2221
c19d1205
ZW
2222 oldname += 6;
2223 if (*oldname == '\0')
d929913e 2224 return FALSE;
b99bd4ef 2225
21d799b5 2226 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2227 if (!old)
b99bd4ef 2228 {
c19d1205 2229 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2230 return TRUE;
b99bd4ef
NC
2231 }
2232
c19d1205
ZW
2233 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2234 the desired alias name, and p points to its end. If not, then
2235 the desired alias name is in the global original_case_string. */
2236#ifdef TC_CASE_SENSITIVE
2237 nlen = p - newname;
2238#else
2239 newname = original_case_string;
2240 nlen = strlen (newname);
2241#endif
b99bd4ef 2242
21d799b5 2243 nbuf = (char *) alloca (nlen + 1);
c19d1205
ZW
2244 memcpy (nbuf, newname, nlen);
2245 nbuf[nlen] = '\0';
b99bd4ef 2246
c19d1205
ZW
2247 /* Create aliases under the new name as stated; an all-lowercase
2248 version of the new name; and an all-uppercase version of the new
2249 name. */
d929913e
NC
2250 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2251 {
2252 for (p = nbuf; *p; p++)
2253 *p = TOUPPER (*p);
c19d1205 2254
d929913e
NC
2255 if (strncmp (nbuf, newname, nlen))
2256 {
2257 /* If this attempt to create an additional alias fails, do not bother
2258 trying to create the all-lower case alias. We will fail and issue
2259 a second, duplicate error message. This situation arises when the
2260 programmer does something like:
2261 foo .req r0
2262 Foo .req r1
2263 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2264 the artificial FOO alias because it has already been created by the
d929913e
NC
2265 first .req. */
2266 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2267 return TRUE;
2268 }
c19d1205 2269
d929913e
NC
2270 for (p = nbuf; *p; p++)
2271 *p = TOLOWER (*p);
c19d1205 2272
d929913e
NC
2273 if (strncmp (nbuf, newname, nlen))
2274 insert_reg_alias (nbuf, old->number, old->type);
2275 }
c19d1205 2276
d929913e 2277 return TRUE;
b99bd4ef
NC
2278}
2279
dcbf9037
JB
2280/* Create a Neon typed/indexed register alias using directives, e.g.:
2281 X .dn d5.s32[1]
2282 Y .qn 6.s16
2283 Z .dn d7
2284 T .dn Z[0]
2285 These typed registers can be used instead of the types specified after the
2286 Neon mnemonic, so long as all operands given have types. Types can also be
2287 specified directly, e.g.:
5f4273c7 2288 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2289
c921be7d 2290static bfd_boolean
dcbf9037
JB
2291create_neon_reg_alias (char *newname, char *p)
2292{
2293 enum arm_reg_type basetype;
2294 struct reg_entry *basereg;
2295 struct reg_entry mybasereg;
2296 struct neon_type ntype;
2297 struct neon_typed_alias typeinfo;
12d6b0b7 2298 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2299 int namelen;
5f4273c7 2300
dcbf9037
JB
2301 typeinfo.defined = 0;
2302 typeinfo.eltype.type = NT_invtype;
2303 typeinfo.eltype.size = -1;
2304 typeinfo.index = -1;
5f4273c7 2305
dcbf9037 2306 nameend = p;
5f4273c7 2307
dcbf9037
JB
2308 if (strncmp (p, " .dn ", 5) == 0)
2309 basetype = REG_TYPE_VFD;
2310 else if (strncmp (p, " .qn ", 5) == 0)
2311 basetype = REG_TYPE_NQ;
2312 else
c921be7d 2313 return FALSE;
5f4273c7 2314
dcbf9037 2315 p += 5;
5f4273c7 2316
dcbf9037 2317 if (*p == '\0')
c921be7d 2318 return FALSE;
5f4273c7 2319
dcbf9037
JB
2320 basereg = arm_reg_parse_multi (&p);
2321
2322 if (basereg && basereg->type != basetype)
2323 {
2324 as_bad (_("bad type for register"));
c921be7d 2325 return FALSE;
dcbf9037
JB
2326 }
2327
2328 if (basereg == NULL)
2329 {
2330 expressionS exp;
2331 /* Try parsing as an integer. */
2332 my_get_expression (&exp, &p, GE_NO_PREFIX);
2333 if (exp.X_op != O_constant)
477330fc
RM
2334 {
2335 as_bad (_("expression must be constant"));
2336 return FALSE;
2337 }
dcbf9037
JB
2338 basereg = &mybasereg;
2339 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2340 : exp.X_add_number;
dcbf9037
JB
2341 basereg->neon = 0;
2342 }
2343
2344 if (basereg->neon)
2345 typeinfo = *basereg->neon;
2346
2347 if (parse_neon_type (&ntype, &p) == SUCCESS)
2348 {
2349 /* We got a type. */
2350 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2351 {
2352 as_bad (_("can't redefine the type of a register alias"));
2353 return FALSE;
2354 }
5f4273c7 2355
dcbf9037
JB
2356 typeinfo.defined |= NTA_HASTYPE;
2357 if (ntype.elems != 1)
477330fc
RM
2358 {
2359 as_bad (_("you must specify a single type only"));
2360 return FALSE;
2361 }
dcbf9037
JB
2362 typeinfo.eltype = ntype.el[0];
2363 }
5f4273c7 2364
dcbf9037
JB
2365 if (skip_past_char (&p, '[') == SUCCESS)
2366 {
2367 expressionS exp;
2368 /* We got a scalar index. */
5f4273c7 2369
dcbf9037 2370 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2371 {
2372 as_bad (_("can't redefine the index of a scalar alias"));
2373 return FALSE;
2374 }
5f4273c7 2375
dcbf9037 2376 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2377
dcbf9037 2378 if (exp.X_op != O_constant)
477330fc
RM
2379 {
2380 as_bad (_("scalar index must be constant"));
2381 return FALSE;
2382 }
5f4273c7 2383
dcbf9037
JB
2384 typeinfo.defined |= NTA_HASINDEX;
2385 typeinfo.index = exp.X_add_number;
5f4273c7 2386
dcbf9037 2387 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2388 {
2389 as_bad (_("expecting ]"));
2390 return FALSE;
2391 }
dcbf9037
JB
2392 }
2393
15735687
NS
2394 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2395 the desired alias name, and p points to its end. If not, then
2396 the desired alias name is in the global original_case_string. */
2397#ifdef TC_CASE_SENSITIVE
dcbf9037 2398 namelen = nameend - newname;
15735687
NS
2399#else
2400 newname = original_case_string;
2401 namelen = strlen (newname);
2402#endif
2403
21d799b5 2404 namebuf = (char *) alloca (namelen + 1);
dcbf9037
JB
2405 strncpy (namebuf, newname, namelen);
2406 namebuf[namelen] = '\0';
5f4273c7 2407
dcbf9037 2408 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2409 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2410
dcbf9037
JB
2411 /* Insert name in all uppercase. */
2412 for (p = namebuf; *p; p++)
2413 *p = TOUPPER (*p);
5f4273c7 2414
dcbf9037
JB
2415 if (strncmp (namebuf, newname, namelen))
2416 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2417 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2418
dcbf9037
JB
2419 /* Insert name in all lowercase. */
2420 for (p = namebuf; *p; p++)
2421 *p = TOLOWER (*p);
5f4273c7 2422
dcbf9037
JB
2423 if (strncmp (namebuf, newname, namelen))
2424 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2425 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2426
c921be7d 2427 return TRUE;
dcbf9037
JB
2428}
2429
c19d1205
ZW
2430/* Should never be called, as .req goes between the alias and the
2431 register name, not at the beginning of the line. */
c921be7d 2432
b99bd4ef 2433static void
c19d1205 2434s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2435{
c19d1205
ZW
2436 as_bad (_("invalid syntax for .req directive"));
2437}
b99bd4ef 2438
dcbf9037
JB
2439static void
2440s_dn (int a ATTRIBUTE_UNUSED)
2441{
2442 as_bad (_("invalid syntax for .dn directive"));
2443}
2444
2445static void
2446s_qn (int a ATTRIBUTE_UNUSED)
2447{
2448 as_bad (_("invalid syntax for .qn directive"));
2449}
2450
c19d1205
ZW
2451/* The .unreq directive deletes an alias which was previously defined
2452 by .req. For example:
b99bd4ef 2453
c19d1205
ZW
2454 my_alias .req r11
2455 .unreq my_alias */
b99bd4ef
NC
2456
2457static void
c19d1205 2458s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2459{
c19d1205
ZW
2460 char * name;
2461 char saved_char;
b99bd4ef 2462
c19d1205
ZW
2463 name = input_line_pointer;
2464
2465 while (*input_line_pointer != 0
2466 && *input_line_pointer != ' '
2467 && *input_line_pointer != '\n')
2468 ++input_line_pointer;
2469
2470 saved_char = *input_line_pointer;
2471 *input_line_pointer = 0;
2472
2473 if (!*name)
2474 as_bad (_("invalid syntax for .unreq directive"));
2475 else
2476 {
21d799b5 2477 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2478 name);
c19d1205
ZW
2479
2480 if (!reg)
2481 as_bad (_("unknown register alias '%s'"), name);
2482 else if (reg->builtin)
a1727c1a 2483 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2484 name);
2485 else
2486 {
d929913e
NC
2487 char * p;
2488 char * nbuf;
2489
db0bc284 2490 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2491 free ((char *) reg->name);
477330fc
RM
2492 if (reg->neon)
2493 free (reg->neon);
c19d1205 2494 free (reg);
d929913e
NC
2495
2496 /* Also locate the all upper case and all lower case versions.
2497 Do not complain if we cannot find one or the other as it
2498 was probably deleted above. */
5f4273c7 2499
d929913e
NC
2500 nbuf = strdup (name);
2501 for (p = nbuf; *p; p++)
2502 *p = TOUPPER (*p);
21d799b5 2503 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2504 if (reg)
2505 {
db0bc284 2506 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2507 free ((char *) reg->name);
2508 if (reg->neon)
2509 free (reg->neon);
2510 free (reg);
2511 }
2512
2513 for (p = nbuf; *p; p++)
2514 *p = TOLOWER (*p);
21d799b5 2515 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2516 if (reg)
2517 {
db0bc284 2518 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2519 free ((char *) reg->name);
2520 if (reg->neon)
2521 free (reg->neon);
2522 free (reg);
2523 }
2524
2525 free (nbuf);
c19d1205
ZW
2526 }
2527 }
b99bd4ef 2528
c19d1205 2529 *input_line_pointer = saved_char;
b99bd4ef
NC
2530 demand_empty_rest_of_line ();
2531}
2532
c19d1205
ZW
2533/* Directives: Instruction set selection. */
2534
2535#ifdef OBJ_ELF
2536/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2537 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2538 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2539 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2540
cd000bff
DJ
2541/* Create a new mapping symbol for the transition to STATE. */
2542
2543static void
2544make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2545{
a737bd4d 2546 symbolS * symbolP;
c19d1205
ZW
2547 const char * symname;
2548 int type;
b99bd4ef 2549
c19d1205 2550 switch (state)
b99bd4ef 2551 {
c19d1205
ZW
2552 case MAP_DATA:
2553 symname = "$d";
2554 type = BSF_NO_FLAGS;
2555 break;
2556 case MAP_ARM:
2557 symname = "$a";
2558 type = BSF_NO_FLAGS;
2559 break;
2560 case MAP_THUMB:
2561 symname = "$t";
2562 type = BSF_NO_FLAGS;
2563 break;
c19d1205
ZW
2564 default:
2565 abort ();
2566 }
2567
cd000bff 2568 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2569 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2570
2571 switch (state)
2572 {
2573 case MAP_ARM:
2574 THUMB_SET_FUNC (symbolP, 0);
2575 ARM_SET_THUMB (symbolP, 0);
2576 ARM_SET_INTERWORK (symbolP, support_interwork);
2577 break;
2578
2579 case MAP_THUMB:
2580 THUMB_SET_FUNC (symbolP, 1);
2581 ARM_SET_THUMB (symbolP, 1);
2582 ARM_SET_INTERWORK (symbolP, support_interwork);
2583 break;
2584
2585 case MAP_DATA:
2586 default:
cd000bff
DJ
2587 break;
2588 }
2589
2590 /* Save the mapping symbols for future reference. Also check that
2591 we do not place two mapping symbols at the same offset within a
2592 frag. We'll handle overlap between frags in
2de7820f
JZ
2593 check_mapping_symbols.
2594
2595 If .fill or other data filling directive generates zero sized data,
2596 the mapping symbol for the following code will have the same value
2597 as the one generated for the data filling directive. In this case,
2598 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2599 if (value == 0)
2600 {
2de7820f
JZ
2601 if (frag->tc_frag_data.first_map != NULL)
2602 {
2603 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2604 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2605 }
cd000bff
DJ
2606 frag->tc_frag_data.first_map = symbolP;
2607 }
2608 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2609 {
2610 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2611 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2612 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2613 }
cd000bff
DJ
2614 frag->tc_frag_data.last_map = symbolP;
2615}
2616
2617/* We must sometimes convert a region marked as code to data during
2618 code alignment, if an odd number of bytes have to be padded. The
2619 code mapping symbol is pushed to an aligned address. */
2620
2621static void
2622insert_data_mapping_symbol (enum mstate state,
2623 valueT value, fragS *frag, offsetT bytes)
2624{
2625 /* If there was already a mapping symbol, remove it. */
2626 if (frag->tc_frag_data.last_map != NULL
2627 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2628 {
2629 symbolS *symp = frag->tc_frag_data.last_map;
2630
2631 if (value == 0)
2632 {
2633 know (frag->tc_frag_data.first_map == symp);
2634 frag->tc_frag_data.first_map = NULL;
2635 }
2636 frag->tc_frag_data.last_map = NULL;
2637 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2638 }
cd000bff
DJ
2639
2640 make_mapping_symbol (MAP_DATA, value, frag);
2641 make_mapping_symbol (state, value + bytes, frag);
2642}
2643
2644static void mapping_state_2 (enum mstate state, int max_chars);
2645
2646/* Set the mapping state to STATE. Only call this when about to
2647 emit some STATE bytes to the file. */
2648
4e9aaefb 2649#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2650void
2651mapping_state (enum mstate state)
2652{
940b5ce0
DJ
2653 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2654
cd000bff
DJ
2655 if (mapstate == state)
2656 /* The mapping symbol has already been emitted.
2657 There is nothing else to do. */
2658 return;
49c62a33
NC
2659
2660 if (state == MAP_ARM || state == MAP_THUMB)
2661 /* PR gas/12931
2662 All ARM instructions require 4-byte alignment.
2663 (Almost) all Thumb instructions require 2-byte alignment.
2664
2665 When emitting instructions into any section, mark the section
2666 appropriately.
2667
2668 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2669 but themselves require 2-byte alignment; this applies to some
2670 PC- relative forms. However, these cases will invovle implicit
2671 literal pool generation or an explicit .align >=2, both of
2672 which will cause the section to me marked with sufficient
2673 alignment. Thus, we don't handle those cases here. */
2674 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2675
2676 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2677 /* This case will be evaluated later. */
cd000bff 2678 return;
cd000bff
DJ
2679
2680 mapping_state_2 (state, 0);
cd000bff
DJ
2681}
2682
2683/* Same as mapping_state, but MAX_CHARS bytes have already been
2684 allocated. Put the mapping symbol that far back. */
2685
2686static void
2687mapping_state_2 (enum mstate state, int max_chars)
2688{
940b5ce0
DJ
2689 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2690
2691 if (!SEG_NORMAL (now_seg))
2692 return;
2693
cd000bff
DJ
2694 if (mapstate == state)
2695 /* The mapping symbol has already been emitted.
2696 There is nothing else to do. */
2697 return;
2698
4e9aaefb
SA
2699 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2700 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2701 {
2702 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2703 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2704
2705 if (add_symbol)
2706 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2707 }
2708
cd000bff
DJ
2709 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2710 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2711}
4e9aaefb 2712#undef TRANSITION
c19d1205 2713#else
d3106081
NS
2714#define mapping_state(x) ((void)0)
2715#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2716#endif
2717
2718/* Find the real, Thumb encoded start of a Thumb function. */
2719
4343666d 2720#ifdef OBJ_COFF
c19d1205
ZW
2721static symbolS *
2722find_real_start (symbolS * symbolP)
2723{
2724 char * real_start;
2725 const char * name = S_GET_NAME (symbolP);
2726 symbolS * new_target;
2727
2728 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2729#define STUB_NAME ".real_start_of"
2730
2731 if (name == NULL)
2732 abort ();
2733
37f6032b
ZW
2734 /* The compiler may generate BL instructions to local labels because
2735 it needs to perform a branch to a far away location. These labels
2736 do not have a corresponding ".real_start_of" label. We check
2737 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2738 the ".real_start_of" convention for nonlocal branches. */
2739 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2740 return symbolP;
2741
37f6032b 2742 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2743 new_target = symbol_find (real_start);
2744
2745 if (new_target == NULL)
2746 {
bd3ba5d1 2747 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2748 new_target = symbolP;
2749 }
2750
c19d1205
ZW
2751 return new_target;
2752}
4343666d 2753#endif
c19d1205
ZW
2754
2755static void
2756opcode_select (int width)
2757{
2758 switch (width)
2759 {
2760 case 16:
2761 if (! thumb_mode)
2762 {
e74cfd16 2763 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2764 as_bad (_("selected processor does not support THUMB opcodes"));
2765
2766 thumb_mode = 1;
2767 /* No need to force the alignment, since we will have been
2768 coming from ARM mode, which is word-aligned. */
2769 record_alignment (now_seg, 1);
2770 }
c19d1205
ZW
2771 break;
2772
2773 case 32:
2774 if (thumb_mode)
2775 {
e74cfd16 2776 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2777 as_bad (_("selected processor does not support ARM opcodes"));
2778
2779 thumb_mode = 0;
2780
2781 if (!need_pass_2)
2782 frag_align (2, 0, 0);
2783
2784 record_alignment (now_seg, 1);
2785 }
c19d1205
ZW
2786 break;
2787
2788 default:
2789 as_bad (_("invalid instruction size selected (%d)"), width);
2790 }
2791}
2792
2793static void
2794s_arm (int ignore ATTRIBUTE_UNUSED)
2795{
2796 opcode_select (32);
2797 demand_empty_rest_of_line ();
2798}
2799
2800static void
2801s_thumb (int ignore ATTRIBUTE_UNUSED)
2802{
2803 opcode_select (16);
2804 demand_empty_rest_of_line ();
2805}
2806
2807static void
2808s_code (int unused ATTRIBUTE_UNUSED)
2809{
2810 int temp;
2811
2812 temp = get_absolute_expression ();
2813 switch (temp)
2814 {
2815 case 16:
2816 case 32:
2817 opcode_select (temp);
2818 break;
2819
2820 default:
2821 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2822 }
2823}
2824
2825static void
2826s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2827{
2828 /* If we are not already in thumb mode go into it, EVEN if
2829 the target processor does not support thumb instructions.
2830 This is used by gcc/config/arm/lib1funcs.asm for example
2831 to compile interworking support functions even if the
2832 target processor should not support interworking. */
2833 if (! thumb_mode)
2834 {
2835 thumb_mode = 2;
2836 record_alignment (now_seg, 1);
2837 }
2838
2839 demand_empty_rest_of_line ();
2840}
2841
2842static void
2843s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2844{
2845 s_thumb (0);
2846
2847 /* The following label is the name/address of the start of a Thumb function.
2848 We need to know this for the interworking support. */
2849 label_is_thumb_function_name = TRUE;
2850}
2851
2852/* Perform a .set directive, but also mark the alias as
2853 being a thumb function. */
2854
2855static void
2856s_thumb_set (int equiv)
2857{
2858 /* XXX the following is a duplicate of the code for s_set() in read.c
2859 We cannot just call that code as we need to get at the symbol that
2860 is created. */
2861 char * name;
2862 char delim;
2863 char * end_name;
2864 symbolS * symbolP;
2865
2866 /* Especial apologies for the random logic:
2867 This just grew, and could be parsed much more simply!
2868 Dean - in haste. */
2869 name = input_line_pointer;
2870 delim = get_symbol_end ();
2871 end_name = input_line_pointer;
2872 *end_name = delim;
2873
2874 if (*input_line_pointer != ',')
2875 {
2876 *end_name = 0;
2877 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2878 *end_name = delim;
2879 ignore_rest_of_line ();
2880 return;
2881 }
2882
2883 input_line_pointer++;
2884 *end_name = 0;
2885
2886 if (name[0] == '.' && name[1] == '\0')
2887 {
2888 /* XXX - this should not happen to .thumb_set. */
2889 abort ();
2890 }
2891
2892 if ((symbolP = symbol_find (name)) == NULL
2893 && (symbolP = md_undefined_symbol (name)) == NULL)
2894 {
2895#ifndef NO_LISTING
2896 /* When doing symbol listings, play games with dummy fragments living
2897 outside the normal fragment chain to record the file and line info
c19d1205 2898 for this symbol. */
b99bd4ef
NC
2899 if (listing & LISTING_SYMBOLS)
2900 {
2901 extern struct list_info_struct * listing_tail;
21d799b5 2902 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2903
2904 memset (dummy_frag, 0, sizeof (fragS));
2905 dummy_frag->fr_type = rs_fill;
2906 dummy_frag->line = listing_tail;
2907 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2908 dummy_frag->fr_symbol = symbolP;
2909 }
2910 else
2911#endif
2912 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2913
2914#ifdef OBJ_COFF
2915 /* "set" symbols are local unless otherwise specified. */
2916 SF_SET_LOCAL (symbolP);
2917#endif /* OBJ_COFF */
2918 } /* Make a new symbol. */
2919
2920 symbol_table_insert (symbolP);
2921
2922 * end_name = delim;
2923
2924 if (equiv
2925 && S_IS_DEFINED (symbolP)
2926 && S_GET_SEGMENT (symbolP) != reg_section)
2927 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2928
2929 pseudo_set (symbolP);
2930
2931 demand_empty_rest_of_line ();
2932
c19d1205 2933 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2934
2935 THUMB_SET_FUNC (symbolP, 1);
2936 ARM_SET_THUMB (symbolP, 1);
2937#if defined OBJ_ELF || defined OBJ_COFF
2938 ARM_SET_INTERWORK (symbolP, support_interwork);
2939#endif
2940}
2941
c19d1205 2942/* Directives: Mode selection. */
b99bd4ef 2943
c19d1205
ZW
2944/* .syntax [unified|divided] - choose the new unified syntax
2945 (same for Arm and Thumb encoding, modulo slight differences in what
2946 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2947static void
c19d1205 2948s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2949{
c19d1205
ZW
2950 char *name, delim;
2951
2952 name = input_line_pointer;
2953 delim = get_symbol_end ();
2954
2955 if (!strcasecmp (name, "unified"))
2956 unified_syntax = TRUE;
2957 else if (!strcasecmp (name, "divided"))
2958 unified_syntax = FALSE;
2959 else
2960 {
2961 as_bad (_("unrecognized syntax mode \"%s\""), name);
2962 return;
2963 }
2964 *input_line_pointer = delim;
b99bd4ef
NC
2965 demand_empty_rest_of_line ();
2966}
2967
c19d1205
ZW
2968/* Directives: sectioning and alignment. */
2969
2970/* Same as s_align_ptwo but align 0 => align 2. */
2971
b99bd4ef 2972static void
c19d1205 2973s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2974{
a737bd4d 2975 int temp;
dce323d1 2976 bfd_boolean fill_p;
c19d1205
ZW
2977 long temp_fill;
2978 long max_alignment = 15;
b99bd4ef
NC
2979
2980 temp = get_absolute_expression ();
c19d1205
ZW
2981 if (temp > max_alignment)
2982 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2983 else if (temp < 0)
b99bd4ef 2984 {
c19d1205
ZW
2985 as_bad (_("alignment negative. 0 assumed."));
2986 temp = 0;
2987 }
b99bd4ef 2988
c19d1205
ZW
2989 if (*input_line_pointer == ',')
2990 {
2991 input_line_pointer++;
2992 temp_fill = get_absolute_expression ();
dce323d1 2993 fill_p = TRUE;
b99bd4ef 2994 }
c19d1205 2995 else
dce323d1
PB
2996 {
2997 fill_p = FALSE;
2998 temp_fill = 0;
2999 }
b99bd4ef 3000
c19d1205
ZW
3001 if (!temp)
3002 temp = 2;
b99bd4ef 3003
c19d1205
ZW
3004 /* Only make a frag if we HAVE to. */
3005 if (temp && !need_pass_2)
dce323d1
PB
3006 {
3007 if (!fill_p && subseg_text_p (now_seg))
3008 frag_align_code (temp, 0);
3009 else
3010 frag_align (temp, (int) temp_fill, 0);
3011 }
c19d1205
ZW
3012 demand_empty_rest_of_line ();
3013
3014 record_alignment (now_seg, temp);
b99bd4ef
NC
3015}
3016
c19d1205
ZW
3017static void
3018s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3019{
c19d1205
ZW
3020 /* We don't support putting frags in the BSS segment, we fake it by
3021 marking in_bss, then looking at s_skip for clues. */
3022 subseg_set (bss_section, 0);
3023 demand_empty_rest_of_line ();
cd000bff
DJ
3024
3025#ifdef md_elf_section_change_hook
3026 md_elf_section_change_hook ();
3027#endif
c19d1205 3028}
b99bd4ef 3029
c19d1205
ZW
3030static void
3031s_even (int ignore ATTRIBUTE_UNUSED)
3032{
3033 /* Never make frag if expect extra pass. */
3034 if (!need_pass_2)
3035 frag_align (1, 0, 0);
b99bd4ef 3036
c19d1205 3037 record_alignment (now_seg, 1);
b99bd4ef 3038
c19d1205 3039 demand_empty_rest_of_line ();
b99bd4ef
NC
3040}
3041
2e6976a8
DG
3042/* Directives: CodeComposer Studio. */
3043
3044/* .ref (for CodeComposer Studio syntax only). */
3045static void
3046s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3047{
3048 if (codecomposer_syntax)
3049 ignore_rest_of_line ();
3050 else
3051 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3052}
3053
3054/* If name is not NULL, then it is used for marking the beginning of a
3055 function, wherease if it is NULL then it means the function end. */
3056static void
3057asmfunc_debug (const char * name)
3058{
3059 static const char * last_name = NULL;
3060
3061 if (name != NULL)
3062 {
3063 gas_assert (last_name == NULL);
3064 last_name = name;
3065
3066 if (debug_type == DEBUG_STABS)
3067 stabs_generate_asm_func (name, name);
3068 }
3069 else
3070 {
3071 gas_assert (last_name != NULL);
3072
3073 if (debug_type == DEBUG_STABS)
3074 stabs_generate_asm_endfunc (last_name, last_name);
3075
3076 last_name = NULL;
3077 }
3078}
3079
3080static void
3081s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3082{
3083 if (codecomposer_syntax)
3084 {
3085 switch (asmfunc_state)
3086 {
3087 case OUTSIDE_ASMFUNC:
3088 asmfunc_state = WAITING_ASMFUNC_NAME;
3089 break;
3090
3091 case WAITING_ASMFUNC_NAME:
3092 as_bad (_(".asmfunc repeated."));
3093 break;
3094
3095 case WAITING_ENDASMFUNC:
3096 as_bad (_(".asmfunc without function."));
3097 break;
3098 }
3099 demand_empty_rest_of_line ();
3100 }
3101 else
3102 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3103}
3104
3105static void
3106s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3107{
3108 if (codecomposer_syntax)
3109 {
3110 switch (asmfunc_state)
3111 {
3112 case OUTSIDE_ASMFUNC:
3113 as_bad (_(".endasmfunc without a .asmfunc."));
3114 break;
3115
3116 case WAITING_ASMFUNC_NAME:
3117 as_bad (_(".endasmfunc without function."));
3118 break;
3119
3120 case WAITING_ENDASMFUNC:
3121 asmfunc_state = OUTSIDE_ASMFUNC;
3122 asmfunc_debug (NULL);
3123 break;
3124 }
3125 demand_empty_rest_of_line ();
3126 }
3127 else
3128 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3129}
3130
3131static void
3132s_ccs_def (int name)
3133{
3134 if (codecomposer_syntax)
3135 s_globl (name);
3136 else
3137 as_bad (_(".def pseudo-op only available with -mccs flag."));
3138}
3139
c19d1205 3140/* Directives: Literal pools. */
a737bd4d 3141
c19d1205
ZW
3142static literal_pool *
3143find_literal_pool (void)
a737bd4d 3144{
c19d1205 3145 literal_pool * pool;
a737bd4d 3146
c19d1205 3147 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3148 {
c19d1205
ZW
3149 if (pool->section == now_seg
3150 && pool->sub_section == now_subseg)
3151 break;
a737bd4d
NC
3152 }
3153
c19d1205 3154 return pool;
a737bd4d
NC
3155}
3156
c19d1205
ZW
3157static literal_pool *
3158find_or_make_literal_pool (void)
a737bd4d 3159{
c19d1205
ZW
3160 /* Next literal pool ID number. */
3161 static unsigned int latest_pool_num = 1;
3162 literal_pool * pool;
a737bd4d 3163
c19d1205 3164 pool = find_literal_pool ();
a737bd4d 3165
c19d1205 3166 if (pool == NULL)
a737bd4d 3167 {
c19d1205 3168 /* Create a new pool. */
21d799b5 3169 pool = (literal_pool *) xmalloc (sizeof (* pool));
c19d1205
ZW
3170 if (! pool)
3171 return NULL;
a737bd4d 3172
c19d1205
ZW
3173 pool->next_free_entry = 0;
3174 pool->section = now_seg;
3175 pool->sub_section = now_subseg;
3176 pool->next = list_of_pools;
3177 pool->symbol = NULL;
8335d6aa 3178 pool->alignment = 2;
c19d1205
ZW
3179
3180 /* Add it to the list. */
3181 list_of_pools = pool;
a737bd4d 3182 }
a737bd4d 3183
c19d1205
ZW
3184 /* New pools, and emptied pools, will have a NULL symbol. */
3185 if (pool->symbol == NULL)
a737bd4d 3186 {
c19d1205
ZW
3187 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3188 (valueT) 0, &zero_address_frag);
3189 pool->id = latest_pool_num ++;
a737bd4d
NC
3190 }
3191
c19d1205
ZW
3192 /* Done. */
3193 return pool;
a737bd4d
NC
3194}
3195
c19d1205 3196/* Add the literal in the global 'inst'
5f4273c7 3197 structure to the relevant literal pool. */
b99bd4ef
NC
3198
3199static int
8335d6aa 3200add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3201{
8335d6aa
JW
3202#define PADDING_SLOT 0x1
3203#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3204 literal_pool * pool;
8335d6aa
JW
3205 unsigned int entry, pool_size = 0;
3206 bfd_boolean padding_slot_p = FALSE;
e56c722b 3207 unsigned imm1 = 0;
8335d6aa
JW
3208 unsigned imm2 = 0;
3209
3210 if (nbytes == 8)
3211 {
3212 imm1 = inst.operands[1].imm;
3213 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3214 : inst.reloc.exp.X_unsigned ? 0
2569ceb0 3215 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3216 if (target_big_endian)
3217 {
3218 imm1 = imm2;
3219 imm2 = inst.operands[1].imm;
3220 }
3221 }
b99bd4ef 3222
c19d1205
ZW
3223 pool = find_or_make_literal_pool ();
3224
3225 /* Check if this literal value is already in the pool. */
3226 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3227 {
8335d6aa
JW
3228 if (nbytes == 4)
3229 {
3230 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3231 && (inst.reloc.exp.X_op == O_constant)
3232 && (pool->literals[entry].X_add_number
3233 == inst.reloc.exp.X_add_number)
3234 && (pool->literals[entry].X_md == nbytes)
3235 && (pool->literals[entry].X_unsigned
3236 == inst.reloc.exp.X_unsigned))
3237 break;
3238
3239 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3240 && (inst.reloc.exp.X_op == O_symbol)
3241 && (pool->literals[entry].X_add_number
3242 == inst.reloc.exp.X_add_number)
3243 && (pool->literals[entry].X_add_symbol
3244 == inst.reloc.exp.X_add_symbol)
3245 && (pool->literals[entry].X_op_symbol
3246 == inst.reloc.exp.X_op_symbol)
3247 && (pool->literals[entry].X_md == nbytes))
3248 break;
3249 }
3250 else if ((nbytes == 8)
3251 && !(pool_size & 0x7)
3252 && ((entry + 1) != pool->next_free_entry)
3253 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3254 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa
JW
3255 && (pool->literals[entry].X_unsigned
3256 == inst.reloc.exp.X_unsigned)
3257 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3258 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa
JW
3259 && (pool->literals[entry + 1].X_unsigned
3260 == inst.reloc.exp.X_unsigned))
c19d1205
ZW
3261 break;
3262
8335d6aa
JW
3263 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3264 if (padding_slot_p && (nbytes == 4))
c19d1205 3265 break;
8335d6aa
JW
3266
3267 pool_size += 4;
b99bd4ef
NC
3268 }
3269
c19d1205
ZW
3270 /* Do we need to create a new entry? */
3271 if (entry == pool->next_free_entry)
3272 {
3273 if (entry >= MAX_LITERAL_POOL_SIZE)
3274 {
3275 inst.error = _("literal pool overflow");
3276 return FAIL;
3277 }
3278
8335d6aa
JW
3279 if (nbytes == 8)
3280 {
3281 /* For 8-byte entries, we align to an 8-byte boundary,
3282 and split it into two 4-byte entries, because on 32-bit
3283 host, 8-byte constants are treated as big num, thus
3284 saved in "generic_bignum" which will be overwritten
3285 by later assignments.
3286
3287 We also need to make sure there is enough space for
3288 the split.
3289
3290 We also check to make sure the literal operand is a
3291 constant number. */
19f2f6a9
JW
3292 if (!(inst.reloc.exp.X_op == O_constant
3293 || inst.reloc.exp.X_op == O_big))
8335d6aa
JW
3294 {
3295 inst.error = _("invalid type for literal pool");
3296 return FAIL;
3297 }
3298 else if (pool_size & 0x7)
3299 {
3300 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3301 {
3302 inst.error = _("literal pool overflow");
3303 return FAIL;
3304 }
3305
3306 pool->literals[entry] = inst.reloc.exp;
3307 pool->literals[entry].X_add_number = 0;
3308 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3309 pool->next_free_entry += 1;
3310 pool_size += 4;
3311 }
3312 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3313 {
3314 inst.error = _("literal pool overflow");
3315 return FAIL;
3316 }
3317
3318 pool->literals[entry] = inst.reloc.exp;
3319 pool->literals[entry].X_op = O_constant;
3320 pool->literals[entry].X_add_number = imm1;
3321 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3322 pool->literals[entry++].X_md = 4;
3323 pool->literals[entry] = inst.reloc.exp;
3324 pool->literals[entry].X_op = O_constant;
3325 pool->literals[entry].X_add_number = imm2;
3326 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3327 pool->literals[entry].X_md = 4;
3328 pool->alignment = 3;
3329 pool->next_free_entry += 1;
3330 }
3331 else
3332 {
3333 pool->literals[entry] = inst.reloc.exp;
3334 pool->literals[entry].X_md = 4;
3335 }
3336
a8040cf2
NC
3337#ifdef OBJ_ELF
3338 /* PR ld/12974: Record the location of the first source line to reference
3339 this entry in the literal pool. If it turns out during linking that the
3340 symbol does not exist we will be able to give an accurate line number for
3341 the (first use of the) missing reference. */
3342 if (debug_type == DEBUG_DWARF2)
3343 dwarf2_where (pool->locs + entry);
3344#endif
c19d1205
ZW
3345 pool->next_free_entry += 1;
3346 }
8335d6aa
JW
3347 else if (padding_slot_p)
3348 {
3349 pool->literals[entry] = inst.reloc.exp;
3350 pool->literals[entry].X_md = nbytes;
3351 }
b99bd4ef 3352
c19d1205 3353 inst.reloc.exp.X_op = O_symbol;
8335d6aa 3354 inst.reloc.exp.X_add_number = pool_size;
c19d1205 3355 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3356
c19d1205 3357 return SUCCESS;
b99bd4ef
NC
3358}
3359
2e6976a8
DG
3360bfd_boolean
3361tc_start_label_without_colon (char unused1 ATTRIBUTE_UNUSED, const char * rest)
3362{
3363 bfd_boolean ret = TRUE;
3364
3365 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3366 {
3367 const char *label = rest;
3368
3369 while (!is_end_of_line[(int) label[-1]])
3370 --label;
3371
3372 if (*label == '.')
3373 {
3374 as_bad (_("Invalid label '%s'"), label);
3375 ret = FALSE;
3376 }
3377
3378 asmfunc_debug (label);
3379
3380 asmfunc_state = WAITING_ENDASMFUNC;
3381 }
3382
3383 return ret;
3384}
3385
c19d1205
ZW
3386/* Can't use symbol_new here, so have to create a symbol and then at
3387 a later date assign it a value. Thats what these functions do. */
e16bb312 3388
c19d1205
ZW
3389static void
3390symbol_locate (symbolS * symbolP,
3391 const char * name, /* It is copied, the caller can modify. */
3392 segT segment, /* Segment identifier (SEG_<something>). */
3393 valueT valu, /* Symbol value. */
3394 fragS * frag) /* Associated fragment. */
3395{
e57e6ddc 3396 size_t name_length;
c19d1205 3397 char * preserved_copy_of_name;
e16bb312 3398
c19d1205
ZW
3399 name_length = strlen (name) + 1; /* +1 for \0. */
3400 obstack_grow (&notes, name, name_length);
21d799b5 3401 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3402
c19d1205
ZW
3403#ifdef tc_canonicalize_symbol_name
3404 preserved_copy_of_name =
3405 tc_canonicalize_symbol_name (preserved_copy_of_name);
3406#endif
b99bd4ef 3407
c19d1205 3408 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3409
c19d1205
ZW
3410 S_SET_SEGMENT (symbolP, segment);
3411 S_SET_VALUE (symbolP, valu);
3412 symbol_clear_list_pointers (symbolP);
b99bd4ef 3413
c19d1205 3414 symbol_set_frag (symbolP, frag);
b99bd4ef 3415
c19d1205
ZW
3416 /* Link to end of symbol chain. */
3417 {
3418 extern int symbol_table_frozen;
b99bd4ef 3419
c19d1205
ZW
3420 if (symbol_table_frozen)
3421 abort ();
3422 }
b99bd4ef 3423
c19d1205 3424 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3425
c19d1205 3426 obj_symbol_new_hook (symbolP);
b99bd4ef 3427
c19d1205
ZW
3428#ifdef tc_symbol_new_hook
3429 tc_symbol_new_hook (symbolP);
3430#endif
3431
3432#ifdef DEBUG_SYMS
3433 verify_symbol_chain (symbol_rootP, symbol_lastP);
3434#endif /* DEBUG_SYMS */
b99bd4ef
NC
3435}
3436
c19d1205
ZW
3437static void
3438s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3439{
c19d1205
ZW
3440 unsigned int entry;
3441 literal_pool * pool;
3442 char sym_name[20];
b99bd4ef 3443
c19d1205
ZW
3444 pool = find_literal_pool ();
3445 if (pool == NULL
3446 || pool->symbol == NULL
3447 || pool->next_free_entry == 0)
3448 return;
b99bd4ef 3449
c19d1205
ZW
3450 /* Align pool as you have word accesses.
3451 Only make a frag if we have to. */
3452 if (!need_pass_2)
8335d6aa 3453 frag_align (pool->alignment, 0, 0);
b99bd4ef 3454
c19d1205 3455 record_alignment (now_seg, 2);
b99bd4ef 3456
aaca88ef 3457#ifdef OBJ_ELF
47fc6e36
WN
3458 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3459 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3460#endif
c19d1205 3461 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3462
c19d1205
ZW
3463 symbol_locate (pool->symbol, sym_name, now_seg,
3464 (valueT) frag_now_fix (), frag_now);
3465 symbol_table_insert (pool->symbol);
b99bd4ef 3466
c19d1205 3467 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3468
c19d1205
ZW
3469#if defined OBJ_COFF || defined OBJ_ELF
3470 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3471#endif
6c43fab6 3472
c19d1205 3473 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3474 {
3475#ifdef OBJ_ELF
3476 if (debug_type == DEBUG_DWARF2)
3477 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3478#endif
3479 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3480 emit_expr (&(pool->literals[entry]),
3481 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3482 }
b99bd4ef 3483
c19d1205
ZW
3484 /* Mark the pool as empty. */
3485 pool->next_free_entry = 0;
3486 pool->symbol = NULL;
b99bd4ef
NC
3487}
3488
c19d1205
ZW
3489#ifdef OBJ_ELF
3490/* Forward declarations for functions below, in the MD interface
3491 section. */
3492static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3493static valueT create_unwind_entry (int);
3494static void start_unwind_section (const segT, int);
3495static void add_unwind_opcode (valueT, int);
3496static void flush_pending_unwind (void);
b99bd4ef 3497
c19d1205 3498/* Directives: Data. */
b99bd4ef 3499
c19d1205
ZW
3500static void
3501s_arm_elf_cons (int nbytes)
3502{
3503 expressionS exp;
b99bd4ef 3504
c19d1205
ZW
3505#ifdef md_flush_pending_output
3506 md_flush_pending_output ();
3507#endif
b99bd4ef 3508
c19d1205 3509 if (is_it_end_of_statement ())
b99bd4ef 3510 {
c19d1205
ZW
3511 demand_empty_rest_of_line ();
3512 return;
b99bd4ef
NC
3513 }
3514
c19d1205
ZW
3515#ifdef md_cons_align
3516 md_cons_align (nbytes);
3517#endif
b99bd4ef 3518
c19d1205
ZW
3519 mapping_state (MAP_DATA);
3520 do
b99bd4ef 3521 {
c19d1205
ZW
3522 int reloc;
3523 char *base = input_line_pointer;
b99bd4ef 3524
c19d1205 3525 expression (& exp);
b99bd4ef 3526
c19d1205
ZW
3527 if (exp.X_op != O_symbol)
3528 emit_expr (&exp, (unsigned int) nbytes);
3529 else
3530 {
3531 char *before_reloc = input_line_pointer;
3532 reloc = parse_reloc (&input_line_pointer);
3533 if (reloc == -1)
3534 {
3535 as_bad (_("unrecognized relocation suffix"));
3536 ignore_rest_of_line ();
3537 return;
3538 }
3539 else if (reloc == BFD_RELOC_UNUSED)
3540 emit_expr (&exp, (unsigned int) nbytes);
3541 else
3542 {
21d799b5 3543 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3544 bfd_reloc_type_lookup (stdoutput,
3545 (bfd_reloc_code_real_type) reloc);
c19d1205 3546 int size = bfd_get_reloc_size (howto);
b99bd4ef 3547
2fc8bdac
ZW
3548 if (reloc == BFD_RELOC_ARM_PLT32)
3549 {
3550 as_bad (_("(plt) is only valid on branch targets"));
3551 reloc = BFD_RELOC_UNUSED;
3552 size = 0;
3553 }
3554
c19d1205 3555 if (size > nbytes)
2fc8bdac 3556 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3557 howto->name, nbytes);
3558 else
3559 {
3560 /* We've parsed an expression stopping at O_symbol.
3561 But there may be more expression left now that we
3562 have parsed the relocation marker. Parse it again.
3563 XXX Surely there is a cleaner way to do this. */
3564 char *p = input_line_pointer;
3565 int offset;
21d799b5 3566 char *save_buf = (char *) alloca (input_line_pointer - base);
c19d1205
ZW
3567 memcpy (save_buf, base, input_line_pointer - base);
3568 memmove (base + (input_line_pointer - before_reloc),
3569 base, before_reloc - base);
3570
3571 input_line_pointer = base + (input_line_pointer-before_reloc);
3572 expression (&exp);
3573 memcpy (base, save_buf, p - base);
3574
3575 offset = nbytes - size;
4b1a927e
AM
3576 p = frag_more (nbytes);
3577 memset (p, 0, nbytes);
c19d1205 3578 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3579 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
c19d1205
ZW
3580 }
3581 }
3582 }
b99bd4ef 3583 }
c19d1205 3584 while (*input_line_pointer++ == ',');
b99bd4ef 3585
c19d1205
ZW
3586 /* Put terminator back into stream. */
3587 input_line_pointer --;
3588 demand_empty_rest_of_line ();
b99bd4ef
NC
3589}
3590
c921be7d
NC
3591/* Emit an expression containing a 32-bit thumb instruction.
3592 Implementation based on put_thumb32_insn. */
3593
3594static void
3595emit_thumb32_expr (expressionS * exp)
3596{
3597 expressionS exp_high = *exp;
3598
3599 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3600 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3601 exp->X_add_number &= 0xffff;
3602 emit_expr (exp, (unsigned int) THUMB_SIZE);
3603}
3604
3605/* Guess the instruction size based on the opcode. */
3606
3607static int
3608thumb_insn_size (int opcode)
3609{
3610 if ((unsigned int) opcode < 0xe800u)
3611 return 2;
3612 else if ((unsigned int) opcode >= 0xe8000000u)
3613 return 4;
3614 else
3615 return 0;
3616}
3617
3618static bfd_boolean
3619emit_insn (expressionS *exp, int nbytes)
3620{
3621 int size = 0;
3622
3623 if (exp->X_op == O_constant)
3624 {
3625 size = nbytes;
3626
3627 if (size == 0)
3628 size = thumb_insn_size (exp->X_add_number);
3629
3630 if (size != 0)
3631 {
3632 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3633 {
3634 as_bad (_(".inst.n operand too big. "\
3635 "Use .inst.w instead"));
3636 size = 0;
3637 }
3638 else
3639 {
3640 if (now_it.state == AUTOMATIC_IT_BLOCK)
3641 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3642 else
3643 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3644
3645 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3646 emit_thumb32_expr (exp);
3647 else
3648 emit_expr (exp, (unsigned int) size);
3649
3650 it_fsm_post_encode ();
3651 }
3652 }
3653 else
3654 as_bad (_("cannot determine Thumb instruction size. " \
3655 "Use .inst.n/.inst.w instead"));
3656 }
3657 else
3658 as_bad (_("constant expression required"));
3659
3660 return (size != 0);
3661}
3662
3663/* Like s_arm_elf_cons but do not use md_cons_align and
3664 set the mapping state to MAP_ARM/MAP_THUMB. */
3665
3666static void
3667s_arm_elf_inst (int nbytes)
3668{
3669 if (is_it_end_of_statement ())
3670 {
3671 demand_empty_rest_of_line ();
3672 return;
3673 }
3674
3675 /* Calling mapping_state () here will not change ARM/THUMB,
3676 but will ensure not to be in DATA state. */
3677
3678 if (thumb_mode)
3679 mapping_state (MAP_THUMB);
3680 else
3681 {
3682 if (nbytes != 0)
3683 {
3684 as_bad (_("width suffixes are invalid in ARM mode"));
3685 ignore_rest_of_line ();
3686 return;
3687 }
3688
3689 nbytes = 4;
3690
3691 mapping_state (MAP_ARM);
3692 }
3693
3694 do
3695 {
3696 expressionS exp;
3697
3698 expression (& exp);
3699
3700 if (! emit_insn (& exp, nbytes))
3701 {
3702 ignore_rest_of_line ();
3703 return;
3704 }
3705 }
3706 while (*input_line_pointer++ == ',');
3707
3708 /* Put terminator back into stream. */
3709 input_line_pointer --;
3710 demand_empty_rest_of_line ();
3711}
b99bd4ef 3712
c19d1205 3713/* Parse a .rel31 directive. */
b99bd4ef 3714
c19d1205
ZW
3715static void
3716s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3717{
3718 expressionS exp;
3719 char *p;
3720 valueT highbit;
b99bd4ef 3721
c19d1205
ZW
3722 highbit = 0;
3723 if (*input_line_pointer == '1')
3724 highbit = 0x80000000;
3725 else if (*input_line_pointer != '0')
3726 as_bad (_("expected 0 or 1"));
b99bd4ef 3727
c19d1205
ZW
3728 input_line_pointer++;
3729 if (*input_line_pointer != ',')
3730 as_bad (_("missing comma"));
3731 input_line_pointer++;
b99bd4ef 3732
c19d1205
ZW
3733#ifdef md_flush_pending_output
3734 md_flush_pending_output ();
3735#endif
b99bd4ef 3736
c19d1205
ZW
3737#ifdef md_cons_align
3738 md_cons_align (4);
3739#endif
b99bd4ef 3740
c19d1205 3741 mapping_state (MAP_DATA);
b99bd4ef 3742
c19d1205 3743 expression (&exp);
b99bd4ef 3744
c19d1205
ZW
3745 p = frag_more (4);
3746 md_number_to_chars (p, highbit, 4);
3747 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3748 BFD_RELOC_ARM_PREL31);
b99bd4ef 3749
c19d1205 3750 demand_empty_rest_of_line ();
b99bd4ef
NC
3751}
3752
c19d1205 3753/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3754
c19d1205 3755/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3756
c19d1205
ZW
3757static void
3758s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3759{
3760 demand_empty_rest_of_line ();
921e5f0a
PB
3761 if (unwind.proc_start)
3762 {
c921be7d 3763 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3764 return;
3765 }
3766
c19d1205
ZW
3767 /* Mark the start of the function. */
3768 unwind.proc_start = expr_build_dot ();
b99bd4ef 3769
c19d1205
ZW
3770 /* Reset the rest of the unwind info. */
3771 unwind.opcode_count = 0;
3772 unwind.table_entry = NULL;
3773 unwind.personality_routine = NULL;
3774 unwind.personality_index = -1;
3775 unwind.frame_size = 0;
3776 unwind.fp_offset = 0;
fdfde340 3777 unwind.fp_reg = REG_SP;
c19d1205
ZW
3778 unwind.fp_used = 0;
3779 unwind.sp_restored = 0;
3780}
b99bd4ef 3781
b99bd4ef 3782
c19d1205
ZW
3783/* Parse a handlerdata directive. Creates the exception handling table entry
3784 for the function. */
b99bd4ef 3785
c19d1205
ZW
3786static void
3787s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3788{
3789 demand_empty_rest_of_line ();
921e5f0a 3790 if (!unwind.proc_start)
c921be7d 3791 as_bad (MISSING_FNSTART);
921e5f0a 3792
c19d1205 3793 if (unwind.table_entry)
6decc662 3794 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3795
c19d1205
ZW
3796 create_unwind_entry (1);
3797}
a737bd4d 3798
c19d1205 3799/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3800
c19d1205
ZW
3801static void
3802s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3803{
3804 long where;
3805 char *ptr;
3806 valueT val;
940b5ce0 3807 unsigned int marked_pr_dependency;
f02232aa 3808
c19d1205 3809 demand_empty_rest_of_line ();
f02232aa 3810
921e5f0a
PB
3811 if (!unwind.proc_start)
3812 {
c921be7d 3813 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3814 return;
3815 }
3816
c19d1205
ZW
3817 /* Add eh table entry. */
3818 if (unwind.table_entry == NULL)
3819 val = create_unwind_entry (0);
3820 else
3821 val = 0;
f02232aa 3822
c19d1205
ZW
3823 /* Add index table entry. This is two words. */
3824 start_unwind_section (unwind.saved_seg, 1);
3825 frag_align (2, 0, 0);
3826 record_alignment (now_seg, 2);
b99bd4ef 3827
c19d1205 3828 ptr = frag_more (8);
5011093d 3829 memset (ptr, 0, 8);
c19d1205 3830 where = frag_now_fix () - 8;
f02232aa 3831
c19d1205
ZW
3832 /* Self relative offset of the function start. */
3833 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3834 BFD_RELOC_ARM_PREL31);
f02232aa 3835
c19d1205
ZW
3836 /* Indicate dependency on EHABI-defined personality routines to the
3837 linker, if it hasn't been done already. */
940b5ce0
DJ
3838 marked_pr_dependency
3839 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3840 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3841 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3842 {
5f4273c7
NC
3843 static const char *const name[] =
3844 {
3845 "__aeabi_unwind_cpp_pr0",
3846 "__aeabi_unwind_cpp_pr1",
3847 "__aeabi_unwind_cpp_pr2"
3848 };
c19d1205
ZW
3849 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3850 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3851 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3852 |= 1 << unwind.personality_index;
c19d1205 3853 }
f02232aa 3854
c19d1205
ZW
3855 if (val)
3856 /* Inline exception table entry. */
3857 md_number_to_chars (ptr + 4, val, 4);
3858 else
3859 /* Self relative offset of the table entry. */
3860 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3861 BFD_RELOC_ARM_PREL31);
f02232aa 3862
c19d1205
ZW
3863 /* Restore the original section. */
3864 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3865
3866 unwind.proc_start = NULL;
c19d1205 3867}
f02232aa 3868
f02232aa 3869
c19d1205 3870/* Parse an unwind_cantunwind directive. */
b99bd4ef 3871
c19d1205
ZW
3872static void
3873s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3874{
3875 demand_empty_rest_of_line ();
921e5f0a 3876 if (!unwind.proc_start)
c921be7d 3877 as_bad (MISSING_FNSTART);
921e5f0a 3878
c19d1205
ZW
3879 if (unwind.personality_routine || unwind.personality_index != -1)
3880 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3881
c19d1205
ZW
3882 unwind.personality_index = -2;
3883}
b99bd4ef 3884
b99bd4ef 3885
c19d1205 3886/* Parse a personalityindex directive. */
b99bd4ef 3887
c19d1205
ZW
3888static void
3889s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3890{
3891 expressionS exp;
b99bd4ef 3892
921e5f0a 3893 if (!unwind.proc_start)
c921be7d 3894 as_bad (MISSING_FNSTART);
921e5f0a 3895
c19d1205
ZW
3896 if (unwind.personality_routine || unwind.personality_index != -1)
3897 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3898
c19d1205 3899 expression (&exp);
b99bd4ef 3900
c19d1205
ZW
3901 if (exp.X_op != O_constant
3902 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3903 {
c19d1205
ZW
3904 as_bad (_("bad personality routine number"));
3905 ignore_rest_of_line ();
3906 return;
b99bd4ef
NC
3907 }
3908
c19d1205 3909 unwind.personality_index = exp.X_add_number;
b99bd4ef 3910
c19d1205
ZW
3911 demand_empty_rest_of_line ();
3912}
e16bb312 3913
e16bb312 3914
c19d1205 3915/* Parse a personality directive. */
e16bb312 3916
c19d1205
ZW
3917static void
3918s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3919{
3920 char *name, *p, c;
a737bd4d 3921
921e5f0a 3922 if (!unwind.proc_start)
c921be7d 3923 as_bad (MISSING_FNSTART);
921e5f0a 3924
c19d1205
ZW
3925 if (unwind.personality_routine || unwind.personality_index != -1)
3926 as_bad (_("duplicate .personality directive"));
a737bd4d 3927
c19d1205
ZW
3928 name = input_line_pointer;
3929 c = get_symbol_end ();
3930 p = input_line_pointer;
3931 unwind.personality_routine = symbol_find_or_make (name);
3932 *p = c;
3933 demand_empty_rest_of_line ();
3934}
e16bb312 3935
e16bb312 3936
c19d1205 3937/* Parse a directive saving core registers. */
e16bb312 3938
c19d1205
ZW
3939static void
3940s_arm_unwind_save_core (void)
e16bb312 3941{
c19d1205
ZW
3942 valueT op;
3943 long range;
3944 int n;
e16bb312 3945
c19d1205
ZW
3946 range = parse_reg_list (&input_line_pointer);
3947 if (range == FAIL)
e16bb312 3948 {
c19d1205
ZW
3949 as_bad (_("expected register list"));
3950 ignore_rest_of_line ();
3951 return;
3952 }
e16bb312 3953
c19d1205 3954 demand_empty_rest_of_line ();
e16bb312 3955
c19d1205
ZW
3956 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3957 into .unwind_save {..., sp...}. We aren't bothered about the value of
3958 ip because it is clobbered by calls. */
3959 if (unwind.sp_restored && unwind.fp_reg == 12
3960 && (range & 0x3000) == 0x1000)
3961 {
3962 unwind.opcode_count--;
3963 unwind.sp_restored = 0;
3964 range = (range | 0x2000) & ~0x1000;
3965 unwind.pending_offset = 0;
3966 }
e16bb312 3967
01ae4198
DJ
3968 /* Pop r4-r15. */
3969 if (range & 0xfff0)
c19d1205 3970 {
01ae4198
DJ
3971 /* See if we can use the short opcodes. These pop a block of up to 8
3972 registers starting with r4, plus maybe r14. */
3973 for (n = 0; n < 8; n++)
3974 {
3975 /* Break at the first non-saved register. */
3976 if ((range & (1 << (n + 4))) == 0)
3977 break;
3978 }
3979 /* See if there are any other bits set. */
3980 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3981 {
3982 /* Use the long form. */
3983 op = 0x8000 | ((range >> 4) & 0xfff);
3984 add_unwind_opcode (op, 2);
3985 }
0dd132b6 3986 else
01ae4198
DJ
3987 {
3988 /* Use the short form. */
3989 if (range & 0x4000)
3990 op = 0xa8; /* Pop r14. */
3991 else
3992 op = 0xa0; /* Do not pop r14. */
3993 op |= (n - 1);
3994 add_unwind_opcode (op, 1);
3995 }
c19d1205 3996 }
0dd132b6 3997
c19d1205
ZW
3998 /* Pop r0-r3. */
3999 if (range & 0xf)
4000 {
4001 op = 0xb100 | (range & 0xf);
4002 add_unwind_opcode (op, 2);
0dd132b6
NC
4003 }
4004
c19d1205
ZW
4005 /* Record the number of bytes pushed. */
4006 for (n = 0; n < 16; n++)
4007 {
4008 if (range & (1 << n))
4009 unwind.frame_size += 4;
4010 }
0dd132b6
NC
4011}
4012
c19d1205
ZW
4013
4014/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4015
4016static void
c19d1205 4017s_arm_unwind_save_fpa (int reg)
b99bd4ef 4018{
c19d1205
ZW
4019 expressionS exp;
4020 int num_regs;
4021 valueT op;
b99bd4ef 4022
c19d1205
ZW
4023 /* Get Number of registers to transfer. */
4024 if (skip_past_comma (&input_line_pointer) != FAIL)
4025 expression (&exp);
4026 else
4027 exp.X_op = O_illegal;
b99bd4ef 4028
c19d1205 4029 if (exp.X_op != O_constant)
b99bd4ef 4030 {
c19d1205
ZW
4031 as_bad (_("expected , <constant>"));
4032 ignore_rest_of_line ();
b99bd4ef
NC
4033 return;
4034 }
4035
c19d1205
ZW
4036 num_regs = exp.X_add_number;
4037
4038 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4039 {
c19d1205
ZW
4040 as_bad (_("number of registers must be in the range [1:4]"));
4041 ignore_rest_of_line ();
b99bd4ef
NC
4042 return;
4043 }
4044
c19d1205 4045 demand_empty_rest_of_line ();
b99bd4ef 4046
c19d1205
ZW
4047 if (reg == 4)
4048 {
4049 /* Short form. */
4050 op = 0xb4 | (num_regs - 1);
4051 add_unwind_opcode (op, 1);
4052 }
b99bd4ef
NC
4053 else
4054 {
c19d1205
ZW
4055 /* Long form. */
4056 op = 0xc800 | (reg << 4) | (num_regs - 1);
4057 add_unwind_opcode (op, 2);
b99bd4ef 4058 }
c19d1205 4059 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4060}
4061
c19d1205 4062
fa073d69
MS
4063/* Parse a directive saving VFP registers for ARMv6 and above. */
4064
4065static void
4066s_arm_unwind_save_vfp_armv6 (void)
4067{
4068 int count;
4069 unsigned int start;
4070 valueT op;
4071 int num_vfpv3_regs = 0;
4072 int num_regs_below_16;
4073
4074 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4075 if (count == FAIL)
4076 {
4077 as_bad (_("expected register list"));
4078 ignore_rest_of_line ();
4079 return;
4080 }
4081
4082 demand_empty_rest_of_line ();
4083
4084 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4085 than FSTMX/FLDMX-style ones). */
4086
4087 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4088 if (start >= 16)
4089 num_vfpv3_regs = count;
4090 else if (start + count > 16)
4091 num_vfpv3_regs = start + count - 16;
4092
4093 if (num_vfpv3_regs > 0)
4094 {
4095 int start_offset = start > 16 ? start - 16 : 0;
4096 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4097 add_unwind_opcode (op, 2);
4098 }
4099
4100 /* Generate opcode for registers numbered in the range 0 .. 15. */
4101 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4102 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4103 if (num_regs_below_16 > 0)
4104 {
4105 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4106 add_unwind_opcode (op, 2);
4107 }
4108
4109 unwind.frame_size += count * 8;
4110}
4111
4112
4113/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4114
4115static void
c19d1205 4116s_arm_unwind_save_vfp (void)
b99bd4ef 4117{
c19d1205 4118 int count;
ca3f61f7 4119 unsigned int reg;
c19d1205 4120 valueT op;
b99bd4ef 4121
5287ad62 4122 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4123 if (count == FAIL)
b99bd4ef 4124 {
c19d1205
ZW
4125 as_bad (_("expected register list"));
4126 ignore_rest_of_line ();
b99bd4ef
NC
4127 return;
4128 }
4129
c19d1205 4130 demand_empty_rest_of_line ();
b99bd4ef 4131
c19d1205 4132 if (reg == 8)
b99bd4ef 4133 {
c19d1205
ZW
4134 /* Short form. */
4135 op = 0xb8 | (count - 1);
4136 add_unwind_opcode (op, 1);
b99bd4ef 4137 }
c19d1205 4138 else
b99bd4ef 4139 {
c19d1205
ZW
4140 /* Long form. */
4141 op = 0xb300 | (reg << 4) | (count - 1);
4142 add_unwind_opcode (op, 2);
b99bd4ef 4143 }
c19d1205
ZW
4144 unwind.frame_size += count * 8 + 4;
4145}
b99bd4ef 4146
b99bd4ef 4147
c19d1205
ZW
4148/* Parse a directive saving iWMMXt data registers. */
4149
4150static void
4151s_arm_unwind_save_mmxwr (void)
4152{
4153 int reg;
4154 int hi_reg;
4155 int i;
4156 unsigned mask = 0;
4157 valueT op;
b99bd4ef 4158
c19d1205
ZW
4159 if (*input_line_pointer == '{')
4160 input_line_pointer++;
b99bd4ef 4161
c19d1205 4162 do
b99bd4ef 4163 {
dcbf9037 4164 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4165
c19d1205 4166 if (reg == FAIL)
b99bd4ef 4167 {
9b7132d3 4168 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4169 goto error;
b99bd4ef
NC
4170 }
4171
c19d1205
ZW
4172 if (mask >> reg)
4173 as_tsktsk (_("register list not in ascending order"));
4174 mask |= 1 << reg;
b99bd4ef 4175
c19d1205
ZW
4176 if (*input_line_pointer == '-')
4177 {
4178 input_line_pointer++;
dcbf9037 4179 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4180 if (hi_reg == FAIL)
4181 {
9b7132d3 4182 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4183 goto error;
4184 }
4185 else if (reg >= hi_reg)
4186 {
4187 as_bad (_("bad register range"));
4188 goto error;
4189 }
4190 for (; reg < hi_reg; reg++)
4191 mask |= 1 << reg;
4192 }
4193 }
4194 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4195
d996d970 4196 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4197
c19d1205 4198 demand_empty_rest_of_line ();
b99bd4ef 4199
708587a4 4200 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4201 the list. */
4202 flush_pending_unwind ();
b99bd4ef 4203
c19d1205 4204 for (i = 0; i < 16; i++)
b99bd4ef 4205 {
c19d1205
ZW
4206 if (mask & (1 << i))
4207 unwind.frame_size += 8;
b99bd4ef
NC
4208 }
4209
c19d1205
ZW
4210 /* Attempt to combine with a previous opcode. We do this because gcc
4211 likes to output separate unwind directives for a single block of
4212 registers. */
4213 if (unwind.opcode_count > 0)
b99bd4ef 4214 {
c19d1205
ZW
4215 i = unwind.opcodes[unwind.opcode_count - 1];
4216 if ((i & 0xf8) == 0xc0)
4217 {
4218 i &= 7;
4219 /* Only merge if the blocks are contiguous. */
4220 if (i < 6)
4221 {
4222 if ((mask & 0xfe00) == (1 << 9))
4223 {
4224 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4225 unwind.opcode_count--;
4226 }
4227 }
4228 else if (i == 6 && unwind.opcode_count >= 2)
4229 {
4230 i = unwind.opcodes[unwind.opcode_count - 2];
4231 reg = i >> 4;
4232 i &= 0xf;
b99bd4ef 4233
c19d1205
ZW
4234 op = 0xffff << (reg - 1);
4235 if (reg > 0
87a1fd79 4236 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4237 {
4238 op = (1 << (reg + i + 1)) - 1;
4239 op &= ~((1 << reg) - 1);
4240 mask |= op;
4241 unwind.opcode_count -= 2;
4242 }
4243 }
4244 }
b99bd4ef
NC
4245 }
4246
c19d1205
ZW
4247 hi_reg = 15;
4248 /* We want to generate opcodes in the order the registers have been
4249 saved, ie. descending order. */
4250 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4251 {
c19d1205
ZW
4252 /* Save registers in blocks. */
4253 if (reg < 0
4254 || !(mask & (1 << reg)))
4255 {
4256 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4257 preceding block. */
c19d1205
ZW
4258 if (reg != hi_reg)
4259 {
4260 if (reg == 9)
4261 {
4262 /* Short form. */
4263 op = 0xc0 | (hi_reg - 10);
4264 add_unwind_opcode (op, 1);
4265 }
4266 else
4267 {
4268 /* Long form. */
4269 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4270 add_unwind_opcode (op, 2);
4271 }
4272 }
4273 hi_reg = reg - 1;
4274 }
b99bd4ef
NC
4275 }
4276
c19d1205
ZW
4277 return;
4278error:
4279 ignore_rest_of_line ();
b99bd4ef
NC
4280}
4281
4282static void
c19d1205 4283s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4284{
c19d1205
ZW
4285 int reg;
4286 int hi_reg;
4287 unsigned mask = 0;
4288 valueT op;
b99bd4ef 4289
c19d1205
ZW
4290 if (*input_line_pointer == '{')
4291 input_line_pointer++;
b99bd4ef 4292
477330fc
RM
4293 skip_whitespace (input_line_pointer);
4294
c19d1205 4295 do
b99bd4ef 4296 {
dcbf9037 4297 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4298
c19d1205
ZW
4299 if (reg == FAIL)
4300 {
9b7132d3 4301 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4302 goto error;
4303 }
b99bd4ef 4304
c19d1205
ZW
4305 reg -= 8;
4306 if (mask >> reg)
4307 as_tsktsk (_("register list not in ascending order"));
4308 mask |= 1 << reg;
b99bd4ef 4309
c19d1205
ZW
4310 if (*input_line_pointer == '-')
4311 {
4312 input_line_pointer++;
dcbf9037 4313 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4314 if (hi_reg == FAIL)
4315 {
9b7132d3 4316 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4317 goto error;
4318 }
4319 else if (reg >= hi_reg)
4320 {
4321 as_bad (_("bad register range"));
4322 goto error;
4323 }
4324 for (; reg < hi_reg; reg++)
4325 mask |= 1 << reg;
4326 }
b99bd4ef 4327 }
c19d1205 4328 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4329
d996d970 4330 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4331
c19d1205
ZW
4332 demand_empty_rest_of_line ();
4333
708587a4 4334 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4335 the list. */
4336 flush_pending_unwind ();
b99bd4ef 4337
c19d1205 4338 for (reg = 0; reg < 16; reg++)
b99bd4ef 4339 {
c19d1205
ZW
4340 if (mask & (1 << reg))
4341 unwind.frame_size += 4;
b99bd4ef 4342 }
c19d1205
ZW
4343 op = 0xc700 | mask;
4344 add_unwind_opcode (op, 2);
4345 return;
4346error:
4347 ignore_rest_of_line ();
b99bd4ef
NC
4348}
4349
c19d1205 4350
fa073d69
MS
4351/* Parse an unwind_save directive.
4352 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4353
b99bd4ef 4354static void
fa073d69 4355s_arm_unwind_save (int arch_v6)
b99bd4ef 4356{
c19d1205
ZW
4357 char *peek;
4358 struct reg_entry *reg;
4359 bfd_boolean had_brace = FALSE;
b99bd4ef 4360
921e5f0a 4361 if (!unwind.proc_start)
c921be7d 4362 as_bad (MISSING_FNSTART);
921e5f0a 4363
c19d1205
ZW
4364 /* Figure out what sort of save we have. */
4365 peek = input_line_pointer;
b99bd4ef 4366
c19d1205 4367 if (*peek == '{')
b99bd4ef 4368 {
c19d1205
ZW
4369 had_brace = TRUE;
4370 peek++;
b99bd4ef
NC
4371 }
4372
c19d1205 4373 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4374
c19d1205 4375 if (!reg)
b99bd4ef 4376 {
c19d1205
ZW
4377 as_bad (_("register expected"));
4378 ignore_rest_of_line ();
b99bd4ef
NC
4379 return;
4380 }
4381
c19d1205 4382 switch (reg->type)
b99bd4ef 4383 {
c19d1205
ZW
4384 case REG_TYPE_FN:
4385 if (had_brace)
4386 {
4387 as_bad (_("FPA .unwind_save does not take a register list"));
4388 ignore_rest_of_line ();
4389 return;
4390 }
93ac2687 4391 input_line_pointer = peek;
c19d1205 4392 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4393 return;
c19d1205 4394
1f5afe1c
NC
4395 case REG_TYPE_RN:
4396 s_arm_unwind_save_core ();
4397 return;
4398
fa073d69
MS
4399 case REG_TYPE_VFD:
4400 if (arch_v6)
477330fc 4401 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4402 else
477330fc 4403 s_arm_unwind_save_vfp ();
fa073d69 4404 return;
1f5afe1c
NC
4405
4406 case REG_TYPE_MMXWR:
4407 s_arm_unwind_save_mmxwr ();
4408 return;
4409
4410 case REG_TYPE_MMXWCG:
4411 s_arm_unwind_save_mmxwcg ();
4412 return;
c19d1205
ZW
4413
4414 default:
4415 as_bad (_(".unwind_save does not support this kind of register"));
4416 ignore_rest_of_line ();
b99bd4ef 4417 }
c19d1205 4418}
b99bd4ef 4419
b99bd4ef 4420
c19d1205
ZW
4421/* Parse an unwind_movsp directive. */
4422
4423static void
4424s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4425{
4426 int reg;
4427 valueT op;
4fa3602b 4428 int offset;
c19d1205 4429
921e5f0a 4430 if (!unwind.proc_start)
c921be7d 4431 as_bad (MISSING_FNSTART);
921e5f0a 4432
dcbf9037 4433 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4434 if (reg == FAIL)
b99bd4ef 4435 {
9b7132d3 4436 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4437 ignore_rest_of_line ();
b99bd4ef
NC
4438 return;
4439 }
4fa3602b
PB
4440
4441 /* Optional constant. */
4442 if (skip_past_comma (&input_line_pointer) != FAIL)
4443 {
4444 if (immediate_for_directive (&offset) == FAIL)
4445 return;
4446 }
4447 else
4448 offset = 0;
4449
c19d1205 4450 demand_empty_rest_of_line ();
b99bd4ef 4451
c19d1205 4452 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4453 {
c19d1205 4454 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4455 return;
4456 }
4457
c19d1205
ZW
4458 if (unwind.fp_reg != REG_SP)
4459 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4460
c19d1205
ZW
4461 /* Generate opcode to restore the value. */
4462 op = 0x90 | reg;
4463 add_unwind_opcode (op, 1);
4464
4465 /* Record the information for later. */
4466 unwind.fp_reg = reg;
4fa3602b 4467 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4468 unwind.sp_restored = 1;
b05fe5cf
ZW
4469}
4470
c19d1205
ZW
4471/* Parse an unwind_pad directive. */
4472
b05fe5cf 4473static void
c19d1205 4474s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4475{
c19d1205 4476 int offset;
b05fe5cf 4477
921e5f0a 4478 if (!unwind.proc_start)
c921be7d 4479 as_bad (MISSING_FNSTART);
921e5f0a 4480
c19d1205
ZW
4481 if (immediate_for_directive (&offset) == FAIL)
4482 return;
b99bd4ef 4483
c19d1205
ZW
4484 if (offset & 3)
4485 {
4486 as_bad (_("stack increment must be multiple of 4"));
4487 ignore_rest_of_line ();
4488 return;
4489 }
b99bd4ef 4490
c19d1205
ZW
4491 /* Don't generate any opcodes, just record the details for later. */
4492 unwind.frame_size += offset;
4493 unwind.pending_offset += offset;
4494
4495 demand_empty_rest_of_line ();
4496}
4497
4498/* Parse an unwind_setfp directive. */
4499
4500static void
4501s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4502{
c19d1205
ZW
4503 int sp_reg;
4504 int fp_reg;
4505 int offset;
4506
921e5f0a 4507 if (!unwind.proc_start)
c921be7d 4508 as_bad (MISSING_FNSTART);
921e5f0a 4509
dcbf9037 4510 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4511 if (skip_past_comma (&input_line_pointer) == FAIL)
4512 sp_reg = FAIL;
4513 else
dcbf9037 4514 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4515
c19d1205
ZW
4516 if (fp_reg == FAIL || sp_reg == FAIL)
4517 {
4518 as_bad (_("expected <reg>, <reg>"));
4519 ignore_rest_of_line ();
4520 return;
4521 }
b99bd4ef 4522
c19d1205
ZW
4523 /* Optional constant. */
4524 if (skip_past_comma (&input_line_pointer) != FAIL)
4525 {
4526 if (immediate_for_directive (&offset) == FAIL)
4527 return;
4528 }
4529 else
4530 offset = 0;
a737bd4d 4531
c19d1205 4532 demand_empty_rest_of_line ();
a737bd4d 4533
fdfde340 4534 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4535 {
c19d1205
ZW
4536 as_bad (_("register must be either sp or set by a previous"
4537 "unwind_movsp directive"));
4538 return;
a737bd4d
NC
4539 }
4540
c19d1205
ZW
4541 /* Don't generate any opcodes, just record the information for later. */
4542 unwind.fp_reg = fp_reg;
4543 unwind.fp_used = 1;
fdfde340 4544 if (sp_reg == REG_SP)
c19d1205
ZW
4545 unwind.fp_offset = unwind.frame_size - offset;
4546 else
4547 unwind.fp_offset -= offset;
a737bd4d
NC
4548}
4549
c19d1205
ZW
4550/* Parse an unwind_raw directive. */
4551
4552static void
4553s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4554{
c19d1205 4555 expressionS exp;
708587a4 4556 /* This is an arbitrary limit. */
c19d1205
ZW
4557 unsigned char op[16];
4558 int count;
a737bd4d 4559
921e5f0a 4560 if (!unwind.proc_start)
c921be7d 4561 as_bad (MISSING_FNSTART);
921e5f0a 4562
c19d1205
ZW
4563 expression (&exp);
4564 if (exp.X_op == O_constant
4565 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4566 {
c19d1205
ZW
4567 unwind.frame_size += exp.X_add_number;
4568 expression (&exp);
4569 }
4570 else
4571 exp.X_op = O_illegal;
a737bd4d 4572
c19d1205
ZW
4573 if (exp.X_op != O_constant)
4574 {
4575 as_bad (_("expected <offset>, <opcode>"));
4576 ignore_rest_of_line ();
4577 return;
4578 }
a737bd4d 4579
c19d1205 4580 count = 0;
a737bd4d 4581
c19d1205
ZW
4582 /* Parse the opcode. */
4583 for (;;)
4584 {
4585 if (count >= 16)
4586 {
4587 as_bad (_("unwind opcode too long"));
4588 ignore_rest_of_line ();
a737bd4d 4589 }
c19d1205 4590 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4591 {
c19d1205
ZW
4592 as_bad (_("invalid unwind opcode"));
4593 ignore_rest_of_line ();
4594 return;
a737bd4d 4595 }
c19d1205 4596 op[count++] = exp.X_add_number;
a737bd4d 4597
c19d1205
ZW
4598 /* Parse the next byte. */
4599 if (skip_past_comma (&input_line_pointer) == FAIL)
4600 break;
a737bd4d 4601
c19d1205
ZW
4602 expression (&exp);
4603 }
b99bd4ef 4604
c19d1205
ZW
4605 /* Add the opcode bytes in reverse order. */
4606 while (count--)
4607 add_unwind_opcode (op[count], 1);
b99bd4ef 4608
c19d1205 4609 demand_empty_rest_of_line ();
b99bd4ef 4610}
ee065d83
PB
4611
4612
4613/* Parse a .eabi_attribute directive. */
4614
4615static void
4616s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4617{
0420f52b 4618 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4619
4620 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4621 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4622}
4623
0855e32b
NS
4624/* Emit a tls fix for the symbol. */
4625
4626static void
4627s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4628{
4629 char *p;
4630 expressionS exp;
4631#ifdef md_flush_pending_output
4632 md_flush_pending_output ();
4633#endif
4634
4635#ifdef md_cons_align
4636 md_cons_align (4);
4637#endif
4638
4639 /* Since we're just labelling the code, there's no need to define a
4640 mapping symbol. */
4641 expression (&exp);
4642 p = obstack_next_free (&frchain_now->frch_obstack);
4643 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4644 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4645 : BFD_RELOC_ARM_TLS_DESCSEQ);
4646}
cdf9ccec 4647#endif /* OBJ_ELF */
0855e32b 4648
ee065d83 4649static void s_arm_arch (int);
7a1d4c38 4650static void s_arm_object_arch (int);
ee065d83
PB
4651static void s_arm_cpu (int);
4652static void s_arm_fpu (int);
69133863 4653static void s_arm_arch_extension (int);
b99bd4ef 4654
f0927246
NC
4655#ifdef TE_PE
4656
4657static void
5f4273c7 4658pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4659{
4660 expressionS exp;
4661
4662 do
4663 {
4664 expression (&exp);
4665 if (exp.X_op == O_symbol)
4666 exp.X_op = O_secrel;
4667
4668 emit_expr (&exp, 4);
4669 }
4670 while (*input_line_pointer++ == ',');
4671
4672 input_line_pointer--;
4673 demand_empty_rest_of_line ();
4674}
4675#endif /* TE_PE */
4676
c19d1205
ZW
4677/* This table describes all the machine specific pseudo-ops the assembler
4678 has to support. The fields are:
4679 pseudo-op name without dot
4680 function to call to execute this pseudo-op
4681 Integer arg to pass to the function. */
b99bd4ef 4682
c19d1205 4683const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4684{
c19d1205
ZW
4685 /* Never called because '.req' does not start a line. */
4686 { "req", s_req, 0 },
dcbf9037
JB
4687 /* Following two are likewise never called. */
4688 { "dn", s_dn, 0 },
4689 { "qn", s_qn, 0 },
c19d1205
ZW
4690 { "unreq", s_unreq, 0 },
4691 { "bss", s_bss, 0 },
4692 { "align", s_align, 0 },
4693 { "arm", s_arm, 0 },
4694 { "thumb", s_thumb, 0 },
4695 { "code", s_code, 0 },
4696 { "force_thumb", s_force_thumb, 0 },
4697 { "thumb_func", s_thumb_func, 0 },
4698 { "thumb_set", s_thumb_set, 0 },
4699 { "even", s_even, 0 },
4700 { "ltorg", s_ltorg, 0 },
4701 { "pool", s_ltorg, 0 },
4702 { "syntax", s_syntax, 0 },
8463be01
PB
4703 { "cpu", s_arm_cpu, 0 },
4704 { "arch", s_arm_arch, 0 },
7a1d4c38 4705 { "object_arch", s_arm_object_arch, 0 },
8463be01 4706 { "fpu", s_arm_fpu, 0 },
69133863 4707 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4708#ifdef OBJ_ELF
c921be7d
NC
4709 { "word", s_arm_elf_cons, 4 },
4710 { "long", s_arm_elf_cons, 4 },
4711 { "inst.n", s_arm_elf_inst, 2 },
4712 { "inst.w", s_arm_elf_inst, 4 },
4713 { "inst", s_arm_elf_inst, 0 },
4714 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4715 { "fnstart", s_arm_unwind_fnstart, 0 },
4716 { "fnend", s_arm_unwind_fnend, 0 },
4717 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4718 { "personality", s_arm_unwind_personality, 0 },
4719 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4720 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4721 { "save", s_arm_unwind_save, 0 },
fa073d69 4722 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4723 { "movsp", s_arm_unwind_movsp, 0 },
4724 { "pad", s_arm_unwind_pad, 0 },
4725 { "setfp", s_arm_unwind_setfp, 0 },
4726 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4727 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4728 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4729#else
4730 { "word", cons, 4},
f0927246
NC
4731
4732 /* These are used for dwarf. */
4733 {"2byte", cons, 2},
4734 {"4byte", cons, 4},
4735 {"8byte", cons, 8},
4736 /* These are used for dwarf2. */
4737 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4738 { "loc", dwarf2_directive_loc, 0 },
4739 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4740#endif
4741 { "extend", float_cons, 'x' },
4742 { "ldouble", float_cons, 'x' },
4743 { "packed", float_cons, 'p' },
f0927246
NC
4744#ifdef TE_PE
4745 {"secrel32", pe_directive_secrel, 0},
4746#endif
2e6976a8
DG
4747
4748 /* These are for compatibility with CodeComposer Studio. */
4749 {"ref", s_ccs_ref, 0},
4750 {"def", s_ccs_def, 0},
4751 {"asmfunc", s_ccs_asmfunc, 0},
4752 {"endasmfunc", s_ccs_endasmfunc, 0},
4753
c19d1205
ZW
4754 { 0, 0, 0 }
4755};
4756\f
4757/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4758
c19d1205
ZW
4759/* Generic immediate-value read function for use in insn parsing.
4760 STR points to the beginning of the immediate (the leading #);
4761 VAL receives the value; if the value is outside [MIN, MAX]
4762 issue an error. PREFIX_OPT is true if the immediate prefix is
4763 optional. */
b99bd4ef 4764
c19d1205
ZW
4765static int
4766parse_immediate (char **str, int *val, int min, int max,
4767 bfd_boolean prefix_opt)
4768{
4769 expressionS exp;
4770 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4771 if (exp.X_op != O_constant)
b99bd4ef 4772 {
c19d1205
ZW
4773 inst.error = _("constant expression required");
4774 return FAIL;
4775 }
b99bd4ef 4776
c19d1205
ZW
4777 if (exp.X_add_number < min || exp.X_add_number > max)
4778 {
4779 inst.error = _("immediate value out of range");
4780 return FAIL;
4781 }
b99bd4ef 4782
c19d1205
ZW
4783 *val = exp.X_add_number;
4784 return SUCCESS;
4785}
b99bd4ef 4786
5287ad62 4787/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4788 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4789 instructions. Puts the result directly in inst.operands[i]. */
4790
4791static int
8335d6aa
JW
4792parse_big_immediate (char **str, int i, expressionS *in_exp,
4793 bfd_boolean allow_symbol_p)
5287ad62
JB
4794{
4795 expressionS exp;
8335d6aa 4796 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4797 char *ptr = *str;
4798
8335d6aa 4799 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 4800
8335d6aa 4801 if (exp_p->X_op == O_constant)
036dc3f7 4802 {
8335d6aa 4803 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
4804 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4805 O_constant. We have to be careful not to break compilation for
4806 32-bit X_add_number, though. */
8335d6aa 4807 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4808 {
8335d6aa
JW
4809 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4810 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4811 & 0xffffffff);
036dc3f7
PB
4812 inst.operands[i].regisimm = 1;
4813 }
4814 }
8335d6aa
JW
4815 else if (exp_p->X_op == O_big
4816 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
4817 {
4818 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4819
5287ad62 4820 /* Bignums have their least significant bits in
477330fc
RM
4821 generic_bignum[0]. Make sure we put 32 bits in imm and
4822 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4823 gas_assert (parts != 0);
95b75c01
NC
4824
4825 /* Make sure that the number is not too big.
4826 PR 11972: Bignums can now be sign-extended to the
4827 size of a .octa so check that the out of range bits
4828 are all zero or all one. */
8335d6aa 4829 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
4830 {
4831 LITTLENUM_TYPE m = -1;
4832
4833 if (generic_bignum[parts * 2] != 0
4834 && generic_bignum[parts * 2] != m)
4835 return FAIL;
4836
8335d6aa 4837 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
4838 if (generic_bignum[j] != generic_bignum[j-1])
4839 return FAIL;
4840 }
4841
5287ad62
JB
4842 inst.operands[i].imm = 0;
4843 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4844 inst.operands[i].imm |= generic_bignum[idx]
4845 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4846 inst.operands[i].reg = 0;
4847 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4848 inst.operands[i].reg |= generic_bignum[idx]
4849 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4850 inst.operands[i].regisimm = 1;
4851 }
8335d6aa 4852 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 4853 return FAIL;
5f4273c7 4854
5287ad62
JB
4855 *str = ptr;
4856
4857 return SUCCESS;
4858}
4859
c19d1205
ZW
4860/* Returns the pseudo-register number of an FPA immediate constant,
4861 or FAIL if there isn't a valid constant here. */
b99bd4ef 4862
c19d1205
ZW
4863static int
4864parse_fpa_immediate (char ** str)
4865{
4866 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4867 char * save_in;
4868 expressionS exp;
4869 int i;
4870 int j;
b99bd4ef 4871
c19d1205
ZW
4872 /* First try and match exact strings, this is to guarantee
4873 that some formats will work even for cross assembly. */
b99bd4ef 4874
c19d1205
ZW
4875 for (i = 0; fp_const[i]; i++)
4876 {
4877 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4878 {
c19d1205 4879 char *start = *str;
b99bd4ef 4880
c19d1205
ZW
4881 *str += strlen (fp_const[i]);
4882 if (is_end_of_line[(unsigned char) **str])
4883 return i + 8;
4884 *str = start;
4885 }
4886 }
b99bd4ef 4887
c19d1205
ZW
4888 /* Just because we didn't get a match doesn't mean that the constant
4889 isn't valid, just that it is in a format that we don't
4890 automatically recognize. Try parsing it with the standard
4891 expression routines. */
b99bd4ef 4892
c19d1205 4893 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4894
c19d1205
ZW
4895 /* Look for a raw floating point number. */
4896 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4897 && is_end_of_line[(unsigned char) *save_in])
4898 {
4899 for (i = 0; i < NUM_FLOAT_VALS; i++)
4900 {
4901 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4902 {
c19d1205
ZW
4903 if (words[j] != fp_values[i][j])
4904 break;
b99bd4ef
NC
4905 }
4906
c19d1205 4907 if (j == MAX_LITTLENUMS)
b99bd4ef 4908 {
c19d1205
ZW
4909 *str = save_in;
4910 return i + 8;
b99bd4ef
NC
4911 }
4912 }
4913 }
b99bd4ef 4914
c19d1205
ZW
4915 /* Try and parse a more complex expression, this will probably fail
4916 unless the code uses a floating point prefix (eg "0f"). */
4917 save_in = input_line_pointer;
4918 input_line_pointer = *str;
4919 if (expression (&exp) == absolute_section
4920 && exp.X_op == O_big
4921 && exp.X_add_number < 0)
4922 {
4923 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4924 Ditto for 15. */
4925 if (gen_to_words (words, 5, (long) 15) == 0)
4926 {
4927 for (i = 0; i < NUM_FLOAT_VALS; i++)
4928 {
4929 for (j = 0; j < MAX_LITTLENUMS; j++)
4930 {
4931 if (words[j] != fp_values[i][j])
4932 break;
4933 }
b99bd4ef 4934
c19d1205
ZW
4935 if (j == MAX_LITTLENUMS)
4936 {
4937 *str = input_line_pointer;
4938 input_line_pointer = save_in;
4939 return i + 8;
4940 }
4941 }
4942 }
b99bd4ef
NC
4943 }
4944
c19d1205
ZW
4945 *str = input_line_pointer;
4946 input_line_pointer = save_in;
4947 inst.error = _("invalid FPA immediate expression");
4948 return FAIL;
b99bd4ef
NC
4949}
4950
136da414
JB
4951/* Returns 1 if a number has "quarter-precision" float format
4952 0baBbbbbbc defgh000 00000000 00000000. */
4953
4954static int
4955is_quarter_float (unsigned imm)
4956{
4957 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4958 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4959}
4960
aacf0b33
KT
4961
4962/* Detect the presence of a floating point or integer zero constant,
4963 i.e. #0.0 or #0. */
4964
4965static bfd_boolean
4966parse_ifimm_zero (char **in)
4967{
4968 int error_code;
4969
4970 if (!is_immediate_prefix (**in))
4971 return FALSE;
4972
4973 ++*in;
0900a05b
JW
4974
4975 /* Accept #0x0 as a synonym for #0. */
4976 if (strncmp (*in, "0x", 2) == 0)
4977 {
4978 int val;
4979 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
4980 return FALSE;
4981 return TRUE;
4982 }
4983
aacf0b33
KT
4984 error_code = atof_generic (in, ".", EXP_CHARS,
4985 &generic_floating_point_number);
4986
4987 if (!error_code
4988 && generic_floating_point_number.sign == '+'
4989 && (generic_floating_point_number.low
4990 > generic_floating_point_number.leader))
4991 return TRUE;
4992
4993 return FALSE;
4994}
4995
136da414
JB
4996/* Parse an 8-bit "quarter-precision" floating point number of the form:
4997 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4998 The zero and minus-zero cases need special handling, since they can't be
4999 encoded in the "quarter-precision" float format, but can nonetheless be
5000 loaded as integer constants. */
136da414
JB
5001
5002static unsigned
5003parse_qfloat_immediate (char **ccp, int *immed)
5004{
5005 char *str = *ccp;
c96612cc 5006 char *fpnum;
136da414 5007 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5008 int found_fpchar = 0;
5f4273c7 5009
136da414 5010 skip_past_char (&str, '#');
5f4273c7 5011
c96612cc
JB
5012 /* We must not accidentally parse an integer as a floating-point number. Make
5013 sure that the value we parse is not an integer by checking for special
5014 characters '.' or 'e'.
5015 FIXME: This is a horrible hack, but doing better is tricky because type
5016 information isn't in a very usable state at parse time. */
5017 fpnum = str;
5018 skip_whitespace (fpnum);
5019
5020 if (strncmp (fpnum, "0x", 2) == 0)
5021 return FAIL;
5022 else
5023 {
5024 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5025 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5026 {
5027 found_fpchar = 1;
5028 break;
5029 }
c96612cc
JB
5030
5031 if (!found_fpchar)
477330fc 5032 return FAIL;
c96612cc 5033 }
5f4273c7 5034
136da414
JB
5035 if ((str = atof_ieee (str, 's', words)) != NULL)
5036 {
5037 unsigned fpword = 0;
5038 int i;
5f4273c7 5039
136da414
JB
5040 /* Our FP word must be 32 bits (single-precision FP). */
5041 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5042 {
5043 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5044 fpword |= words[i];
5045 }
5f4273c7 5046
c96612cc 5047 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5048 *immed = fpword;
136da414 5049 else
477330fc 5050 return FAIL;
136da414
JB
5051
5052 *ccp = str;
5f4273c7 5053
136da414
JB
5054 return SUCCESS;
5055 }
5f4273c7 5056
136da414
JB
5057 return FAIL;
5058}
5059
c19d1205
ZW
5060/* Shift operands. */
5061enum shift_kind
b99bd4ef 5062{
c19d1205
ZW
5063 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5064};
b99bd4ef 5065
c19d1205
ZW
5066struct asm_shift_name
5067{
5068 const char *name;
5069 enum shift_kind kind;
5070};
b99bd4ef 5071
c19d1205
ZW
5072/* Third argument to parse_shift. */
5073enum parse_shift_mode
5074{
5075 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5076 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5077 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5078 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5079 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5080};
b99bd4ef 5081
c19d1205
ZW
5082/* Parse a <shift> specifier on an ARM data processing instruction.
5083 This has three forms:
b99bd4ef 5084
c19d1205
ZW
5085 (LSL|LSR|ASL|ASR|ROR) Rs
5086 (LSL|LSR|ASL|ASR|ROR) #imm
5087 RRX
b99bd4ef 5088
c19d1205
ZW
5089 Note that ASL is assimilated to LSL in the instruction encoding, and
5090 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5091
c19d1205
ZW
5092static int
5093parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5094{
c19d1205
ZW
5095 const struct asm_shift_name *shift_name;
5096 enum shift_kind shift;
5097 char *s = *str;
5098 char *p = s;
5099 int reg;
b99bd4ef 5100
c19d1205
ZW
5101 for (p = *str; ISALPHA (*p); p++)
5102 ;
b99bd4ef 5103
c19d1205 5104 if (p == *str)
b99bd4ef 5105 {
c19d1205
ZW
5106 inst.error = _("shift expression expected");
5107 return FAIL;
b99bd4ef
NC
5108 }
5109
21d799b5 5110 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5111 p - *str);
c19d1205
ZW
5112
5113 if (shift_name == NULL)
b99bd4ef 5114 {
c19d1205
ZW
5115 inst.error = _("shift expression expected");
5116 return FAIL;
b99bd4ef
NC
5117 }
5118
c19d1205 5119 shift = shift_name->kind;
b99bd4ef 5120
c19d1205
ZW
5121 switch (mode)
5122 {
5123 case NO_SHIFT_RESTRICT:
5124 case SHIFT_IMMEDIATE: break;
b99bd4ef 5125
c19d1205
ZW
5126 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5127 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5128 {
5129 inst.error = _("'LSL' or 'ASR' required");
5130 return FAIL;
5131 }
5132 break;
b99bd4ef 5133
c19d1205
ZW
5134 case SHIFT_LSL_IMMEDIATE:
5135 if (shift != SHIFT_LSL)
5136 {
5137 inst.error = _("'LSL' required");
5138 return FAIL;
5139 }
5140 break;
b99bd4ef 5141
c19d1205
ZW
5142 case SHIFT_ASR_IMMEDIATE:
5143 if (shift != SHIFT_ASR)
5144 {
5145 inst.error = _("'ASR' required");
5146 return FAIL;
5147 }
5148 break;
b99bd4ef 5149
c19d1205
ZW
5150 default: abort ();
5151 }
b99bd4ef 5152
c19d1205
ZW
5153 if (shift != SHIFT_RRX)
5154 {
5155 /* Whitespace can appear here if the next thing is a bare digit. */
5156 skip_whitespace (p);
b99bd4ef 5157
c19d1205 5158 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5159 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5160 {
5161 inst.operands[i].imm = reg;
5162 inst.operands[i].immisreg = 1;
5163 }
5164 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5165 return FAIL;
5166 }
5167 inst.operands[i].shift_kind = shift;
5168 inst.operands[i].shifted = 1;
5169 *str = p;
5170 return SUCCESS;
b99bd4ef
NC
5171}
5172
c19d1205 5173/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5174
c19d1205
ZW
5175 #<immediate>
5176 #<immediate>, <rotate>
5177 <Rm>
5178 <Rm>, <shift>
b99bd4ef 5179
c19d1205
ZW
5180 where <shift> is defined by parse_shift above, and <rotate> is a
5181 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5182 is deferred to md_apply_fix. */
b99bd4ef 5183
c19d1205
ZW
5184static int
5185parse_shifter_operand (char **str, int i)
5186{
5187 int value;
91d6fa6a 5188 expressionS exp;
b99bd4ef 5189
dcbf9037 5190 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5191 {
5192 inst.operands[i].reg = value;
5193 inst.operands[i].isreg = 1;
b99bd4ef 5194
c19d1205
ZW
5195 /* parse_shift will override this if appropriate */
5196 inst.reloc.exp.X_op = O_constant;
5197 inst.reloc.exp.X_add_number = 0;
b99bd4ef 5198
c19d1205
ZW
5199 if (skip_past_comma (str) == FAIL)
5200 return SUCCESS;
b99bd4ef 5201
c19d1205
ZW
5202 /* Shift operation on register. */
5203 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5204 }
5205
c19d1205
ZW
5206 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5207 return FAIL;
b99bd4ef 5208
c19d1205 5209 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5210 {
c19d1205 5211 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5212 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5213 return FAIL;
b99bd4ef 5214
91d6fa6a 5215 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
5216 {
5217 inst.error = _("constant expression expected");
5218 return FAIL;
5219 }
b99bd4ef 5220
91d6fa6a 5221 value = exp.X_add_number;
c19d1205
ZW
5222 if (value < 0 || value > 30 || value % 2 != 0)
5223 {
5224 inst.error = _("invalid rotation");
5225 return FAIL;
5226 }
5227 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5228 {
5229 inst.error = _("invalid constant");
5230 return FAIL;
5231 }
09d92015 5232
a415b1cd
JB
5233 /* Encode as specified. */
5234 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5235 return SUCCESS;
09d92015
MM
5236 }
5237
c19d1205
ZW
5238 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5239 inst.reloc.pc_rel = 0;
5240 return SUCCESS;
09d92015
MM
5241}
5242
4962c51a
MS
5243/* Group relocation information. Each entry in the table contains the
5244 textual name of the relocation as may appear in assembler source
5245 and must end with a colon.
5246 Along with this textual name are the relocation codes to be used if
5247 the corresponding instruction is an ALU instruction (ADD or SUB only),
5248 an LDR, an LDRS, or an LDC. */
5249
5250struct group_reloc_table_entry
5251{
5252 const char *name;
5253 int alu_code;
5254 int ldr_code;
5255 int ldrs_code;
5256 int ldc_code;
5257};
5258
5259typedef enum
5260{
5261 /* Varieties of non-ALU group relocation. */
5262
5263 GROUP_LDR,
5264 GROUP_LDRS,
5265 GROUP_LDC
5266} group_reloc_type;
5267
5268static struct group_reloc_table_entry group_reloc_table[] =
5269 { /* Program counter relative: */
5270 { "pc_g0_nc",
5271 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5272 0, /* LDR */
5273 0, /* LDRS */
5274 0 }, /* LDC */
5275 { "pc_g0",
5276 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5277 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5278 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5279 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5280 { "pc_g1_nc",
5281 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5282 0, /* LDR */
5283 0, /* LDRS */
5284 0 }, /* LDC */
5285 { "pc_g1",
5286 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5287 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5288 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5289 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5290 { "pc_g2",
5291 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5292 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5293 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5294 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5295 /* Section base relative */
5296 { "sb_g0_nc",
5297 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5298 0, /* LDR */
5299 0, /* LDRS */
5300 0 }, /* LDC */
5301 { "sb_g0",
5302 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5303 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5304 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5305 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5306 { "sb_g1_nc",
5307 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5308 0, /* LDR */
5309 0, /* LDRS */
5310 0 }, /* LDC */
5311 { "sb_g1",
5312 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5313 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5314 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5315 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5316 { "sb_g2",
5317 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5318 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5319 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
5320 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
5321
5322/* Given the address of a pointer pointing to the textual name of a group
5323 relocation as may appear in assembler source, attempt to find its details
5324 in group_reloc_table. The pointer will be updated to the character after
5325 the trailing colon. On failure, FAIL will be returned; SUCCESS
5326 otherwise. On success, *entry will be updated to point at the relevant
5327 group_reloc_table entry. */
5328
5329static int
5330find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5331{
5332 unsigned int i;
5333 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5334 {
5335 int length = strlen (group_reloc_table[i].name);
5336
5f4273c7
NC
5337 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5338 && (*str)[length] == ':')
477330fc
RM
5339 {
5340 *out = &group_reloc_table[i];
5341 *str += (length + 1);
5342 return SUCCESS;
5343 }
4962c51a
MS
5344 }
5345
5346 return FAIL;
5347}
5348
5349/* Parse a <shifter_operand> for an ARM data processing instruction
5350 (as for parse_shifter_operand) where group relocations are allowed:
5351
5352 #<immediate>
5353 #<immediate>, <rotate>
5354 #:<group_reloc>:<expression>
5355 <Rm>
5356 <Rm>, <shift>
5357
5358 where <group_reloc> is one of the strings defined in group_reloc_table.
5359 The hashes are optional.
5360
5361 Everything else is as for parse_shifter_operand. */
5362
5363static parse_operand_result
5364parse_shifter_operand_group_reloc (char **str, int i)
5365{
5366 /* Determine if we have the sequence of characters #: or just :
5367 coming next. If we do, then we check for a group relocation.
5368 If we don't, punt the whole lot to parse_shifter_operand. */
5369
5370 if (((*str)[0] == '#' && (*str)[1] == ':')
5371 || (*str)[0] == ':')
5372 {
5373 struct group_reloc_table_entry *entry;
5374
5375 if ((*str)[0] == '#')
477330fc 5376 (*str) += 2;
4962c51a 5377 else
477330fc 5378 (*str)++;
4962c51a
MS
5379
5380 /* Try to parse a group relocation. Anything else is an error. */
5381 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5382 {
5383 inst.error = _("unknown group relocation");
5384 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5385 }
4962c51a
MS
5386
5387 /* We now have the group relocation table entry corresponding to
477330fc 5388 the name in the assembler source. Next, we parse the expression. */
4962c51a 5389 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
477330fc 5390 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5391
5392 /* Record the relocation type (always the ALU variant here). */
21d799b5 5393 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5394 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5395
5396 return PARSE_OPERAND_SUCCESS;
5397 }
5398 else
5399 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5400 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5401
5402 /* Never reached. */
5403}
5404
8e560766
MGD
5405/* Parse a Neon alignment expression. Information is written to
5406 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5407
8e560766
MGD
5408 align .imm = align << 8, .immisalign=1, .preind=0 */
5409static parse_operand_result
5410parse_neon_alignment (char **str, int i)
5411{
5412 char *p = *str;
5413 expressionS exp;
5414
5415 my_get_expression (&exp, &p, GE_NO_PREFIX);
5416
5417 if (exp.X_op != O_constant)
5418 {
5419 inst.error = _("alignment must be constant");
5420 return PARSE_OPERAND_FAIL;
5421 }
5422
5423 inst.operands[i].imm = exp.X_add_number << 8;
5424 inst.operands[i].immisalign = 1;
5425 /* Alignments are not pre-indexes. */
5426 inst.operands[i].preind = 0;
5427
5428 *str = p;
5429 return PARSE_OPERAND_SUCCESS;
5430}
5431
c19d1205
ZW
5432/* Parse all forms of an ARM address expression. Information is written
5433 to inst.operands[i] and/or inst.reloc.
09d92015 5434
c19d1205 5435 Preindexed addressing (.preind=1):
09d92015 5436
c19d1205
ZW
5437 [Rn, #offset] .reg=Rn .reloc.exp=offset
5438 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5439 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5440 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5441
c19d1205 5442 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5443
c19d1205 5444 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5445
c19d1205
ZW
5446 [Rn], #offset .reg=Rn .reloc.exp=offset
5447 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5448 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5449 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5450
c19d1205 5451 Unindexed addressing (.preind=0, .postind=0):
09d92015 5452
c19d1205 5453 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5454
c19d1205 5455 Other:
09d92015 5456
c19d1205
ZW
5457 [Rn]{!} shorthand for [Rn,#0]{!}
5458 =immediate .isreg=0 .reloc.exp=immediate
5459 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5460
c19d1205
ZW
5461 It is the caller's responsibility to check for addressing modes not
5462 supported by the instruction, and to set inst.reloc.type. */
5463
4962c51a
MS
5464static parse_operand_result
5465parse_address_main (char **str, int i, int group_relocations,
477330fc 5466 group_reloc_type group_type)
09d92015 5467{
c19d1205
ZW
5468 char *p = *str;
5469 int reg;
09d92015 5470
c19d1205 5471 if (skip_past_char (&p, '[') == FAIL)
09d92015 5472 {
c19d1205
ZW
5473 if (skip_past_char (&p, '=') == FAIL)
5474 {
974da60d 5475 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5476 inst.reloc.pc_rel = 1;
5477 inst.operands[i].reg = REG_PC;
5478 inst.operands[i].isreg = 1;
5479 inst.operands[i].preind = 1;
09d92015 5480
8335d6aa
JW
5481 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5482 return PARSE_OPERAND_FAIL;
5483 }
5484 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5485 /*allow_symbol_p=*/TRUE))
4962c51a 5486 return PARSE_OPERAND_FAIL;
09d92015 5487
c19d1205 5488 *str = p;
4962c51a 5489 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5490 }
5491
8ab8155f
NC
5492 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5493 skip_whitespace (p);
5494
dcbf9037 5495 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5496 {
c19d1205 5497 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5498 return PARSE_OPERAND_FAIL;
09d92015 5499 }
c19d1205
ZW
5500 inst.operands[i].reg = reg;
5501 inst.operands[i].isreg = 1;
09d92015 5502
c19d1205 5503 if (skip_past_comma (&p) == SUCCESS)
09d92015 5504 {
c19d1205 5505 inst.operands[i].preind = 1;
09d92015 5506
c19d1205
ZW
5507 if (*p == '+') p++;
5508 else if (*p == '-') p++, inst.operands[i].negative = 1;
5509
dcbf9037 5510 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5511 {
c19d1205
ZW
5512 inst.operands[i].imm = reg;
5513 inst.operands[i].immisreg = 1;
5514
5515 if (skip_past_comma (&p) == SUCCESS)
5516 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5517 return PARSE_OPERAND_FAIL;
c19d1205 5518 }
5287ad62 5519 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5520 {
5521 /* FIXME: '@' should be used here, but it's filtered out by generic
5522 code before we get to see it here. This may be subject to
5523 change. */
5524 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5525
8e560766
MGD
5526 if (result != PARSE_OPERAND_SUCCESS)
5527 return result;
5528 }
c19d1205
ZW
5529 else
5530 {
5531 if (inst.operands[i].negative)
5532 {
5533 inst.operands[i].negative = 0;
5534 p--;
5535 }
4962c51a 5536
5f4273c7
NC
5537 if (group_relocations
5538 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5539 {
5540 struct group_reloc_table_entry *entry;
5541
477330fc
RM
5542 /* Skip over the #: or : sequence. */
5543 if (*p == '#')
5544 p += 2;
5545 else
5546 p++;
4962c51a
MS
5547
5548 /* Try to parse a group relocation. Anything else is an
477330fc 5549 error. */
4962c51a
MS
5550 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5551 {
5552 inst.error = _("unknown group relocation");
5553 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5554 }
5555
5556 /* We now have the group relocation table entry corresponding to
5557 the name in the assembler source. Next, we parse the
477330fc 5558 expression. */
4962c51a
MS
5559 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5560 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5561
5562 /* Record the relocation type. */
477330fc
RM
5563 switch (group_type)
5564 {
5565 case GROUP_LDR:
5566 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5567 break;
4962c51a 5568
477330fc
RM
5569 case GROUP_LDRS:
5570 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5571 break;
4962c51a 5572
477330fc
RM
5573 case GROUP_LDC:
5574 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5575 break;
4962c51a 5576
477330fc
RM
5577 default:
5578 gas_assert (0);
5579 }
4962c51a 5580
477330fc 5581 if (inst.reloc.type == 0)
4962c51a
MS
5582 {
5583 inst.error = _("this group relocation is not allowed on this instruction");
5584 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5585 }
477330fc
RM
5586 }
5587 else
26d97720
NS
5588 {
5589 char *q = p;
5590 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5591 return PARSE_OPERAND_FAIL;
5592 /* If the offset is 0, find out if it's a +0 or -0. */
5593 if (inst.reloc.exp.X_op == O_constant
5594 && inst.reloc.exp.X_add_number == 0)
5595 {
5596 skip_whitespace (q);
5597 if (*q == '#')
5598 {
5599 q++;
5600 skip_whitespace (q);
5601 }
5602 if (*q == '-')
5603 inst.operands[i].negative = 1;
5604 }
5605 }
09d92015
MM
5606 }
5607 }
8e560766
MGD
5608 else if (skip_past_char (&p, ':') == SUCCESS)
5609 {
5610 /* FIXME: '@' should be used here, but it's filtered out by generic code
5611 before we get to see it here. This may be subject to change. */
5612 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5613
8e560766
MGD
5614 if (result != PARSE_OPERAND_SUCCESS)
5615 return result;
5616 }
09d92015 5617
c19d1205 5618 if (skip_past_char (&p, ']') == FAIL)
09d92015 5619 {
c19d1205 5620 inst.error = _("']' expected");
4962c51a 5621 return PARSE_OPERAND_FAIL;
09d92015
MM
5622 }
5623
c19d1205
ZW
5624 if (skip_past_char (&p, '!') == SUCCESS)
5625 inst.operands[i].writeback = 1;
09d92015 5626
c19d1205 5627 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5628 {
c19d1205
ZW
5629 if (skip_past_char (&p, '{') == SUCCESS)
5630 {
5631 /* [Rn], {expr} - unindexed, with option */
5632 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5633 0, 255, TRUE) == FAIL)
4962c51a 5634 return PARSE_OPERAND_FAIL;
09d92015 5635
c19d1205
ZW
5636 if (skip_past_char (&p, '}') == FAIL)
5637 {
5638 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5639 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5640 }
5641 if (inst.operands[i].preind)
5642 {
5643 inst.error = _("cannot combine index with option");
4962c51a 5644 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5645 }
5646 *str = p;
4962c51a 5647 return PARSE_OPERAND_SUCCESS;
09d92015 5648 }
c19d1205
ZW
5649 else
5650 {
5651 inst.operands[i].postind = 1;
5652 inst.operands[i].writeback = 1;
09d92015 5653
c19d1205
ZW
5654 if (inst.operands[i].preind)
5655 {
5656 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5657 return PARSE_OPERAND_FAIL;
c19d1205 5658 }
09d92015 5659
c19d1205
ZW
5660 if (*p == '+') p++;
5661 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5662
dcbf9037 5663 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5664 {
477330fc
RM
5665 /* We might be using the immediate for alignment already. If we
5666 are, OR the register number into the low-order bits. */
5667 if (inst.operands[i].immisalign)
5668 inst.operands[i].imm |= reg;
5669 else
5670 inst.operands[i].imm = reg;
c19d1205 5671 inst.operands[i].immisreg = 1;
a737bd4d 5672
c19d1205
ZW
5673 if (skip_past_comma (&p) == SUCCESS)
5674 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5675 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5676 }
5677 else
5678 {
26d97720 5679 char *q = p;
c19d1205
ZW
5680 if (inst.operands[i].negative)
5681 {
5682 inst.operands[i].negative = 0;
5683 p--;
5684 }
5685 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5686 return PARSE_OPERAND_FAIL;
26d97720
NS
5687 /* If the offset is 0, find out if it's a +0 or -0. */
5688 if (inst.reloc.exp.X_op == O_constant
5689 && inst.reloc.exp.X_add_number == 0)
5690 {
5691 skip_whitespace (q);
5692 if (*q == '#')
5693 {
5694 q++;
5695 skip_whitespace (q);
5696 }
5697 if (*q == '-')
5698 inst.operands[i].negative = 1;
5699 }
c19d1205
ZW
5700 }
5701 }
a737bd4d
NC
5702 }
5703
c19d1205
ZW
5704 /* If at this point neither .preind nor .postind is set, we have a
5705 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5706 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5707 {
5708 inst.operands[i].preind = 1;
5709 inst.reloc.exp.X_op = O_constant;
5710 inst.reloc.exp.X_add_number = 0;
5711 }
5712 *str = p;
4962c51a
MS
5713 return PARSE_OPERAND_SUCCESS;
5714}
5715
5716static int
5717parse_address (char **str, int i)
5718{
21d799b5 5719 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5720 ? SUCCESS : FAIL;
4962c51a
MS
5721}
5722
5723static parse_operand_result
5724parse_address_group_reloc (char **str, int i, group_reloc_type type)
5725{
5726 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5727}
5728
b6895b4f
PB
5729/* Parse an operand for a MOVW or MOVT instruction. */
5730static int
5731parse_half (char **str)
5732{
5733 char * p;
5f4273c7 5734
b6895b4f
PB
5735 p = *str;
5736 skip_past_char (&p, '#');
5f4273c7 5737 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5738 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5739 else if (strncasecmp (p, ":upper16:", 9) == 0)
5740 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5741
5742 if (inst.reloc.type != BFD_RELOC_UNUSED)
5743 {
5744 p += 9;
5f4273c7 5745 skip_whitespace (p);
b6895b4f
PB
5746 }
5747
5748 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5749 return FAIL;
5750
5751 if (inst.reloc.type == BFD_RELOC_UNUSED)
5752 {
5753 if (inst.reloc.exp.X_op != O_constant)
5754 {
5755 inst.error = _("constant expression expected");
5756 return FAIL;
5757 }
5758 if (inst.reloc.exp.X_add_number < 0
5759 || inst.reloc.exp.X_add_number > 0xffff)
5760 {
5761 inst.error = _("immediate value out of range");
5762 return FAIL;
5763 }
5764 }
5765 *str = p;
5766 return SUCCESS;
5767}
5768
c19d1205 5769/* Miscellaneous. */
a737bd4d 5770
c19d1205
ZW
5771/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5772 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5773static int
d2cd1205 5774parse_psr (char **str, bfd_boolean lhs)
09d92015 5775{
c19d1205
ZW
5776 char *p;
5777 unsigned long psr_field;
62b3e311
PB
5778 const struct asm_psr *psr;
5779 char *start;
d2cd1205 5780 bfd_boolean is_apsr = FALSE;
ac7f631b 5781 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5782
a4482bb6
NC
5783 /* PR gas/12698: If the user has specified -march=all then m_profile will
5784 be TRUE, but we want to ignore it in this case as we are building for any
5785 CPU type, including non-m variants. */
823d2571 5786 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
5787 m_profile = FALSE;
5788
c19d1205
ZW
5789 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5790 feature for ease of use and backwards compatibility. */
5791 p = *str;
62b3e311 5792 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5793 {
5794 if (m_profile)
5795 goto unsupported_psr;
fa94de6b 5796
d2cd1205
JB
5797 psr_field = SPSR_BIT;
5798 }
5799 else if (strncasecmp (p, "CPSR", 4) == 0)
5800 {
5801 if (m_profile)
5802 goto unsupported_psr;
5803
5804 psr_field = 0;
5805 }
5806 else if (strncasecmp (p, "APSR", 4) == 0)
5807 {
5808 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5809 and ARMv7-R architecture CPUs. */
5810 is_apsr = TRUE;
5811 psr_field = 0;
5812 }
5813 else if (m_profile)
62b3e311
PB
5814 {
5815 start = p;
5816 do
5817 p++;
5818 while (ISALNUM (*p) || *p == '_');
5819
d2cd1205
JB
5820 if (strncasecmp (start, "iapsr", 5) == 0
5821 || strncasecmp (start, "eapsr", 5) == 0
5822 || strncasecmp (start, "xpsr", 4) == 0
5823 || strncasecmp (start, "psr", 3) == 0)
5824 p = start + strcspn (start, "rR") + 1;
5825
21d799b5 5826 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5827 p - start);
d2cd1205 5828
62b3e311
PB
5829 if (!psr)
5830 return FAIL;
09d92015 5831
d2cd1205
JB
5832 /* If APSR is being written, a bitfield may be specified. Note that
5833 APSR itself is handled above. */
5834 if (psr->field <= 3)
5835 {
5836 psr_field = psr->field;
5837 is_apsr = TRUE;
5838 goto check_suffix;
5839 }
5840
62b3e311 5841 *str = p;
d2cd1205
JB
5842 /* M-profile MSR instructions have the mask field set to "10", except
5843 *PSR variants which modify APSR, which may use a different mask (and
5844 have been handled already). Do that by setting the PSR_f field
5845 here. */
5846 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5847 }
d2cd1205
JB
5848 else
5849 goto unsupported_psr;
09d92015 5850
62b3e311 5851 p += 4;
d2cd1205 5852check_suffix:
c19d1205
ZW
5853 if (*p == '_')
5854 {
5855 /* A suffix follows. */
c19d1205
ZW
5856 p++;
5857 start = p;
a737bd4d 5858
c19d1205
ZW
5859 do
5860 p++;
5861 while (ISALNUM (*p) || *p == '_');
a737bd4d 5862
d2cd1205
JB
5863 if (is_apsr)
5864 {
5865 /* APSR uses a notation for bits, rather than fields. */
5866 unsigned int nzcvq_bits = 0;
5867 unsigned int g_bit = 0;
5868 char *bit;
fa94de6b 5869
d2cd1205
JB
5870 for (bit = start; bit != p; bit++)
5871 {
5872 switch (TOLOWER (*bit))
477330fc 5873 {
d2cd1205
JB
5874 case 'n':
5875 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5876 break;
5877
5878 case 'z':
5879 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5880 break;
5881
5882 case 'c':
5883 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5884 break;
5885
5886 case 'v':
5887 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5888 break;
fa94de6b 5889
d2cd1205
JB
5890 case 'q':
5891 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5892 break;
fa94de6b 5893
d2cd1205
JB
5894 case 'g':
5895 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5896 break;
fa94de6b 5897
d2cd1205
JB
5898 default:
5899 inst.error = _("unexpected bit specified after APSR");
5900 return FAIL;
5901 }
5902 }
fa94de6b 5903
d2cd1205
JB
5904 if (nzcvq_bits == 0x1f)
5905 psr_field |= PSR_f;
fa94de6b 5906
d2cd1205
JB
5907 if (g_bit == 0x1)
5908 {
5909 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5910 {
d2cd1205
JB
5911 inst.error = _("selected processor does not "
5912 "support DSP extension");
5913 return FAIL;
5914 }
5915
5916 psr_field |= PSR_s;
5917 }
fa94de6b 5918
d2cd1205
JB
5919 if ((nzcvq_bits & 0x20) != 0
5920 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5921 || (g_bit & 0x2) != 0)
5922 {
5923 inst.error = _("bad bitmask specified after APSR");
5924 return FAIL;
5925 }
5926 }
5927 else
477330fc 5928 {
d2cd1205 5929 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 5930 p - start);
d2cd1205 5931 if (!psr)
477330fc 5932 goto error;
a737bd4d 5933
d2cd1205
JB
5934 psr_field |= psr->field;
5935 }
a737bd4d 5936 }
c19d1205 5937 else
a737bd4d 5938 {
c19d1205
ZW
5939 if (ISALNUM (*p))
5940 goto error; /* Garbage after "[CS]PSR". */
5941
d2cd1205 5942 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 5943 is deprecated, but allow it anyway. */
d2cd1205
JB
5944 if (is_apsr && lhs)
5945 {
5946 psr_field |= PSR_f;
5947 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5948 "deprecated"));
5949 }
5950 else if (!m_profile)
5951 /* These bits are never right for M-profile devices: don't set them
5952 (only code paths which read/write APSR reach here). */
5953 psr_field |= (PSR_c | PSR_f);
a737bd4d 5954 }
c19d1205
ZW
5955 *str = p;
5956 return psr_field;
a737bd4d 5957
d2cd1205
JB
5958 unsupported_psr:
5959 inst.error = _("selected processor does not support requested special "
5960 "purpose register");
5961 return FAIL;
5962
c19d1205
ZW
5963 error:
5964 inst.error = _("flag for {c}psr instruction expected");
5965 return FAIL;
a737bd4d
NC
5966}
5967
c19d1205
ZW
5968/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5969 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5970
c19d1205
ZW
5971static int
5972parse_cps_flags (char **str)
a737bd4d 5973{
c19d1205
ZW
5974 int val = 0;
5975 int saw_a_flag = 0;
5976 char *s = *str;
a737bd4d 5977
c19d1205
ZW
5978 for (;;)
5979 switch (*s++)
5980 {
5981 case '\0': case ',':
5982 goto done;
a737bd4d 5983
c19d1205
ZW
5984 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5985 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5986 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5987
c19d1205
ZW
5988 default:
5989 inst.error = _("unrecognized CPS flag");
5990 return FAIL;
5991 }
a737bd4d 5992
c19d1205
ZW
5993 done:
5994 if (saw_a_flag == 0)
a737bd4d 5995 {
c19d1205
ZW
5996 inst.error = _("missing CPS flags");
5997 return FAIL;
a737bd4d 5998 }
a737bd4d 5999
c19d1205
ZW
6000 *str = s - 1;
6001 return val;
a737bd4d
NC
6002}
6003
c19d1205
ZW
6004/* Parse an endian specifier ("BE" or "LE", case insensitive);
6005 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6006
6007static int
c19d1205 6008parse_endian_specifier (char **str)
a737bd4d 6009{
c19d1205
ZW
6010 int little_endian;
6011 char *s = *str;
a737bd4d 6012
c19d1205
ZW
6013 if (strncasecmp (s, "BE", 2))
6014 little_endian = 0;
6015 else if (strncasecmp (s, "LE", 2))
6016 little_endian = 1;
6017 else
a737bd4d 6018 {
c19d1205 6019 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6020 return FAIL;
6021 }
6022
c19d1205 6023 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6024 {
c19d1205 6025 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6026 return FAIL;
6027 }
6028
c19d1205
ZW
6029 *str = s + 2;
6030 return little_endian;
6031}
a737bd4d 6032
c19d1205
ZW
6033/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6034 value suitable for poking into the rotate field of an sxt or sxta
6035 instruction, or FAIL on error. */
6036
6037static int
6038parse_ror (char **str)
6039{
6040 int rot;
6041 char *s = *str;
6042
6043 if (strncasecmp (s, "ROR", 3) == 0)
6044 s += 3;
6045 else
a737bd4d 6046 {
c19d1205 6047 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6048 return FAIL;
6049 }
c19d1205
ZW
6050
6051 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6052 return FAIL;
6053
6054 switch (rot)
a737bd4d 6055 {
c19d1205
ZW
6056 case 0: *str = s; return 0x0;
6057 case 8: *str = s; return 0x1;
6058 case 16: *str = s; return 0x2;
6059 case 24: *str = s; return 0x3;
6060
6061 default:
6062 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6063 return FAIL;
6064 }
c19d1205 6065}
a737bd4d 6066
c19d1205
ZW
6067/* Parse a conditional code (from conds[] below). The value returned is in the
6068 range 0 .. 14, or FAIL. */
6069static int
6070parse_cond (char **str)
6071{
c462b453 6072 char *q;
c19d1205 6073 const struct asm_cond *c;
c462b453
PB
6074 int n;
6075 /* Condition codes are always 2 characters, so matching up to
6076 3 characters is sufficient. */
6077 char cond[3];
a737bd4d 6078
c462b453
PB
6079 q = *str;
6080 n = 0;
6081 while (ISALPHA (*q) && n < 3)
6082 {
e07e6e58 6083 cond[n] = TOLOWER (*q);
c462b453
PB
6084 q++;
6085 n++;
6086 }
a737bd4d 6087
21d799b5 6088 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6089 if (!c)
a737bd4d 6090 {
c19d1205 6091 inst.error = _("condition required");
a737bd4d
NC
6092 return FAIL;
6093 }
6094
c19d1205
ZW
6095 *str = q;
6096 return c->value;
6097}
6098
e797f7e0
MGD
6099/* If the given feature available in the selected CPU, mark it as used.
6100 Returns TRUE iff feature is available. */
6101static bfd_boolean
6102mark_feature_used (const arm_feature_set *feature)
6103{
6104 /* Ensure the option is valid on the current architecture. */
6105 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6106 return FALSE;
6107
6108 /* Add the appropriate architecture feature for the barrier option used.
6109 */
6110 if (thumb_mode)
6111 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6112 else
6113 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6114
6115 return TRUE;
6116}
6117
62b3e311
PB
6118/* Parse an option for a barrier instruction. Returns the encoding for the
6119 option, or FAIL. */
6120static int
6121parse_barrier (char **str)
6122{
6123 char *p, *q;
6124 const struct asm_barrier_opt *o;
6125
6126 p = q = *str;
6127 while (ISALPHA (*q))
6128 q++;
6129
21d799b5 6130 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6131 q - p);
62b3e311
PB
6132 if (!o)
6133 return FAIL;
6134
e797f7e0
MGD
6135 if (!mark_feature_used (&o->arch))
6136 return FAIL;
6137
62b3e311
PB
6138 *str = q;
6139 return o->value;
6140}
6141
92e90b6e
PB
6142/* Parse the operands of a table branch instruction. Similar to a memory
6143 operand. */
6144static int
6145parse_tb (char **str)
6146{
6147 char * p = *str;
6148 int reg;
6149
6150 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6151 {
6152 inst.error = _("'[' expected");
6153 return FAIL;
6154 }
92e90b6e 6155
dcbf9037 6156 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6157 {
6158 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6159 return FAIL;
6160 }
6161 inst.operands[0].reg = reg;
6162
6163 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6164 {
6165 inst.error = _("',' expected");
6166 return FAIL;
6167 }
5f4273c7 6168
dcbf9037 6169 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6170 {
6171 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6172 return FAIL;
6173 }
6174 inst.operands[0].imm = reg;
6175
6176 if (skip_past_comma (&p) == SUCCESS)
6177 {
6178 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6179 return FAIL;
6180 if (inst.reloc.exp.X_add_number != 1)
6181 {
6182 inst.error = _("invalid shift");
6183 return FAIL;
6184 }
6185 inst.operands[0].shifted = 1;
6186 }
6187
6188 if (skip_past_char (&p, ']') == FAIL)
6189 {
6190 inst.error = _("']' expected");
6191 return FAIL;
6192 }
6193 *str = p;
6194 return SUCCESS;
6195}
6196
5287ad62
JB
6197/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6198 information on the types the operands can take and how they are encoded.
037e8744
JB
6199 Up to four operands may be read; this function handles setting the
6200 ".present" field for each read operand itself.
5287ad62
JB
6201 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6202 else returns FAIL. */
6203
6204static int
6205parse_neon_mov (char **str, int *which_operand)
6206{
6207 int i = *which_operand, val;
6208 enum arm_reg_type rtype;
6209 char *ptr = *str;
dcbf9037 6210 struct neon_type_el optype;
5f4273c7 6211
dcbf9037 6212 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6213 {
6214 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6215 inst.operands[i].reg = val;
6216 inst.operands[i].isscalar = 1;
dcbf9037 6217 inst.operands[i].vectype = optype;
5287ad62
JB
6218 inst.operands[i++].present = 1;
6219
6220 if (skip_past_comma (&ptr) == FAIL)
477330fc 6221 goto wanted_comma;
5f4273c7 6222
dcbf9037 6223 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6224 goto wanted_arm;
5f4273c7 6225
5287ad62
JB
6226 inst.operands[i].reg = val;
6227 inst.operands[i].isreg = 1;
6228 inst.operands[i].present = 1;
6229 }
037e8744 6230 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6231 != FAIL)
5287ad62
JB
6232 {
6233 /* Cases 0, 1, 2, 3, 5 (D only). */
6234 if (skip_past_comma (&ptr) == FAIL)
477330fc 6235 goto wanted_comma;
5f4273c7 6236
5287ad62
JB
6237 inst.operands[i].reg = val;
6238 inst.operands[i].isreg = 1;
6239 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6240 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6241 inst.operands[i].isvec = 1;
dcbf9037 6242 inst.operands[i].vectype = optype;
5287ad62
JB
6243 inst.operands[i++].present = 1;
6244
dcbf9037 6245 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6246 {
6247 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6248 Case 13: VMOV <Sd>, <Rm> */
6249 inst.operands[i].reg = val;
6250 inst.operands[i].isreg = 1;
6251 inst.operands[i].present = 1;
6252
6253 if (rtype == REG_TYPE_NQ)
6254 {
6255 first_error (_("can't use Neon quad register here"));
6256 return FAIL;
6257 }
6258 else if (rtype != REG_TYPE_VFS)
6259 {
6260 i++;
6261 if (skip_past_comma (&ptr) == FAIL)
6262 goto wanted_comma;
6263 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6264 goto wanted_arm;
6265 inst.operands[i].reg = val;
6266 inst.operands[i].isreg = 1;
6267 inst.operands[i].present = 1;
6268 }
6269 }
037e8744 6270 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6271 &optype)) != FAIL)
6272 {
6273 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6274 Case 1: VMOV<c><q> <Dd>, <Dm>
6275 Case 8: VMOV.F32 <Sd>, <Sm>
6276 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6277
6278 inst.operands[i].reg = val;
6279 inst.operands[i].isreg = 1;
6280 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6281 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6282 inst.operands[i].isvec = 1;
6283 inst.operands[i].vectype = optype;
6284 inst.operands[i].present = 1;
6285
6286 if (skip_past_comma (&ptr) == SUCCESS)
6287 {
6288 /* Case 15. */
6289 i++;
6290
6291 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6292 goto wanted_arm;
6293
6294 inst.operands[i].reg = val;
6295 inst.operands[i].isreg = 1;
6296 inst.operands[i++].present = 1;
6297
6298 if (skip_past_comma (&ptr) == FAIL)
6299 goto wanted_comma;
6300
6301 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6302 goto wanted_arm;
6303
6304 inst.operands[i].reg = val;
6305 inst.operands[i].isreg = 1;
6306 inst.operands[i].present = 1;
6307 }
6308 }
4641781c 6309 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6310 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6311 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6312 Case 10: VMOV.F32 <Sd>, #<imm>
6313 Case 11: VMOV.F64 <Dd>, #<imm> */
6314 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6315 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6316 == SUCCESS)
477330fc
RM
6317 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6318 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6319 ;
5287ad62 6320 else
477330fc
RM
6321 {
6322 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6323 return FAIL;
6324 }
5287ad62 6325 }
dcbf9037 6326 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6327 {
6328 /* Cases 6, 7. */
6329 inst.operands[i].reg = val;
6330 inst.operands[i].isreg = 1;
6331 inst.operands[i++].present = 1;
5f4273c7 6332
5287ad62 6333 if (skip_past_comma (&ptr) == FAIL)
477330fc 6334 goto wanted_comma;
5f4273c7 6335
dcbf9037 6336 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6337 {
6338 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6339 inst.operands[i].reg = val;
6340 inst.operands[i].isscalar = 1;
6341 inst.operands[i].present = 1;
6342 inst.operands[i].vectype = optype;
6343 }
dcbf9037 6344 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6345 {
6346 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6347 inst.operands[i].reg = val;
6348 inst.operands[i].isreg = 1;
6349 inst.operands[i++].present = 1;
6350
6351 if (skip_past_comma (&ptr) == FAIL)
6352 goto wanted_comma;
6353
6354 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6355 == FAIL)
6356 {
6357 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6358 return FAIL;
6359 }
6360
6361 inst.operands[i].reg = val;
6362 inst.operands[i].isreg = 1;
6363 inst.operands[i].isvec = 1;
6364 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6365 inst.operands[i].vectype = optype;
6366 inst.operands[i].present = 1;
6367
6368 if (rtype == REG_TYPE_VFS)
6369 {
6370 /* Case 14. */
6371 i++;
6372 if (skip_past_comma (&ptr) == FAIL)
6373 goto wanted_comma;
6374 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6375 &optype)) == FAIL)
6376 {
6377 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6378 return FAIL;
6379 }
6380 inst.operands[i].reg = val;
6381 inst.operands[i].isreg = 1;
6382 inst.operands[i].isvec = 1;
6383 inst.operands[i].issingle = 1;
6384 inst.operands[i].vectype = optype;
6385 inst.operands[i].present = 1;
6386 }
6387 }
037e8744 6388 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6389 != FAIL)
6390 {
6391 /* Case 13. */
6392 inst.operands[i].reg = val;
6393 inst.operands[i].isreg = 1;
6394 inst.operands[i].isvec = 1;
6395 inst.operands[i].issingle = 1;
6396 inst.operands[i].vectype = optype;
6397 inst.operands[i].present = 1;
6398 }
5287ad62
JB
6399 }
6400 else
6401 {
dcbf9037 6402 first_error (_("parse error"));
5287ad62
JB
6403 return FAIL;
6404 }
6405
6406 /* Successfully parsed the operands. Update args. */
6407 *which_operand = i;
6408 *str = ptr;
6409 return SUCCESS;
6410
5f4273c7 6411 wanted_comma:
dcbf9037 6412 first_error (_("expected comma"));
5287ad62 6413 return FAIL;
5f4273c7
NC
6414
6415 wanted_arm:
dcbf9037 6416 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6417 return FAIL;
5287ad62
JB
6418}
6419
5be8be5d
DG
6420/* Use this macro when the operand constraints are different
6421 for ARM and THUMB (e.g. ldrd). */
6422#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6423 ((arm_operand) | ((thumb_operand) << 16))
6424
c19d1205
ZW
6425/* Matcher codes for parse_operands. */
6426enum operand_parse_code
6427{
6428 OP_stop, /* end of line */
6429
6430 OP_RR, /* ARM register */
6431 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6432 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6433 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6434 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6435 optional trailing ! */
c19d1205
ZW
6436 OP_RRw, /* ARM register, not r15, optional trailing ! */
6437 OP_RCP, /* Coprocessor number */
6438 OP_RCN, /* Coprocessor register */
6439 OP_RF, /* FPA register */
6440 OP_RVS, /* VFP single precision register */
5287ad62
JB
6441 OP_RVD, /* VFP double precision register (0..15) */
6442 OP_RND, /* Neon double precision register (0..31) */
6443 OP_RNQ, /* Neon quad precision register */
037e8744 6444 OP_RVSD, /* VFP single or double precision register */
5287ad62 6445 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6446 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6447 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6448 OP_RVC, /* VFP control register */
6449 OP_RMF, /* Maverick F register */
6450 OP_RMD, /* Maverick D register */
6451 OP_RMFX, /* Maverick FX register */
6452 OP_RMDX, /* Maverick DX register */
6453 OP_RMAX, /* Maverick AX register */
6454 OP_RMDS, /* Maverick DSPSC register */
6455 OP_RIWR, /* iWMMXt wR register */
6456 OP_RIWC, /* iWMMXt wC register */
6457 OP_RIWG, /* iWMMXt wCG register */
6458 OP_RXA, /* XScale accumulator register */
6459
6460 OP_REGLST, /* ARM register list */
6461 OP_VRSLST, /* VFP single-precision register list */
6462 OP_VRDLST, /* VFP double-precision register list */
037e8744 6463 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6464 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6465 OP_NSTRLST, /* Neon element/structure list */
6466
5287ad62 6467 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6468 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6469 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6470 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6471 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6472 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6473 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6474 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6475 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6476 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6477 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6478
6479 OP_I0, /* immediate zero */
c19d1205
ZW
6480 OP_I7, /* immediate value 0 .. 7 */
6481 OP_I15, /* 0 .. 15 */
6482 OP_I16, /* 1 .. 16 */
5287ad62 6483 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6484 OP_I31, /* 0 .. 31 */
6485 OP_I31w, /* 0 .. 31, optional trailing ! */
6486 OP_I32, /* 1 .. 32 */
5287ad62
JB
6487 OP_I32z, /* 0 .. 32 */
6488 OP_I63, /* 0 .. 63 */
c19d1205 6489 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6490 OP_I64, /* 1 .. 64 */
6491 OP_I64z, /* 0 .. 64 */
c19d1205 6492 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6493
6494 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6495 OP_I7b, /* 0 .. 7 */
6496 OP_I15b, /* 0 .. 15 */
6497 OP_I31b, /* 0 .. 31 */
6498
6499 OP_SH, /* shifter operand */
4962c51a 6500 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6501 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6502 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6503 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6504 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6505 OP_EXP, /* arbitrary expression */
6506 OP_EXPi, /* same, with optional immediate prefix */
6507 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6508 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
6509
6510 OP_CPSF, /* CPS flags */
6511 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6512 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6513 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6514 OP_COND, /* conditional code */
92e90b6e 6515 OP_TB, /* Table branch. */
c19d1205 6516
037e8744
JB
6517 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6518
c19d1205
ZW
6519 OP_RRnpc_I0, /* ARM register or literal 0 */
6520 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6521 OP_RR_EXi, /* ARM register or expression with imm prefix */
6522 OP_RF_IF, /* FPA register or immediate */
6523 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6524 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6525
6526 /* Optional operands. */
6527 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6528 OP_oI31b, /* 0 .. 31 */
5287ad62 6529 OP_oI32b, /* 1 .. 32 */
5f1af56b 6530 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6531 OP_oIffffb, /* 0 .. 65535 */
6532 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6533
6534 OP_oRR, /* ARM register */
6535 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6536 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6537 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6538 OP_oRND, /* Optional Neon double precision register */
6539 OP_oRNQ, /* Optional Neon quad precision register */
6540 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6541 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6542 OP_oSHll, /* LSL immediate */
6543 OP_oSHar, /* ASR immediate */
6544 OP_oSHllar, /* LSL or ASR immediate */
6545 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6546 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6547
5be8be5d
DG
6548 /* Some pre-defined mixed (ARM/THUMB) operands. */
6549 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6550 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6551 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6552
c19d1205
ZW
6553 OP_FIRST_OPTIONAL = OP_oI7b
6554};
a737bd4d 6555
c19d1205
ZW
6556/* Generic instruction operand parser. This does no encoding and no
6557 semantic validation; it merely squirrels values away in the inst
6558 structure. Returns SUCCESS or FAIL depending on whether the
6559 specified grammar matched. */
6560static int
5be8be5d 6561parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6562{
5be8be5d 6563 unsigned const int *upat = pattern;
c19d1205
ZW
6564 char *backtrack_pos = 0;
6565 const char *backtrack_error = 0;
99aad254 6566 int i, val = 0, backtrack_index = 0;
5287ad62 6567 enum arm_reg_type rtype;
4962c51a 6568 parse_operand_result result;
5be8be5d 6569 unsigned int op_parse_code;
c19d1205 6570
e07e6e58
NC
6571#define po_char_or_fail(chr) \
6572 do \
6573 { \
6574 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6575 goto bad_args; \
e07e6e58
NC
6576 } \
6577 while (0)
c19d1205 6578
e07e6e58
NC
6579#define po_reg_or_fail(regtype) \
6580 do \
dcbf9037 6581 { \
e07e6e58 6582 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6583 & inst.operands[i].vectype); \
e07e6e58 6584 if (val == FAIL) \
477330fc
RM
6585 { \
6586 first_error (_(reg_expected_msgs[regtype])); \
6587 goto failure; \
6588 } \
e07e6e58
NC
6589 inst.operands[i].reg = val; \
6590 inst.operands[i].isreg = 1; \
6591 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6592 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6593 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6594 || rtype == REG_TYPE_VFD \
6595 || rtype == REG_TYPE_NQ); \
dcbf9037 6596 } \
e07e6e58
NC
6597 while (0)
6598
6599#define po_reg_or_goto(regtype, label) \
6600 do \
6601 { \
6602 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6603 & inst.operands[i].vectype); \
6604 if (val == FAIL) \
6605 goto label; \
dcbf9037 6606 \
e07e6e58
NC
6607 inst.operands[i].reg = val; \
6608 inst.operands[i].isreg = 1; \
6609 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6610 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6611 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6612 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6613 || rtype == REG_TYPE_NQ); \
6614 } \
6615 while (0)
6616
6617#define po_imm_or_fail(min, max, popt) \
6618 do \
6619 { \
6620 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6621 goto failure; \
6622 inst.operands[i].imm = val; \
6623 } \
6624 while (0)
6625
6626#define po_scalar_or_goto(elsz, label) \
6627 do \
6628 { \
6629 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6630 if (val == FAIL) \
6631 goto label; \
6632 inst.operands[i].reg = val; \
6633 inst.operands[i].isscalar = 1; \
6634 } \
6635 while (0)
6636
6637#define po_misc_or_fail(expr) \
6638 do \
6639 { \
6640 if (expr) \
6641 goto failure; \
6642 } \
6643 while (0)
6644
6645#define po_misc_or_fail_no_backtrack(expr) \
6646 do \
6647 { \
6648 result = expr; \
6649 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6650 backtrack_pos = 0; \
6651 if (result != PARSE_OPERAND_SUCCESS) \
6652 goto failure; \
6653 } \
6654 while (0)
4962c51a 6655
52e7f43d
RE
6656#define po_barrier_or_imm(str) \
6657 do \
6658 { \
6659 val = parse_barrier (&str); \
ccb84d65
JB
6660 if (val == FAIL && ! ISALPHA (*str)) \
6661 goto immediate; \
6662 if (val == FAIL \
6663 /* ISB can only take SY as an option. */ \
6664 || ((inst.instruction & 0xf0) == 0x60 \
6665 && val != 0xf)) \
52e7f43d 6666 { \
ccb84d65
JB
6667 inst.error = _("invalid barrier type"); \
6668 backtrack_pos = 0; \
6669 goto failure; \
52e7f43d
RE
6670 } \
6671 } \
6672 while (0)
6673
c19d1205
ZW
6674 skip_whitespace (str);
6675
6676 for (i = 0; upat[i] != OP_stop; i++)
6677 {
5be8be5d
DG
6678 op_parse_code = upat[i];
6679 if (op_parse_code >= 1<<16)
6680 op_parse_code = thumb ? (op_parse_code >> 16)
6681 : (op_parse_code & ((1<<16)-1));
6682
6683 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6684 {
6685 /* Remember where we are in case we need to backtrack. */
9c2799c2 6686 gas_assert (!backtrack_pos);
c19d1205
ZW
6687 backtrack_pos = str;
6688 backtrack_error = inst.error;
6689 backtrack_index = i;
6690 }
6691
b6702015 6692 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6693 po_char_or_fail (',');
6694
5be8be5d 6695 switch (op_parse_code)
c19d1205
ZW
6696 {
6697 /* Registers */
6698 case OP_oRRnpc:
5be8be5d 6699 case OP_oRRnpcsp:
c19d1205 6700 case OP_RRnpc:
5be8be5d 6701 case OP_RRnpcsp:
c19d1205
ZW
6702 case OP_oRR:
6703 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6704 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6705 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6706 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6707 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6708 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6709 case OP_oRND:
5287ad62 6710 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6711 case OP_RVC:
6712 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6713 break;
6714 /* Also accept generic coprocessor regs for unknown registers. */
6715 coproc_reg:
6716 po_reg_or_fail (REG_TYPE_CN);
6717 break;
c19d1205
ZW
6718 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6719 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6720 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6721 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6722 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6723 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6724 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6725 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6726 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6727 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6728 case OP_oRNQ:
5287ad62 6729 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
477330fc 6730 case OP_oRNDQ:
5287ad62 6731 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6732 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6733 case OP_oRNSDQ:
6734 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6735
6736 /* Neon scalar. Using an element size of 8 means that some invalid
6737 scalars are accepted here, so deal with those in later code. */
6738 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6739
6740 case OP_RNDQ_I0:
6741 {
6742 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6743 break;
6744 try_imm0:
6745 po_imm_or_fail (0, 0, TRUE);
6746 }
6747 break;
6748
6749 case OP_RVSD_I0:
6750 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6751 break;
6752
aacf0b33
KT
6753 case OP_RSVD_FI0:
6754 {
6755 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6756 break;
6757 try_ifimm0:
6758 if (parse_ifimm_zero (&str))
6759 inst.operands[i].imm = 0;
6760 else
6761 {
6762 inst.error
6763 = _("only floating point zero is allowed as immediate value");
6764 goto failure;
6765 }
6766 }
6767 break;
6768
477330fc
RM
6769 case OP_RR_RNSC:
6770 {
6771 po_scalar_or_goto (8, try_rr);
6772 break;
6773 try_rr:
6774 po_reg_or_fail (REG_TYPE_RN);
6775 }
6776 break;
6777
6778 case OP_RNSDQ_RNSC:
6779 {
6780 po_scalar_or_goto (8, try_nsdq);
6781 break;
6782 try_nsdq:
6783 po_reg_or_fail (REG_TYPE_NSDQ);
6784 }
6785 break;
6786
6787 case OP_RNDQ_RNSC:
6788 {
6789 po_scalar_or_goto (8, try_ndq);
6790 break;
6791 try_ndq:
6792 po_reg_or_fail (REG_TYPE_NDQ);
6793 }
6794 break;
6795
6796 case OP_RND_RNSC:
6797 {
6798 po_scalar_or_goto (8, try_vfd);
6799 break;
6800 try_vfd:
6801 po_reg_or_fail (REG_TYPE_VFD);
6802 }
6803 break;
6804
6805 case OP_VMOV:
6806 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6807 not careful then bad things might happen. */
6808 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6809 break;
6810
6811 case OP_RNDQ_Ibig:
6812 {
6813 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6814 break;
6815 try_immbig:
6816 /* There's a possibility of getting a 64-bit immediate here, so
6817 we need special handling. */
8335d6aa
JW
6818 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6819 == FAIL)
477330fc
RM
6820 {
6821 inst.error = _("immediate value is out of range");
6822 goto failure;
6823 }
6824 }
6825 break;
6826
6827 case OP_RNDQ_I63b:
6828 {
6829 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6830 break;
6831 try_shimm:
6832 po_imm_or_fail (0, 63, TRUE);
6833 }
6834 break;
c19d1205
ZW
6835
6836 case OP_RRnpcb:
6837 po_char_or_fail ('[');
6838 po_reg_or_fail (REG_TYPE_RN);
6839 po_char_or_fail (']');
6840 break;
a737bd4d 6841
55881a11 6842 case OP_RRnpctw:
c19d1205 6843 case OP_RRw:
b6702015 6844 case OP_oRRw:
c19d1205
ZW
6845 po_reg_or_fail (REG_TYPE_RN);
6846 if (skip_past_char (&str, '!') == SUCCESS)
6847 inst.operands[i].writeback = 1;
6848 break;
6849
6850 /* Immediates */
6851 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6852 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6853 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6854 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6855 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6856 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6857 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6858 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6859 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6860 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6861 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6862 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6863
6864 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6865 case OP_oI7b:
6866 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6867 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6868 case OP_oI31b:
6869 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6870 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6871 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6872 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6873
6874 /* Immediate variants */
6875 case OP_oI255c:
6876 po_char_or_fail ('{');
6877 po_imm_or_fail (0, 255, TRUE);
6878 po_char_or_fail ('}');
6879 break;
6880
6881 case OP_I31w:
6882 /* The expression parser chokes on a trailing !, so we have
6883 to find it first and zap it. */
6884 {
6885 char *s = str;
6886 while (*s && *s != ',')
6887 s++;
6888 if (s[-1] == '!')
6889 {
6890 s[-1] = '\0';
6891 inst.operands[i].writeback = 1;
6892 }
6893 po_imm_or_fail (0, 31, TRUE);
6894 if (str == s - 1)
6895 str = s;
6896 }
6897 break;
6898
6899 /* Expressions */
6900 case OP_EXPi: EXPi:
6901 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6902 GE_OPT_PREFIX));
6903 break;
6904
6905 case OP_EXP:
6906 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6907 GE_NO_PREFIX));
6908 break;
6909
6910 case OP_EXPr: EXPr:
6911 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6912 GE_NO_PREFIX));
6913 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6914 {
c19d1205
ZW
6915 val = parse_reloc (&str);
6916 if (val == -1)
6917 {
6918 inst.error = _("unrecognized relocation suffix");
6919 goto failure;
6920 }
6921 else if (val != BFD_RELOC_UNUSED)
6922 {
6923 inst.operands[i].imm = val;
6924 inst.operands[i].hasreloc = 1;
6925 }
a737bd4d 6926 }
c19d1205 6927 break;
a737bd4d 6928
b6895b4f
PB
6929 /* Operand for MOVW or MOVT. */
6930 case OP_HALF:
6931 po_misc_or_fail (parse_half (&str));
6932 break;
6933
e07e6e58 6934 /* Register or expression. */
c19d1205
ZW
6935 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6936 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6937
e07e6e58 6938 /* Register or immediate. */
c19d1205
ZW
6939 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6940 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6941
c19d1205
ZW
6942 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6943 IF:
6944 if (!is_immediate_prefix (*str))
6945 goto bad_args;
6946 str++;
6947 val = parse_fpa_immediate (&str);
6948 if (val == FAIL)
6949 goto failure;
6950 /* FPA immediates are encoded as registers 8-15.
6951 parse_fpa_immediate has already applied the offset. */
6952 inst.operands[i].reg = val;
6953 inst.operands[i].isreg = 1;
6954 break;
09d92015 6955
2d447fca
JM
6956 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6957 I32z: po_imm_or_fail (0, 32, FALSE); break;
6958
e07e6e58 6959 /* Two kinds of register. */
c19d1205
ZW
6960 case OP_RIWR_RIWC:
6961 {
6962 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6963 if (!rege
6964 || (rege->type != REG_TYPE_MMXWR
6965 && rege->type != REG_TYPE_MMXWC
6966 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6967 {
6968 inst.error = _("iWMMXt data or control register expected");
6969 goto failure;
6970 }
6971 inst.operands[i].reg = rege->number;
6972 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6973 }
6974 break;
09d92015 6975
41adaa5c
JM
6976 case OP_RIWC_RIWG:
6977 {
6978 struct reg_entry *rege = arm_reg_parse_multi (&str);
6979 if (!rege
6980 || (rege->type != REG_TYPE_MMXWC
6981 && rege->type != REG_TYPE_MMXWCG))
6982 {
6983 inst.error = _("iWMMXt control register expected");
6984 goto failure;
6985 }
6986 inst.operands[i].reg = rege->number;
6987 inst.operands[i].isreg = 1;
6988 }
6989 break;
6990
c19d1205
ZW
6991 /* Misc */
6992 case OP_CPSF: val = parse_cps_flags (&str); break;
6993 case OP_ENDI: val = parse_endian_specifier (&str); break;
6994 case OP_oROR: val = parse_ror (&str); break;
c19d1205 6995 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
6996 case OP_oBARRIER_I15:
6997 po_barrier_or_imm (str); break;
6998 immediate:
6999 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7000 goto failure;
52e7f43d 7001 break;
c19d1205 7002
fa94de6b 7003 case OP_wPSR:
d2cd1205 7004 case OP_rPSR:
90ec0d68
MGD
7005 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7006 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7007 {
7008 inst.error = _("Banked registers are not available with this "
7009 "architecture.");
7010 goto failure;
7011 }
7012 break;
d2cd1205
JB
7013 try_psr:
7014 val = parse_psr (&str, op_parse_code == OP_wPSR);
7015 break;
037e8744 7016
477330fc
RM
7017 case OP_APSR_RR:
7018 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7019 break;
7020 try_apsr:
7021 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7022 instruction). */
7023 if (strncasecmp (str, "APSR_", 5) == 0)
7024 {
7025 unsigned found = 0;
7026 str += 5;
7027 while (found < 15)
7028 switch (*str++)
7029 {
7030 case 'c': found = (found & 1) ? 16 : found | 1; break;
7031 case 'n': found = (found & 2) ? 16 : found | 2; break;
7032 case 'z': found = (found & 4) ? 16 : found | 4; break;
7033 case 'v': found = (found & 8) ? 16 : found | 8; break;
7034 default: found = 16;
7035 }
7036 if (found != 15)
7037 goto failure;
7038 inst.operands[i].isvec = 1;
f7c21dc7
NC
7039 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7040 inst.operands[i].reg = REG_PC;
477330fc
RM
7041 }
7042 else
7043 goto failure;
7044 break;
037e8744 7045
92e90b6e
PB
7046 case OP_TB:
7047 po_misc_or_fail (parse_tb (&str));
7048 break;
7049
e07e6e58 7050 /* Register lists. */
c19d1205
ZW
7051 case OP_REGLST:
7052 val = parse_reg_list (&str);
7053 if (*str == '^')
7054 {
5e0d7f77 7055 inst.operands[i].writeback = 1;
c19d1205
ZW
7056 str++;
7057 }
7058 break;
09d92015 7059
c19d1205 7060 case OP_VRSLST:
5287ad62 7061 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7062 break;
09d92015 7063
c19d1205 7064 case OP_VRDLST:
5287ad62 7065 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7066 break;
a737bd4d 7067
477330fc
RM
7068 case OP_VRSDLST:
7069 /* Allow Q registers too. */
7070 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7071 REGLIST_NEON_D);
7072 if (val == FAIL)
7073 {
7074 inst.error = NULL;
7075 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7076 REGLIST_VFP_S);
7077 inst.operands[i].issingle = 1;
7078 }
7079 break;
7080
7081 case OP_NRDLST:
7082 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7083 REGLIST_NEON_D);
7084 break;
5287ad62
JB
7085
7086 case OP_NSTRLST:
477330fc
RM
7087 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7088 &inst.operands[i].vectype);
7089 break;
5287ad62 7090
c19d1205
ZW
7091 /* Addressing modes */
7092 case OP_ADDR:
7093 po_misc_or_fail (parse_address (&str, i));
7094 break;
09d92015 7095
4962c51a
MS
7096 case OP_ADDRGLDR:
7097 po_misc_or_fail_no_backtrack (
477330fc 7098 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7099 break;
7100
7101 case OP_ADDRGLDRS:
7102 po_misc_or_fail_no_backtrack (
477330fc 7103 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7104 break;
7105
7106 case OP_ADDRGLDC:
7107 po_misc_or_fail_no_backtrack (
477330fc 7108 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7109 break;
7110
c19d1205
ZW
7111 case OP_SH:
7112 po_misc_or_fail (parse_shifter_operand (&str, i));
7113 break;
09d92015 7114
4962c51a
MS
7115 case OP_SHG:
7116 po_misc_or_fail_no_backtrack (
477330fc 7117 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7118 break;
7119
c19d1205
ZW
7120 case OP_oSHll:
7121 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7122 break;
09d92015 7123
c19d1205
ZW
7124 case OP_oSHar:
7125 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7126 break;
09d92015 7127
c19d1205
ZW
7128 case OP_oSHllar:
7129 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7130 break;
09d92015 7131
c19d1205 7132 default:
5be8be5d 7133 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7134 }
09d92015 7135
c19d1205
ZW
7136 /* Various value-based sanity checks and shared operations. We
7137 do not signal immediate failures for the register constraints;
7138 this allows a syntax error to take precedence. */
5be8be5d 7139 switch (op_parse_code)
c19d1205
ZW
7140 {
7141 case OP_oRRnpc:
7142 case OP_RRnpc:
7143 case OP_RRnpcb:
7144 case OP_RRw:
b6702015 7145 case OP_oRRw:
c19d1205
ZW
7146 case OP_RRnpc_I0:
7147 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7148 inst.error = BAD_PC;
7149 break;
09d92015 7150
5be8be5d
DG
7151 case OP_oRRnpcsp:
7152 case OP_RRnpcsp:
7153 if (inst.operands[i].isreg)
7154 {
7155 if (inst.operands[i].reg == REG_PC)
7156 inst.error = BAD_PC;
7157 else if (inst.operands[i].reg == REG_SP)
7158 inst.error = BAD_SP;
7159 }
7160 break;
7161
55881a11 7162 case OP_RRnpctw:
fa94de6b
RM
7163 if (inst.operands[i].isreg
7164 && inst.operands[i].reg == REG_PC
55881a11
MGD
7165 && (inst.operands[i].writeback || thumb))
7166 inst.error = BAD_PC;
7167 break;
7168
c19d1205
ZW
7169 case OP_CPSF:
7170 case OP_ENDI:
7171 case OP_oROR:
d2cd1205
JB
7172 case OP_wPSR:
7173 case OP_rPSR:
c19d1205 7174 case OP_COND:
52e7f43d 7175 case OP_oBARRIER_I15:
c19d1205
ZW
7176 case OP_REGLST:
7177 case OP_VRSLST:
7178 case OP_VRDLST:
477330fc
RM
7179 case OP_VRSDLST:
7180 case OP_NRDLST:
7181 case OP_NSTRLST:
c19d1205
ZW
7182 if (val == FAIL)
7183 goto failure;
7184 inst.operands[i].imm = val;
7185 break;
a737bd4d 7186
c19d1205
ZW
7187 default:
7188 break;
7189 }
09d92015 7190
c19d1205
ZW
7191 /* If we get here, this operand was successfully parsed. */
7192 inst.operands[i].present = 1;
7193 continue;
09d92015 7194
c19d1205 7195 bad_args:
09d92015 7196 inst.error = BAD_ARGS;
c19d1205
ZW
7197
7198 failure:
7199 if (!backtrack_pos)
d252fdde
PB
7200 {
7201 /* The parse routine should already have set inst.error, but set a
5f4273c7 7202 default here just in case. */
d252fdde
PB
7203 if (!inst.error)
7204 inst.error = _("syntax error");
7205 return FAIL;
7206 }
c19d1205
ZW
7207
7208 /* Do not backtrack over a trailing optional argument that
7209 absorbed some text. We will only fail again, with the
7210 'garbage following instruction' error message, which is
7211 probably less helpful than the current one. */
7212 if (backtrack_index == i && backtrack_pos != str
7213 && upat[i+1] == OP_stop)
d252fdde
PB
7214 {
7215 if (!inst.error)
7216 inst.error = _("syntax error");
7217 return FAIL;
7218 }
c19d1205
ZW
7219
7220 /* Try again, skipping the optional argument at backtrack_pos. */
7221 str = backtrack_pos;
7222 inst.error = backtrack_error;
7223 inst.operands[backtrack_index].present = 0;
7224 i = backtrack_index;
7225 backtrack_pos = 0;
09d92015 7226 }
09d92015 7227
c19d1205
ZW
7228 /* Check that we have parsed all the arguments. */
7229 if (*str != '\0' && !inst.error)
7230 inst.error = _("garbage following instruction");
09d92015 7231
c19d1205 7232 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7233}
7234
c19d1205
ZW
7235#undef po_char_or_fail
7236#undef po_reg_or_fail
7237#undef po_reg_or_goto
7238#undef po_imm_or_fail
5287ad62 7239#undef po_scalar_or_fail
52e7f43d 7240#undef po_barrier_or_imm
e07e6e58 7241
c19d1205 7242/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7243#define constraint(expr, err) \
7244 do \
c19d1205 7245 { \
e07e6e58
NC
7246 if (expr) \
7247 { \
7248 inst.error = err; \
7249 return; \
7250 } \
c19d1205 7251 } \
e07e6e58 7252 while (0)
c19d1205 7253
fdfde340
JM
7254/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7255 instructions are unpredictable if these registers are used. This
7256 is the BadReg predicate in ARM's Thumb-2 documentation. */
7257#define reject_bad_reg(reg) \
7258 do \
7259 if (reg == REG_SP || reg == REG_PC) \
7260 { \
7261 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
7262 return; \
7263 } \
7264 while (0)
7265
94206790
MM
7266/* If REG is R13 (the stack pointer), warn that its use is
7267 deprecated. */
7268#define warn_deprecated_sp(reg) \
7269 do \
7270 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7271 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7272 while (0)
7273
c19d1205
ZW
7274/* Functions for operand encoding. ARM, then Thumb. */
7275
d840c081 7276#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205
ZW
7277
7278/* If VAL can be encoded in the immediate field of an ARM instruction,
7279 return the encoded form. Otherwise, return FAIL. */
7280
7281static unsigned int
7282encode_arm_immediate (unsigned int val)
09d92015 7283{
c19d1205
ZW
7284 unsigned int a, i;
7285
7286 for (i = 0; i < 32; i += 2)
7287 if ((a = rotate_left (val, i)) <= 0xff)
7288 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7289
7290 return FAIL;
09d92015
MM
7291}
7292
c19d1205
ZW
7293/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7294 return the encoded form. Otherwise, return FAIL. */
7295static unsigned int
7296encode_thumb32_immediate (unsigned int val)
09d92015 7297{
c19d1205 7298 unsigned int a, i;
09d92015 7299
9c3c69f2 7300 if (val <= 0xff)
c19d1205 7301 return val;
a737bd4d 7302
9c3c69f2 7303 for (i = 1; i <= 24; i++)
09d92015 7304 {
9c3c69f2
PB
7305 a = val >> i;
7306 if ((val & ~(0xff << i)) == 0)
7307 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7308 }
a737bd4d 7309
c19d1205
ZW
7310 a = val & 0xff;
7311 if (val == ((a << 16) | a))
7312 return 0x100 | a;
7313 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7314 return 0x300 | a;
09d92015 7315
c19d1205
ZW
7316 a = val & 0xff00;
7317 if (val == ((a << 16) | a))
7318 return 0x200 | (a >> 8);
a737bd4d 7319
c19d1205 7320 return FAIL;
09d92015 7321}
5287ad62 7322/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7323
7324static void
5287ad62
JB
7325encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7326{
7327 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7328 && reg > 15)
7329 {
b1cc4aeb 7330 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7331 {
7332 if (thumb_mode)
7333 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7334 fpu_vfp_ext_d32);
7335 else
7336 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7337 fpu_vfp_ext_d32);
7338 }
5287ad62 7339 else
477330fc
RM
7340 {
7341 first_error (_("D register out of range for selected VFP version"));
7342 return;
7343 }
5287ad62
JB
7344 }
7345
c19d1205 7346 switch (pos)
09d92015 7347 {
c19d1205
ZW
7348 case VFP_REG_Sd:
7349 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7350 break;
7351
7352 case VFP_REG_Sn:
7353 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7354 break;
7355
7356 case VFP_REG_Sm:
7357 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7358 break;
7359
5287ad62
JB
7360 case VFP_REG_Dd:
7361 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7362 break;
5f4273c7 7363
5287ad62
JB
7364 case VFP_REG_Dn:
7365 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7366 break;
5f4273c7 7367
5287ad62
JB
7368 case VFP_REG_Dm:
7369 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7370 break;
7371
c19d1205
ZW
7372 default:
7373 abort ();
09d92015 7374 }
09d92015
MM
7375}
7376
c19d1205 7377/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7378 if any, is handled by md_apply_fix. */
09d92015 7379static void
c19d1205 7380encode_arm_shift (int i)
09d92015 7381{
c19d1205
ZW
7382 if (inst.operands[i].shift_kind == SHIFT_RRX)
7383 inst.instruction |= SHIFT_ROR << 5;
7384 else
09d92015 7385 {
c19d1205
ZW
7386 inst.instruction |= inst.operands[i].shift_kind << 5;
7387 if (inst.operands[i].immisreg)
7388 {
7389 inst.instruction |= SHIFT_BY_REG;
7390 inst.instruction |= inst.operands[i].imm << 8;
7391 }
7392 else
7393 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7394 }
c19d1205 7395}
09d92015 7396
c19d1205
ZW
7397static void
7398encode_arm_shifter_operand (int i)
7399{
7400 if (inst.operands[i].isreg)
09d92015 7401 {
c19d1205
ZW
7402 inst.instruction |= inst.operands[i].reg;
7403 encode_arm_shift (i);
09d92015 7404 }
c19d1205 7405 else
a415b1cd
JB
7406 {
7407 inst.instruction |= INST_IMMEDIATE;
7408 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7409 inst.instruction |= inst.operands[i].imm;
7410 }
09d92015
MM
7411}
7412
c19d1205 7413/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7414static void
c19d1205 7415encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7416{
2b2f5df9
NC
7417 /* PR 14260:
7418 Generate an error if the operand is not a register. */
7419 constraint (!inst.operands[i].isreg,
7420 _("Instruction does not support =N addresses"));
7421
c19d1205 7422 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7423
c19d1205 7424 if (inst.operands[i].preind)
09d92015 7425 {
c19d1205
ZW
7426 if (is_t)
7427 {
7428 inst.error = _("instruction does not accept preindexed addressing");
7429 return;
7430 }
7431 inst.instruction |= PRE_INDEX;
7432 if (inst.operands[i].writeback)
7433 inst.instruction |= WRITE_BACK;
09d92015 7434
c19d1205
ZW
7435 }
7436 else if (inst.operands[i].postind)
7437 {
9c2799c2 7438 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7439 if (is_t)
7440 inst.instruction |= WRITE_BACK;
7441 }
7442 else /* unindexed - only for coprocessor */
09d92015 7443 {
c19d1205 7444 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7445 return;
7446 }
7447
c19d1205
ZW
7448 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7449 && (((inst.instruction & 0x000f0000) >> 16)
7450 == ((inst.instruction & 0x0000f000) >> 12)))
7451 as_warn ((inst.instruction & LOAD_BIT)
7452 ? _("destination register same as write-back base")
7453 : _("source register same as write-back base"));
09d92015
MM
7454}
7455
c19d1205
ZW
7456/* inst.operands[i] was set up by parse_address. Encode it into an
7457 ARM-format mode 2 load or store instruction. If is_t is true,
7458 reject forms that cannot be used with a T instruction (i.e. not
7459 post-indexed). */
a737bd4d 7460static void
c19d1205 7461encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7462{
5be8be5d
DG
7463 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7464
c19d1205 7465 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7466
c19d1205 7467 if (inst.operands[i].immisreg)
09d92015 7468 {
5be8be5d
DG
7469 constraint ((inst.operands[i].imm == REG_PC
7470 || (is_pc && inst.operands[i].writeback)),
7471 BAD_PC_ADDRESSING);
c19d1205
ZW
7472 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7473 inst.instruction |= inst.operands[i].imm;
7474 if (!inst.operands[i].negative)
7475 inst.instruction |= INDEX_UP;
7476 if (inst.operands[i].shifted)
7477 {
7478 if (inst.operands[i].shift_kind == SHIFT_RRX)
7479 inst.instruction |= SHIFT_ROR << 5;
7480 else
7481 {
7482 inst.instruction |= inst.operands[i].shift_kind << 5;
7483 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7484 }
7485 }
09d92015 7486 }
c19d1205 7487 else /* immediate offset in inst.reloc */
09d92015 7488 {
5be8be5d
DG
7489 if (is_pc && !inst.reloc.pc_rel)
7490 {
7491 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7492
7493 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7494 cannot use PC in addressing.
7495 PC cannot be used in writeback addressing, either. */
7496 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7497 BAD_PC_ADDRESSING);
23a10334 7498
dc5ec521 7499 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7500 if (warn_on_deprecated
7501 && !is_load
7502 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7503 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7504 }
7505
c19d1205 7506 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7507 {
7508 /* Prefer + for zero encoded value. */
7509 if (!inst.operands[i].negative)
7510 inst.instruction |= INDEX_UP;
7511 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7512 }
09d92015 7513 }
09d92015
MM
7514}
7515
c19d1205
ZW
7516/* inst.operands[i] was set up by parse_address. Encode it into an
7517 ARM-format mode 3 load or store instruction. Reject forms that
7518 cannot be used with such instructions. If is_t is true, reject
7519 forms that cannot be used with a T instruction (i.e. not
7520 post-indexed). */
7521static void
7522encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7523{
c19d1205 7524 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7525 {
c19d1205
ZW
7526 inst.error = _("instruction does not accept scaled register index");
7527 return;
09d92015 7528 }
a737bd4d 7529
c19d1205 7530 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7531
c19d1205
ZW
7532 if (inst.operands[i].immisreg)
7533 {
5be8be5d 7534 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7535 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7536 BAD_PC_ADDRESSING);
eb9f3f00
JB
7537 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7538 BAD_PC_WRITEBACK);
c19d1205
ZW
7539 inst.instruction |= inst.operands[i].imm;
7540 if (!inst.operands[i].negative)
7541 inst.instruction |= INDEX_UP;
7542 }
7543 else /* immediate offset in inst.reloc */
7544 {
5be8be5d
DG
7545 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7546 && inst.operands[i].writeback),
7547 BAD_PC_WRITEBACK);
c19d1205
ZW
7548 inst.instruction |= HWOFFSET_IMM;
7549 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7550 {
7551 /* Prefer + for zero encoded value. */
7552 if (!inst.operands[i].negative)
7553 inst.instruction |= INDEX_UP;
7554
7555 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7556 }
c19d1205 7557 }
a737bd4d
NC
7558}
7559
8335d6aa
JW
7560/* Write immediate bits [7:0] to the following locations:
7561
7562 |28/24|23 19|18 16|15 4|3 0|
7563 | 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|
7564
7565 This function is used by VMOV/VMVN/VORR/VBIC. */
7566
7567static void
7568neon_write_immbits (unsigned immbits)
7569{
7570 inst.instruction |= immbits & 0xf;
7571 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7572 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7573}
7574
7575/* Invert low-order SIZE bits of XHI:XLO. */
7576
7577static void
7578neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7579{
7580 unsigned immlo = xlo ? *xlo : 0;
7581 unsigned immhi = xhi ? *xhi : 0;
7582
7583 switch (size)
7584 {
7585 case 8:
7586 immlo = (~immlo) & 0xff;
7587 break;
7588
7589 case 16:
7590 immlo = (~immlo) & 0xffff;
7591 break;
7592
7593 case 64:
7594 immhi = (~immhi) & 0xffffffff;
7595 /* fall through. */
7596
7597 case 32:
7598 immlo = (~immlo) & 0xffffffff;
7599 break;
7600
7601 default:
7602 abort ();
7603 }
7604
7605 if (xlo)
7606 *xlo = immlo;
7607
7608 if (xhi)
7609 *xhi = immhi;
7610}
7611
7612/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7613 A, B, C, D. */
09d92015 7614
c19d1205 7615static int
8335d6aa 7616neon_bits_same_in_bytes (unsigned imm)
09d92015 7617{
8335d6aa
JW
7618 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7619 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7620 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7621 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7622}
a737bd4d 7623
8335d6aa 7624/* For immediate of above form, return 0bABCD. */
09d92015 7625
8335d6aa
JW
7626static unsigned
7627neon_squash_bits (unsigned imm)
7628{
7629 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7630 | ((imm & 0x01000000) >> 21);
7631}
7632
7633/* Compress quarter-float representation to 0b...000 abcdefgh. */
7634
7635static unsigned
7636neon_qfloat_bits (unsigned imm)
7637{
7638 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7639}
7640
7641/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7642 the instruction. *OP is passed as the initial value of the op field, and
7643 may be set to a different value depending on the constant (i.e.
7644 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7645 MVN). If the immediate looks like a repeated pattern then also
7646 try smaller element sizes. */
7647
7648static int
7649neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7650 unsigned *immbits, int *op, int size,
7651 enum neon_el_type type)
7652{
7653 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7654 float. */
7655 if (type == NT_float && !float_p)
7656 return FAIL;
7657
7658 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7659 {
8335d6aa
JW
7660 if (size != 32 || *op == 1)
7661 return FAIL;
7662 *immbits = neon_qfloat_bits (immlo);
7663 return 0xf;
7664 }
7665
7666 if (size == 64)
7667 {
7668 if (neon_bits_same_in_bytes (immhi)
7669 && neon_bits_same_in_bytes (immlo))
c19d1205 7670 {
8335d6aa
JW
7671 if (*op == 1)
7672 return FAIL;
7673 *immbits = (neon_squash_bits (immhi) << 4)
7674 | neon_squash_bits (immlo);
7675 *op = 1;
7676 return 0xe;
c19d1205 7677 }
a737bd4d 7678
8335d6aa
JW
7679 if (immhi != immlo)
7680 return FAIL;
7681 }
a737bd4d 7682
8335d6aa 7683 if (size >= 32)
09d92015 7684 {
8335d6aa 7685 if (immlo == (immlo & 0x000000ff))
c19d1205 7686 {
8335d6aa
JW
7687 *immbits = immlo;
7688 return 0x0;
c19d1205 7689 }
8335d6aa 7690 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7691 {
8335d6aa
JW
7692 *immbits = immlo >> 8;
7693 return 0x2;
c19d1205 7694 }
8335d6aa
JW
7695 else if (immlo == (immlo & 0x00ff0000))
7696 {
7697 *immbits = immlo >> 16;
7698 return 0x4;
7699 }
7700 else if (immlo == (immlo & 0xff000000))
7701 {
7702 *immbits = immlo >> 24;
7703 return 0x6;
7704 }
7705 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7706 {
7707 *immbits = (immlo >> 8) & 0xff;
7708 return 0xc;
7709 }
7710 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7711 {
7712 *immbits = (immlo >> 16) & 0xff;
7713 return 0xd;
7714 }
7715
7716 if ((immlo & 0xffff) != (immlo >> 16))
7717 return FAIL;
7718 immlo &= 0xffff;
09d92015 7719 }
a737bd4d 7720
8335d6aa 7721 if (size >= 16)
4962c51a 7722 {
8335d6aa
JW
7723 if (immlo == (immlo & 0x000000ff))
7724 {
7725 *immbits = immlo;
7726 return 0x8;
7727 }
7728 else if (immlo == (immlo & 0x0000ff00))
7729 {
7730 *immbits = immlo >> 8;
7731 return 0xa;
7732 }
7733
7734 if ((immlo & 0xff) != (immlo >> 8))
7735 return FAIL;
7736 immlo &= 0xff;
4962c51a
MS
7737 }
7738
8335d6aa
JW
7739 if (immlo == (immlo & 0x000000ff))
7740 {
7741 /* Don't allow MVN with 8-bit immediate. */
7742 if (*op == 1)
7743 return FAIL;
7744 *immbits = immlo;
7745 return 0xe;
7746 }
26d97720 7747
8335d6aa 7748 return FAIL;
c19d1205 7749}
a737bd4d 7750
8335d6aa
JW
7751enum lit_type
7752{
7753 CONST_THUMB,
7754 CONST_ARM,
7755 CONST_VEC
7756};
7757
c19d1205
ZW
7758/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7759 Determine whether it can be performed with a move instruction; if
7760 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7761 return TRUE; if it can't, convert inst.instruction to a literal-pool
7762 load and return FALSE. If this is not a valid thing to do in the
7763 current context, set inst.error and return TRUE.
a737bd4d 7764
c19d1205
ZW
7765 inst.operands[i] describes the destination register. */
7766
c921be7d 7767static bfd_boolean
8335d6aa 7768move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7769{
53365c0d 7770 unsigned long tbit;
8335d6aa
JW
7771 bfd_boolean thumb_p = (t == CONST_THUMB);
7772 bfd_boolean arm_p = (t == CONST_ARM);
7773 bfd_boolean vec64_p = (t == CONST_VEC) && !inst.operands[i].issingle;
53365c0d
PB
7774
7775 if (thumb_p)
7776 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7777 else
7778 tbit = LOAD_BIT;
7779
7780 if ((inst.instruction & tbit) == 0)
09d92015 7781 {
c19d1205 7782 inst.error = _("invalid pseudo operation");
c921be7d 7783 return TRUE;
09d92015 7784 }
8335d6aa
JW
7785 if (inst.reloc.exp.X_op != O_constant
7786 && inst.reloc.exp.X_op != O_symbol
7787 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7788 {
7789 inst.error = _("constant expression expected");
c921be7d 7790 return TRUE;
09d92015 7791 }
8335d6aa
JW
7792 if ((inst.reloc.exp.X_op == O_constant
7793 || inst.reloc.exp.X_op == O_big)
7794 && !inst.operands[i].issingle)
7795 {
7796 if (thumb_p && inst.reloc.exp.X_op == O_constant)
7797 {
7798 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
7799 {
7800 /* This can be done with a mov(1) instruction. */
7801 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7802 inst.instruction |= inst.reloc.exp.X_add_number;
7803 return TRUE;
7804 }
7805 }
7806 else if (arm_p && inst.reloc.exp.X_op == O_constant)
7807 {
7808 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
7809 if (value != FAIL)
7810 {
7811 /* This can be done with a mov instruction. */
7812 inst.instruction &= LITERAL_MASK;
7813 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7814 inst.instruction |= value & 0xfff;
7815 return TRUE;
7816 }
7817
7818 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
7819 if (value != FAIL)
7820 {
7821 /* This can be done with a mvn instruction. */
7822 inst.instruction &= LITERAL_MASK;
7823 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7824 inst.instruction |= value & 0xfff;
7825 return TRUE;
7826 }
7827 }
7828 else if (vec64_p)
7829 {
7830 int op = 0;
7831 unsigned immbits = 0;
7832 unsigned immlo = inst.operands[1].imm;
7833 unsigned immhi = inst.operands[1].regisimm
7834 ? inst.operands[1].reg
7835 : inst.reloc.exp.X_unsigned
7836 ? 0
2569ceb0 7837 : ((bfd_int64_t)((int) immlo)) >> 32;
8335d6aa
JW
7838 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
7839 &op, 64, NT_invtype);
7840
7841 if (cmode == FAIL)
7842 {
7843 neon_invert_size (&immlo, &immhi, 64);
7844 op = !op;
7845 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
7846 &op, 64, NT_invtype);
7847 }
7848 if (cmode != FAIL)
7849 {
7850 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
7851 | (1 << 23)
7852 | (cmode << 8)
7853 | (op << 5)
7854 | (1 << 4);
7855 /* Fill other bits in vmov encoding for both thumb and arm. */
7856 if (thumb_mode)
7857 inst.instruction |= (0x7 << 29) | (0xF << 24);
7858 else
7859 inst.instruction |= (0xF << 28) | (0x1 << 25);
7860 neon_write_immbits (immbits);
7861 return TRUE;
7862 }
7863 }
7864 }
7865
7866 if (add_to_lit_pool ((!inst.operands[i].isvec
7867 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
7868 return TRUE;
7869
7870 inst.operands[1].reg = REG_PC;
7871 inst.operands[1].isreg = 1;
7872 inst.operands[1].preind = 1;
7873 inst.reloc.pc_rel = 1;
7874 inst.reloc.type = (thumb_p
7875 ? BFD_RELOC_ARM_THUMB_OFFSET
7876 : (mode_3
7877 ? BFD_RELOC_ARM_HWLITERAL
7878 : BFD_RELOC_ARM_LITERAL));
7879 return FALSE;
7880}
7881
7882/* inst.operands[i] was set up by parse_address. Encode it into an
7883 ARM-format instruction. Reject all forms which cannot be encoded
7884 into a coprocessor load/store instruction. If wb_ok is false,
7885 reject use of writeback; if unind_ok is false, reject use of
7886 unindexed addressing. If reloc_override is not 0, use it instead
7887 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
7888 (in which case it is preserved). */
7889
7890static int
7891encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
7892{
7893 if (!inst.operands[i].isreg)
7894 {
99b2a2dd
NC
7895 /* PR 18256 */
7896 if (! inst.operands[0].isvec)
7897 {
7898 inst.error = _("invalid co-processor operand");
7899 return FAIL;
7900 }
8335d6aa
JW
7901 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
7902 return SUCCESS;
7903 }
7904
7905 inst.instruction |= inst.operands[i].reg << 16;
7906
7907 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
7908
7909 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
7910 {
7911 gas_assert (!inst.operands[i].writeback);
7912 if (!unind_ok)
7913 {
7914 inst.error = _("instruction does not support unindexed addressing");
7915 return FAIL;
7916 }
7917 inst.instruction |= inst.operands[i].imm;
7918 inst.instruction |= INDEX_UP;
7919 return SUCCESS;
7920 }
7921
7922 if (inst.operands[i].preind)
7923 inst.instruction |= PRE_INDEX;
7924
7925 if (inst.operands[i].writeback)
09d92015 7926 {
8335d6aa 7927 if (inst.operands[i].reg == REG_PC)
c19d1205 7928 {
8335d6aa
JW
7929 inst.error = _("pc may not be used with write-back");
7930 return FAIL;
c19d1205 7931 }
8335d6aa 7932 if (!wb_ok)
c19d1205 7933 {
8335d6aa
JW
7934 inst.error = _("instruction does not support writeback");
7935 return FAIL;
c19d1205 7936 }
8335d6aa 7937 inst.instruction |= WRITE_BACK;
09d92015
MM
7938 }
7939
8335d6aa
JW
7940 if (reloc_override)
7941 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
7942 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
7943 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
7944 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 7945 {
8335d6aa
JW
7946 if (thumb_mode)
7947 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
7948 else
7949 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 7950 }
8335d6aa
JW
7951
7952 /* Prefer + for zero encoded value. */
7953 if (!inst.operands[i].negative)
7954 inst.instruction |= INDEX_UP;
7955
7956 return SUCCESS;
09d92015
MM
7957}
7958
5f4273c7 7959/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
7960 First some generics; their names are taken from the conventional
7961 bit positions for register arguments in ARM format instructions. */
09d92015 7962
a737bd4d 7963static void
c19d1205 7964do_noargs (void)
09d92015 7965{
c19d1205 7966}
a737bd4d 7967
c19d1205
ZW
7968static void
7969do_rd (void)
7970{
7971 inst.instruction |= inst.operands[0].reg << 12;
7972}
a737bd4d 7973
c19d1205
ZW
7974static void
7975do_rd_rm (void)
7976{
7977 inst.instruction |= inst.operands[0].reg << 12;
7978 inst.instruction |= inst.operands[1].reg;
7979}
09d92015 7980
9eb6c0f1
MGD
7981static void
7982do_rm_rn (void)
7983{
7984 inst.instruction |= inst.operands[0].reg;
7985 inst.instruction |= inst.operands[1].reg << 16;
7986}
7987
c19d1205
ZW
7988static void
7989do_rd_rn (void)
7990{
7991 inst.instruction |= inst.operands[0].reg << 12;
7992 inst.instruction |= inst.operands[1].reg << 16;
7993}
a737bd4d 7994
c19d1205
ZW
7995static void
7996do_rn_rd (void)
7997{
7998 inst.instruction |= inst.operands[0].reg << 16;
7999 inst.instruction |= inst.operands[1].reg << 12;
8000}
09d92015 8001
59d09be6
MGD
8002static bfd_boolean
8003check_obsolete (const arm_feature_set *feature, const char *msg)
8004{
8005 if (ARM_CPU_IS_ANY (cpu_variant))
8006 {
5c3696f8 8007 as_tsktsk ("%s", msg);
59d09be6
MGD
8008 return TRUE;
8009 }
8010 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8011 {
8012 as_bad ("%s", msg);
8013 return TRUE;
8014 }
8015
8016 return FALSE;
8017}
8018
c19d1205
ZW
8019static void
8020do_rd_rm_rn (void)
8021{
9a64e435 8022 unsigned Rn = inst.operands[2].reg;
708587a4 8023 /* Enforce restrictions on SWP instruction. */
9a64e435 8024 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8025 {
8026 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8027 _("Rn must not overlap other operands"));
8028
59d09be6
MGD
8029 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8030 */
8031 if (!check_obsolete (&arm_ext_v8,
8032 _("swp{b} use is obsoleted for ARMv8 and later"))
8033 && warn_on_deprecated
8034 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8035 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8036 }
59d09be6 8037
c19d1205
ZW
8038 inst.instruction |= inst.operands[0].reg << 12;
8039 inst.instruction |= inst.operands[1].reg;
9a64e435 8040 inst.instruction |= Rn << 16;
c19d1205 8041}
09d92015 8042
c19d1205
ZW
8043static void
8044do_rd_rn_rm (void)
8045{
8046 inst.instruction |= inst.operands[0].reg << 12;
8047 inst.instruction |= inst.operands[1].reg << 16;
8048 inst.instruction |= inst.operands[2].reg;
8049}
a737bd4d 8050
c19d1205
ZW
8051static void
8052do_rm_rd_rn (void)
8053{
5be8be5d
DG
8054 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8055 constraint (((inst.reloc.exp.X_op != O_constant
8056 && inst.reloc.exp.X_op != O_illegal)
8057 || inst.reloc.exp.X_add_number != 0),
8058 BAD_ADDR_MODE);
c19d1205
ZW
8059 inst.instruction |= inst.operands[0].reg;
8060 inst.instruction |= inst.operands[1].reg << 12;
8061 inst.instruction |= inst.operands[2].reg << 16;
8062}
09d92015 8063
c19d1205
ZW
8064static void
8065do_imm0 (void)
8066{
8067 inst.instruction |= inst.operands[0].imm;
8068}
09d92015 8069
c19d1205
ZW
8070static void
8071do_rd_cpaddr (void)
8072{
8073 inst.instruction |= inst.operands[0].reg << 12;
8074 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8075}
a737bd4d 8076
c19d1205
ZW
8077/* ARM instructions, in alphabetical order by function name (except
8078 that wrapper functions appear immediately after the function they
8079 wrap). */
09d92015 8080
c19d1205
ZW
8081/* This is a pseudo-op of the form "adr rd, label" to be converted
8082 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8083
8084static void
c19d1205 8085do_adr (void)
09d92015 8086{
c19d1205 8087 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8088
c19d1205
ZW
8089 /* Frag hacking will turn this into a sub instruction if the offset turns
8090 out to be negative. */
8091 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8092 inst.reloc.pc_rel = 1;
2fc8bdac 8093 inst.reloc.exp.X_add_number -= 8;
c19d1205 8094}
b99bd4ef 8095
c19d1205
ZW
8096/* This is a pseudo-op of the form "adrl rd, label" to be converted
8097 into a relative address of the form:
8098 add rd, pc, #low(label-.-8)"
8099 add rd, rd, #high(label-.-8)" */
b99bd4ef 8100
c19d1205
ZW
8101static void
8102do_adrl (void)
8103{
8104 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8105
c19d1205
ZW
8106 /* Frag hacking will turn this into a sub instruction if the offset turns
8107 out to be negative. */
8108 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8109 inst.reloc.pc_rel = 1;
8110 inst.size = INSN_SIZE * 2;
2fc8bdac 8111 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
8112}
8113
b99bd4ef 8114static void
c19d1205 8115do_arit (void)
b99bd4ef 8116{
c19d1205
ZW
8117 if (!inst.operands[1].present)
8118 inst.operands[1].reg = inst.operands[0].reg;
8119 inst.instruction |= inst.operands[0].reg << 12;
8120 inst.instruction |= inst.operands[1].reg << 16;
8121 encode_arm_shifter_operand (2);
8122}
b99bd4ef 8123
62b3e311
PB
8124static void
8125do_barrier (void)
8126{
8127 if (inst.operands[0].present)
ccb84d65 8128 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8129 else
8130 inst.instruction |= 0xf;
8131}
8132
c19d1205
ZW
8133static void
8134do_bfc (void)
8135{
8136 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8137 constraint (msb > 32, _("bit-field extends past end of register"));
8138 /* The instruction encoding stores the LSB and MSB,
8139 not the LSB and width. */
8140 inst.instruction |= inst.operands[0].reg << 12;
8141 inst.instruction |= inst.operands[1].imm << 7;
8142 inst.instruction |= (msb - 1) << 16;
8143}
b99bd4ef 8144
c19d1205
ZW
8145static void
8146do_bfi (void)
8147{
8148 unsigned int msb;
b99bd4ef 8149
c19d1205
ZW
8150 /* #0 in second position is alternative syntax for bfc, which is
8151 the same instruction but with REG_PC in the Rm field. */
8152 if (!inst.operands[1].isreg)
8153 inst.operands[1].reg = REG_PC;
b99bd4ef 8154
c19d1205
ZW
8155 msb = inst.operands[2].imm + inst.operands[3].imm;
8156 constraint (msb > 32, _("bit-field extends past end of register"));
8157 /* The instruction encoding stores the LSB and MSB,
8158 not the LSB and width. */
8159 inst.instruction |= inst.operands[0].reg << 12;
8160 inst.instruction |= inst.operands[1].reg;
8161 inst.instruction |= inst.operands[2].imm << 7;
8162 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8163}
8164
b99bd4ef 8165static void
c19d1205 8166do_bfx (void)
b99bd4ef 8167{
c19d1205
ZW
8168 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8169 _("bit-field extends past end of register"));
8170 inst.instruction |= inst.operands[0].reg << 12;
8171 inst.instruction |= inst.operands[1].reg;
8172 inst.instruction |= inst.operands[2].imm << 7;
8173 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8174}
09d92015 8175
c19d1205
ZW
8176/* ARM V5 breakpoint instruction (argument parse)
8177 BKPT <16 bit unsigned immediate>
8178 Instruction is not conditional.
8179 The bit pattern given in insns[] has the COND_ALWAYS condition,
8180 and it is an error if the caller tried to override that. */
b99bd4ef 8181
c19d1205
ZW
8182static void
8183do_bkpt (void)
8184{
8185 /* Top 12 of 16 bits to bits 19:8. */
8186 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8187
c19d1205
ZW
8188 /* Bottom 4 of 16 bits to bits 3:0. */
8189 inst.instruction |= inst.operands[0].imm & 0xf;
8190}
09d92015 8191
c19d1205
ZW
8192static void
8193encode_branch (int default_reloc)
8194{
8195 if (inst.operands[0].hasreloc)
8196 {
0855e32b
NS
8197 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8198 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8199 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8200 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8201 ? BFD_RELOC_ARM_PLT32
8202 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8203 }
b99bd4ef 8204 else
9ae92b05 8205 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8206 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8207}
8208
b99bd4ef 8209static void
c19d1205 8210do_branch (void)
b99bd4ef 8211{
39b41c9c
PB
8212#ifdef OBJ_ELF
8213 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8214 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8215 else
8216#endif
8217 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8218}
8219
8220static void
8221do_bl (void)
8222{
8223#ifdef OBJ_ELF
8224 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8225 {
8226 if (inst.cond == COND_ALWAYS)
8227 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8228 else
8229 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8230 }
8231 else
8232#endif
8233 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8234}
b99bd4ef 8235
c19d1205
ZW
8236/* ARM V5 branch-link-exchange instruction (argument parse)
8237 BLX <target_addr> ie BLX(1)
8238 BLX{<condition>} <Rm> ie BLX(2)
8239 Unfortunately, there are two different opcodes for this mnemonic.
8240 So, the insns[].value is not used, and the code here zaps values
8241 into inst.instruction.
8242 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8243
c19d1205
ZW
8244static void
8245do_blx (void)
8246{
8247 if (inst.operands[0].isreg)
b99bd4ef 8248 {
c19d1205
ZW
8249 /* Arg is a register; the opcode provided by insns[] is correct.
8250 It is not illegal to do "blx pc", just useless. */
8251 if (inst.operands[0].reg == REG_PC)
8252 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8253
c19d1205
ZW
8254 inst.instruction |= inst.operands[0].reg;
8255 }
8256 else
b99bd4ef 8257 {
c19d1205 8258 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8259 conditionally, and the opcode must be adjusted.
8260 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8261 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8262 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8263 inst.instruction = 0xfa000000;
267bf995 8264 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8265 }
c19d1205
ZW
8266}
8267
8268static void
8269do_bx (void)
8270{
845b51d6
PB
8271 bfd_boolean want_reloc;
8272
c19d1205
ZW
8273 if (inst.operands[0].reg == REG_PC)
8274 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8275
c19d1205 8276 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8277 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8278 it is for ARMv4t or earlier. */
8279 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8280 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
8281 want_reloc = TRUE;
8282
5ad34203 8283#ifdef OBJ_ELF
845b51d6 8284 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8285#endif
584206db 8286 want_reloc = FALSE;
845b51d6
PB
8287
8288 if (want_reloc)
8289 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8290}
8291
c19d1205
ZW
8292
8293/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8294
8295static void
c19d1205 8296do_bxj (void)
a737bd4d 8297{
c19d1205
ZW
8298 if (inst.operands[0].reg == REG_PC)
8299 as_tsktsk (_("use of r15 in bxj is not really useful"));
8300
8301 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8302}
8303
c19d1205
ZW
8304/* Co-processor data operation:
8305 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8306 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8307static void
8308do_cdp (void)
8309{
8310 inst.instruction |= inst.operands[0].reg << 8;
8311 inst.instruction |= inst.operands[1].imm << 20;
8312 inst.instruction |= inst.operands[2].reg << 12;
8313 inst.instruction |= inst.operands[3].reg << 16;
8314 inst.instruction |= inst.operands[4].reg;
8315 inst.instruction |= inst.operands[5].imm << 5;
8316}
a737bd4d
NC
8317
8318static void
c19d1205 8319do_cmp (void)
a737bd4d 8320{
c19d1205
ZW
8321 inst.instruction |= inst.operands[0].reg << 16;
8322 encode_arm_shifter_operand (1);
a737bd4d
NC
8323}
8324
c19d1205
ZW
8325/* Transfer between coprocessor and ARM registers.
8326 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8327 MRC2
8328 MCR{cond}
8329 MCR2
8330
8331 No special properties. */
09d92015 8332
dcbd0d71
MGD
8333struct deprecated_coproc_regs_s
8334{
8335 unsigned cp;
8336 int opc1;
8337 unsigned crn;
8338 unsigned crm;
8339 int opc2;
8340 arm_feature_set deprecated;
8341 arm_feature_set obsoleted;
8342 const char *dep_msg;
8343 const char *obs_msg;
8344};
8345
8346#define DEPR_ACCESS_V8 \
8347 N_("This coprocessor register access is deprecated in ARMv8")
8348
8349/* Table of all deprecated coprocessor registers. */
8350static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8351{
8352 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8353 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8354 DEPR_ACCESS_V8, NULL},
8355 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8356 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8357 DEPR_ACCESS_V8, NULL},
8358 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8359 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8360 DEPR_ACCESS_V8, NULL},
8361 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8362 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8363 DEPR_ACCESS_V8, NULL},
8364 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8365 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8366 DEPR_ACCESS_V8, NULL},
8367};
8368
8369#undef DEPR_ACCESS_V8
8370
8371static const size_t deprecated_coproc_reg_count =
8372 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8373
09d92015 8374static void
c19d1205 8375do_co_reg (void)
09d92015 8376{
fdfde340 8377 unsigned Rd;
dcbd0d71 8378 size_t i;
fdfde340
JM
8379
8380 Rd = inst.operands[2].reg;
8381 if (thumb_mode)
8382 {
8383 if (inst.instruction == 0xee000010
8384 || inst.instruction == 0xfe000010)
8385 /* MCR, MCR2 */
8386 reject_bad_reg (Rd);
8387 else
8388 /* MRC, MRC2 */
8389 constraint (Rd == REG_SP, BAD_SP);
8390 }
8391 else
8392 {
8393 /* MCR */
8394 if (inst.instruction == 0xe000010)
8395 constraint (Rd == REG_PC, BAD_PC);
8396 }
8397
dcbd0d71
MGD
8398 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8399 {
8400 const struct deprecated_coproc_regs_s *r =
8401 deprecated_coproc_regs + i;
8402
8403 if (inst.operands[0].reg == r->cp
8404 && inst.operands[1].imm == r->opc1
8405 && inst.operands[3].reg == r->crn
8406 && inst.operands[4].reg == r->crm
8407 && inst.operands[5].imm == r->opc2)
8408 {
b10bf8c5 8409 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8410 && warn_on_deprecated
dcbd0d71 8411 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8412 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8413 }
8414 }
fdfde340 8415
c19d1205
ZW
8416 inst.instruction |= inst.operands[0].reg << 8;
8417 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8418 inst.instruction |= Rd << 12;
c19d1205
ZW
8419 inst.instruction |= inst.operands[3].reg << 16;
8420 inst.instruction |= inst.operands[4].reg;
8421 inst.instruction |= inst.operands[5].imm << 5;
8422}
09d92015 8423
c19d1205
ZW
8424/* Transfer between coprocessor register and pair of ARM registers.
8425 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8426 MCRR2
8427 MRRC{cond}
8428 MRRC2
b99bd4ef 8429
c19d1205 8430 Two XScale instructions are special cases of these:
09d92015 8431
c19d1205
ZW
8432 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8433 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8434
5f4273c7 8435 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8436
c19d1205
ZW
8437static void
8438do_co_reg2c (void)
8439{
fdfde340
JM
8440 unsigned Rd, Rn;
8441
8442 Rd = inst.operands[2].reg;
8443 Rn = inst.operands[3].reg;
8444
8445 if (thumb_mode)
8446 {
8447 reject_bad_reg (Rd);
8448 reject_bad_reg (Rn);
8449 }
8450 else
8451 {
8452 constraint (Rd == REG_PC, BAD_PC);
8453 constraint (Rn == REG_PC, BAD_PC);
8454 }
8455
c19d1205
ZW
8456 inst.instruction |= inst.operands[0].reg << 8;
8457 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8458 inst.instruction |= Rd << 12;
8459 inst.instruction |= Rn << 16;
c19d1205 8460 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8461}
8462
c19d1205
ZW
8463static void
8464do_cpsi (void)
8465{
8466 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8467 if (inst.operands[1].present)
8468 {
8469 inst.instruction |= CPSI_MMOD;
8470 inst.instruction |= inst.operands[1].imm;
8471 }
c19d1205 8472}
b99bd4ef 8473
62b3e311
PB
8474static void
8475do_dbg (void)
8476{
8477 inst.instruction |= inst.operands[0].imm;
8478}
8479
eea54501
MGD
8480static void
8481do_div (void)
8482{
8483 unsigned Rd, Rn, Rm;
8484
8485 Rd = inst.operands[0].reg;
8486 Rn = (inst.operands[1].present
8487 ? inst.operands[1].reg : Rd);
8488 Rm = inst.operands[2].reg;
8489
8490 constraint ((Rd == REG_PC), BAD_PC);
8491 constraint ((Rn == REG_PC), BAD_PC);
8492 constraint ((Rm == REG_PC), BAD_PC);
8493
8494 inst.instruction |= Rd << 16;
8495 inst.instruction |= Rn << 0;
8496 inst.instruction |= Rm << 8;
8497}
8498
b99bd4ef 8499static void
c19d1205 8500do_it (void)
b99bd4ef 8501{
c19d1205 8502 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8503 process it to do the validation as if in
8504 thumb mode, just in case the code gets
8505 assembled for thumb using the unified syntax. */
8506
c19d1205 8507 inst.size = 0;
e07e6e58
NC
8508 if (unified_syntax)
8509 {
8510 set_it_insn_type (IT_INSN);
8511 now_it.mask = (inst.instruction & 0xf) | 0x10;
8512 now_it.cc = inst.operands[0].imm;
8513 }
09d92015 8514}
b99bd4ef 8515
6530b175
NC
8516/* If there is only one register in the register list,
8517 then return its register number. Otherwise return -1. */
8518static int
8519only_one_reg_in_list (int range)
8520{
8521 int i = ffs (range) - 1;
8522 return (i > 15 || range != (1 << i)) ? -1 : i;
8523}
8524
09d92015 8525static void
6530b175 8526encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8527{
c19d1205
ZW
8528 int base_reg = inst.operands[0].reg;
8529 int range = inst.operands[1].imm;
6530b175 8530 int one_reg;
ea6ef066 8531
c19d1205
ZW
8532 inst.instruction |= base_reg << 16;
8533 inst.instruction |= range;
ea6ef066 8534
c19d1205
ZW
8535 if (inst.operands[1].writeback)
8536 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8537
c19d1205 8538 if (inst.operands[0].writeback)
ea6ef066 8539 {
c19d1205
ZW
8540 inst.instruction |= WRITE_BACK;
8541 /* Check for unpredictable uses of writeback. */
8542 if (inst.instruction & LOAD_BIT)
09d92015 8543 {
c19d1205
ZW
8544 /* Not allowed in LDM type 2. */
8545 if ((inst.instruction & LDM_TYPE_2_OR_3)
8546 && ((range & (1 << REG_PC)) == 0))
8547 as_warn (_("writeback of base register is UNPREDICTABLE"));
8548 /* Only allowed if base reg not in list for other types. */
8549 else if (range & (1 << base_reg))
8550 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8551 }
8552 else /* STM. */
8553 {
8554 /* Not allowed for type 2. */
8555 if (inst.instruction & LDM_TYPE_2_OR_3)
8556 as_warn (_("writeback of base register is UNPREDICTABLE"));
8557 /* Only allowed if base reg not in list, or first in list. */
8558 else if ((range & (1 << base_reg))
8559 && (range & ((1 << base_reg) - 1)))
8560 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8561 }
ea6ef066 8562 }
6530b175
NC
8563
8564 /* If PUSH/POP has only one register, then use the A2 encoding. */
8565 one_reg = only_one_reg_in_list (range);
8566 if (from_push_pop_mnem && one_reg >= 0)
8567 {
8568 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8569
8570 inst.instruction &= A_COND_MASK;
8571 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8572 inst.instruction |= one_reg << 12;
8573 }
8574}
8575
8576static void
8577do_ldmstm (void)
8578{
8579 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8580}
8581
c19d1205
ZW
8582/* ARMv5TE load-consecutive (argument parse)
8583 Mode is like LDRH.
8584
8585 LDRccD R, mode
8586 STRccD R, mode. */
8587
a737bd4d 8588static void
c19d1205 8589do_ldrd (void)
a737bd4d 8590{
c19d1205 8591 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8592 _("first transfer register must be even"));
c19d1205
ZW
8593 constraint (inst.operands[1].present
8594 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8595 _("can only transfer two consecutive registers"));
c19d1205
ZW
8596 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8597 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8598
c19d1205
ZW
8599 if (!inst.operands[1].present)
8600 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8601
c56791bb
RE
8602 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8603 register and the first register written; we have to diagnose
8604 overlap between the base and the second register written here. */
ea6ef066 8605
c56791bb
RE
8606 if (inst.operands[2].reg == inst.operands[1].reg
8607 && (inst.operands[2].writeback || inst.operands[2].postind))
8608 as_warn (_("base register written back, and overlaps "
8609 "second transfer register"));
b05fe5cf 8610
c56791bb
RE
8611 if (!(inst.instruction & V4_STR_BIT))
8612 {
c19d1205 8613 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8614 destination (even if not write-back). */
8615 if (inst.operands[2].immisreg
8616 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8617 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8618 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8619 }
c19d1205
ZW
8620 inst.instruction |= inst.operands[0].reg << 12;
8621 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8622}
8623
8624static void
c19d1205 8625do_ldrex (void)
b05fe5cf 8626{
c19d1205
ZW
8627 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8628 || inst.operands[1].postind || inst.operands[1].writeback
8629 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8630 || inst.operands[1].negative
8631 /* This can arise if the programmer has written
8632 strex rN, rM, foo
8633 or if they have mistakenly used a register name as the last
8634 operand, eg:
8635 strex rN, rM, rX
8636 It is very difficult to distinguish between these two cases
8637 because "rX" might actually be a label. ie the register
8638 name has been occluded by a symbol of the same name. So we
8639 just generate a general 'bad addressing mode' type error
8640 message and leave it up to the programmer to discover the
8641 true cause and fix their mistake. */
8642 || (inst.operands[1].reg == REG_PC),
8643 BAD_ADDR_MODE);
b05fe5cf 8644
c19d1205
ZW
8645 constraint (inst.reloc.exp.X_op != O_constant
8646 || inst.reloc.exp.X_add_number != 0,
8647 _("offset must be zero in ARM encoding"));
b05fe5cf 8648
5be8be5d
DG
8649 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8650
c19d1205
ZW
8651 inst.instruction |= inst.operands[0].reg << 12;
8652 inst.instruction |= inst.operands[1].reg << 16;
8653 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
8654}
8655
8656static void
c19d1205 8657do_ldrexd (void)
b05fe5cf 8658{
c19d1205
ZW
8659 constraint (inst.operands[0].reg % 2 != 0,
8660 _("even register required"));
8661 constraint (inst.operands[1].present
8662 && inst.operands[1].reg != inst.operands[0].reg + 1,
8663 _("can only load two consecutive registers"));
8664 /* If op 1 were present and equal to PC, this function wouldn't
8665 have been called in the first place. */
8666 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 8667
c19d1205
ZW
8668 inst.instruction |= inst.operands[0].reg << 12;
8669 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
8670}
8671
1be5fd2e
NC
8672/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8673 which is not a multiple of four is UNPREDICTABLE. */
8674static void
8675check_ldr_r15_aligned (void)
8676{
8677 constraint (!(inst.operands[1].immisreg)
8678 && (inst.operands[0].reg == REG_PC
8679 && inst.operands[1].reg == REG_PC
8680 && (inst.reloc.exp.X_add_number & 0x3)),
8681 _("ldr to register 15 must be 4-byte alligned"));
8682}
8683
b05fe5cf 8684static void
c19d1205 8685do_ldst (void)
b05fe5cf 8686{
c19d1205
ZW
8687 inst.instruction |= inst.operands[0].reg << 12;
8688 if (!inst.operands[1].isreg)
8335d6aa 8689 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 8690 return;
c19d1205 8691 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 8692 check_ldr_r15_aligned ();
b05fe5cf
ZW
8693}
8694
8695static void
c19d1205 8696do_ldstt (void)
b05fe5cf 8697{
c19d1205
ZW
8698 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8699 reject [Rn,...]. */
8700 if (inst.operands[1].preind)
b05fe5cf 8701 {
bd3ba5d1
NC
8702 constraint (inst.reloc.exp.X_op != O_constant
8703 || inst.reloc.exp.X_add_number != 0,
c19d1205 8704 _("this instruction requires a post-indexed address"));
b05fe5cf 8705
c19d1205
ZW
8706 inst.operands[1].preind = 0;
8707 inst.operands[1].postind = 1;
8708 inst.operands[1].writeback = 1;
b05fe5cf 8709 }
c19d1205
ZW
8710 inst.instruction |= inst.operands[0].reg << 12;
8711 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
8712}
b05fe5cf 8713
c19d1205 8714/* Halfword and signed-byte load/store operations. */
b05fe5cf 8715
c19d1205
ZW
8716static void
8717do_ldstv4 (void)
8718{
ff4a8d2b 8719 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
8720 inst.instruction |= inst.operands[0].reg << 12;
8721 if (!inst.operands[1].isreg)
8335d6aa 8722 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 8723 return;
c19d1205 8724 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
8725}
8726
8727static void
c19d1205 8728do_ldsttv4 (void)
b05fe5cf 8729{
c19d1205
ZW
8730 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8731 reject [Rn,...]. */
8732 if (inst.operands[1].preind)
b05fe5cf 8733 {
bd3ba5d1
NC
8734 constraint (inst.reloc.exp.X_op != O_constant
8735 || inst.reloc.exp.X_add_number != 0,
c19d1205 8736 _("this instruction requires a post-indexed address"));
b05fe5cf 8737
c19d1205
ZW
8738 inst.operands[1].preind = 0;
8739 inst.operands[1].postind = 1;
8740 inst.operands[1].writeback = 1;
b05fe5cf 8741 }
c19d1205
ZW
8742 inst.instruction |= inst.operands[0].reg << 12;
8743 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
8744}
b05fe5cf 8745
c19d1205
ZW
8746/* Co-processor register load/store.
8747 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
8748static void
8749do_lstc (void)
8750{
8751 inst.instruction |= inst.operands[0].reg << 8;
8752 inst.instruction |= inst.operands[1].reg << 12;
8753 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
8754}
8755
b05fe5cf 8756static void
c19d1205 8757do_mlas (void)
b05fe5cf 8758{
8fb9d7b9 8759 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 8760 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 8761 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 8762 && !(inst.instruction & 0x00400000))
8fb9d7b9 8763 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 8764
c19d1205
ZW
8765 inst.instruction |= inst.operands[0].reg << 16;
8766 inst.instruction |= inst.operands[1].reg;
8767 inst.instruction |= inst.operands[2].reg << 8;
8768 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 8769}
b05fe5cf 8770
c19d1205
ZW
8771static void
8772do_mov (void)
8773{
8774 inst.instruction |= inst.operands[0].reg << 12;
8775 encode_arm_shifter_operand (1);
8776}
b05fe5cf 8777
c19d1205
ZW
8778/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
8779static void
8780do_mov16 (void)
8781{
b6895b4f
PB
8782 bfd_vma imm;
8783 bfd_boolean top;
8784
8785 top = (inst.instruction & 0x00400000) != 0;
8786 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
8787 _(":lower16: not allowed this instruction"));
8788 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
8789 _(":upper16: not allowed instruction"));
c19d1205 8790 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
8791 if (inst.reloc.type == BFD_RELOC_UNUSED)
8792 {
8793 imm = inst.reloc.exp.X_add_number;
8794 /* The value is in two pieces: 0:11, 16:19. */
8795 inst.instruction |= (imm & 0x00000fff);
8796 inst.instruction |= (imm & 0x0000f000) << 4;
8797 }
b05fe5cf 8798}
b99bd4ef 8799
037e8744
JB
8800static void do_vfp_nsyn_opcode (const char *);
8801
8802static int
8803do_vfp_nsyn_mrs (void)
8804{
8805 if (inst.operands[0].isvec)
8806 {
8807 if (inst.operands[1].reg != 1)
477330fc 8808 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
8809 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
8810 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
8811 do_vfp_nsyn_opcode ("fmstat");
8812 }
8813 else if (inst.operands[1].isvec)
8814 do_vfp_nsyn_opcode ("fmrx");
8815 else
8816 return FAIL;
5f4273c7 8817
037e8744
JB
8818 return SUCCESS;
8819}
8820
8821static int
8822do_vfp_nsyn_msr (void)
8823{
8824 if (inst.operands[0].isvec)
8825 do_vfp_nsyn_opcode ("fmxr");
8826 else
8827 return FAIL;
8828
8829 return SUCCESS;
8830}
8831
f7c21dc7
NC
8832static void
8833do_vmrs (void)
8834{
8835 unsigned Rt = inst.operands[0].reg;
fa94de6b 8836
16d02dc9 8837 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
8838 {
8839 inst.error = BAD_SP;
8840 return;
8841 }
8842
8843 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 8844 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
8845 {
8846 inst.error = BAD_PC;
8847 return;
8848 }
8849
16d02dc9
JB
8850 /* If we get through parsing the register name, we just insert the number
8851 generated into the instruction without further validation. */
8852 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
8853 inst.instruction |= (Rt << 12);
8854}
8855
8856static void
8857do_vmsr (void)
8858{
8859 unsigned Rt = inst.operands[1].reg;
fa94de6b 8860
f7c21dc7
NC
8861 if (thumb_mode)
8862 reject_bad_reg (Rt);
8863 else if (Rt == REG_PC)
8864 {
8865 inst.error = BAD_PC;
8866 return;
8867 }
8868
16d02dc9
JB
8869 /* If we get through parsing the register name, we just insert the number
8870 generated into the instruction without further validation. */
8871 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
8872 inst.instruction |= (Rt << 12);
8873}
8874
b99bd4ef 8875static void
c19d1205 8876do_mrs (void)
b99bd4ef 8877{
90ec0d68
MGD
8878 unsigned br;
8879
037e8744
JB
8880 if (do_vfp_nsyn_mrs () == SUCCESS)
8881 return;
8882
ff4a8d2b 8883 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 8884 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
8885
8886 if (inst.operands[1].isreg)
8887 {
8888 br = inst.operands[1].reg;
8889 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
8890 as_bad (_("bad register for mrs"));
8891 }
8892 else
8893 {
8894 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
8895 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
8896 != (PSR_c|PSR_f),
d2cd1205 8897 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
8898 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
8899 }
8900
8901 inst.instruction |= br;
c19d1205 8902}
b99bd4ef 8903
c19d1205
ZW
8904/* Two possible forms:
8905 "{C|S}PSR_<field>, Rm",
8906 "{C|S}PSR_f, #expression". */
b99bd4ef 8907
c19d1205
ZW
8908static void
8909do_msr (void)
8910{
037e8744
JB
8911 if (do_vfp_nsyn_msr () == SUCCESS)
8912 return;
8913
c19d1205
ZW
8914 inst.instruction |= inst.operands[0].imm;
8915 if (inst.operands[1].isreg)
8916 inst.instruction |= inst.operands[1].reg;
8917 else
b99bd4ef 8918 {
c19d1205
ZW
8919 inst.instruction |= INST_IMMEDIATE;
8920 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
8921 inst.reloc.pc_rel = 0;
b99bd4ef 8922 }
b99bd4ef
NC
8923}
8924
c19d1205
ZW
8925static void
8926do_mul (void)
a737bd4d 8927{
ff4a8d2b
NC
8928 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
8929
c19d1205
ZW
8930 if (!inst.operands[2].present)
8931 inst.operands[2].reg = inst.operands[0].reg;
8932 inst.instruction |= inst.operands[0].reg << 16;
8933 inst.instruction |= inst.operands[1].reg;
8934 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 8935
8fb9d7b9
MS
8936 if (inst.operands[0].reg == inst.operands[1].reg
8937 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
8938 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
8939}
8940
c19d1205
ZW
8941/* Long Multiply Parser
8942 UMULL RdLo, RdHi, Rm, Rs
8943 SMULL RdLo, RdHi, Rm, Rs
8944 UMLAL RdLo, RdHi, Rm, Rs
8945 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
8946
8947static void
c19d1205 8948do_mull (void)
b99bd4ef 8949{
c19d1205
ZW
8950 inst.instruction |= inst.operands[0].reg << 12;
8951 inst.instruction |= inst.operands[1].reg << 16;
8952 inst.instruction |= inst.operands[2].reg;
8953 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 8954
682b27ad
PB
8955 /* rdhi and rdlo must be different. */
8956 if (inst.operands[0].reg == inst.operands[1].reg)
8957 as_tsktsk (_("rdhi and rdlo must be different"));
8958
8959 /* rdhi, rdlo and rm must all be different before armv6. */
8960 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 8961 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 8962 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
8963 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
8964}
b99bd4ef 8965
c19d1205
ZW
8966static void
8967do_nop (void)
8968{
e7495e45
NS
8969 if (inst.operands[0].present
8970 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
8971 {
8972 /* Architectural NOP hints are CPSR sets with no bits selected. */
8973 inst.instruction &= 0xf0000000;
e7495e45
NS
8974 inst.instruction |= 0x0320f000;
8975 if (inst.operands[0].present)
8976 inst.instruction |= inst.operands[0].imm;
c19d1205 8977 }
b99bd4ef
NC
8978}
8979
c19d1205
ZW
8980/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
8981 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
8982 Condition defaults to COND_ALWAYS.
8983 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
8984
8985static void
c19d1205 8986do_pkhbt (void)
b99bd4ef 8987{
c19d1205
ZW
8988 inst.instruction |= inst.operands[0].reg << 12;
8989 inst.instruction |= inst.operands[1].reg << 16;
8990 inst.instruction |= inst.operands[2].reg;
8991 if (inst.operands[3].present)
8992 encode_arm_shift (3);
8993}
b99bd4ef 8994
c19d1205 8995/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 8996
c19d1205
ZW
8997static void
8998do_pkhtb (void)
8999{
9000 if (!inst.operands[3].present)
b99bd4ef 9001 {
c19d1205
ZW
9002 /* If the shift specifier is omitted, turn the instruction
9003 into pkhbt rd, rm, rn. */
9004 inst.instruction &= 0xfff00010;
9005 inst.instruction |= inst.operands[0].reg << 12;
9006 inst.instruction |= inst.operands[1].reg;
9007 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9008 }
9009 else
9010 {
c19d1205
ZW
9011 inst.instruction |= inst.operands[0].reg << 12;
9012 inst.instruction |= inst.operands[1].reg << 16;
9013 inst.instruction |= inst.operands[2].reg;
9014 encode_arm_shift (3);
b99bd4ef
NC
9015 }
9016}
9017
c19d1205 9018/* ARMv5TE: Preload-Cache
60e5ef9f 9019 MP Extensions: Preload for write
c19d1205 9020
60e5ef9f 9021 PLD(W) <addr_mode>
c19d1205
ZW
9022
9023 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9024
9025static void
c19d1205 9026do_pld (void)
b99bd4ef 9027{
c19d1205
ZW
9028 constraint (!inst.operands[0].isreg,
9029 _("'[' expected after PLD mnemonic"));
9030 constraint (inst.operands[0].postind,
9031 _("post-indexed expression used in preload instruction"));
9032 constraint (inst.operands[0].writeback,
9033 _("writeback used in preload instruction"));
9034 constraint (!inst.operands[0].preind,
9035 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9036 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9037}
b99bd4ef 9038
62b3e311
PB
9039/* ARMv7: PLI <addr_mode> */
9040static void
9041do_pli (void)
9042{
9043 constraint (!inst.operands[0].isreg,
9044 _("'[' expected after PLI mnemonic"));
9045 constraint (inst.operands[0].postind,
9046 _("post-indexed expression used in preload instruction"));
9047 constraint (inst.operands[0].writeback,
9048 _("writeback used in preload instruction"));
9049 constraint (!inst.operands[0].preind,
9050 _("unindexed addressing used in preload instruction"));
9051 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9052 inst.instruction &= ~PRE_INDEX;
9053}
9054
c19d1205
ZW
9055static void
9056do_push_pop (void)
9057{
5e0d7f77
MP
9058 constraint (inst.operands[0].writeback,
9059 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9060 inst.operands[1] = inst.operands[0];
9061 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9062 inst.operands[0].isreg = 1;
9063 inst.operands[0].writeback = 1;
9064 inst.operands[0].reg = REG_SP;
6530b175 9065 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9066}
b99bd4ef 9067
c19d1205
ZW
9068/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9069 word at the specified address and the following word
9070 respectively.
9071 Unconditionally executed.
9072 Error if Rn is R15. */
b99bd4ef 9073
c19d1205
ZW
9074static void
9075do_rfe (void)
9076{
9077 inst.instruction |= inst.operands[0].reg << 16;
9078 if (inst.operands[0].writeback)
9079 inst.instruction |= WRITE_BACK;
9080}
b99bd4ef 9081
c19d1205 9082/* ARM V6 ssat (argument parse). */
b99bd4ef 9083
c19d1205
ZW
9084static void
9085do_ssat (void)
9086{
9087 inst.instruction |= inst.operands[0].reg << 12;
9088 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9089 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9090
c19d1205
ZW
9091 if (inst.operands[3].present)
9092 encode_arm_shift (3);
b99bd4ef
NC
9093}
9094
c19d1205 9095/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9096
9097static void
c19d1205 9098do_usat (void)
b99bd4ef 9099{
c19d1205
ZW
9100 inst.instruction |= inst.operands[0].reg << 12;
9101 inst.instruction |= inst.operands[1].imm << 16;
9102 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9103
c19d1205
ZW
9104 if (inst.operands[3].present)
9105 encode_arm_shift (3);
b99bd4ef
NC
9106}
9107
c19d1205 9108/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9109
9110static void
c19d1205 9111do_ssat16 (void)
09d92015 9112{
c19d1205
ZW
9113 inst.instruction |= inst.operands[0].reg << 12;
9114 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9115 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9116}
9117
c19d1205
ZW
9118static void
9119do_usat16 (void)
a737bd4d 9120{
c19d1205
ZW
9121 inst.instruction |= inst.operands[0].reg << 12;
9122 inst.instruction |= inst.operands[1].imm << 16;
9123 inst.instruction |= inst.operands[2].reg;
9124}
a737bd4d 9125
c19d1205
ZW
9126/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9127 preserving the other bits.
a737bd4d 9128
c19d1205
ZW
9129 setend <endian_specifier>, where <endian_specifier> is either
9130 BE or LE. */
a737bd4d 9131
c19d1205
ZW
9132static void
9133do_setend (void)
9134{
12e37cbc
MGD
9135 if (warn_on_deprecated
9136 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9137 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9138
c19d1205
ZW
9139 if (inst.operands[0].imm)
9140 inst.instruction |= 0x200;
a737bd4d
NC
9141}
9142
9143static void
c19d1205 9144do_shift (void)
a737bd4d 9145{
c19d1205
ZW
9146 unsigned int Rm = (inst.operands[1].present
9147 ? inst.operands[1].reg
9148 : inst.operands[0].reg);
a737bd4d 9149
c19d1205
ZW
9150 inst.instruction |= inst.operands[0].reg << 12;
9151 inst.instruction |= Rm;
9152 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9153 {
c19d1205
ZW
9154 inst.instruction |= inst.operands[2].reg << 8;
9155 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9156 /* PR 12854: Error on extraneous shifts. */
9157 constraint (inst.operands[2].shifted,
9158 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9159 }
9160 else
c19d1205 9161 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9162}
9163
09d92015 9164static void
3eb17e6b 9165do_smc (void)
09d92015 9166{
3eb17e6b 9167 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9168 inst.reloc.pc_rel = 0;
09d92015
MM
9169}
9170
90ec0d68
MGD
9171static void
9172do_hvc (void)
9173{
9174 inst.reloc.type = BFD_RELOC_ARM_HVC;
9175 inst.reloc.pc_rel = 0;
9176}
9177
09d92015 9178static void
c19d1205 9179do_swi (void)
09d92015 9180{
c19d1205
ZW
9181 inst.reloc.type = BFD_RELOC_ARM_SWI;
9182 inst.reloc.pc_rel = 0;
09d92015
MM
9183}
9184
ddfded2f
MW
9185static void
9186do_setpan (void)
9187{
9188 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9189 _("selected processor does not support SETPAN instruction"));
9190
9191 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9192}
9193
9194static void
9195do_t_setpan (void)
9196{
9197 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9198 _("selected processor does not support SETPAN instruction"));
9199
9200 inst.instruction |= (inst.operands[0].imm << 3);
9201}
9202
c19d1205
ZW
9203/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9204 SMLAxy{cond} Rd,Rm,Rs,Rn
9205 SMLAWy{cond} Rd,Rm,Rs,Rn
9206 Error if any register is R15. */
e16bb312 9207
c19d1205
ZW
9208static void
9209do_smla (void)
e16bb312 9210{
c19d1205
ZW
9211 inst.instruction |= inst.operands[0].reg << 16;
9212 inst.instruction |= inst.operands[1].reg;
9213 inst.instruction |= inst.operands[2].reg << 8;
9214 inst.instruction |= inst.operands[3].reg << 12;
9215}
a737bd4d 9216
c19d1205
ZW
9217/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9218 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9219 Error if any register is R15.
9220 Warning if Rdlo == Rdhi. */
a737bd4d 9221
c19d1205
ZW
9222static void
9223do_smlal (void)
9224{
9225 inst.instruction |= inst.operands[0].reg << 12;
9226 inst.instruction |= inst.operands[1].reg << 16;
9227 inst.instruction |= inst.operands[2].reg;
9228 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9229
c19d1205
ZW
9230 if (inst.operands[0].reg == inst.operands[1].reg)
9231 as_tsktsk (_("rdhi and rdlo must be different"));
9232}
a737bd4d 9233
c19d1205
ZW
9234/* ARM V5E (El Segundo) signed-multiply (argument parse)
9235 SMULxy{cond} Rd,Rm,Rs
9236 Error if any register is R15. */
a737bd4d 9237
c19d1205
ZW
9238static void
9239do_smul (void)
9240{
9241 inst.instruction |= inst.operands[0].reg << 16;
9242 inst.instruction |= inst.operands[1].reg;
9243 inst.instruction |= inst.operands[2].reg << 8;
9244}
a737bd4d 9245
b6702015
PB
9246/* ARM V6 srs (argument parse). The variable fields in the encoding are
9247 the same for both ARM and Thumb-2. */
a737bd4d 9248
c19d1205
ZW
9249static void
9250do_srs (void)
9251{
b6702015
PB
9252 int reg;
9253
9254 if (inst.operands[0].present)
9255 {
9256 reg = inst.operands[0].reg;
fdfde340 9257 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9258 }
9259 else
fdfde340 9260 reg = REG_SP;
b6702015
PB
9261
9262 inst.instruction |= reg << 16;
9263 inst.instruction |= inst.operands[1].imm;
9264 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9265 inst.instruction |= WRITE_BACK;
9266}
a737bd4d 9267
c19d1205 9268/* ARM V6 strex (argument parse). */
a737bd4d 9269
c19d1205
ZW
9270static void
9271do_strex (void)
9272{
9273 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9274 || inst.operands[2].postind || inst.operands[2].writeback
9275 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9276 || inst.operands[2].negative
9277 /* See comment in do_ldrex(). */
9278 || (inst.operands[2].reg == REG_PC),
9279 BAD_ADDR_MODE);
a737bd4d 9280
c19d1205
ZW
9281 constraint (inst.operands[0].reg == inst.operands[1].reg
9282 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9283
c19d1205
ZW
9284 constraint (inst.reloc.exp.X_op != O_constant
9285 || inst.reloc.exp.X_add_number != 0,
9286 _("offset must be zero in ARM encoding"));
a737bd4d 9287
c19d1205
ZW
9288 inst.instruction |= inst.operands[0].reg << 12;
9289 inst.instruction |= inst.operands[1].reg;
9290 inst.instruction |= inst.operands[2].reg << 16;
9291 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9292}
9293
877807f8
NC
9294static void
9295do_t_strexbh (void)
9296{
9297 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9298 || inst.operands[2].postind || inst.operands[2].writeback
9299 || inst.operands[2].immisreg || inst.operands[2].shifted
9300 || inst.operands[2].negative,
9301 BAD_ADDR_MODE);
9302
9303 constraint (inst.operands[0].reg == inst.operands[1].reg
9304 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9305
9306 do_rm_rd_rn ();
9307}
9308
e16bb312 9309static void
c19d1205 9310do_strexd (void)
e16bb312 9311{
c19d1205
ZW
9312 constraint (inst.operands[1].reg % 2 != 0,
9313 _("even register required"));
9314 constraint (inst.operands[2].present
9315 && inst.operands[2].reg != inst.operands[1].reg + 1,
9316 _("can only store two consecutive registers"));
9317 /* If op 2 were present and equal to PC, this function wouldn't
9318 have been called in the first place. */
9319 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9320
c19d1205
ZW
9321 constraint (inst.operands[0].reg == inst.operands[1].reg
9322 || inst.operands[0].reg == inst.operands[1].reg + 1
9323 || inst.operands[0].reg == inst.operands[3].reg,
9324 BAD_OVERLAP);
e16bb312 9325
c19d1205
ZW
9326 inst.instruction |= inst.operands[0].reg << 12;
9327 inst.instruction |= inst.operands[1].reg;
9328 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9329}
9330
9eb6c0f1
MGD
9331/* ARM V8 STRL. */
9332static void
4b8c8c02 9333do_stlex (void)
9eb6c0f1
MGD
9334{
9335 constraint (inst.operands[0].reg == inst.operands[1].reg
9336 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9337
9338 do_rd_rm_rn ();
9339}
9340
9341static void
4b8c8c02 9342do_t_stlex (void)
9eb6c0f1
MGD
9343{
9344 constraint (inst.operands[0].reg == inst.operands[1].reg
9345 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9346
9347 do_rm_rd_rn ();
9348}
9349
c19d1205
ZW
9350/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9351 extends it to 32-bits, and adds the result to a value in another
9352 register. You can specify a rotation by 0, 8, 16, or 24 bits
9353 before extracting the 16-bit value.
9354 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9355 Condition defaults to COND_ALWAYS.
9356 Error if any register uses R15. */
9357
e16bb312 9358static void
c19d1205 9359do_sxtah (void)
e16bb312 9360{
c19d1205
ZW
9361 inst.instruction |= inst.operands[0].reg << 12;
9362 inst.instruction |= inst.operands[1].reg << 16;
9363 inst.instruction |= inst.operands[2].reg;
9364 inst.instruction |= inst.operands[3].imm << 10;
9365}
e16bb312 9366
c19d1205 9367/* ARM V6 SXTH.
e16bb312 9368
c19d1205
ZW
9369 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9370 Condition defaults to COND_ALWAYS.
9371 Error if any register uses R15. */
e16bb312
NC
9372
9373static void
c19d1205 9374do_sxth (void)
e16bb312 9375{
c19d1205
ZW
9376 inst.instruction |= inst.operands[0].reg << 12;
9377 inst.instruction |= inst.operands[1].reg;
9378 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9379}
c19d1205
ZW
9380\f
9381/* VFP instructions. In a logical order: SP variant first, monad
9382 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9383
9384static void
c19d1205 9385do_vfp_sp_monadic (void)
e16bb312 9386{
5287ad62
JB
9387 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9388 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9389}
9390
9391static void
c19d1205 9392do_vfp_sp_dyadic (void)
e16bb312 9393{
5287ad62
JB
9394 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9395 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9396 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9397}
9398
9399static void
c19d1205 9400do_vfp_sp_compare_z (void)
e16bb312 9401{
5287ad62 9402 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9403}
9404
9405static void
c19d1205 9406do_vfp_dp_sp_cvt (void)
e16bb312 9407{
5287ad62
JB
9408 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9409 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9410}
9411
9412static void
c19d1205 9413do_vfp_sp_dp_cvt (void)
e16bb312 9414{
5287ad62
JB
9415 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9416 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9417}
9418
9419static void
c19d1205 9420do_vfp_reg_from_sp (void)
e16bb312 9421{
c19d1205 9422 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9423 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9424}
9425
9426static void
c19d1205 9427do_vfp_reg2_from_sp2 (void)
e16bb312 9428{
c19d1205
ZW
9429 constraint (inst.operands[2].imm != 2,
9430 _("only two consecutive VFP SP registers allowed here"));
9431 inst.instruction |= inst.operands[0].reg << 12;
9432 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9433 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9434}
9435
9436static void
c19d1205 9437do_vfp_sp_from_reg (void)
e16bb312 9438{
5287ad62 9439 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9440 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9441}
9442
9443static void
c19d1205 9444do_vfp_sp2_from_reg2 (void)
e16bb312 9445{
c19d1205
ZW
9446 constraint (inst.operands[0].imm != 2,
9447 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9448 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9449 inst.instruction |= inst.operands[1].reg << 12;
9450 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9451}
9452
9453static void
c19d1205 9454do_vfp_sp_ldst (void)
e16bb312 9455{
5287ad62 9456 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9457 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9458}
9459
9460static void
c19d1205 9461do_vfp_dp_ldst (void)
e16bb312 9462{
5287ad62 9463 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9464 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9465}
9466
c19d1205 9467
e16bb312 9468static void
c19d1205 9469vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9470{
c19d1205
ZW
9471 if (inst.operands[0].writeback)
9472 inst.instruction |= WRITE_BACK;
9473 else
9474 constraint (ldstm_type != VFP_LDSTMIA,
9475 _("this addressing mode requires base-register writeback"));
9476 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9477 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9478 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9479}
9480
9481static void
c19d1205 9482vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9483{
c19d1205 9484 int count;
e16bb312 9485
c19d1205
ZW
9486 if (inst.operands[0].writeback)
9487 inst.instruction |= WRITE_BACK;
9488 else
9489 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9490 _("this addressing mode requires base-register writeback"));
e16bb312 9491
c19d1205 9492 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9493 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9494
c19d1205
ZW
9495 count = inst.operands[1].imm << 1;
9496 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9497 count += 1;
e16bb312 9498
c19d1205 9499 inst.instruction |= count;
e16bb312
NC
9500}
9501
9502static void
c19d1205 9503do_vfp_sp_ldstmia (void)
e16bb312 9504{
c19d1205 9505 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9506}
9507
9508static void
c19d1205 9509do_vfp_sp_ldstmdb (void)
e16bb312 9510{
c19d1205 9511 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9512}
9513
9514static void
c19d1205 9515do_vfp_dp_ldstmia (void)
e16bb312 9516{
c19d1205 9517 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9518}
9519
9520static void
c19d1205 9521do_vfp_dp_ldstmdb (void)
e16bb312 9522{
c19d1205 9523 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9524}
9525
9526static void
c19d1205 9527do_vfp_xp_ldstmia (void)
e16bb312 9528{
c19d1205
ZW
9529 vfp_dp_ldstm (VFP_LDSTMIAX);
9530}
e16bb312 9531
c19d1205
ZW
9532static void
9533do_vfp_xp_ldstmdb (void)
9534{
9535 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9536}
5287ad62
JB
9537
9538static void
9539do_vfp_dp_rd_rm (void)
9540{
9541 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9542 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9543}
9544
9545static void
9546do_vfp_dp_rn_rd (void)
9547{
9548 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9549 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9550}
9551
9552static void
9553do_vfp_dp_rd_rn (void)
9554{
9555 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9556 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9557}
9558
9559static void
9560do_vfp_dp_rd_rn_rm (void)
9561{
9562 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9563 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9564 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9565}
9566
9567static void
9568do_vfp_dp_rd (void)
9569{
9570 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9571}
9572
9573static void
9574do_vfp_dp_rm_rd_rn (void)
9575{
9576 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9577 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9578 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9579}
9580
9581/* VFPv3 instructions. */
9582static void
9583do_vfp_sp_const (void)
9584{
9585 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9586 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9587 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9588}
9589
9590static void
9591do_vfp_dp_const (void)
9592{
9593 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9594 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9595 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9596}
9597
9598static void
9599vfp_conv (int srcsize)
9600{
5f1af56b
MGD
9601 int immbits = srcsize - inst.operands[1].imm;
9602
fa94de6b
RM
9603 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9604 {
5f1af56b 9605 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9606 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9607 inst.error = _("immediate value out of range, expected range [0, 16]");
9608 return;
9609 }
fa94de6b 9610 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9611 {
9612 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9613 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9614 inst.error = _("immediate value out of range, expected range [1, 32]");
9615 return;
9616 }
9617
5287ad62
JB
9618 inst.instruction |= (immbits & 1) << 5;
9619 inst.instruction |= (immbits >> 1);
9620}
9621
9622static void
9623do_vfp_sp_conv_16 (void)
9624{
9625 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9626 vfp_conv (16);
9627}
9628
9629static void
9630do_vfp_dp_conv_16 (void)
9631{
9632 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9633 vfp_conv (16);
9634}
9635
9636static void
9637do_vfp_sp_conv_32 (void)
9638{
9639 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9640 vfp_conv (32);
9641}
9642
9643static void
9644do_vfp_dp_conv_32 (void)
9645{
9646 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9647 vfp_conv (32);
9648}
c19d1205
ZW
9649\f
9650/* FPA instructions. Also in a logical order. */
e16bb312 9651
c19d1205
ZW
9652static void
9653do_fpa_cmp (void)
9654{
9655 inst.instruction |= inst.operands[0].reg << 16;
9656 inst.instruction |= inst.operands[1].reg;
9657}
b99bd4ef
NC
9658
9659static void
c19d1205 9660do_fpa_ldmstm (void)
b99bd4ef 9661{
c19d1205
ZW
9662 inst.instruction |= inst.operands[0].reg << 12;
9663 switch (inst.operands[1].imm)
9664 {
9665 case 1: inst.instruction |= CP_T_X; break;
9666 case 2: inst.instruction |= CP_T_Y; break;
9667 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9668 case 4: break;
9669 default: abort ();
9670 }
b99bd4ef 9671
c19d1205
ZW
9672 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9673 {
9674 /* The instruction specified "ea" or "fd", so we can only accept
9675 [Rn]{!}. The instruction does not really support stacking or
9676 unstacking, so we have to emulate these by setting appropriate
9677 bits and offsets. */
9678 constraint (inst.reloc.exp.X_op != O_constant
9679 || inst.reloc.exp.X_add_number != 0,
9680 _("this instruction does not support indexing"));
b99bd4ef 9681
c19d1205
ZW
9682 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9683 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 9684
c19d1205
ZW
9685 if (!(inst.instruction & INDEX_UP))
9686 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 9687
c19d1205
ZW
9688 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
9689 {
9690 inst.operands[2].preind = 0;
9691 inst.operands[2].postind = 1;
9692 }
9693 }
b99bd4ef 9694
c19d1205 9695 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 9696}
c19d1205
ZW
9697\f
9698/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 9699
c19d1205
ZW
9700static void
9701do_iwmmxt_tandorc (void)
9702{
9703 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
9704}
b99bd4ef 9705
c19d1205
ZW
9706static void
9707do_iwmmxt_textrc (void)
9708{
9709 inst.instruction |= inst.operands[0].reg << 12;
9710 inst.instruction |= inst.operands[1].imm;
9711}
b99bd4ef
NC
9712
9713static void
c19d1205 9714do_iwmmxt_textrm (void)
b99bd4ef 9715{
c19d1205
ZW
9716 inst.instruction |= inst.operands[0].reg << 12;
9717 inst.instruction |= inst.operands[1].reg << 16;
9718 inst.instruction |= inst.operands[2].imm;
9719}
b99bd4ef 9720
c19d1205
ZW
9721static void
9722do_iwmmxt_tinsr (void)
9723{
9724 inst.instruction |= inst.operands[0].reg << 16;
9725 inst.instruction |= inst.operands[1].reg << 12;
9726 inst.instruction |= inst.operands[2].imm;
9727}
b99bd4ef 9728
c19d1205
ZW
9729static void
9730do_iwmmxt_tmia (void)
9731{
9732 inst.instruction |= inst.operands[0].reg << 5;
9733 inst.instruction |= inst.operands[1].reg;
9734 inst.instruction |= inst.operands[2].reg << 12;
9735}
b99bd4ef 9736
c19d1205
ZW
9737static void
9738do_iwmmxt_waligni (void)
9739{
9740 inst.instruction |= inst.operands[0].reg << 12;
9741 inst.instruction |= inst.operands[1].reg << 16;
9742 inst.instruction |= inst.operands[2].reg;
9743 inst.instruction |= inst.operands[3].imm << 20;
9744}
b99bd4ef 9745
2d447fca
JM
9746static void
9747do_iwmmxt_wmerge (void)
9748{
9749 inst.instruction |= inst.operands[0].reg << 12;
9750 inst.instruction |= inst.operands[1].reg << 16;
9751 inst.instruction |= inst.operands[2].reg;
9752 inst.instruction |= inst.operands[3].imm << 21;
9753}
9754
c19d1205
ZW
9755static void
9756do_iwmmxt_wmov (void)
9757{
9758 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
9759 inst.instruction |= inst.operands[0].reg << 12;
9760 inst.instruction |= inst.operands[1].reg << 16;
9761 inst.instruction |= inst.operands[1].reg;
9762}
b99bd4ef 9763
c19d1205
ZW
9764static void
9765do_iwmmxt_wldstbh (void)
9766{
8f06b2d8 9767 int reloc;
c19d1205 9768 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
9769 if (thumb_mode)
9770 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
9771 else
9772 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
9773 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
9774}
9775
c19d1205
ZW
9776static void
9777do_iwmmxt_wldstw (void)
9778{
9779 /* RIWR_RIWC clears .isreg for a control register. */
9780 if (!inst.operands[0].isreg)
9781 {
9782 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9783 inst.instruction |= 0xf0000000;
9784 }
b99bd4ef 9785
c19d1205
ZW
9786 inst.instruction |= inst.operands[0].reg << 12;
9787 encode_arm_cp_address (1, TRUE, TRUE, 0);
9788}
b99bd4ef
NC
9789
9790static void
c19d1205 9791do_iwmmxt_wldstd (void)
b99bd4ef 9792{
c19d1205 9793 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
9794 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
9795 && inst.operands[1].immisreg)
9796 {
9797 inst.instruction &= ~0x1a000ff;
9798 inst.instruction |= (0xf << 28);
9799 if (inst.operands[1].preind)
9800 inst.instruction |= PRE_INDEX;
9801 if (!inst.operands[1].negative)
9802 inst.instruction |= INDEX_UP;
9803 if (inst.operands[1].writeback)
9804 inst.instruction |= WRITE_BACK;
9805 inst.instruction |= inst.operands[1].reg << 16;
9806 inst.instruction |= inst.reloc.exp.X_add_number << 4;
9807 inst.instruction |= inst.operands[1].imm;
9808 }
9809 else
9810 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 9811}
b99bd4ef 9812
c19d1205
ZW
9813static void
9814do_iwmmxt_wshufh (void)
9815{
9816 inst.instruction |= inst.operands[0].reg << 12;
9817 inst.instruction |= inst.operands[1].reg << 16;
9818 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
9819 inst.instruction |= (inst.operands[2].imm & 0x0f);
9820}
b99bd4ef 9821
c19d1205
ZW
9822static void
9823do_iwmmxt_wzero (void)
9824{
9825 /* WZERO reg is an alias for WANDN reg, reg, reg. */
9826 inst.instruction |= inst.operands[0].reg;
9827 inst.instruction |= inst.operands[0].reg << 12;
9828 inst.instruction |= inst.operands[0].reg << 16;
9829}
2d447fca
JM
9830
9831static void
9832do_iwmmxt_wrwrwr_or_imm5 (void)
9833{
9834 if (inst.operands[2].isreg)
9835 do_rd_rn_rm ();
9836 else {
9837 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
9838 _("immediate operand requires iWMMXt2"));
9839 do_rd_rn ();
9840 if (inst.operands[2].imm == 0)
9841 {
9842 switch ((inst.instruction >> 20) & 0xf)
9843 {
9844 case 4:
9845 case 5:
9846 case 6:
5f4273c7 9847 case 7:
2d447fca
JM
9848 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
9849 inst.operands[2].imm = 16;
9850 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
9851 break;
9852 case 8:
9853 case 9:
9854 case 10:
9855 case 11:
9856 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
9857 inst.operands[2].imm = 32;
9858 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
9859 break;
9860 case 12:
9861 case 13:
9862 case 14:
9863 case 15:
9864 {
9865 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
9866 unsigned long wrn;
9867 wrn = (inst.instruction >> 16) & 0xf;
9868 inst.instruction &= 0xff0fff0f;
9869 inst.instruction |= wrn;
9870 /* Bail out here; the instruction is now assembled. */
9871 return;
9872 }
9873 }
9874 }
9875 /* Map 32 -> 0, etc. */
9876 inst.operands[2].imm &= 0x1f;
9877 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
9878 }
9879}
c19d1205
ZW
9880\f
9881/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
9882 operations first, then control, shift, and load/store. */
b99bd4ef 9883
c19d1205 9884/* Insns like "foo X,Y,Z". */
b99bd4ef 9885
c19d1205
ZW
9886static void
9887do_mav_triple (void)
9888{
9889 inst.instruction |= inst.operands[0].reg << 16;
9890 inst.instruction |= inst.operands[1].reg;
9891 inst.instruction |= inst.operands[2].reg << 12;
9892}
b99bd4ef 9893
c19d1205
ZW
9894/* Insns like "foo W,X,Y,Z".
9895 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 9896
c19d1205
ZW
9897static void
9898do_mav_quad (void)
9899{
9900 inst.instruction |= inst.operands[0].reg << 5;
9901 inst.instruction |= inst.operands[1].reg << 12;
9902 inst.instruction |= inst.operands[2].reg << 16;
9903 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
9904}
9905
c19d1205
ZW
9906/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
9907static void
9908do_mav_dspsc (void)
a737bd4d 9909{
c19d1205
ZW
9910 inst.instruction |= inst.operands[1].reg << 12;
9911}
a737bd4d 9912
c19d1205
ZW
9913/* Maverick shift immediate instructions.
9914 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
9915 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 9916
c19d1205
ZW
9917static void
9918do_mav_shift (void)
9919{
9920 int imm = inst.operands[2].imm;
a737bd4d 9921
c19d1205
ZW
9922 inst.instruction |= inst.operands[0].reg << 12;
9923 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 9924
c19d1205
ZW
9925 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
9926 Bits 5-7 of the insn should have bits 4-6 of the immediate.
9927 Bit 4 should be 0. */
9928 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 9929
c19d1205
ZW
9930 inst.instruction |= imm;
9931}
9932\f
9933/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 9934
c19d1205
ZW
9935/* Xscale multiply-accumulate (argument parse)
9936 MIAcc acc0,Rm,Rs
9937 MIAPHcc acc0,Rm,Rs
9938 MIAxycc acc0,Rm,Rs. */
a737bd4d 9939
c19d1205
ZW
9940static void
9941do_xsc_mia (void)
9942{
9943 inst.instruction |= inst.operands[1].reg;
9944 inst.instruction |= inst.operands[2].reg << 12;
9945}
a737bd4d 9946
c19d1205 9947/* Xscale move-accumulator-register (argument parse)
a737bd4d 9948
c19d1205 9949 MARcc acc0,RdLo,RdHi. */
b99bd4ef 9950
c19d1205
ZW
9951static void
9952do_xsc_mar (void)
9953{
9954 inst.instruction |= inst.operands[1].reg << 12;
9955 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9956}
9957
c19d1205 9958/* Xscale move-register-accumulator (argument parse)
b99bd4ef 9959
c19d1205 9960 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
9961
9962static void
c19d1205 9963do_xsc_mra (void)
b99bd4ef 9964{
c19d1205
ZW
9965 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
9966 inst.instruction |= inst.operands[0].reg << 12;
9967 inst.instruction |= inst.operands[1].reg << 16;
9968}
9969\f
9970/* Encoding functions relevant only to Thumb. */
b99bd4ef 9971
c19d1205
ZW
9972/* inst.operands[i] is a shifted-register operand; encode
9973 it into inst.instruction in the format used by Thumb32. */
9974
9975static void
9976encode_thumb32_shifted_operand (int i)
9977{
9978 unsigned int value = inst.reloc.exp.X_add_number;
9979 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 9980
9c3c69f2
PB
9981 constraint (inst.operands[i].immisreg,
9982 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
9983 inst.instruction |= inst.operands[i].reg;
9984 if (shift == SHIFT_RRX)
9985 inst.instruction |= SHIFT_ROR << 4;
9986 else
b99bd4ef 9987 {
c19d1205
ZW
9988 constraint (inst.reloc.exp.X_op != O_constant,
9989 _("expression too complex"));
9990
9991 constraint (value > 32
9992 || (value == 32 && (shift == SHIFT_LSL
9993 || shift == SHIFT_ROR)),
9994 _("shift expression is too large"));
9995
9996 if (value == 0)
9997 shift = SHIFT_LSL;
9998 else if (value == 32)
9999 value = 0;
10000
10001 inst.instruction |= shift << 4;
10002 inst.instruction |= (value & 0x1c) << 10;
10003 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10004 }
c19d1205 10005}
b99bd4ef 10006
b99bd4ef 10007
c19d1205
ZW
10008/* inst.operands[i] was set up by parse_address. Encode it into a
10009 Thumb32 format load or store instruction. Reject forms that cannot
10010 be used with such instructions. If is_t is true, reject forms that
10011 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10012 that cannot be used with a D instruction. If it is a store insn,
10013 reject PC in Rn. */
b99bd4ef 10014
c19d1205
ZW
10015static void
10016encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10017{
5be8be5d 10018 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10019
10020 constraint (!inst.operands[i].isreg,
53365c0d 10021 _("Instruction does not support =N addresses"));
b99bd4ef 10022
c19d1205
ZW
10023 inst.instruction |= inst.operands[i].reg << 16;
10024 if (inst.operands[i].immisreg)
b99bd4ef 10025 {
5be8be5d 10026 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10027 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10028 constraint (inst.operands[i].negative,
10029 _("Thumb does not support negative register indexing"));
10030 constraint (inst.operands[i].postind,
10031 _("Thumb does not support register post-indexing"));
10032 constraint (inst.operands[i].writeback,
10033 _("Thumb does not support register indexing with writeback"));
10034 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10035 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10036
f40d1643 10037 inst.instruction |= inst.operands[i].imm;
c19d1205 10038 if (inst.operands[i].shifted)
b99bd4ef 10039 {
c19d1205
ZW
10040 constraint (inst.reloc.exp.X_op != O_constant,
10041 _("expression too complex"));
9c3c69f2
PB
10042 constraint (inst.reloc.exp.X_add_number < 0
10043 || inst.reloc.exp.X_add_number > 3,
c19d1205 10044 _("shift out of range"));
9c3c69f2 10045 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10046 }
10047 inst.reloc.type = BFD_RELOC_UNUSED;
10048 }
10049 else if (inst.operands[i].preind)
10050 {
5be8be5d 10051 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10052 constraint (is_t && inst.operands[i].writeback,
c19d1205 10053 _("cannot use writeback with this instruction"));
4755303e
WN
10054 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10055 BAD_PC_ADDRESSING);
c19d1205
ZW
10056
10057 if (is_d)
10058 {
10059 inst.instruction |= 0x01000000;
10060 if (inst.operands[i].writeback)
10061 inst.instruction |= 0x00200000;
b99bd4ef 10062 }
c19d1205 10063 else
b99bd4ef 10064 {
c19d1205
ZW
10065 inst.instruction |= 0x00000c00;
10066 if (inst.operands[i].writeback)
10067 inst.instruction |= 0x00000100;
b99bd4ef 10068 }
c19d1205 10069 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10070 }
c19d1205 10071 else if (inst.operands[i].postind)
b99bd4ef 10072 {
9c2799c2 10073 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10074 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10075 constraint (is_t, _("cannot use post-indexing with this instruction"));
10076
10077 if (is_d)
10078 inst.instruction |= 0x00200000;
10079 else
10080 inst.instruction |= 0x00000900;
10081 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10082 }
10083 else /* unindexed - only for coprocessor */
10084 inst.error = _("instruction does not accept unindexed addressing");
10085}
10086
10087/* Table of Thumb instructions which exist in both 16- and 32-bit
10088 encodings (the latter only in post-V6T2 cores). The index is the
10089 value used in the insns table below. When there is more than one
10090 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10091 holds variant (1).
10092 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10093#define T16_32_TAB \
21d799b5
NC
10094 X(_adc, 4140, eb400000), \
10095 X(_adcs, 4140, eb500000), \
10096 X(_add, 1c00, eb000000), \
10097 X(_adds, 1c00, eb100000), \
10098 X(_addi, 0000, f1000000), \
10099 X(_addis, 0000, f1100000), \
10100 X(_add_pc,000f, f20f0000), \
10101 X(_add_sp,000d, f10d0000), \
10102 X(_adr, 000f, f20f0000), \
10103 X(_and, 4000, ea000000), \
10104 X(_ands, 4000, ea100000), \
10105 X(_asr, 1000, fa40f000), \
10106 X(_asrs, 1000, fa50f000), \
10107 X(_b, e000, f000b000), \
10108 X(_bcond, d000, f0008000), \
10109 X(_bic, 4380, ea200000), \
10110 X(_bics, 4380, ea300000), \
10111 X(_cmn, 42c0, eb100f00), \
10112 X(_cmp, 2800, ebb00f00), \
10113 X(_cpsie, b660, f3af8400), \
10114 X(_cpsid, b670, f3af8600), \
10115 X(_cpy, 4600, ea4f0000), \
10116 X(_dec_sp,80dd, f1ad0d00), \
10117 X(_eor, 4040, ea800000), \
10118 X(_eors, 4040, ea900000), \
10119 X(_inc_sp,00dd, f10d0d00), \
10120 X(_ldmia, c800, e8900000), \
10121 X(_ldr, 6800, f8500000), \
10122 X(_ldrb, 7800, f8100000), \
10123 X(_ldrh, 8800, f8300000), \
10124 X(_ldrsb, 5600, f9100000), \
10125 X(_ldrsh, 5e00, f9300000), \
10126 X(_ldr_pc,4800, f85f0000), \
10127 X(_ldr_pc2,4800, f85f0000), \
10128 X(_ldr_sp,9800, f85d0000), \
10129 X(_lsl, 0000, fa00f000), \
10130 X(_lsls, 0000, fa10f000), \
10131 X(_lsr, 0800, fa20f000), \
10132 X(_lsrs, 0800, fa30f000), \
10133 X(_mov, 2000, ea4f0000), \
10134 X(_movs, 2000, ea5f0000), \
10135 X(_mul, 4340, fb00f000), \
10136 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10137 X(_mvn, 43c0, ea6f0000), \
10138 X(_mvns, 43c0, ea7f0000), \
10139 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10140 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10141 X(_orr, 4300, ea400000), \
10142 X(_orrs, 4300, ea500000), \
10143 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10144 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10145 X(_rev, ba00, fa90f080), \
10146 X(_rev16, ba40, fa90f090), \
10147 X(_revsh, bac0, fa90f0b0), \
10148 X(_ror, 41c0, fa60f000), \
10149 X(_rors, 41c0, fa70f000), \
10150 X(_sbc, 4180, eb600000), \
10151 X(_sbcs, 4180, eb700000), \
10152 X(_stmia, c000, e8800000), \
10153 X(_str, 6000, f8400000), \
10154 X(_strb, 7000, f8000000), \
10155 X(_strh, 8000, f8200000), \
10156 X(_str_sp,9000, f84d0000), \
10157 X(_sub, 1e00, eba00000), \
10158 X(_subs, 1e00, ebb00000), \
10159 X(_subi, 8000, f1a00000), \
10160 X(_subis, 8000, f1b00000), \
10161 X(_sxtb, b240, fa4ff080), \
10162 X(_sxth, b200, fa0ff080), \
10163 X(_tst, 4200, ea100f00), \
10164 X(_uxtb, b2c0, fa5ff080), \
10165 X(_uxth, b280, fa1ff080), \
10166 X(_nop, bf00, f3af8000), \
10167 X(_yield, bf10, f3af8001), \
10168 X(_wfe, bf20, f3af8002), \
10169 X(_wfi, bf30, f3af8003), \
53c4b28b 10170 X(_sev, bf40, f3af8004), \
74db7efb
NC
10171 X(_sevl, bf50, f3af8005), \
10172 X(_udf, de00, f7f0a000)
c19d1205
ZW
10173
10174/* To catch errors in encoding functions, the codes are all offset by
10175 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10176 as 16-bit instructions. */
21d799b5 10177#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10178enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10179#undef X
10180
10181#define X(a,b,c) 0x##b
10182static const unsigned short thumb_op16[] = { T16_32_TAB };
10183#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10184#undef X
10185
10186#define X(a,b,c) 0x##c
10187static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10188#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10189#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10190#undef X
10191#undef T16_32_TAB
10192
10193/* Thumb instruction encoders, in alphabetical order. */
10194
92e90b6e 10195/* ADDW or SUBW. */
c921be7d 10196
92e90b6e
PB
10197static void
10198do_t_add_sub_w (void)
10199{
10200 int Rd, Rn;
10201
10202 Rd = inst.operands[0].reg;
10203 Rn = inst.operands[1].reg;
10204
539d4391
NC
10205 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10206 is the SP-{plus,minus}-immediate form of the instruction. */
10207 if (Rn == REG_SP)
10208 constraint (Rd == REG_PC, BAD_PC);
10209 else
10210 reject_bad_reg (Rd);
fdfde340 10211
92e90b6e
PB
10212 inst.instruction |= (Rn << 16) | (Rd << 8);
10213 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10214}
10215
c19d1205
ZW
10216/* Parse an add or subtract instruction. We get here with inst.instruction
10217 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
10218
10219static void
10220do_t_add_sub (void)
10221{
10222 int Rd, Rs, Rn;
10223
10224 Rd = inst.operands[0].reg;
10225 Rs = (inst.operands[1].present
10226 ? inst.operands[1].reg /* Rd, Rs, foo */
10227 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10228
e07e6e58
NC
10229 if (Rd == REG_PC)
10230 set_it_insn_type_last ();
10231
c19d1205
ZW
10232 if (unified_syntax)
10233 {
0110f2b8
PB
10234 bfd_boolean flags;
10235 bfd_boolean narrow;
10236 int opcode;
10237
10238 flags = (inst.instruction == T_MNEM_adds
10239 || inst.instruction == T_MNEM_subs);
10240 if (flags)
e07e6e58 10241 narrow = !in_it_block ();
0110f2b8 10242 else
e07e6e58 10243 narrow = in_it_block ();
c19d1205 10244 if (!inst.operands[2].isreg)
b99bd4ef 10245 {
16805f35
PB
10246 int add;
10247
fdfde340
JM
10248 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10249
16805f35
PB
10250 add = (inst.instruction == T_MNEM_add
10251 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10252 opcode = 0;
10253 if (inst.size_req != 4)
10254 {
0110f2b8 10255 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10256 appropriate. */
0110f2b8
PB
10257 if (Rd == REG_SP && Rs == REG_SP && !flags)
10258 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10259 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10260 opcode = T_MNEM_add_sp;
10261 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10262 opcode = T_MNEM_add_pc;
10263 else if (Rd <= 7 && Rs <= 7 && narrow)
10264 {
10265 if (flags)
10266 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10267 else
10268 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10269 }
10270 if (opcode)
10271 {
10272 inst.instruction = THUMB_OP16(opcode);
10273 inst.instruction |= (Rd << 4) | Rs;
10274 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10275 if (inst.size_req != 2)
10276 inst.relax = opcode;
10277 }
10278 else
10279 constraint (inst.size_req == 2, BAD_HIREG);
10280 }
10281 if (inst.size_req == 4
10282 || (inst.size_req != 2 && !opcode))
10283 {
efd81785
PB
10284 if (Rd == REG_PC)
10285 {
fdfde340 10286 constraint (add, BAD_PC);
efd81785
PB
10287 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10288 _("only SUBS PC, LR, #const allowed"));
10289 constraint (inst.reloc.exp.X_op != O_constant,
10290 _("expression too complex"));
10291 constraint (inst.reloc.exp.X_add_number < 0
10292 || inst.reloc.exp.X_add_number > 0xff,
10293 _("immediate value out of range"));
10294 inst.instruction = T2_SUBS_PC_LR
10295 | inst.reloc.exp.X_add_number;
10296 inst.reloc.type = BFD_RELOC_UNUSED;
10297 return;
10298 }
10299 else if (Rs == REG_PC)
16805f35
PB
10300 {
10301 /* Always use addw/subw. */
10302 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10303 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10304 }
10305 else
10306 {
10307 inst.instruction = THUMB_OP32 (inst.instruction);
10308 inst.instruction = (inst.instruction & 0xe1ffffff)
10309 | 0x10000000;
10310 if (flags)
10311 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10312 else
10313 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10314 }
dc4503c6
PB
10315 inst.instruction |= Rd << 8;
10316 inst.instruction |= Rs << 16;
0110f2b8 10317 }
b99bd4ef 10318 }
c19d1205
ZW
10319 else
10320 {
5f4cb198
NC
10321 unsigned int value = inst.reloc.exp.X_add_number;
10322 unsigned int shift = inst.operands[2].shift_kind;
10323
c19d1205
ZW
10324 Rn = inst.operands[2].reg;
10325 /* See if we can do this with a 16-bit instruction. */
10326 if (!inst.operands[2].shifted && inst.size_req != 4)
10327 {
e27ec89e
PB
10328 if (Rd > 7 || Rs > 7 || Rn > 7)
10329 narrow = FALSE;
10330
10331 if (narrow)
c19d1205 10332 {
e27ec89e
PB
10333 inst.instruction = ((inst.instruction == T_MNEM_adds
10334 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10335 ? T_OPCODE_ADD_R3
10336 : T_OPCODE_SUB_R3);
10337 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10338 return;
10339 }
b99bd4ef 10340
7e806470 10341 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10342 {
7e806470
PB
10343 /* Thumb-1 cores (except v6-M) require at least one high
10344 register in a narrow non flag setting add. */
10345 if (Rd > 7 || Rn > 7
10346 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10347 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10348 {
7e806470
PB
10349 if (Rd == Rn)
10350 {
10351 Rn = Rs;
10352 Rs = Rd;
10353 }
c19d1205
ZW
10354 inst.instruction = T_OPCODE_ADD_HI;
10355 inst.instruction |= (Rd & 8) << 4;
10356 inst.instruction |= (Rd & 7);
10357 inst.instruction |= Rn << 3;
10358 return;
10359 }
c19d1205
ZW
10360 }
10361 }
c921be7d 10362
fdfde340
JM
10363 constraint (Rd == REG_PC, BAD_PC);
10364 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10365 constraint (Rs == REG_PC, BAD_PC);
10366 reject_bad_reg (Rn);
10367
c19d1205
ZW
10368 /* If we get here, it can't be done in 16 bits. */
10369 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10370 _("shift must be constant"));
10371 inst.instruction = THUMB_OP32 (inst.instruction);
10372 inst.instruction |= Rd << 8;
10373 inst.instruction |= Rs << 16;
5f4cb198
NC
10374 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10375 _("shift value over 3 not allowed in thumb mode"));
10376 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10377 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10378 encode_thumb32_shifted_operand (2);
10379 }
10380 }
10381 else
10382 {
10383 constraint (inst.instruction == T_MNEM_adds
10384 || inst.instruction == T_MNEM_subs,
10385 BAD_THUMB32);
b99bd4ef 10386
c19d1205 10387 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10388 {
c19d1205
ZW
10389 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10390 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10391 BAD_HIREG);
10392
10393 inst.instruction = (inst.instruction == T_MNEM_add
10394 ? 0x0000 : 0x8000);
10395 inst.instruction |= (Rd << 4) | Rs;
10396 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10397 return;
10398 }
10399
c19d1205
ZW
10400 Rn = inst.operands[2].reg;
10401 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10402
c19d1205
ZW
10403 /* We now have Rd, Rs, and Rn set to registers. */
10404 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10405 {
c19d1205
ZW
10406 /* Can't do this for SUB. */
10407 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10408 inst.instruction = T_OPCODE_ADD_HI;
10409 inst.instruction |= (Rd & 8) << 4;
10410 inst.instruction |= (Rd & 7);
10411 if (Rs == Rd)
10412 inst.instruction |= Rn << 3;
10413 else if (Rn == Rd)
10414 inst.instruction |= Rs << 3;
10415 else
10416 constraint (1, _("dest must overlap one source register"));
10417 }
10418 else
10419 {
10420 inst.instruction = (inst.instruction == T_MNEM_add
10421 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10422 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10423 }
b99bd4ef 10424 }
b99bd4ef
NC
10425}
10426
c19d1205
ZW
10427static void
10428do_t_adr (void)
10429{
fdfde340
JM
10430 unsigned Rd;
10431
10432 Rd = inst.operands[0].reg;
10433 reject_bad_reg (Rd);
10434
10435 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10436 {
10437 /* Defer to section relaxation. */
10438 inst.relax = inst.instruction;
10439 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10440 inst.instruction |= Rd << 4;
0110f2b8
PB
10441 }
10442 else if (unified_syntax && inst.size_req != 2)
e9f89963 10443 {
0110f2b8 10444 /* Generate a 32-bit opcode. */
e9f89963 10445 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10446 inst.instruction |= Rd << 8;
e9f89963
PB
10447 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10448 inst.reloc.pc_rel = 1;
10449 }
10450 else
10451 {
0110f2b8 10452 /* Generate a 16-bit opcode. */
e9f89963
PB
10453 inst.instruction = THUMB_OP16 (inst.instruction);
10454 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10455 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10456 inst.reloc.pc_rel = 1;
b99bd4ef 10457
fdfde340 10458 inst.instruction |= Rd << 4;
e9f89963 10459 }
c19d1205 10460}
b99bd4ef 10461
c19d1205
ZW
10462/* Arithmetic instructions for which there is just one 16-bit
10463 instruction encoding, and it allows only two low registers.
10464 For maximal compatibility with ARM syntax, we allow three register
10465 operands even when Thumb-32 instructions are not available, as long
10466 as the first two are identical. For instance, both "sbc r0,r1" and
10467 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10468static void
c19d1205 10469do_t_arit3 (void)
b99bd4ef 10470{
c19d1205 10471 int Rd, Rs, Rn;
b99bd4ef 10472
c19d1205
ZW
10473 Rd = inst.operands[0].reg;
10474 Rs = (inst.operands[1].present
10475 ? inst.operands[1].reg /* Rd, Rs, foo */
10476 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10477 Rn = inst.operands[2].reg;
b99bd4ef 10478
fdfde340
JM
10479 reject_bad_reg (Rd);
10480 reject_bad_reg (Rs);
10481 if (inst.operands[2].isreg)
10482 reject_bad_reg (Rn);
10483
c19d1205 10484 if (unified_syntax)
b99bd4ef 10485 {
c19d1205
ZW
10486 if (!inst.operands[2].isreg)
10487 {
10488 /* For an immediate, we always generate a 32-bit opcode;
10489 section relaxation will shrink it later if possible. */
10490 inst.instruction = THUMB_OP32 (inst.instruction);
10491 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10492 inst.instruction |= Rd << 8;
10493 inst.instruction |= Rs << 16;
10494 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10495 }
10496 else
10497 {
e27ec89e
PB
10498 bfd_boolean narrow;
10499
c19d1205 10500 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10501 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10502 narrow = !in_it_block ();
e27ec89e 10503 else
e07e6e58 10504 narrow = in_it_block ();
e27ec89e
PB
10505
10506 if (Rd > 7 || Rn > 7 || Rs > 7)
10507 narrow = FALSE;
10508 if (inst.operands[2].shifted)
10509 narrow = FALSE;
10510 if (inst.size_req == 4)
10511 narrow = FALSE;
10512
10513 if (narrow
c19d1205
ZW
10514 && Rd == Rs)
10515 {
10516 inst.instruction = THUMB_OP16 (inst.instruction);
10517 inst.instruction |= Rd;
10518 inst.instruction |= Rn << 3;
10519 return;
10520 }
b99bd4ef 10521
c19d1205
ZW
10522 /* If we get here, it can't be done in 16 bits. */
10523 constraint (inst.operands[2].shifted
10524 && inst.operands[2].immisreg,
10525 _("shift must be constant"));
10526 inst.instruction = THUMB_OP32 (inst.instruction);
10527 inst.instruction |= Rd << 8;
10528 inst.instruction |= Rs << 16;
10529 encode_thumb32_shifted_operand (2);
10530 }
a737bd4d 10531 }
c19d1205 10532 else
b99bd4ef 10533 {
c19d1205
ZW
10534 /* On its face this is a lie - the instruction does set the
10535 flags. However, the only supported mnemonic in this mode
10536 says it doesn't. */
10537 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10538
c19d1205
ZW
10539 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10540 _("unshifted register required"));
10541 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10542 constraint (Rd != Rs,
10543 _("dest and source1 must be the same register"));
a737bd4d 10544
c19d1205
ZW
10545 inst.instruction = THUMB_OP16 (inst.instruction);
10546 inst.instruction |= Rd;
10547 inst.instruction |= Rn << 3;
b99bd4ef 10548 }
a737bd4d 10549}
b99bd4ef 10550
c19d1205
ZW
10551/* Similarly, but for instructions where the arithmetic operation is
10552 commutative, so we can allow either of them to be different from
10553 the destination operand in a 16-bit instruction. For instance, all
10554 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10555 accepted. */
10556static void
10557do_t_arit3c (void)
a737bd4d 10558{
c19d1205 10559 int Rd, Rs, Rn;
b99bd4ef 10560
c19d1205
ZW
10561 Rd = inst.operands[0].reg;
10562 Rs = (inst.operands[1].present
10563 ? inst.operands[1].reg /* Rd, Rs, foo */
10564 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10565 Rn = inst.operands[2].reg;
c921be7d 10566
fdfde340
JM
10567 reject_bad_reg (Rd);
10568 reject_bad_reg (Rs);
10569 if (inst.operands[2].isreg)
10570 reject_bad_reg (Rn);
a737bd4d 10571
c19d1205 10572 if (unified_syntax)
a737bd4d 10573 {
c19d1205 10574 if (!inst.operands[2].isreg)
b99bd4ef 10575 {
c19d1205
ZW
10576 /* For an immediate, we always generate a 32-bit opcode;
10577 section relaxation will shrink it later if possible. */
10578 inst.instruction = THUMB_OP32 (inst.instruction);
10579 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10580 inst.instruction |= Rd << 8;
10581 inst.instruction |= Rs << 16;
10582 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10583 }
c19d1205 10584 else
a737bd4d 10585 {
e27ec89e
PB
10586 bfd_boolean narrow;
10587
c19d1205 10588 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10589 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10590 narrow = !in_it_block ();
e27ec89e 10591 else
e07e6e58 10592 narrow = in_it_block ();
e27ec89e
PB
10593
10594 if (Rd > 7 || Rn > 7 || Rs > 7)
10595 narrow = FALSE;
10596 if (inst.operands[2].shifted)
10597 narrow = FALSE;
10598 if (inst.size_req == 4)
10599 narrow = FALSE;
10600
10601 if (narrow)
a737bd4d 10602 {
c19d1205 10603 if (Rd == Rs)
a737bd4d 10604 {
c19d1205
ZW
10605 inst.instruction = THUMB_OP16 (inst.instruction);
10606 inst.instruction |= Rd;
10607 inst.instruction |= Rn << 3;
10608 return;
a737bd4d 10609 }
c19d1205 10610 if (Rd == Rn)
a737bd4d 10611 {
c19d1205
ZW
10612 inst.instruction = THUMB_OP16 (inst.instruction);
10613 inst.instruction |= Rd;
10614 inst.instruction |= Rs << 3;
10615 return;
a737bd4d
NC
10616 }
10617 }
c19d1205
ZW
10618
10619 /* If we get here, it can't be done in 16 bits. */
10620 constraint (inst.operands[2].shifted
10621 && inst.operands[2].immisreg,
10622 _("shift must be constant"));
10623 inst.instruction = THUMB_OP32 (inst.instruction);
10624 inst.instruction |= Rd << 8;
10625 inst.instruction |= Rs << 16;
10626 encode_thumb32_shifted_operand (2);
a737bd4d 10627 }
b99bd4ef 10628 }
c19d1205
ZW
10629 else
10630 {
10631 /* On its face this is a lie - the instruction does set the
10632 flags. However, the only supported mnemonic in this mode
10633 says it doesn't. */
10634 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10635
c19d1205
ZW
10636 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10637 _("unshifted register required"));
10638 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10639
10640 inst.instruction = THUMB_OP16 (inst.instruction);
10641 inst.instruction |= Rd;
10642
10643 if (Rd == Rs)
10644 inst.instruction |= Rn << 3;
10645 else if (Rd == Rn)
10646 inst.instruction |= Rs << 3;
10647 else
10648 constraint (1, _("dest must overlap one source register"));
10649 }
a737bd4d
NC
10650}
10651
c19d1205
ZW
10652static void
10653do_t_bfc (void)
a737bd4d 10654{
fdfde340 10655 unsigned Rd;
c19d1205
ZW
10656 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10657 constraint (msb > 32, _("bit-field extends past end of register"));
10658 /* The instruction encoding stores the LSB and MSB,
10659 not the LSB and width. */
fdfde340
JM
10660 Rd = inst.operands[0].reg;
10661 reject_bad_reg (Rd);
10662 inst.instruction |= Rd << 8;
c19d1205
ZW
10663 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10664 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10665 inst.instruction |= msb - 1;
b99bd4ef
NC
10666}
10667
c19d1205
ZW
10668static void
10669do_t_bfi (void)
b99bd4ef 10670{
fdfde340 10671 int Rd, Rn;
c19d1205 10672 unsigned int msb;
b99bd4ef 10673
fdfde340
JM
10674 Rd = inst.operands[0].reg;
10675 reject_bad_reg (Rd);
10676
c19d1205
ZW
10677 /* #0 in second position is alternative syntax for bfc, which is
10678 the same instruction but with REG_PC in the Rm field. */
10679 if (!inst.operands[1].isreg)
fdfde340
JM
10680 Rn = REG_PC;
10681 else
10682 {
10683 Rn = inst.operands[1].reg;
10684 reject_bad_reg (Rn);
10685 }
b99bd4ef 10686
c19d1205
ZW
10687 msb = inst.operands[2].imm + inst.operands[3].imm;
10688 constraint (msb > 32, _("bit-field extends past end of register"));
10689 /* The instruction encoding stores the LSB and MSB,
10690 not the LSB and width. */
fdfde340
JM
10691 inst.instruction |= Rd << 8;
10692 inst.instruction |= Rn << 16;
c19d1205
ZW
10693 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10694 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10695 inst.instruction |= msb - 1;
b99bd4ef
NC
10696}
10697
c19d1205
ZW
10698static void
10699do_t_bfx (void)
b99bd4ef 10700{
fdfde340
JM
10701 unsigned Rd, Rn;
10702
10703 Rd = inst.operands[0].reg;
10704 Rn = inst.operands[1].reg;
10705
10706 reject_bad_reg (Rd);
10707 reject_bad_reg (Rn);
10708
c19d1205
ZW
10709 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
10710 _("bit-field extends past end of register"));
fdfde340
JM
10711 inst.instruction |= Rd << 8;
10712 inst.instruction |= Rn << 16;
c19d1205
ZW
10713 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10714 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10715 inst.instruction |= inst.operands[3].imm - 1;
10716}
b99bd4ef 10717
c19d1205
ZW
10718/* ARM V5 Thumb BLX (argument parse)
10719 BLX <target_addr> which is BLX(1)
10720 BLX <Rm> which is BLX(2)
10721 Unfortunately, there are two different opcodes for this mnemonic.
10722 So, the insns[].value is not used, and the code here zaps values
10723 into inst.instruction.
b99bd4ef 10724
c19d1205
ZW
10725 ??? How to take advantage of the additional two bits of displacement
10726 available in Thumb32 mode? Need new relocation? */
b99bd4ef 10727
c19d1205
ZW
10728static void
10729do_t_blx (void)
10730{
e07e6e58
NC
10731 set_it_insn_type_last ();
10732
c19d1205 10733 if (inst.operands[0].isreg)
fdfde340
JM
10734 {
10735 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10736 /* We have a register, so this is BLX(2). */
10737 inst.instruction |= inst.operands[0].reg << 3;
10738 }
b99bd4ef
NC
10739 else
10740 {
c19d1205 10741 /* No register. This must be BLX(1). */
2fc8bdac 10742 inst.instruction = 0xf000e800;
0855e32b 10743 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
10744 }
10745}
10746
c19d1205
ZW
10747static void
10748do_t_branch (void)
b99bd4ef 10749{
0110f2b8 10750 int opcode;
dfa9f0d5 10751 int cond;
9ae92b05 10752 int reloc;
dfa9f0d5 10753
e07e6e58
NC
10754 cond = inst.cond;
10755 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
10756
10757 if (in_it_block ())
dfa9f0d5
PB
10758 {
10759 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 10760 branches. */
dfa9f0d5 10761 cond = COND_ALWAYS;
dfa9f0d5
PB
10762 }
10763 else
10764 cond = inst.cond;
10765
10766 if (cond != COND_ALWAYS)
0110f2b8
PB
10767 opcode = T_MNEM_bcond;
10768 else
10769 opcode = inst.instruction;
10770
12d6b0b7
RS
10771 if (unified_syntax
10772 && (inst.size_req == 4
10960bfb
PB
10773 || (inst.size_req != 2
10774 && (inst.operands[0].hasreloc
10775 || inst.reloc.exp.X_op == O_constant))))
c19d1205 10776 {
0110f2b8 10777 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 10778 if (cond == COND_ALWAYS)
9ae92b05 10779 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
10780 else
10781 {
9c2799c2 10782 gas_assert (cond != 0xF);
dfa9f0d5 10783 inst.instruction |= cond << 22;
9ae92b05 10784 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
10785 }
10786 }
b99bd4ef
NC
10787 else
10788 {
0110f2b8 10789 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 10790 if (cond == COND_ALWAYS)
9ae92b05 10791 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 10792 else
b99bd4ef 10793 {
dfa9f0d5 10794 inst.instruction |= cond << 8;
9ae92b05 10795 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 10796 }
0110f2b8
PB
10797 /* Allow section relaxation. */
10798 if (unified_syntax && inst.size_req != 2)
10799 inst.relax = opcode;
b99bd4ef 10800 }
9ae92b05 10801 inst.reloc.type = reloc;
c19d1205 10802 inst.reloc.pc_rel = 1;
b99bd4ef
NC
10803}
10804
8884b720 10805/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 10806 between the two is the maximum immediate allowed - which is passed in
8884b720 10807 RANGE. */
b99bd4ef 10808static void
8884b720 10809do_t_bkpt_hlt1 (int range)
b99bd4ef 10810{
dfa9f0d5
PB
10811 constraint (inst.cond != COND_ALWAYS,
10812 _("instruction is always unconditional"));
c19d1205 10813 if (inst.operands[0].present)
b99bd4ef 10814 {
8884b720 10815 constraint (inst.operands[0].imm > range,
c19d1205
ZW
10816 _("immediate value out of range"));
10817 inst.instruction |= inst.operands[0].imm;
b99bd4ef 10818 }
8884b720
MGD
10819
10820 set_it_insn_type (NEUTRAL_IT_INSN);
10821}
10822
10823static void
10824do_t_hlt (void)
10825{
10826 do_t_bkpt_hlt1 (63);
10827}
10828
10829static void
10830do_t_bkpt (void)
10831{
10832 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
10833}
10834
10835static void
c19d1205 10836do_t_branch23 (void)
b99bd4ef 10837{
e07e6e58 10838 set_it_insn_type_last ();
0855e32b 10839 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 10840
0855e32b
NS
10841 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
10842 this file. We used to simply ignore the PLT reloc type here --
10843 the branch encoding is now needed to deal with TLSCALL relocs.
10844 So if we see a PLT reloc now, put it back to how it used to be to
10845 keep the preexisting behaviour. */
10846 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
10847 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 10848
4343666d 10849#if defined(OBJ_COFF)
c19d1205
ZW
10850 /* If the destination of the branch is a defined symbol which does not have
10851 the THUMB_FUNC attribute, then we must be calling a function which has
10852 the (interfacearm) attribute. We look for the Thumb entry point to that
10853 function and change the branch to refer to that function instead. */
10854 if ( inst.reloc.exp.X_op == O_symbol
10855 && inst.reloc.exp.X_add_symbol != NULL
10856 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10857 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10858 inst.reloc.exp.X_add_symbol =
10859 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 10860#endif
90e4755a
RE
10861}
10862
10863static void
c19d1205 10864do_t_bx (void)
90e4755a 10865{
e07e6e58 10866 set_it_insn_type_last ();
c19d1205
ZW
10867 inst.instruction |= inst.operands[0].reg << 3;
10868 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
10869 should cause the alignment to be checked once it is known. This is
10870 because BX PC only works if the instruction is word aligned. */
10871}
90e4755a 10872
c19d1205
ZW
10873static void
10874do_t_bxj (void)
10875{
fdfde340 10876 int Rm;
90e4755a 10877
e07e6e58 10878 set_it_insn_type_last ();
fdfde340
JM
10879 Rm = inst.operands[0].reg;
10880 reject_bad_reg (Rm);
10881 inst.instruction |= Rm << 16;
90e4755a
RE
10882}
10883
10884static void
c19d1205 10885do_t_clz (void)
90e4755a 10886{
fdfde340
JM
10887 unsigned Rd;
10888 unsigned Rm;
10889
10890 Rd = inst.operands[0].reg;
10891 Rm = inst.operands[1].reg;
10892
10893 reject_bad_reg (Rd);
10894 reject_bad_reg (Rm);
10895
10896 inst.instruction |= Rd << 8;
10897 inst.instruction |= Rm << 16;
10898 inst.instruction |= Rm;
c19d1205 10899}
90e4755a 10900
dfa9f0d5
PB
10901static void
10902do_t_cps (void)
10903{
e07e6e58 10904 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
10905 inst.instruction |= inst.operands[0].imm;
10906}
10907
c19d1205
ZW
10908static void
10909do_t_cpsi (void)
10910{
e07e6e58 10911 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 10912 if (unified_syntax
62b3e311
PB
10913 && (inst.operands[1].present || inst.size_req == 4)
10914 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 10915 {
c19d1205
ZW
10916 unsigned int imod = (inst.instruction & 0x0030) >> 4;
10917 inst.instruction = 0xf3af8000;
10918 inst.instruction |= imod << 9;
10919 inst.instruction |= inst.operands[0].imm << 5;
10920 if (inst.operands[1].present)
10921 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 10922 }
c19d1205 10923 else
90e4755a 10924 {
62b3e311
PB
10925 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
10926 && (inst.operands[0].imm & 4),
10927 _("selected processor does not support 'A' form "
10928 "of this instruction"));
10929 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
10930 _("Thumb does not support the 2-argument "
10931 "form of this instruction"));
10932 inst.instruction |= inst.operands[0].imm;
90e4755a 10933 }
90e4755a
RE
10934}
10935
c19d1205
ZW
10936/* THUMB CPY instruction (argument parse). */
10937
90e4755a 10938static void
c19d1205 10939do_t_cpy (void)
90e4755a 10940{
c19d1205 10941 if (inst.size_req == 4)
90e4755a 10942 {
c19d1205
ZW
10943 inst.instruction = THUMB_OP32 (T_MNEM_mov);
10944 inst.instruction |= inst.operands[0].reg << 8;
10945 inst.instruction |= inst.operands[1].reg;
90e4755a 10946 }
c19d1205 10947 else
90e4755a 10948 {
c19d1205
ZW
10949 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
10950 inst.instruction |= (inst.operands[0].reg & 0x7);
10951 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 10952 }
90e4755a
RE
10953}
10954
90e4755a 10955static void
25fe350b 10956do_t_cbz (void)
90e4755a 10957{
e07e6e58 10958 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
10959 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10960 inst.instruction |= inst.operands[0].reg;
10961 inst.reloc.pc_rel = 1;
10962 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
10963}
90e4755a 10964
62b3e311
PB
10965static void
10966do_t_dbg (void)
10967{
10968 inst.instruction |= inst.operands[0].imm;
10969}
10970
10971static void
10972do_t_div (void)
10973{
fdfde340
JM
10974 unsigned Rd, Rn, Rm;
10975
10976 Rd = inst.operands[0].reg;
10977 Rn = (inst.operands[1].present
10978 ? inst.operands[1].reg : Rd);
10979 Rm = inst.operands[2].reg;
10980
10981 reject_bad_reg (Rd);
10982 reject_bad_reg (Rn);
10983 reject_bad_reg (Rm);
10984
10985 inst.instruction |= Rd << 8;
10986 inst.instruction |= Rn << 16;
10987 inst.instruction |= Rm;
62b3e311
PB
10988}
10989
c19d1205
ZW
10990static void
10991do_t_hint (void)
10992{
10993 if (unified_syntax && inst.size_req == 4)
10994 inst.instruction = THUMB_OP32 (inst.instruction);
10995 else
10996 inst.instruction = THUMB_OP16 (inst.instruction);
10997}
90e4755a 10998
c19d1205
ZW
10999static void
11000do_t_it (void)
11001{
11002 unsigned int cond = inst.operands[0].imm;
e27ec89e 11003
e07e6e58
NC
11004 set_it_insn_type (IT_INSN);
11005 now_it.mask = (inst.instruction & 0xf) | 0x10;
11006 now_it.cc = cond;
5a01bb1d 11007 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11008
11009 /* If the condition is a negative condition, invert the mask. */
c19d1205 11010 if ((cond & 0x1) == 0x0)
90e4755a 11011 {
c19d1205 11012 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11013
c19d1205 11014 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11015 {
11016 /* No conversion needed. */
11017 now_it.block_length = 1;
11018 }
c19d1205 11019 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11020 {
11021 mask ^= 0x8;
11022 now_it.block_length = 2;
11023 }
e27ec89e 11024 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11025 {
11026 mask ^= 0xC;
11027 now_it.block_length = 3;
11028 }
c19d1205 11029 else
5a01bb1d
MGD
11030 {
11031 mask ^= 0xE;
11032 now_it.block_length = 4;
11033 }
90e4755a 11034
e27ec89e
PB
11035 inst.instruction &= 0xfff0;
11036 inst.instruction |= mask;
c19d1205 11037 }
90e4755a 11038
c19d1205
ZW
11039 inst.instruction |= cond << 4;
11040}
90e4755a 11041
3c707909
PB
11042/* Helper function used for both push/pop and ldm/stm. */
11043static void
11044encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11045{
11046 bfd_boolean load;
11047
11048 load = (inst.instruction & (1 << 20)) != 0;
11049
11050 if (mask & (1 << 13))
11051 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11052
11053 if ((mask & (1 << base)) != 0
11054 && writeback)
11055 inst.error = _("having the base register in the register list when "
11056 "using write back is UNPREDICTABLE");
11057
3c707909
PB
11058 if (load)
11059 {
e07e6e58 11060 if (mask & (1 << 15))
477330fc
RM
11061 {
11062 if (mask & (1 << 14))
11063 inst.error = _("LR and PC should not both be in register list");
11064 else
11065 set_it_insn_type_last ();
11066 }
3c707909
PB
11067 }
11068 else
11069 {
11070 if (mask & (1 << 15))
11071 inst.error = _("PC not allowed in register list");
3c707909
PB
11072 }
11073
11074 if ((mask & (mask - 1)) == 0)
11075 {
11076 /* Single register transfers implemented as str/ldr. */
11077 if (writeback)
11078 {
11079 if (inst.instruction & (1 << 23))
11080 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11081 else
11082 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11083 }
11084 else
11085 {
11086 if (inst.instruction & (1 << 23))
11087 inst.instruction = 0x00800000; /* ia -> [base] */
11088 else
11089 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11090 }
11091
11092 inst.instruction |= 0xf8400000;
11093 if (load)
11094 inst.instruction |= 0x00100000;
11095
5f4273c7 11096 mask = ffs (mask) - 1;
3c707909
PB
11097 mask <<= 12;
11098 }
11099 else if (writeback)
11100 inst.instruction |= WRITE_BACK;
11101
11102 inst.instruction |= mask;
11103 inst.instruction |= base << 16;
11104}
11105
c19d1205
ZW
11106static void
11107do_t_ldmstm (void)
11108{
11109 /* This really doesn't seem worth it. */
11110 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11111 _("expression too complex"));
11112 constraint (inst.operands[1].writeback,
11113 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11114
c19d1205
ZW
11115 if (unified_syntax)
11116 {
3c707909
PB
11117 bfd_boolean narrow;
11118 unsigned mask;
11119
11120 narrow = FALSE;
c19d1205
ZW
11121 /* See if we can use a 16-bit instruction. */
11122 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11123 && inst.size_req != 4
3c707909 11124 && !(inst.operands[1].imm & ~0xff))
90e4755a 11125 {
3c707909 11126 mask = 1 << inst.operands[0].reg;
90e4755a 11127
eab4f823 11128 if (inst.operands[0].reg <= 7)
90e4755a 11129 {
3c707909 11130 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11131 ? inst.operands[0].writeback
11132 : (inst.operands[0].writeback
11133 == !(inst.operands[1].imm & mask)))
477330fc 11134 {
eab4f823
MGD
11135 if (inst.instruction == T_MNEM_stmia
11136 && (inst.operands[1].imm & mask)
11137 && (inst.operands[1].imm & (mask - 1)))
11138 as_warn (_("value stored for r%d is UNKNOWN"),
11139 inst.operands[0].reg);
3c707909 11140
eab4f823
MGD
11141 inst.instruction = THUMB_OP16 (inst.instruction);
11142 inst.instruction |= inst.operands[0].reg << 8;
11143 inst.instruction |= inst.operands[1].imm;
11144 narrow = TRUE;
11145 }
11146 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11147 {
11148 /* This means 1 register in reg list one of 3 situations:
11149 1. Instruction is stmia, but without writeback.
11150 2. lmdia without writeback, but with Rn not in
477330fc 11151 reglist.
eab4f823
MGD
11152 3. ldmia with writeback, but with Rn in reglist.
11153 Case 3 is UNPREDICTABLE behaviour, so we handle
11154 case 1 and 2 which can be converted into a 16-bit
11155 str or ldr. The SP cases are handled below. */
11156 unsigned long opcode;
11157 /* First, record an error for Case 3. */
11158 if (inst.operands[1].imm & mask
11159 && inst.operands[0].writeback)
fa94de6b 11160 inst.error =
eab4f823
MGD
11161 _("having the base register in the register list when "
11162 "using write back is UNPREDICTABLE");
fa94de6b
RM
11163
11164 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11165 : T_MNEM_ldr);
11166 inst.instruction = THUMB_OP16 (opcode);
11167 inst.instruction |= inst.operands[0].reg << 3;
11168 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11169 narrow = TRUE;
11170 }
90e4755a 11171 }
eab4f823 11172 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11173 {
eab4f823
MGD
11174 if (inst.operands[0].writeback)
11175 {
fa94de6b 11176 inst.instruction =
eab4f823 11177 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11178 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11179 inst.instruction |= inst.operands[1].imm;
477330fc 11180 narrow = TRUE;
eab4f823
MGD
11181 }
11182 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11183 {
fa94de6b 11184 inst.instruction =
eab4f823 11185 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11186 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11187 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11188 narrow = TRUE;
eab4f823 11189 }
90e4755a 11190 }
3c707909
PB
11191 }
11192
11193 if (!narrow)
11194 {
c19d1205
ZW
11195 if (inst.instruction < 0xffff)
11196 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11197
5f4273c7
NC
11198 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11199 inst.operands[0].writeback);
90e4755a
RE
11200 }
11201 }
c19d1205 11202 else
90e4755a 11203 {
c19d1205
ZW
11204 constraint (inst.operands[0].reg > 7
11205 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11206 constraint (inst.instruction != T_MNEM_ldmia
11207 && inst.instruction != T_MNEM_stmia,
11208 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11209 if (inst.instruction == T_MNEM_stmia)
f03698e6 11210 {
c19d1205
ZW
11211 if (!inst.operands[0].writeback)
11212 as_warn (_("this instruction will write back the base register"));
11213 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11214 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11215 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11216 inst.operands[0].reg);
f03698e6 11217 }
c19d1205 11218 else
90e4755a 11219 {
c19d1205
ZW
11220 if (!inst.operands[0].writeback
11221 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11222 as_warn (_("this instruction will write back the base register"));
11223 else if (inst.operands[0].writeback
11224 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11225 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11226 }
11227
c19d1205
ZW
11228 inst.instruction = THUMB_OP16 (inst.instruction);
11229 inst.instruction |= inst.operands[0].reg << 8;
11230 inst.instruction |= inst.operands[1].imm;
11231 }
11232}
e28cd48c 11233
c19d1205
ZW
11234static void
11235do_t_ldrex (void)
11236{
11237 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11238 || inst.operands[1].postind || inst.operands[1].writeback
11239 || inst.operands[1].immisreg || inst.operands[1].shifted
11240 || inst.operands[1].negative,
01cfc07f 11241 BAD_ADDR_MODE);
e28cd48c 11242
5be8be5d
DG
11243 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11244
c19d1205
ZW
11245 inst.instruction |= inst.operands[0].reg << 12;
11246 inst.instruction |= inst.operands[1].reg << 16;
11247 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11248}
e28cd48c 11249
c19d1205
ZW
11250static void
11251do_t_ldrexd (void)
11252{
11253 if (!inst.operands[1].present)
1cac9012 11254 {
c19d1205
ZW
11255 constraint (inst.operands[0].reg == REG_LR,
11256 _("r14 not allowed as first register "
11257 "when second register is omitted"));
11258 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11259 }
c19d1205
ZW
11260 constraint (inst.operands[0].reg == inst.operands[1].reg,
11261 BAD_OVERLAP);
b99bd4ef 11262
c19d1205
ZW
11263 inst.instruction |= inst.operands[0].reg << 12;
11264 inst.instruction |= inst.operands[1].reg << 8;
11265 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11266}
11267
11268static void
c19d1205 11269do_t_ldst (void)
b99bd4ef 11270{
0110f2b8
PB
11271 unsigned long opcode;
11272 int Rn;
11273
e07e6e58
NC
11274 if (inst.operands[0].isreg
11275 && !inst.operands[0].preind
11276 && inst.operands[0].reg == REG_PC)
11277 set_it_insn_type_last ();
11278
0110f2b8 11279 opcode = inst.instruction;
c19d1205 11280 if (unified_syntax)
b99bd4ef 11281 {
53365c0d
PB
11282 if (!inst.operands[1].isreg)
11283 {
11284 if (opcode <= 0xffff)
11285 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11286 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11287 return;
11288 }
0110f2b8
PB
11289 if (inst.operands[1].isreg
11290 && !inst.operands[1].writeback
c19d1205
ZW
11291 && !inst.operands[1].shifted && !inst.operands[1].postind
11292 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11293 && opcode <= 0xffff
11294 && inst.size_req != 4)
c19d1205 11295 {
0110f2b8
PB
11296 /* Insn may have a 16-bit form. */
11297 Rn = inst.operands[1].reg;
11298 if (inst.operands[1].immisreg)
11299 {
11300 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11301 /* [Rn, Rik] */
0110f2b8
PB
11302 if (Rn <= 7 && inst.operands[1].imm <= 7)
11303 goto op16;
5be8be5d
DG
11304 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11305 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11306 }
11307 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11308 && opcode != T_MNEM_ldrsb)
11309 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11310 || (Rn == REG_SP && opcode == T_MNEM_str))
11311 {
11312 /* [Rn, #const] */
11313 if (Rn > 7)
11314 {
11315 if (Rn == REG_PC)
11316 {
11317 if (inst.reloc.pc_rel)
11318 opcode = T_MNEM_ldr_pc2;
11319 else
11320 opcode = T_MNEM_ldr_pc;
11321 }
11322 else
11323 {
11324 if (opcode == T_MNEM_ldr)
11325 opcode = T_MNEM_ldr_sp;
11326 else
11327 opcode = T_MNEM_str_sp;
11328 }
11329 inst.instruction = inst.operands[0].reg << 8;
11330 }
11331 else
11332 {
11333 inst.instruction = inst.operands[0].reg;
11334 inst.instruction |= inst.operands[1].reg << 3;
11335 }
11336 inst.instruction |= THUMB_OP16 (opcode);
11337 if (inst.size_req == 2)
11338 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11339 else
11340 inst.relax = opcode;
11341 return;
11342 }
c19d1205 11343 }
0110f2b8 11344 /* Definitely a 32-bit variant. */
5be8be5d 11345
8d67f500
NC
11346 /* Warning for Erratum 752419. */
11347 if (opcode == T_MNEM_ldr
11348 && inst.operands[0].reg == REG_SP
11349 && inst.operands[1].writeback == 1
11350 && !inst.operands[1].immisreg)
11351 {
11352 if (no_cpu_selected ()
11353 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11354 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11355 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11356 as_warn (_("This instruction may be unpredictable "
11357 "if executed on M-profile cores "
11358 "with interrupts enabled."));
11359 }
11360
5be8be5d 11361 /* Do some validations regarding addressing modes. */
1be5fd2e 11362 if (inst.operands[1].immisreg)
5be8be5d
DG
11363 reject_bad_reg (inst.operands[1].imm);
11364
1be5fd2e
NC
11365 constraint (inst.operands[1].writeback == 1
11366 && inst.operands[0].reg == inst.operands[1].reg,
11367 BAD_OVERLAP);
11368
0110f2b8 11369 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11370 inst.instruction |= inst.operands[0].reg << 12;
11371 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11372 check_ldr_r15_aligned ();
b99bd4ef
NC
11373 return;
11374 }
11375
c19d1205
ZW
11376 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11377
11378 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11379 {
c19d1205
ZW
11380 /* Only [Rn,Rm] is acceptable. */
11381 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11382 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11383 || inst.operands[1].postind || inst.operands[1].shifted
11384 || inst.operands[1].negative,
11385 _("Thumb does not support this addressing mode"));
11386 inst.instruction = THUMB_OP16 (inst.instruction);
11387 goto op16;
b99bd4ef 11388 }
5f4273c7 11389
c19d1205
ZW
11390 inst.instruction = THUMB_OP16 (inst.instruction);
11391 if (!inst.operands[1].isreg)
8335d6aa 11392 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11393 return;
b99bd4ef 11394
c19d1205
ZW
11395 constraint (!inst.operands[1].preind
11396 || inst.operands[1].shifted
11397 || inst.operands[1].writeback,
11398 _("Thumb does not support this addressing mode"));
11399 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11400 {
c19d1205
ZW
11401 constraint (inst.instruction & 0x0600,
11402 _("byte or halfword not valid for base register"));
11403 constraint (inst.operands[1].reg == REG_PC
11404 && !(inst.instruction & THUMB_LOAD_BIT),
11405 _("r15 based store not allowed"));
11406 constraint (inst.operands[1].immisreg,
11407 _("invalid base register for register offset"));
b99bd4ef 11408
c19d1205
ZW
11409 if (inst.operands[1].reg == REG_PC)
11410 inst.instruction = T_OPCODE_LDR_PC;
11411 else if (inst.instruction & THUMB_LOAD_BIT)
11412 inst.instruction = T_OPCODE_LDR_SP;
11413 else
11414 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11415
c19d1205
ZW
11416 inst.instruction |= inst.operands[0].reg << 8;
11417 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11418 return;
11419 }
90e4755a 11420
c19d1205
ZW
11421 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11422 if (!inst.operands[1].immisreg)
11423 {
11424 /* Immediate offset. */
11425 inst.instruction |= inst.operands[0].reg;
11426 inst.instruction |= inst.operands[1].reg << 3;
11427 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11428 return;
11429 }
90e4755a 11430
c19d1205
ZW
11431 /* Register offset. */
11432 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11433 constraint (inst.operands[1].negative,
11434 _("Thumb does not support this addressing mode"));
90e4755a 11435
c19d1205
ZW
11436 op16:
11437 switch (inst.instruction)
11438 {
11439 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11440 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11441 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11442 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11443 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11444 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11445 case 0x5600 /* ldrsb */:
11446 case 0x5e00 /* ldrsh */: break;
11447 default: abort ();
11448 }
90e4755a 11449
c19d1205
ZW
11450 inst.instruction |= inst.operands[0].reg;
11451 inst.instruction |= inst.operands[1].reg << 3;
11452 inst.instruction |= inst.operands[1].imm << 6;
11453}
90e4755a 11454
c19d1205
ZW
11455static void
11456do_t_ldstd (void)
11457{
11458 if (!inst.operands[1].present)
b99bd4ef 11459 {
c19d1205
ZW
11460 inst.operands[1].reg = inst.operands[0].reg + 1;
11461 constraint (inst.operands[0].reg == REG_LR,
11462 _("r14 not allowed here"));
bd340a04 11463 constraint (inst.operands[0].reg == REG_R12,
477330fc 11464 _("r12 not allowed here"));
b99bd4ef 11465 }
bd340a04
MGD
11466
11467 if (inst.operands[2].writeback
11468 && (inst.operands[0].reg == inst.operands[2].reg
11469 || inst.operands[1].reg == inst.operands[2].reg))
11470 as_warn (_("base register written back, and overlaps "
477330fc 11471 "one of transfer registers"));
bd340a04 11472
c19d1205
ZW
11473 inst.instruction |= inst.operands[0].reg << 12;
11474 inst.instruction |= inst.operands[1].reg << 8;
11475 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11476}
11477
c19d1205
ZW
11478static void
11479do_t_ldstt (void)
11480{
11481 inst.instruction |= inst.operands[0].reg << 12;
11482 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11483}
a737bd4d 11484
b99bd4ef 11485static void
c19d1205 11486do_t_mla (void)
b99bd4ef 11487{
fdfde340 11488 unsigned Rd, Rn, Rm, Ra;
c921be7d 11489
fdfde340
JM
11490 Rd = inst.operands[0].reg;
11491 Rn = inst.operands[1].reg;
11492 Rm = inst.operands[2].reg;
11493 Ra = inst.operands[3].reg;
11494
11495 reject_bad_reg (Rd);
11496 reject_bad_reg (Rn);
11497 reject_bad_reg (Rm);
11498 reject_bad_reg (Ra);
11499
11500 inst.instruction |= Rd << 8;
11501 inst.instruction |= Rn << 16;
11502 inst.instruction |= Rm;
11503 inst.instruction |= Ra << 12;
c19d1205 11504}
b99bd4ef 11505
c19d1205
ZW
11506static void
11507do_t_mlal (void)
11508{
fdfde340
JM
11509 unsigned RdLo, RdHi, Rn, Rm;
11510
11511 RdLo = inst.operands[0].reg;
11512 RdHi = inst.operands[1].reg;
11513 Rn = inst.operands[2].reg;
11514 Rm = inst.operands[3].reg;
11515
11516 reject_bad_reg (RdLo);
11517 reject_bad_reg (RdHi);
11518 reject_bad_reg (Rn);
11519 reject_bad_reg (Rm);
11520
11521 inst.instruction |= RdLo << 12;
11522 inst.instruction |= RdHi << 8;
11523 inst.instruction |= Rn << 16;
11524 inst.instruction |= Rm;
c19d1205 11525}
b99bd4ef 11526
c19d1205
ZW
11527static void
11528do_t_mov_cmp (void)
11529{
fdfde340
JM
11530 unsigned Rn, Rm;
11531
11532 Rn = inst.operands[0].reg;
11533 Rm = inst.operands[1].reg;
11534
e07e6e58
NC
11535 if (Rn == REG_PC)
11536 set_it_insn_type_last ();
11537
c19d1205 11538 if (unified_syntax)
b99bd4ef 11539 {
c19d1205
ZW
11540 int r0off = (inst.instruction == T_MNEM_mov
11541 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11542 unsigned long opcode;
3d388997
PB
11543 bfd_boolean narrow;
11544 bfd_boolean low_regs;
11545
fdfde340 11546 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11547 opcode = inst.instruction;
e07e6e58 11548 if (in_it_block ())
0110f2b8 11549 narrow = opcode != T_MNEM_movs;
3d388997 11550 else
0110f2b8 11551 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11552 if (inst.size_req == 4
11553 || inst.operands[1].shifted)
11554 narrow = FALSE;
11555
efd81785
PB
11556 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11557 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11558 && !inst.operands[1].shifted
fdfde340
JM
11559 && Rn == REG_PC
11560 && Rm == REG_LR)
efd81785
PB
11561 {
11562 inst.instruction = T2_SUBS_PC_LR;
11563 return;
11564 }
11565
fdfde340
JM
11566 if (opcode == T_MNEM_cmp)
11567 {
11568 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11569 if (narrow)
11570 {
11571 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11572 but valid. */
11573 warn_deprecated_sp (Rm);
11574 /* R15 was documented as a valid choice for Rm in ARMv6,
11575 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11576 tools reject R15, so we do too. */
11577 constraint (Rm == REG_PC, BAD_PC);
11578 }
11579 else
11580 reject_bad_reg (Rm);
fdfde340
JM
11581 }
11582 else if (opcode == T_MNEM_mov
11583 || opcode == T_MNEM_movs)
11584 {
11585 if (inst.operands[1].isreg)
11586 {
11587 if (opcode == T_MNEM_movs)
11588 {
11589 reject_bad_reg (Rn);
11590 reject_bad_reg (Rm);
11591 }
76fa04a4
MGD
11592 else if (narrow)
11593 {
11594 /* This is mov.n. */
11595 if ((Rn == REG_SP || Rn == REG_PC)
11596 && (Rm == REG_SP || Rm == REG_PC))
11597 {
5c3696f8 11598 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
11599 "deprecated when r%u is the destination "
11600 "register."), Rm, Rn);
11601 }
11602 }
11603 else
11604 {
11605 /* This is mov.w. */
11606 constraint (Rn == REG_PC, BAD_PC);
11607 constraint (Rm == REG_PC, BAD_PC);
11608 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
11609 }
fdfde340
JM
11610 }
11611 else
11612 reject_bad_reg (Rn);
11613 }
11614
c19d1205
ZW
11615 if (!inst.operands[1].isreg)
11616 {
0110f2b8 11617 /* Immediate operand. */
e07e6e58 11618 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
11619 narrow = 0;
11620 if (low_regs && narrow)
11621 {
11622 inst.instruction = THUMB_OP16 (opcode);
fdfde340 11623 inst.instruction |= Rn << 8;
0110f2b8
PB
11624 if (inst.size_req == 2)
11625 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11626 else
11627 inst.relax = opcode;
11628 }
11629 else
11630 {
11631 inst.instruction = THUMB_OP32 (inst.instruction);
11632 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11633 inst.instruction |= Rn << r0off;
0110f2b8
PB
11634 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11635 }
c19d1205 11636 }
728ca7c9
PB
11637 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11638 && (inst.instruction == T_MNEM_mov
11639 || inst.instruction == T_MNEM_movs))
11640 {
11641 /* Register shifts are encoded as separate shift instructions. */
11642 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11643
e07e6e58 11644 if (in_it_block ())
728ca7c9
PB
11645 narrow = !flags;
11646 else
11647 narrow = flags;
11648
11649 if (inst.size_req == 4)
11650 narrow = FALSE;
11651
11652 if (!low_regs || inst.operands[1].imm > 7)
11653 narrow = FALSE;
11654
fdfde340 11655 if (Rn != Rm)
728ca7c9
PB
11656 narrow = FALSE;
11657
11658 switch (inst.operands[1].shift_kind)
11659 {
11660 case SHIFT_LSL:
11661 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
11662 break;
11663 case SHIFT_ASR:
11664 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
11665 break;
11666 case SHIFT_LSR:
11667 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
11668 break;
11669 case SHIFT_ROR:
11670 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
11671 break;
11672 default:
5f4273c7 11673 abort ();
728ca7c9
PB
11674 }
11675
11676 inst.instruction = opcode;
11677 if (narrow)
11678 {
fdfde340 11679 inst.instruction |= Rn;
728ca7c9
PB
11680 inst.instruction |= inst.operands[1].imm << 3;
11681 }
11682 else
11683 {
11684 if (flags)
11685 inst.instruction |= CONDS_BIT;
11686
fdfde340
JM
11687 inst.instruction |= Rn << 8;
11688 inst.instruction |= Rm << 16;
728ca7c9
PB
11689 inst.instruction |= inst.operands[1].imm;
11690 }
11691 }
3d388997 11692 else if (!narrow)
c19d1205 11693 {
728ca7c9
PB
11694 /* Some mov with immediate shift have narrow variants.
11695 Register shifts are handled above. */
11696 if (low_regs && inst.operands[1].shifted
11697 && (inst.instruction == T_MNEM_mov
11698 || inst.instruction == T_MNEM_movs))
11699 {
e07e6e58 11700 if (in_it_block ())
728ca7c9
PB
11701 narrow = (inst.instruction == T_MNEM_mov);
11702 else
11703 narrow = (inst.instruction == T_MNEM_movs);
11704 }
11705
11706 if (narrow)
11707 {
11708 switch (inst.operands[1].shift_kind)
11709 {
11710 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11711 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11712 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11713 default: narrow = FALSE; break;
11714 }
11715 }
11716
11717 if (narrow)
11718 {
fdfde340
JM
11719 inst.instruction |= Rn;
11720 inst.instruction |= Rm << 3;
728ca7c9
PB
11721 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11722 }
11723 else
11724 {
11725 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11726 inst.instruction |= Rn << r0off;
728ca7c9
PB
11727 encode_thumb32_shifted_operand (1);
11728 }
c19d1205
ZW
11729 }
11730 else
11731 switch (inst.instruction)
11732 {
11733 case T_MNEM_mov:
837b3435 11734 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
11735 results. Don't allow this. */
11736 if (low_regs)
11737 {
11738 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
11739 "MOV Rd, Rs with two low registers is not "
11740 "permitted on this architecture");
fa94de6b 11741 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
11742 arm_ext_v6);
11743 }
11744
c19d1205 11745 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
11746 inst.instruction |= (Rn & 0x8) << 4;
11747 inst.instruction |= (Rn & 0x7);
11748 inst.instruction |= Rm << 3;
c19d1205 11749 break;
b99bd4ef 11750
c19d1205
ZW
11751 case T_MNEM_movs:
11752 /* We know we have low registers at this point.
941a8a52
MGD
11753 Generate LSLS Rd, Rs, #0. */
11754 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
11755 inst.instruction |= Rn;
11756 inst.instruction |= Rm << 3;
c19d1205
ZW
11757 break;
11758
11759 case T_MNEM_cmp:
3d388997 11760 if (low_regs)
c19d1205
ZW
11761 {
11762 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
11763 inst.instruction |= Rn;
11764 inst.instruction |= Rm << 3;
c19d1205
ZW
11765 }
11766 else
11767 {
11768 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
11769 inst.instruction |= (Rn & 0x8) << 4;
11770 inst.instruction |= (Rn & 0x7);
11771 inst.instruction |= Rm << 3;
c19d1205
ZW
11772 }
11773 break;
11774 }
b99bd4ef
NC
11775 return;
11776 }
11777
c19d1205 11778 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
11779
11780 /* PR 10443: Do not silently ignore shifted operands. */
11781 constraint (inst.operands[1].shifted,
11782 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
11783
c19d1205 11784 if (inst.operands[1].isreg)
b99bd4ef 11785 {
fdfde340 11786 if (Rn < 8 && Rm < 8)
b99bd4ef 11787 {
c19d1205
ZW
11788 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
11789 since a MOV instruction produces unpredictable results. */
11790 if (inst.instruction == T_OPCODE_MOV_I8)
11791 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 11792 else
c19d1205 11793 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 11794
fdfde340
JM
11795 inst.instruction |= Rn;
11796 inst.instruction |= Rm << 3;
b99bd4ef
NC
11797 }
11798 else
11799 {
c19d1205
ZW
11800 if (inst.instruction == T_OPCODE_MOV_I8)
11801 inst.instruction = T_OPCODE_MOV_HR;
11802 else
11803 inst.instruction = T_OPCODE_CMP_HR;
11804 do_t_cpy ();
b99bd4ef
NC
11805 }
11806 }
c19d1205 11807 else
b99bd4ef 11808 {
fdfde340 11809 constraint (Rn > 7,
c19d1205 11810 _("only lo regs allowed with immediate"));
fdfde340 11811 inst.instruction |= Rn << 8;
c19d1205
ZW
11812 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11813 }
11814}
b99bd4ef 11815
c19d1205
ZW
11816static void
11817do_t_mov16 (void)
11818{
fdfde340 11819 unsigned Rd;
b6895b4f
PB
11820 bfd_vma imm;
11821 bfd_boolean top;
11822
11823 top = (inst.instruction & 0x00800000) != 0;
11824 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
11825 {
11826 constraint (top, _(":lower16: not allowed this instruction"));
11827 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
11828 }
11829 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
11830 {
11831 constraint (!top, _(":upper16: not allowed this instruction"));
11832 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
11833 }
11834
fdfde340
JM
11835 Rd = inst.operands[0].reg;
11836 reject_bad_reg (Rd);
11837
11838 inst.instruction |= Rd << 8;
b6895b4f
PB
11839 if (inst.reloc.type == BFD_RELOC_UNUSED)
11840 {
11841 imm = inst.reloc.exp.X_add_number;
11842 inst.instruction |= (imm & 0xf000) << 4;
11843 inst.instruction |= (imm & 0x0800) << 15;
11844 inst.instruction |= (imm & 0x0700) << 4;
11845 inst.instruction |= (imm & 0x00ff);
11846 }
c19d1205 11847}
b99bd4ef 11848
c19d1205
ZW
11849static void
11850do_t_mvn_tst (void)
11851{
fdfde340 11852 unsigned Rn, Rm;
c921be7d 11853
fdfde340
JM
11854 Rn = inst.operands[0].reg;
11855 Rm = inst.operands[1].reg;
11856
11857 if (inst.instruction == T_MNEM_cmp
11858 || inst.instruction == T_MNEM_cmn)
11859 constraint (Rn == REG_PC, BAD_PC);
11860 else
11861 reject_bad_reg (Rn);
11862 reject_bad_reg (Rm);
11863
c19d1205
ZW
11864 if (unified_syntax)
11865 {
11866 int r0off = (inst.instruction == T_MNEM_mvn
11867 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
11868 bfd_boolean narrow;
11869
11870 if (inst.size_req == 4
11871 || inst.instruction > 0xffff
11872 || inst.operands[1].shifted
fdfde340 11873 || Rn > 7 || Rm > 7)
3d388997 11874 narrow = FALSE;
fe8b4cc3
KT
11875 else if (inst.instruction == T_MNEM_cmn
11876 || inst.instruction == T_MNEM_tst)
3d388997
PB
11877 narrow = TRUE;
11878 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11879 narrow = !in_it_block ();
3d388997 11880 else
e07e6e58 11881 narrow = in_it_block ();
3d388997 11882
c19d1205 11883 if (!inst.operands[1].isreg)
b99bd4ef 11884 {
c19d1205
ZW
11885 /* For an immediate, we always generate a 32-bit opcode;
11886 section relaxation will shrink it later if possible. */
11887 if (inst.instruction < 0xffff)
11888 inst.instruction = THUMB_OP32 (inst.instruction);
11889 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11890 inst.instruction |= Rn << r0off;
c19d1205 11891 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 11892 }
c19d1205 11893 else
b99bd4ef 11894 {
c19d1205 11895 /* See if we can do this with a 16-bit instruction. */
3d388997 11896 if (narrow)
b99bd4ef 11897 {
c19d1205 11898 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11899 inst.instruction |= Rn;
11900 inst.instruction |= Rm << 3;
b99bd4ef 11901 }
c19d1205 11902 else
b99bd4ef 11903 {
c19d1205
ZW
11904 constraint (inst.operands[1].shifted
11905 && inst.operands[1].immisreg,
11906 _("shift must be constant"));
11907 if (inst.instruction < 0xffff)
11908 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11909 inst.instruction |= Rn << r0off;
c19d1205 11910 encode_thumb32_shifted_operand (1);
b99bd4ef 11911 }
b99bd4ef
NC
11912 }
11913 }
11914 else
11915 {
c19d1205
ZW
11916 constraint (inst.instruction > 0xffff
11917 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
11918 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
11919 _("unshifted register required"));
fdfde340 11920 constraint (Rn > 7 || Rm > 7,
c19d1205 11921 BAD_HIREG);
b99bd4ef 11922
c19d1205 11923 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11924 inst.instruction |= Rn;
11925 inst.instruction |= Rm << 3;
b99bd4ef 11926 }
b99bd4ef
NC
11927}
11928
b05fe5cf 11929static void
c19d1205 11930do_t_mrs (void)
b05fe5cf 11931{
fdfde340 11932 unsigned Rd;
037e8744
JB
11933
11934 if (do_vfp_nsyn_mrs () == SUCCESS)
11935 return;
11936
90ec0d68
MGD
11937 Rd = inst.operands[0].reg;
11938 reject_bad_reg (Rd);
11939 inst.instruction |= Rd << 8;
11940
11941 if (inst.operands[1].isreg)
62b3e311 11942 {
90ec0d68
MGD
11943 unsigned br = inst.operands[1].reg;
11944 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
11945 as_bad (_("bad register for mrs"));
11946
11947 inst.instruction |= br & (0xf << 16);
11948 inst.instruction |= (br & 0x300) >> 4;
11949 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
11950 }
11951 else
11952 {
90ec0d68 11953 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 11954
d2cd1205 11955 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
11956 {
11957 /* PR gas/12698: The constraint is only applied for m_profile.
11958 If the user has specified -march=all, we want to ignore it as
11959 we are building for any CPU type, including non-m variants. */
823d2571
TG
11960 bfd_boolean m_profile =
11961 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
11962 constraint ((flags != 0) && m_profile, _("selected processor does "
11963 "not support requested special purpose register"));
11964 }
90ec0d68 11965 else
d2cd1205
JB
11966 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
11967 devices). */
11968 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
11969 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 11970
90ec0d68
MGD
11971 inst.instruction |= (flags & SPSR_BIT) >> 2;
11972 inst.instruction |= inst.operands[1].imm & 0xff;
11973 inst.instruction |= 0xf0000;
11974 }
c19d1205 11975}
b05fe5cf 11976
c19d1205
ZW
11977static void
11978do_t_msr (void)
11979{
62b3e311 11980 int flags;
fdfde340 11981 unsigned Rn;
62b3e311 11982
037e8744
JB
11983 if (do_vfp_nsyn_msr () == SUCCESS)
11984 return;
11985
c19d1205
ZW
11986 constraint (!inst.operands[1].isreg,
11987 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
11988
11989 if (inst.operands[0].isreg)
11990 flags = (int)(inst.operands[0].reg);
11991 else
11992 flags = inst.operands[0].imm;
11993
d2cd1205 11994 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 11995 {
d2cd1205
JB
11996 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
11997
1a43faaf 11998 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
11999 If the user has specified -march=all, we want to ignore it as
12000 we are building for any CPU type, including non-m variants. */
823d2571
TG
12001 bfd_boolean m_profile =
12002 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12003 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12004 && (bits & ~(PSR_s | PSR_f)) != 0)
12005 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12006 && bits != PSR_f)) && m_profile,
12007 _("selected processor does not support requested special "
12008 "purpose register"));
62b3e311
PB
12009 }
12010 else
d2cd1205
JB
12011 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12012 "requested special purpose register"));
c921be7d 12013
fdfde340
JM
12014 Rn = inst.operands[1].reg;
12015 reject_bad_reg (Rn);
12016
62b3e311 12017 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12018 inst.instruction |= (flags & 0xf0000) >> 8;
12019 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12020 inst.instruction |= (flags & 0xff);
fdfde340 12021 inst.instruction |= Rn << 16;
c19d1205 12022}
b05fe5cf 12023
c19d1205
ZW
12024static void
12025do_t_mul (void)
12026{
17828f45 12027 bfd_boolean narrow;
fdfde340 12028 unsigned Rd, Rn, Rm;
17828f45 12029
c19d1205
ZW
12030 if (!inst.operands[2].present)
12031 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12032
fdfde340
JM
12033 Rd = inst.operands[0].reg;
12034 Rn = inst.operands[1].reg;
12035 Rm = inst.operands[2].reg;
12036
17828f45 12037 if (unified_syntax)
b05fe5cf 12038 {
17828f45 12039 if (inst.size_req == 4
fdfde340
JM
12040 || (Rd != Rn
12041 && Rd != Rm)
12042 || Rn > 7
12043 || Rm > 7)
17828f45
JM
12044 narrow = FALSE;
12045 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12046 narrow = !in_it_block ();
17828f45 12047 else
e07e6e58 12048 narrow = in_it_block ();
b05fe5cf 12049 }
c19d1205 12050 else
b05fe5cf 12051 {
17828f45 12052 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12053 constraint (Rn > 7 || Rm > 7,
c19d1205 12054 BAD_HIREG);
17828f45
JM
12055 narrow = TRUE;
12056 }
b05fe5cf 12057
17828f45
JM
12058 if (narrow)
12059 {
12060 /* 16-bit MULS/Conditional MUL. */
c19d1205 12061 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12062 inst.instruction |= Rd;
b05fe5cf 12063
fdfde340
JM
12064 if (Rd == Rn)
12065 inst.instruction |= Rm << 3;
12066 else if (Rd == Rm)
12067 inst.instruction |= Rn << 3;
c19d1205
ZW
12068 else
12069 constraint (1, _("dest must overlap one source register"));
12070 }
17828f45
JM
12071 else
12072 {
e07e6e58
NC
12073 constraint (inst.instruction != T_MNEM_mul,
12074 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12075 /* 32-bit MUL. */
12076 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12077 inst.instruction |= Rd << 8;
12078 inst.instruction |= Rn << 16;
12079 inst.instruction |= Rm << 0;
12080
12081 reject_bad_reg (Rd);
12082 reject_bad_reg (Rn);
12083 reject_bad_reg (Rm);
17828f45 12084 }
c19d1205 12085}
b05fe5cf 12086
c19d1205
ZW
12087static void
12088do_t_mull (void)
12089{
fdfde340 12090 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12091
fdfde340
JM
12092 RdLo = inst.operands[0].reg;
12093 RdHi = inst.operands[1].reg;
12094 Rn = inst.operands[2].reg;
12095 Rm = inst.operands[3].reg;
12096
12097 reject_bad_reg (RdLo);
12098 reject_bad_reg (RdHi);
12099 reject_bad_reg (Rn);
12100 reject_bad_reg (Rm);
12101
12102 inst.instruction |= RdLo << 12;
12103 inst.instruction |= RdHi << 8;
12104 inst.instruction |= Rn << 16;
12105 inst.instruction |= Rm;
12106
12107 if (RdLo == RdHi)
c19d1205
ZW
12108 as_tsktsk (_("rdhi and rdlo must be different"));
12109}
b05fe5cf 12110
c19d1205
ZW
12111static void
12112do_t_nop (void)
12113{
e07e6e58
NC
12114 set_it_insn_type (NEUTRAL_IT_INSN);
12115
c19d1205
ZW
12116 if (unified_syntax)
12117 {
12118 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12119 {
c19d1205
ZW
12120 inst.instruction = THUMB_OP32 (inst.instruction);
12121 inst.instruction |= inst.operands[0].imm;
12122 }
12123 else
12124 {
bc2d1808
NC
12125 /* PR9722: Check for Thumb2 availability before
12126 generating a thumb2 nop instruction. */
afa62d5e 12127 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12128 {
12129 inst.instruction = THUMB_OP16 (inst.instruction);
12130 inst.instruction |= inst.operands[0].imm << 4;
12131 }
12132 else
12133 inst.instruction = 0x46c0;
c19d1205
ZW
12134 }
12135 }
12136 else
12137 {
12138 constraint (inst.operands[0].present,
12139 _("Thumb does not support NOP with hints"));
12140 inst.instruction = 0x46c0;
12141 }
12142}
b05fe5cf 12143
c19d1205
ZW
12144static void
12145do_t_neg (void)
12146{
12147 if (unified_syntax)
12148 {
3d388997
PB
12149 bfd_boolean narrow;
12150
12151 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12152 narrow = !in_it_block ();
3d388997 12153 else
e07e6e58 12154 narrow = in_it_block ();
3d388997
PB
12155 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12156 narrow = FALSE;
12157 if (inst.size_req == 4)
12158 narrow = FALSE;
12159
12160 if (!narrow)
c19d1205
ZW
12161 {
12162 inst.instruction = THUMB_OP32 (inst.instruction);
12163 inst.instruction |= inst.operands[0].reg << 8;
12164 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12165 }
12166 else
12167 {
c19d1205
ZW
12168 inst.instruction = THUMB_OP16 (inst.instruction);
12169 inst.instruction |= inst.operands[0].reg;
12170 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12171 }
12172 }
12173 else
12174 {
c19d1205
ZW
12175 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12176 BAD_HIREG);
12177 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12178
12179 inst.instruction = THUMB_OP16 (inst.instruction);
12180 inst.instruction |= inst.operands[0].reg;
12181 inst.instruction |= inst.operands[1].reg << 3;
12182 }
12183}
12184
1c444d06
JM
12185static void
12186do_t_orn (void)
12187{
12188 unsigned Rd, Rn;
12189
12190 Rd = inst.operands[0].reg;
12191 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12192
fdfde340
JM
12193 reject_bad_reg (Rd);
12194 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12195 reject_bad_reg (Rn);
12196
1c444d06
JM
12197 inst.instruction |= Rd << 8;
12198 inst.instruction |= Rn << 16;
12199
12200 if (!inst.operands[2].isreg)
12201 {
12202 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12203 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12204 }
12205 else
12206 {
12207 unsigned Rm;
12208
12209 Rm = inst.operands[2].reg;
fdfde340 12210 reject_bad_reg (Rm);
1c444d06
JM
12211
12212 constraint (inst.operands[2].shifted
12213 && inst.operands[2].immisreg,
12214 _("shift must be constant"));
12215 encode_thumb32_shifted_operand (2);
12216 }
12217}
12218
c19d1205
ZW
12219static void
12220do_t_pkhbt (void)
12221{
fdfde340
JM
12222 unsigned Rd, Rn, Rm;
12223
12224 Rd = inst.operands[0].reg;
12225 Rn = inst.operands[1].reg;
12226 Rm = inst.operands[2].reg;
12227
12228 reject_bad_reg (Rd);
12229 reject_bad_reg (Rn);
12230 reject_bad_reg (Rm);
12231
12232 inst.instruction |= Rd << 8;
12233 inst.instruction |= Rn << 16;
12234 inst.instruction |= Rm;
c19d1205
ZW
12235 if (inst.operands[3].present)
12236 {
12237 unsigned int val = inst.reloc.exp.X_add_number;
12238 constraint (inst.reloc.exp.X_op != O_constant,
12239 _("expression too complex"));
12240 inst.instruction |= (val & 0x1c) << 10;
12241 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12242 }
c19d1205 12243}
b05fe5cf 12244
c19d1205
ZW
12245static void
12246do_t_pkhtb (void)
12247{
12248 if (!inst.operands[3].present)
1ef52f49
NC
12249 {
12250 unsigned Rtmp;
12251
12252 inst.instruction &= ~0x00000020;
12253
12254 /* PR 10168. Swap the Rm and Rn registers. */
12255 Rtmp = inst.operands[1].reg;
12256 inst.operands[1].reg = inst.operands[2].reg;
12257 inst.operands[2].reg = Rtmp;
12258 }
c19d1205 12259 do_t_pkhbt ();
b05fe5cf
ZW
12260}
12261
c19d1205
ZW
12262static void
12263do_t_pld (void)
12264{
fdfde340
JM
12265 if (inst.operands[0].immisreg)
12266 reject_bad_reg (inst.operands[0].imm);
12267
c19d1205
ZW
12268 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12269}
b05fe5cf 12270
c19d1205
ZW
12271static void
12272do_t_push_pop (void)
b99bd4ef 12273{
e9f89963 12274 unsigned mask;
5f4273c7 12275
c19d1205
ZW
12276 constraint (inst.operands[0].writeback,
12277 _("push/pop do not support {reglist}^"));
12278 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12279 _("expression too complex"));
b99bd4ef 12280
e9f89963 12281 mask = inst.operands[0].imm;
d3bfe16e 12282 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12283 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e
JB
12284 else if (inst.size_req != 4
12285 && (mask & ~0xff) == (1 << (inst.instruction == T_MNEM_push
12286 ? REG_LR : REG_PC)))
b99bd4ef 12287 {
c19d1205
ZW
12288 inst.instruction = THUMB_OP16 (inst.instruction);
12289 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12290 inst.instruction |= mask & 0xff;
c19d1205
ZW
12291 }
12292 else if (unified_syntax)
12293 {
3c707909 12294 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12295 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12296 }
12297 else
12298 {
12299 inst.error = _("invalid register list to push/pop instruction");
12300 return;
12301 }
c19d1205 12302}
b99bd4ef 12303
c19d1205
ZW
12304static void
12305do_t_rbit (void)
12306{
fdfde340
JM
12307 unsigned Rd, Rm;
12308
12309 Rd = inst.operands[0].reg;
12310 Rm = inst.operands[1].reg;
12311
12312 reject_bad_reg (Rd);
12313 reject_bad_reg (Rm);
12314
12315 inst.instruction |= Rd << 8;
12316 inst.instruction |= Rm << 16;
12317 inst.instruction |= Rm;
c19d1205 12318}
b99bd4ef 12319
c19d1205
ZW
12320static void
12321do_t_rev (void)
12322{
fdfde340
JM
12323 unsigned Rd, Rm;
12324
12325 Rd = inst.operands[0].reg;
12326 Rm = inst.operands[1].reg;
12327
12328 reject_bad_reg (Rd);
12329 reject_bad_reg (Rm);
12330
12331 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12332 && inst.size_req != 4)
12333 {
12334 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12335 inst.instruction |= Rd;
12336 inst.instruction |= Rm << 3;
c19d1205
ZW
12337 }
12338 else if (unified_syntax)
12339 {
12340 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12341 inst.instruction |= Rd << 8;
12342 inst.instruction |= Rm << 16;
12343 inst.instruction |= Rm;
c19d1205
ZW
12344 }
12345 else
12346 inst.error = BAD_HIREG;
12347}
b99bd4ef 12348
1c444d06
JM
12349static void
12350do_t_rrx (void)
12351{
12352 unsigned Rd, Rm;
12353
12354 Rd = inst.operands[0].reg;
12355 Rm = inst.operands[1].reg;
12356
fdfde340
JM
12357 reject_bad_reg (Rd);
12358 reject_bad_reg (Rm);
c921be7d 12359
1c444d06
JM
12360 inst.instruction |= Rd << 8;
12361 inst.instruction |= Rm;
12362}
12363
c19d1205
ZW
12364static void
12365do_t_rsb (void)
12366{
fdfde340 12367 unsigned Rd, Rs;
b99bd4ef 12368
c19d1205
ZW
12369 Rd = inst.operands[0].reg;
12370 Rs = (inst.operands[1].present
12371 ? inst.operands[1].reg /* Rd, Rs, foo */
12372 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12373
fdfde340
JM
12374 reject_bad_reg (Rd);
12375 reject_bad_reg (Rs);
12376 if (inst.operands[2].isreg)
12377 reject_bad_reg (inst.operands[2].reg);
12378
c19d1205
ZW
12379 inst.instruction |= Rd << 8;
12380 inst.instruction |= Rs << 16;
12381 if (!inst.operands[2].isreg)
12382 {
026d3abb
PB
12383 bfd_boolean narrow;
12384
12385 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12386 narrow = !in_it_block ();
026d3abb 12387 else
e07e6e58 12388 narrow = in_it_block ();
026d3abb
PB
12389
12390 if (Rd > 7 || Rs > 7)
12391 narrow = FALSE;
12392
12393 if (inst.size_req == 4 || !unified_syntax)
12394 narrow = FALSE;
12395
12396 if (inst.reloc.exp.X_op != O_constant
12397 || inst.reloc.exp.X_add_number != 0)
12398 narrow = FALSE;
12399
12400 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12401 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12402 if (narrow)
12403 {
12404 inst.reloc.type = BFD_RELOC_UNUSED;
12405 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12406 inst.instruction |= Rs << 3;
12407 inst.instruction |= Rd;
12408 }
12409 else
12410 {
12411 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12412 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12413 }
c19d1205
ZW
12414 }
12415 else
12416 encode_thumb32_shifted_operand (2);
12417}
b99bd4ef 12418
c19d1205
ZW
12419static void
12420do_t_setend (void)
12421{
12e37cbc
MGD
12422 if (warn_on_deprecated
12423 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12424 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12425
e07e6e58 12426 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12427 if (inst.operands[0].imm)
12428 inst.instruction |= 0x8;
12429}
b99bd4ef 12430
c19d1205
ZW
12431static void
12432do_t_shift (void)
12433{
12434 if (!inst.operands[1].present)
12435 inst.operands[1].reg = inst.operands[0].reg;
12436
12437 if (unified_syntax)
12438 {
3d388997
PB
12439 bfd_boolean narrow;
12440 int shift_kind;
12441
12442 switch (inst.instruction)
12443 {
12444 case T_MNEM_asr:
12445 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12446 case T_MNEM_lsl:
12447 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12448 case T_MNEM_lsr:
12449 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12450 case T_MNEM_ror:
12451 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12452 default: abort ();
12453 }
12454
12455 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12456 narrow = !in_it_block ();
3d388997 12457 else
e07e6e58 12458 narrow = in_it_block ();
3d388997
PB
12459 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12460 narrow = FALSE;
12461 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12462 narrow = FALSE;
12463 if (inst.operands[2].isreg
12464 && (inst.operands[1].reg != inst.operands[0].reg
12465 || inst.operands[2].reg > 7))
12466 narrow = FALSE;
12467 if (inst.size_req == 4)
12468 narrow = FALSE;
12469
fdfde340
JM
12470 reject_bad_reg (inst.operands[0].reg);
12471 reject_bad_reg (inst.operands[1].reg);
c921be7d 12472
3d388997 12473 if (!narrow)
c19d1205
ZW
12474 {
12475 if (inst.operands[2].isreg)
b99bd4ef 12476 {
fdfde340 12477 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12478 inst.instruction = THUMB_OP32 (inst.instruction);
12479 inst.instruction |= inst.operands[0].reg << 8;
12480 inst.instruction |= inst.operands[1].reg << 16;
12481 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12482
12483 /* PR 12854: Error on extraneous shifts. */
12484 constraint (inst.operands[2].shifted,
12485 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12486 }
12487 else
12488 {
12489 inst.operands[1].shifted = 1;
3d388997 12490 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12491 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12492 ? T_MNEM_movs : T_MNEM_mov);
12493 inst.instruction |= inst.operands[0].reg << 8;
12494 encode_thumb32_shifted_operand (1);
12495 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12496 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12497 }
12498 }
12499 else
12500 {
c19d1205 12501 if (inst.operands[2].isreg)
b99bd4ef 12502 {
3d388997 12503 switch (shift_kind)
b99bd4ef 12504 {
3d388997
PB
12505 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12506 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12507 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12508 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12509 default: abort ();
b99bd4ef 12510 }
5f4273c7 12511
c19d1205
ZW
12512 inst.instruction |= inst.operands[0].reg;
12513 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12514
12515 /* PR 12854: Error on extraneous shifts. */
12516 constraint (inst.operands[2].shifted,
12517 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12518 }
12519 else
12520 {
3d388997 12521 switch (shift_kind)
b99bd4ef 12522 {
3d388997
PB
12523 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12524 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12525 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12526 default: abort ();
b99bd4ef 12527 }
c19d1205
ZW
12528 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12529 inst.instruction |= inst.operands[0].reg;
12530 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12531 }
12532 }
c19d1205
ZW
12533 }
12534 else
12535 {
12536 constraint (inst.operands[0].reg > 7
12537 || inst.operands[1].reg > 7, BAD_HIREG);
12538 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12539
c19d1205
ZW
12540 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12541 {
12542 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12543 constraint (inst.operands[0].reg != inst.operands[1].reg,
12544 _("source1 and dest must be same register"));
b99bd4ef 12545
c19d1205
ZW
12546 switch (inst.instruction)
12547 {
12548 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12549 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12550 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12551 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12552 default: abort ();
12553 }
5f4273c7 12554
c19d1205
ZW
12555 inst.instruction |= inst.operands[0].reg;
12556 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12557
12558 /* PR 12854: Error on extraneous shifts. */
12559 constraint (inst.operands[2].shifted,
12560 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12561 }
12562 else
b99bd4ef 12563 {
c19d1205
ZW
12564 switch (inst.instruction)
12565 {
12566 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12567 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12568 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12569 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12570 default: abort ();
12571 }
12572 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12573 inst.instruction |= inst.operands[0].reg;
12574 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12575 }
12576 }
b99bd4ef
NC
12577}
12578
12579static void
c19d1205 12580do_t_simd (void)
b99bd4ef 12581{
fdfde340
JM
12582 unsigned Rd, Rn, Rm;
12583
12584 Rd = inst.operands[0].reg;
12585 Rn = inst.operands[1].reg;
12586 Rm = inst.operands[2].reg;
12587
12588 reject_bad_reg (Rd);
12589 reject_bad_reg (Rn);
12590 reject_bad_reg (Rm);
12591
12592 inst.instruction |= Rd << 8;
12593 inst.instruction |= Rn << 16;
12594 inst.instruction |= Rm;
c19d1205 12595}
b99bd4ef 12596
03ee1b7f
NC
12597static void
12598do_t_simd2 (void)
12599{
12600 unsigned Rd, Rn, Rm;
12601
12602 Rd = inst.operands[0].reg;
12603 Rm = inst.operands[1].reg;
12604 Rn = inst.operands[2].reg;
12605
12606 reject_bad_reg (Rd);
12607 reject_bad_reg (Rn);
12608 reject_bad_reg (Rm);
12609
12610 inst.instruction |= Rd << 8;
12611 inst.instruction |= Rn << 16;
12612 inst.instruction |= Rm;
12613}
12614
c19d1205 12615static void
3eb17e6b 12616do_t_smc (void)
c19d1205
ZW
12617{
12618 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
12619 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12620 _("SMC is not permitted on this architecture"));
c19d1205
ZW
12621 constraint (inst.reloc.exp.X_op != O_constant,
12622 _("expression too complex"));
12623 inst.reloc.type = BFD_RELOC_UNUSED;
12624 inst.instruction |= (value & 0xf000) >> 12;
12625 inst.instruction |= (value & 0x0ff0);
12626 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
12627 /* PR gas/15623: SMC instructions must be last in an IT block. */
12628 set_it_insn_type_last ();
c19d1205 12629}
b99bd4ef 12630
90ec0d68
MGD
12631static void
12632do_t_hvc (void)
12633{
12634 unsigned int value = inst.reloc.exp.X_add_number;
12635
12636 inst.reloc.type = BFD_RELOC_UNUSED;
12637 inst.instruction |= (value & 0x0fff);
12638 inst.instruction |= (value & 0xf000) << 4;
12639}
12640
c19d1205 12641static void
3a21c15a 12642do_t_ssat_usat (int bias)
c19d1205 12643{
fdfde340
JM
12644 unsigned Rd, Rn;
12645
12646 Rd = inst.operands[0].reg;
12647 Rn = inst.operands[2].reg;
12648
12649 reject_bad_reg (Rd);
12650 reject_bad_reg (Rn);
12651
12652 inst.instruction |= Rd << 8;
3a21c15a 12653 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 12654 inst.instruction |= Rn << 16;
b99bd4ef 12655
c19d1205 12656 if (inst.operands[3].present)
b99bd4ef 12657 {
3a21c15a
NC
12658 offsetT shift_amount = inst.reloc.exp.X_add_number;
12659
12660 inst.reloc.type = BFD_RELOC_UNUSED;
12661
c19d1205
ZW
12662 constraint (inst.reloc.exp.X_op != O_constant,
12663 _("expression too complex"));
b99bd4ef 12664
3a21c15a 12665 if (shift_amount != 0)
6189168b 12666 {
3a21c15a
NC
12667 constraint (shift_amount > 31,
12668 _("shift expression is too large"));
12669
c19d1205 12670 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
12671 inst.instruction |= 0x00200000; /* sh bit. */
12672
12673 inst.instruction |= (shift_amount & 0x1c) << 10;
12674 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
12675 }
12676 }
b99bd4ef 12677}
c921be7d 12678
3a21c15a
NC
12679static void
12680do_t_ssat (void)
12681{
12682 do_t_ssat_usat (1);
12683}
b99bd4ef 12684
0dd132b6 12685static void
c19d1205 12686do_t_ssat16 (void)
0dd132b6 12687{
fdfde340
JM
12688 unsigned Rd, Rn;
12689
12690 Rd = inst.operands[0].reg;
12691 Rn = inst.operands[2].reg;
12692
12693 reject_bad_reg (Rd);
12694 reject_bad_reg (Rn);
12695
12696 inst.instruction |= Rd << 8;
c19d1205 12697 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 12698 inst.instruction |= Rn << 16;
c19d1205 12699}
0dd132b6 12700
c19d1205
ZW
12701static void
12702do_t_strex (void)
12703{
12704 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
12705 || inst.operands[2].postind || inst.operands[2].writeback
12706 || inst.operands[2].immisreg || inst.operands[2].shifted
12707 || inst.operands[2].negative,
01cfc07f 12708 BAD_ADDR_MODE);
0dd132b6 12709
5be8be5d
DG
12710 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
12711
c19d1205
ZW
12712 inst.instruction |= inst.operands[0].reg << 8;
12713 inst.instruction |= inst.operands[1].reg << 12;
12714 inst.instruction |= inst.operands[2].reg << 16;
12715 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
12716}
12717
b99bd4ef 12718static void
c19d1205 12719do_t_strexd (void)
b99bd4ef 12720{
c19d1205
ZW
12721 if (!inst.operands[2].present)
12722 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 12723
c19d1205
ZW
12724 constraint (inst.operands[0].reg == inst.operands[1].reg
12725 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 12726 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 12727 BAD_OVERLAP);
b99bd4ef 12728
c19d1205
ZW
12729 inst.instruction |= inst.operands[0].reg;
12730 inst.instruction |= inst.operands[1].reg << 12;
12731 inst.instruction |= inst.operands[2].reg << 8;
12732 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
12733}
12734
12735static void
c19d1205 12736do_t_sxtah (void)
b99bd4ef 12737{
fdfde340
JM
12738 unsigned Rd, Rn, Rm;
12739
12740 Rd = inst.operands[0].reg;
12741 Rn = inst.operands[1].reg;
12742 Rm = inst.operands[2].reg;
12743
12744 reject_bad_reg (Rd);
12745 reject_bad_reg (Rn);
12746 reject_bad_reg (Rm);
12747
12748 inst.instruction |= Rd << 8;
12749 inst.instruction |= Rn << 16;
12750 inst.instruction |= Rm;
c19d1205
ZW
12751 inst.instruction |= inst.operands[3].imm << 4;
12752}
b99bd4ef 12753
c19d1205
ZW
12754static void
12755do_t_sxth (void)
12756{
fdfde340
JM
12757 unsigned Rd, Rm;
12758
12759 Rd = inst.operands[0].reg;
12760 Rm = inst.operands[1].reg;
12761
12762 reject_bad_reg (Rd);
12763 reject_bad_reg (Rm);
c921be7d
NC
12764
12765 if (inst.instruction <= 0xffff
12766 && inst.size_req != 4
fdfde340 12767 && Rd <= 7 && Rm <= 7
c19d1205 12768 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 12769 {
c19d1205 12770 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12771 inst.instruction |= Rd;
12772 inst.instruction |= Rm << 3;
b99bd4ef 12773 }
c19d1205 12774 else if (unified_syntax)
b99bd4ef 12775 {
c19d1205
ZW
12776 if (inst.instruction <= 0xffff)
12777 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12778 inst.instruction |= Rd << 8;
12779 inst.instruction |= Rm;
c19d1205 12780 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 12781 }
c19d1205 12782 else
b99bd4ef 12783 {
c19d1205
ZW
12784 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
12785 _("Thumb encoding does not support rotation"));
12786 constraint (1, BAD_HIREG);
b99bd4ef 12787 }
c19d1205 12788}
b99bd4ef 12789
c19d1205
ZW
12790static void
12791do_t_swi (void)
12792{
b2a5fbdc
MGD
12793 /* We have to do the following check manually as ARM_EXT_OS only applies
12794 to ARM_EXT_V6M. */
12795 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
12796 {
ac7f631b
NC
12797 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
12798 /* This only applies to the v6m howver, not later architectures. */
12799 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
12800 as_bad (_("SVC is not permitted on this architecture"));
12801 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
12802 }
12803
c19d1205
ZW
12804 inst.reloc.type = BFD_RELOC_ARM_SWI;
12805}
b99bd4ef 12806
92e90b6e
PB
12807static void
12808do_t_tb (void)
12809{
fdfde340 12810 unsigned Rn, Rm;
92e90b6e
PB
12811 int half;
12812
12813 half = (inst.instruction & 0x10) != 0;
e07e6e58 12814 set_it_insn_type_last ();
dfa9f0d5
PB
12815 constraint (inst.operands[0].immisreg,
12816 _("instruction requires register index"));
fdfde340
JM
12817
12818 Rn = inst.operands[0].reg;
12819 Rm = inst.operands[0].imm;
c921be7d 12820
fdfde340
JM
12821 constraint (Rn == REG_SP, BAD_SP);
12822 reject_bad_reg (Rm);
12823
92e90b6e
PB
12824 constraint (!half && inst.operands[0].shifted,
12825 _("instruction does not allow shifted index"));
fdfde340 12826 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
12827}
12828
74db7efb
NC
12829static void
12830do_t_udf (void)
12831{
12832 if (!inst.operands[0].present)
12833 inst.operands[0].imm = 0;
12834
12835 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
12836 {
12837 constraint (inst.size_req == 2,
12838 _("immediate value out of range"));
12839 inst.instruction = THUMB_OP32 (inst.instruction);
12840 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
12841 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
12842 }
12843 else
12844 {
12845 inst.instruction = THUMB_OP16 (inst.instruction);
12846 inst.instruction |= inst.operands[0].imm;
12847 }
12848
12849 set_it_insn_type (NEUTRAL_IT_INSN);
12850}
12851
12852
c19d1205
ZW
12853static void
12854do_t_usat (void)
12855{
3a21c15a 12856 do_t_ssat_usat (0);
b99bd4ef
NC
12857}
12858
12859static void
c19d1205 12860do_t_usat16 (void)
b99bd4ef 12861{
fdfde340
JM
12862 unsigned Rd, Rn;
12863
12864 Rd = inst.operands[0].reg;
12865 Rn = inst.operands[2].reg;
12866
12867 reject_bad_reg (Rd);
12868 reject_bad_reg (Rn);
12869
12870 inst.instruction |= Rd << 8;
c19d1205 12871 inst.instruction |= inst.operands[1].imm;
fdfde340 12872 inst.instruction |= Rn << 16;
b99bd4ef 12873}
c19d1205 12874
5287ad62 12875/* Neon instruction encoder helpers. */
5f4273c7 12876
5287ad62 12877/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 12878
5287ad62
JB
12879/* An "invalid" code for the following tables. */
12880#define N_INV -1u
12881
12882struct neon_tab_entry
b99bd4ef 12883{
5287ad62
JB
12884 unsigned integer;
12885 unsigned float_or_poly;
12886 unsigned scalar_or_imm;
12887};
5f4273c7 12888
5287ad62
JB
12889/* Map overloaded Neon opcodes to their respective encodings. */
12890#define NEON_ENC_TAB \
12891 X(vabd, 0x0000700, 0x1200d00, N_INV), \
12892 X(vmax, 0x0000600, 0x0000f00, N_INV), \
12893 X(vmin, 0x0000610, 0x0200f00, N_INV), \
12894 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
12895 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
12896 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
12897 X(vadd, 0x0000800, 0x0000d00, N_INV), \
12898 X(vsub, 0x1000800, 0x0200d00, N_INV), \
12899 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
12900 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
12901 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
12902 /* Register variants of the following two instructions are encoded as
e07e6e58 12903 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
12904 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
12905 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
12906 X(vfma, N_INV, 0x0000c10, N_INV), \
12907 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
12908 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
12909 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
12910 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
12911 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
12912 X(vmlal, 0x0800800, N_INV, 0x0800240), \
12913 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
12914 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
12915 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
12916 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
12917 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
12918 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
12919 X(vshl, 0x0000400, N_INV, 0x0800510), \
12920 X(vqshl, 0x0000410, N_INV, 0x0800710), \
12921 X(vand, 0x0000110, N_INV, 0x0800030), \
12922 X(vbic, 0x0100110, N_INV, 0x0800030), \
12923 X(veor, 0x1000110, N_INV, N_INV), \
12924 X(vorn, 0x0300110, N_INV, 0x0800010), \
12925 X(vorr, 0x0200110, N_INV, 0x0800010), \
12926 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
12927 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
12928 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
12929 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
12930 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
12931 X(vst1, 0x0000000, 0x0800000, N_INV), \
12932 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
12933 X(vst2, 0x0000100, 0x0800100, N_INV), \
12934 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
12935 X(vst3, 0x0000200, 0x0800200, N_INV), \
12936 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
12937 X(vst4, 0x0000300, 0x0800300, N_INV), \
12938 X(vmovn, 0x1b20200, N_INV, N_INV), \
12939 X(vtrn, 0x1b20080, N_INV, N_INV), \
12940 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
12941 X(vqmovun, 0x1b20240, N_INV, N_INV), \
12942 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
12943 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
12944 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
12945 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
12946 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
12947 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
12948 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
12949 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
12950 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
12951 X(vseleq, 0xe000a00, N_INV, N_INV), \
12952 X(vselvs, 0xe100a00, N_INV, N_INV), \
12953 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
12954 X(vselgt, 0xe300a00, N_INV, N_INV), \
12955 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 12956 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
12957 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
12958 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 12959 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 12960 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
12961 X(sha3op, 0x2000c00, N_INV, N_INV), \
12962 X(sha1h, 0x3b902c0, N_INV, N_INV), \
12963 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
12964
12965enum neon_opc
12966{
12967#define X(OPC,I,F,S) N_MNEM_##OPC
12968NEON_ENC_TAB
12969#undef X
12970};
b99bd4ef 12971
5287ad62
JB
12972static const struct neon_tab_entry neon_enc_tab[] =
12973{
12974#define X(OPC,I,F,S) { (I), (F), (S) }
12975NEON_ENC_TAB
12976#undef X
12977};
b99bd4ef 12978
88714cb8
DG
12979/* Do not use these macros; instead, use NEON_ENCODE defined below. */
12980#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12981#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12982#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12983#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12984#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12985#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12986#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12987#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12988#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12989#define NEON_ENC_SINGLE_(X) \
037e8744 12990 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 12991#define NEON_ENC_DOUBLE_(X) \
037e8744 12992 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
12993#define NEON_ENC_FPV8_(X) \
12994 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 12995
88714cb8
DG
12996#define NEON_ENCODE(type, inst) \
12997 do \
12998 { \
12999 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13000 inst.is_neon = 1; \
13001 } \
13002 while (0)
13003
13004#define check_neon_suffixes \
13005 do \
13006 { \
13007 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13008 { \
13009 as_bad (_("invalid neon suffix for non neon instruction")); \
13010 return; \
13011 } \
13012 } \
13013 while (0)
13014
037e8744
JB
13015/* Define shapes for instruction operands. The following mnemonic characters
13016 are used in this table:
5287ad62 13017
037e8744 13018 F - VFP S<n> register
5287ad62
JB
13019 D - Neon D<n> register
13020 Q - Neon Q<n> register
13021 I - Immediate
13022 S - Scalar
13023 R - ARM register
13024 L - D<n> register list
5f4273c7 13025
037e8744
JB
13026 This table is used to generate various data:
13027 - enumerations of the form NS_DDR to be used as arguments to
13028 neon_select_shape.
13029 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13030 - a table used to drive neon_select_shape. */
b99bd4ef 13031
037e8744
JB
13032#define NEON_SHAPE_DEF \
13033 X(3, (D, D, D), DOUBLE), \
13034 X(3, (Q, Q, Q), QUAD), \
13035 X(3, (D, D, I), DOUBLE), \
13036 X(3, (Q, Q, I), QUAD), \
13037 X(3, (D, D, S), DOUBLE), \
13038 X(3, (Q, Q, S), QUAD), \
13039 X(2, (D, D), DOUBLE), \
13040 X(2, (Q, Q), QUAD), \
13041 X(2, (D, S), DOUBLE), \
13042 X(2, (Q, S), QUAD), \
13043 X(2, (D, R), DOUBLE), \
13044 X(2, (Q, R), QUAD), \
13045 X(2, (D, I), DOUBLE), \
13046 X(2, (Q, I), QUAD), \
13047 X(3, (D, L, D), DOUBLE), \
13048 X(2, (D, Q), MIXED), \
13049 X(2, (Q, D), MIXED), \
13050 X(3, (D, Q, I), MIXED), \
13051 X(3, (Q, D, I), MIXED), \
13052 X(3, (Q, D, D), MIXED), \
13053 X(3, (D, Q, Q), MIXED), \
13054 X(3, (Q, Q, D), MIXED), \
13055 X(3, (Q, D, S), MIXED), \
13056 X(3, (D, Q, S), MIXED), \
13057 X(4, (D, D, D, I), DOUBLE), \
13058 X(4, (Q, Q, Q, I), QUAD), \
13059 X(2, (F, F), SINGLE), \
13060 X(3, (F, F, F), SINGLE), \
13061 X(2, (F, I), SINGLE), \
13062 X(2, (F, D), MIXED), \
13063 X(2, (D, F), MIXED), \
13064 X(3, (F, F, I), MIXED), \
13065 X(4, (R, R, F, F), SINGLE), \
13066 X(4, (F, F, R, R), SINGLE), \
13067 X(3, (D, R, R), DOUBLE), \
13068 X(3, (R, R, D), DOUBLE), \
13069 X(2, (S, R), SINGLE), \
13070 X(2, (R, S), SINGLE), \
13071 X(2, (F, R), SINGLE), \
13072 X(2, (R, F), SINGLE)
13073
13074#define S2(A,B) NS_##A##B
13075#define S3(A,B,C) NS_##A##B##C
13076#define S4(A,B,C,D) NS_##A##B##C##D
13077
13078#define X(N, L, C) S##N L
13079
5287ad62
JB
13080enum neon_shape
13081{
037e8744
JB
13082 NEON_SHAPE_DEF,
13083 NS_NULL
5287ad62 13084};
b99bd4ef 13085
037e8744
JB
13086#undef X
13087#undef S2
13088#undef S3
13089#undef S4
13090
13091enum neon_shape_class
13092{
13093 SC_SINGLE,
13094 SC_DOUBLE,
13095 SC_QUAD,
13096 SC_MIXED
13097};
13098
13099#define X(N, L, C) SC_##C
13100
13101static enum neon_shape_class neon_shape_class[] =
13102{
13103 NEON_SHAPE_DEF
13104};
13105
13106#undef X
13107
13108enum neon_shape_el
13109{
13110 SE_F,
13111 SE_D,
13112 SE_Q,
13113 SE_I,
13114 SE_S,
13115 SE_R,
13116 SE_L
13117};
13118
13119/* Register widths of above. */
13120static unsigned neon_shape_el_size[] =
13121{
13122 32,
13123 64,
13124 128,
13125 0,
13126 32,
13127 32,
13128 0
13129};
13130
13131struct neon_shape_info
13132{
13133 unsigned els;
13134 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13135};
13136
13137#define S2(A,B) { SE_##A, SE_##B }
13138#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13139#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13140
13141#define X(N, L, C) { N, S##N L }
13142
13143static struct neon_shape_info neon_shape_tab[] =
13144{
13145 NEON_SHAPE_DEF
13146};
13147
13148#undef X
13149#undef S2
13150#undef S3
13151#undef S4
13152
5287ad62
JB
13153/* Bit masks used in type checking given instructions.
13154 'N_EQK' means the type must be the same as (or based on in some way) the key
13155 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13156 set, various other bits can be set as well in order to modify the meaning of
13157 the type constraint. */
13158
13159enum neon_type_mask
13160{
8e79c3df
CM
13161 N_S8 = 0x0000001,
13162 N_S16 = 0x0000002,
13163 N_S32 = 0x0000004,
13164 N_S64 = 0x0000008,
13165 N_U8 = 0x0000010,
13166 N_U16 = 0x0000020,
13167 N_U32 = 0x0000040,
13168 N_U64 = 0x0000080,
13169 N_I8 = 0x0000100,
13170 N_I16 = 0x0000200,
13171 N_I32 = 0x0000400,
13172 N_I64 = 0x0000800,
13173 N_8 = 0x0001000,
13174 N_16 = 0x0002000,
13175 N_32 = 0x0004000,
13176 N_64 = 0x0008000,
13177 N_P8 = 0x0010000,
13178 N_P16 = 0x0020000,
13179 N_F16 = 0x0040000,
13180 N_F32 = 0x0080000,
13181 N_F64 = 0x0100000,
4f51b4bd 13182 N_P64 = 0x0200000,
c921be7d
NC
13183 N_KEY = 0x1000000, /* Key element (main type specifier). */
13184 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13185 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13186 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13187 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13188 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13189 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13190 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13191 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13192 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13193 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13194 N_UTYP = 0,
4f51b4bd 13195 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13196};
13197
dcbf9037
JB
13198#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13199
5287ad62
JB
13200#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13201#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13202#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
13203#define N_SUF_32 (N_SU_32 | N_F32)
13204#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
13205#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
13206
13207/* Pass this as the first type argument to neon_check_type to ignore types
13208 altogether. */
13209#define N_IGNORE_TYPE (N_KEY | N_EQK)
13210
037e8744
JB
13211/* Select a "shape" for the current instruction (describing register types or
13212 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13213 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13214 function of operand parsing, so this function doesn't need to be called.
13215 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13216
13217static enum neon_shape
037e8744 13218neon_select_shape (enum neon_shape shape, ...)
5287ad62 13219{
037e8744
JB
13220 va_list ap;
13221 enum neon_shape first_shape = shape;
5287ad62
JB
13222
13223 /* Fix missing optional operands. FIXME: we don't know at this point how
13224 many arguments we should have, so this makes the assumption that we have
13225 > 1. This is true of all current Neon opcodes, I think, but may not be
13226 true in the future. */
13227 if (!inst.operands[1].present)
13228 inst.operands[1] = inst.operands[0];
13229
037e8744 13230 va_start (ap, shape);
5f4273c7 13231
21d799b5 13232 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13233 {
13234 unsigned j;
13235 int matches = 1;
13236
13237 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13238 {
13239 if (!inst.operands[j].present)
13240 {
13241 matches = 0;
13242 break;
13243 }
13244
13245 switch (neon_shape_tab[shape].el[j])
13246 {
13247 case SE_F:
13248 if (!(inst.operands[j].isreg
13249 && inst.operands[j].isvec
13250 && inst.operands[j].issingle
13251 && !inst.operands[j].isquad))
13252 matches = 0;
13253 break;
13254
13255 case SE_D:
13256 if (!(inst.operands[j].isreg
13257 && inst.operands[j].isvec
13258 && !inst.operands[j].isquad
13259 && !inst.operands[j].issingle))
13260 matches = 0;
13261 break;
13262
13263 case SE_R:
13264 if (!(inst.operands[j].isreg
13265 && !inst.operands[j].isvec))
13266 matches = 0;
13267 break;
13268
13269 case SE_Q:
13270 if (!(inst.operands[j].isreg
13271 && inst.operands[j].isvec
13272 && inst.operands[j].isquad
13273 && !inst.operands[j].issingle))
13274 matches = 0;
13275 break;
13276
13277 case SE_I:
13278 if (!(!inst.operands[j].isreg
13279 && !inst.operands[j].isscalar))
13280 matches = 0;
13281 break;
13282
13283 case SE_S:
13284 if (!(!inst.operands[j].isreg
13285 && inst.operands[j].isscalar))
13286 matches = 0;
13287 break;
13288
13289 case SE_L:
13290 break;
13291 }
3fde54a2
JZ
13292 if (!matches)
13293 break;
477330fc 13294 }
ad6cec43
MGD
13295 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13296 /* We've matched all the entries in the shape table, and we don't
13297 have any left over operands which have not been matched. */
477330fc 13298 break;
037e8744 13299 }
5f4273c7 13300
037e8744 13301 va_end (ap);
5287ad62 13302
037e8744
JB
13303 if (shape == NS_NULL && first_shape != NS_NULL)
13304 first_error (_("invalid instruction shape"));
5287ad62 13305
037e8744
JB
13306 return shape;
13307}
5287ad62 13308
037e8744
JB
13309/* True if SHAPE is predominantly a quadword operation (most of the time, this
13310 means the Q bit should be set). */
13311
13312static int
13313neon_quad (enum neon_shape shape)
13314{
13315 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13316}
037e8744 13317
5287ad62
JB
13318static void
13319neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13320 unsigned *g_size)
5287ad62
JB
13321{
13322 /* Allow modification to be made to types which are constrained to be
13323 based on the key element, based on bits set alongside N_EQK. */
13324 if ((typebits & N_EQK) != 0)
13325 {
13326 if ((typebits & N_HLF) != 0)
13327 *g_size /= 2;
13328 else if ((typebits & N_DBL) != 0)
13329 *g_size *= 2;
13330 if ((typebits & N_SGN) != 0)
13331 *g_type = NT_signed;
13332 else if ((typebits & N_UNS) != 0)
477330fc 13333 *g_type = NT_unsigned;
5287ad62 13334 else if ((typebits & N_INT) != 0)
477330fc 13335 *g_type = NT_integer;
5287ad62 13336 else if ((typebits & N_FLT) != 0)
477330fc 13337 *g_type = NT_float;
dcbf9037 13338 else if ((typebits & N_SIZ) != 0)
477330fc 13339 *g_type = NT_untyped;
5287ad62
JB
13340 }
13341}
5f4273c7 13342
5287ad62
JB
13343/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13344 operand type, i.e. the single type specified in a Neon instruction when it
13345 is the only one given. */
13346
13347static struct neon_type_el
13348neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13349{
13350 struct neon_type_el dest = *key;
5f4273c7 13351
9c2799c2 13352 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13353
5287ad62
JB
13354 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13355
13356 return dest;
13357}
13358
13359/* Convert Neon type and size into compact bitmask representation. */
13360
13361static enum neon_type_mask
13362type_chk_of_el_type (enum neon_el_type type, unsigned size)
13363{
13364 switch (type)
13365 {
13366 case NT_untyped:
13367 switch (size)
477330fc
RM
13368 {
13369 case 8: return N_8;
13370 case 16: return N_16;
13371 case 32: return N_32;
13372 case 64: return N_64;
13373 default: ;
13374 }
5287ad62
JB
13375 break;
13376
13377 case NT_integer:
13378 switch (size)
477330fc
RM
13379 {
13380 case 8: return N_I8;
13381 case 16: return N_I16;
13382 case 32: return N_I32;
13383 case 64: return N_I64;
13384 default: ;
13385 }
5287ad62
JB
13386 break;
13387
13388 case NT_float:
037e8744 13389 switch (size)
477330fc 13390 {
8e79c3df 13391 case 16: return N_F16;
477330fc
RM
13392 case 32: return N_F32;
13393 case 64: return N_F64;
13394 default: ;
13395 }
5287ad62
JB
13396 break;
13397
13398 case NT_poly:
13399 switch (size)
477330fc
RM
13400 {
13401 case 8: return N_P8;
13402 case 16: return N_P16;
4f51b4bd 13403 case 64: return N_P64;
477330fc
RM
13404 default: ;
13405 }
5287ad62
JB
13406 break;
13407
13408 case NT_signed:
13409 switch (size)
477330fc
RM
13410 {
13411 case 8: return N_S8;
13412 case 16: return N_S16;
13413 case 32: return N_S32;
13414 case 64: return N_S64;
13415 default: ;
13416 }
5287ad62
JB
13417 break;
13418
13419 case NT_unsigned:
13420 switch (size)
477330fc
RM
13421 {
13422 case 8: return N_U8;
13423 case 16: return N_U16;
13424 case 32: return N_U32;
13425 case 64: return N_U64;
13426 default: ;
13427 }
5287ad62
JB
13428 break;
13429
13430 default: ;
13431 }
5f4273c7 13432
5287ad62
JB
13433 return N_UTYP;
13434}
13435
13436/* Convert compact Neon bitmask type representation to a type and size. Only
13437 handles the case where a single bit is set in the mask. */
13438
dcbf9037 13439static int
5287ad62 13440el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13441 enum neon_type_mask mask)
5287ad62 13442{
dcbf9037
JB
13443 if ((mask & N_EQK) != 0)
13444 return FAIL;
13445
5287ad62
JB
13446 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13447 *size = 8;
c70a8987 13448 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13449 *size = 16;
dcbf9037 13450 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13451 *size = 32;
4f51b4bd 13452 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13453 *size = 64;
dcbf9037
JB
13454 else
13455 return FAIL;
13456
5287ad62
JB
13457 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13458 *type = NT_signed;
dcbf9037 13459 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13460 *type = NT_unsigned;
dcbf9037 13461 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13462 *type = NT_integer;
dcbf9037 13463 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13464 *type = NT_untyped;
4f51b4bd 13465 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13466 *type = NT_poly;
c70a8987 13467 else if ((mask & (N_F16 | N_F32 | N_F64)) != 0)
5287ad62 13468 *type = NT_float;
dcbf9037
JB
13469 else
13470 return FAIL;
5f4273c7 13471
dcbf9037 13472 return SUCCESS;
5287ad62
JB
13473}
13474
13475/* Modify a bitmask of allowed types. This is only needed for type
13476 relaxation. */
13477
13478static unsigned
13479modify_types_allowed (unsigned allowed, unsigned mods)
13480{
13481 unsigned size;
13482 enum neon_el_type type;
13483 unsigned destmask;
13484 int i;
5f4273c7 13485
5287ad62 13486 destmask = 0;
5f4273c7 13487
5287ad62
JB
13488 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13489 {
21d799b5 13490 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13491 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13492 {
13493 neon_modify_type_size (mods, &type, &size);
13494 destmask |= type_chk_of_el_type (type, size);
13495 }
5287ad62 13496 }
5f4273c7 13497
5287ad62
JB
13498 return destmask;
13499}
13500
13501/* Check type and return type classification.
13502 The manual states (paraphrase): If one datatype is given, it indicates the
13503 type given in:
13504 - the second operand, if there is one
13505 - the operand, if there is no second operand
13506 - the result, if there are no operands.
13507 This isn't quite good enough though, so we use a concept of a "key" datatype
13508 which is set on a per-instruction basis, which is the one which matters when
13509 only one data type is written.
13510 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13511 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13512
13513static struct neon_type_el
13514neon_check_type (unsigned els, enum neon_shape ns, ...)
13515{
13516 va_list ap;
13517 unsigned i, pass, key_el = 0;
13518 unsigned types[NEON_MAX_TYPE_ELS];
13519 enum neon_el_type k_type = NT_invtype;
13520 unsigned k_size = -1u;
13521 struct neon_type_el badtype = {NT_invtype, -1};
13522 unsigned key_allowed = 0;
13523
13524 /* Optional registers in Neon instructions are always (not) in operand 1.
13525 Fill in the missing operand here, if it was omitted. */
13526 if (els > 1 && !inst.operands[1].present)
13527 inst.operands[1] = inst.operands[0];
13528
13529 /* Suck up all the varargs. */
13530 va_start (ap, ns);
13531 for (i = 0; i < els; i++)
13532 {
13533 unsigned thisarg = va_arg (ap, unsigned);
13534 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
13535 {
13536 va_end (ap);
13537 return badtype;
13538 }
5287ad62
JB
13539 types[i] = thisarg;
13540 if ((thisarg & N_KEY) != 0)
477330fc 13541 key_el = i;
5287ad62
JB
13542 }
13543 va_end (ap);
13544
dcbf9037
JB
13545 if (inst.vectype.elems > 0)
13546 for (i = 0; i < els; i++)
13547 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
13548 {
13549 first_error (_("types specified in both the mnemonic and operands"));
13550 return badtype;
13551 }
dcbf9037 13552
5287ad62
JB
13553 /* Duplicate inst.vectype elements here as necessary.
13554 FIXME: No idea if this is exactly the same as the ARM assembler,
13555 particularly when an insn takes one register and one non-register
13556 operand. */
13557 if (inst.vectype.elems == 1 && els > 1)
13558 {
13559 unsigned j;
13560 inst.vectype.elems = els;
13561 inst.vectype.el[key_el] = inst.vectype.el[0];
13562 for (j = 0; j < els; j++)
477330fc
RM
13563 if (j != key_el)
13564 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13565 types[j]);
dcbf9037
JB
13566 }
13567 else if (inst.vectype.elems == 0 && els > 0)
13568 {
13569 unsigned j;
13570 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
13571 after each operand. We allow some flexibility here; as long as the
13572 "key" operand has a type, we can infer the others. */
dcbf9037 13573 for (j = 0; j < els; j++)
477330fc
RM
13574 if (inst.operands[j].vectype.type != NT_invtype)
13575 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
13576
13577 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
13578 {
13579 for (j = 0; j < els; j++)
13580 if (inst.operands[j].vectype.type == NT_invtype)
13581 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13582 types[j]);
13583 }
dcbf9037 13584 else
477330fc
RM
13585 {
13586 first_error (_("operand types can't be inferred"));
13587 return badtype;
13588 }
5287ad62
JB
13589 }
13590 else if (inst.vectype.elems != els)
13591 {
dcbf9037 13592 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
13593 return badtype;
13594 }
13595
13596 for (pass = 0; pass < 2; pass++)
13597 {
13598 for (i = 0; i < els; i++)
477330fc
RM
13599 {
13600 unsigned thisarg = types[i];
13601 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
13602 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
13603 enum neon_el_type g_type = inst.vectype.el[i].type;
13604 unsigned g_size = inst.vectype.el[i].size;
13605
13606 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 13607 integer types if sign-specific variants are unavailable. */
477330fc 13608 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
13609 && (types_allowed & N_SU_ALL) == 0)
13610 g_type = NT_integer;
13611
477330fc 13612 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
13613 them. Some instructions only care about signs for some element
13614 sizes, so handle that properly. */
477330fc 13615 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
13616 && ((g_size == 8 && (types_allowed & N_8) != 0)
13617 || (g_size == 16 && (types_allowed & N_16) != 0)
13618 || (g_size == 32 && (types_allowed & N_32) != 0)
13619 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
13620 g_type = NT_untyped;
13621
477330fc
RM
13622 if (pass == 0)
13623 {
13624 if ((thisarg & N_KEY) != 0)
13625 {
13626 k_type = g_type;
13627 k_size = g_size;
13628 key_allowed = thisarg & ~N_KEY;
13629 }
13630 }
13631 else
13632 {
13633 if ((thisarg & N_VFP) != 0)
13634 {
13635 enum neon_shape_el regshape;
13636 unsigned regwidth, match;
99b253c5
NC
13637
13638 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
13639 if (ns == NS_NULL)
13640 {
13641 first_error (_("invalid instruction shape"));
13642 return badtype;
13643 }
477330fc
RM
13644 regshape = neon_shape_tab[ns].el[i];
13645 regwidth = neon_shape_el_size[regshape];
13646
13647 /* In VFP mode, operands must match register widths. If we
13648 have a key operand, use its width, else use the width of
13649 the current operand. */
13650 if (k_size != -1u)
13651 match = k_size;
13652 else
13653 match = g_size;
13654
13655 if (regwidth != match)
13656 {
13657 first_error (_("operand size must match register width"));
13658 return badtype;
13659 }
13660 }
13661
13662 if ((thisarg & N_EQK) == 0)
13663 {
13664 unsigned given_type = type_chk_of_el_type (g_type, g_size);
13665
13666 if ((given_type & types_allowed) == 0)
13667 {
13668 first_error (_("bad type in Neon instruction"));
13669 return badtype;
13670 }
13671 }
13672 else
13673 {
13674 enum neon_el_type mod_k_type = k_type;
13675 unsigned mod_k_size = k_size;
13676 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
13677 if (g_type != mod_k_type || g_size != mod_k_size)
13678 {
13679 first_error (_("inconsistent types in Neon instruction"));
13680 return badtype;
13681 }
13682 }
13683 }
13684 }
5287ad62
JB
13685 }
13686
13687 return inst.vectype.el[key_el];
13688}
13689
037e8744 13690/* Neon-style VFP instruction forwarding. */
5287ad62 13691
037e8744
JB
13692/* Thumb VFP instructions have 0xE in the condition field. */
13693
13694static void
13695do_vfp_cond_or_thumb (void)
5287ad62 13696{
88714cb8
DG
13697 inst.is_neon = 1;
13698
5287ad62 13699 if (thumb_mode)
037e8744 13700 inst.instruction |= 0xe0000000;
5287ad62 13701 else
037e8744 13702 inst.instruction |= inst.cond << 28;
5287ad62
JB
13703}
13704
037e8744
JB
13705/* Look up and encode a simple mnemonic, for use as a helper function for the
13706 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
13707 etc. It is assumed that operand parsing has already been done, and that the
13708 operands are in the form expected by the given opcode (this isn't necessarily
13709 the same as the form in which they were parsed, hence some massaging must
13710 take place before this function is called).
13711 Checks current arch version against that in the looked-up opcode. */
5287ad62 13712
037e8744
JB
13713static void
13714do_vfp_nsyn_opcode (const char *opname)
5287ad62 13715{
037e8744 13716 const struct asm_opcode *opcode;
5f4273c7 13717
21d799b5 13718 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 13719
037e8744
JB
13720 if (!opcode)
13721 abort ();
5287ad62 13722
037e8744 13723 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
13724 thumb_mode ? *opcode->tvariant : *opcode->avariant),
13725 _(BAD_FPU));
5287ad62 13726
88714cb8
DG
13727 inst.is_neon = 1;
13728
037e8744
JB
13729 if (thumb_mode)
13730 {
13731 inst.instruction = opcode->tvalue;
13732 opcode->tencode ();
13733 }
13734 else
13735 {
13736 inst.instruction = (inst.cond << 28) | opcode->avalue;
13737 opcode->aencode ();
13738 }
13739}
5287ad62
JB
13740
13741static void
037e8744 13742do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 13743{
037e8744
JB
13744 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
13745
13746 if (rs == NS_FFF)
13747 {
13748 if (is_add)
477330fc 13749 do_vfp_nsyn_opcode ("fadds");
037e8744 13750 else
477330fc 13751 do_vfp_nsyn_opcode ("fsubs");
037e8744
JB
13752 }
13753 else
13754 {
13755 if (is_add)
477330fc 13756 do_vfp_nsyn_opcode ("faddd");
037e8744 13757 else
477330fc 13758 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
13759 }
13760}
13761
13762/* Check operand types to see if this is a VFP instruction, and if so call
13763 PFN (). */
13764
13765static int
13766try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
13767{
13768 enum neon_shape rs;
13769 struct neon_type_el et;
13770
13771 switch (args)
13772 {
13773 case 2:
13774 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13775 et = neon_check_type (2, rs,
477330fc 13776 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
037e8744 13777 break;
5f4273c7 13778
037e8744
JB
13779 case 3:
13780 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13781 et = neon_check_type (3, rs,
477330fc 13782 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
037e8744
JB
13783 break;
13784
13785 default:
13786 abort ();
13787 }
13788
13789 if (et.type != NT_invtype)
13790 {
13791 pfn (rs);
13792 return SUCCESS;
13793 }
037e8744 13794
99b253c5 13795 inst.error = NULL;
037e8744
JB
13796 return FAIL;
13797}
13798
13799static void
13800do_vfp_nsyn_mla_mls (enum neon_shape rs)
13801{
13802 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 13803
037e8744
JB
13804 if (rs == NS_FFF)
13805 {
13806 if (is_mla)
477330fc 13807 do_vfp_nsyn_opcode ("fmacs");
037e8744 13808 else
477330fc 13809 do_vfp_nsyn_opcode ("fnmacs");
037e8744
JB
13810 }
13811 else
13812 {
13813 if (is_mla)
477330fc 13814 do_vfp_nsyn_opcode ("fmacd");
037e8744 13815 else
477330fc 13816 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
13817 }
13818}
13819
62f3b8c8
PB
13820static void
13821do_vfp_nsyn_fma_fms (enum neon_shape rs)
13822{
13823 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
13824
13825 if (rs == NS_FFF)
13826 {
13827 if (is_fma)
477330fc 13828 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 13829 else
477330fc 13830 do_vfp_nsyn_opcode ("ffnmas");
62f3b8c8
PB
13831 }
13832 else
13833 {
13834 if (is_fma)
477330fc 13835 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 13836 else
477330fc 13837 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
13838 }
13839}
13840
037e8744
JB
13841static void
13842do_vfp_nsyn_mul (enum neon_shape rs)
13843{
13844 if (rs == NS_FFF)
13845 do_vfp_nsyn_opcode ("fmuls");
13846 else
13847 do_vfp_nsyn_opcode ("fmuld");
13848}
13849
13850static void
13851do_vfp_nsyn_abs_neg (enum neon_shape rs)
13852{
13853 int is_neg = (inst.instruction & 0x80) != 0;
13854 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
13855
13856 if (rs == NS_FF)
13857 {
13858 if (is_neg)
477330fc 13859 do_vfp_nsyn_opcode ("fnegs");
037e8744 13860 else
477330fc 13861 do_vfp_nsyn_opcode ("fabss");
037e8744
JB
13862 }
13863 else
13864 {
13865 if (is_neg)
477330fc 13866 do_vfp_nsyn_opcode ("fnegd");
037e8744 13867 else
477330fc 13868 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
13869 }
13870}
13871
13872/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
13873 insns belong to Neon, and are handled elsewhere. */
13874
13875static void
13876do_vfp_nsyn_ldm_stm (int is_dbmode)
13877{
13878 int is_ldm = (inst.instruction & (1 << 20)) != 0;
13879 if (is_ldm)
13880 {
13881 if (is_dbmode)
477330fc 13882 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 13883 else
477330fc 13884 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
13885 }
13886 else
13887 {
13888 if (is_dbmode)
477330fc 13889 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 13890 else
477330fc 13891 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
13892 }
13893}
13894
037e8744
JB
13895static void
13896do_vfp_nsyn_sqrt (void)
13897{
13898 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13899 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13900
037e8744
JB
13901 if (rs == NS_FF)
13902 do_vfp_nsyn_opcode ("fsqrts");
13903 else
13904 do_vfp_nsyn_opcode ("fsqrtd");
13905}
13906
13907static void
13908do_vfp_nsyn_div (void)
13909{
13910 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13911 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
13912 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13913
037e8744
JB
13914 if (rs == NS_FFF)
13915 do_vfp_nsyn_opcode ("fdivs");
13916 else
13917 do_vfp_nsyn_opcode ("fdivd");
13918}
13919
13920static void
13921do_vfp_nsyn_nmul (void)
13922{
13923 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13924 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
13925 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13926
037e8744
JB
13927 if (rs == NS_FFF)
13928 {
88714cb8 13929 NEON_ENCODE (SINGLE, inst);
037e8744
JB
13930 do_vfp_sp_dyadic ();
13931 }
13932 else
13933 {
88714cb8 13934 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
13935 do_vfp_dp_rd_rn_rm ();
13936 }
13937 do_vfp_cond_or_thumb ();
13938}
13939
13940static void
13941do_vfp_nsyn_cmp (void)
13942{
13943 if (inst.operands[1].isreg)
13944 {
13945 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13946 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 13947
037e8744 13948 if (rs == NS_FF)
477330fc
RM
13949 {
13950 NEON_ENCODE (SINGLE, inst);
13951 do_vfp_sp_monadic ();
13952 }
037e8744 13953 else
477330fc
RM
13954 {
13955 NEON_ENCODE (DOUBLE, inst);
13956 do_vfp_dp_rd_rm ();
13957 }
037e8744
JB
13958 }
13959 else
13960 {
13961 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
13962 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
13963
13964 switch (inst.instruction & 0x0fffffff)
477330fc
RM
13965 {
13966 case N_MNEM_vcmp:
13967 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
13968 break;
13969 case N_MNEM_vcmpe:
13970 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
13971 break;
13972 default:
13973 abort ();
13974 }
5f4273c7 13975
037e8744 13976 if (rs == NS_FI)
477330fc
RM
13977 {
13978 NEON_ENCODE (SINGLE, inst);
13979 do_vfp_sp_compare_z ();
13980 }
037e8744 13981 else
477330fc
RM
13982 {
13983 NEON_ENCODE (DOUBLE, inst);
13984 do_vfp_dp_rd ();
13985 }
037e8744
JB
13986 }
13987 do_vfp_cond_or_thumb ();
13988}
13989
13990static void
13991nsyn_insert_sp (void)
13992{
13993 inst.operands[1] = inst.operands[0];
13994 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 13995 inst.operands[0].reg = REG_SP;
037e8744
JB
13996 inst.operands[0].isreg = 1;
13997 inst.operands[0].writeback = 1;
13998 inst.operands[0].present = 1;
13999}
14000
14001static void
14002do_vfp_nsyn_push (void)
14003{
14004 nsyn_insert_sp ();
14005 if (inst.operands[1].issingle)
14006 do_vfp_nsyn_opcode ("fstmdbs");
14007 else
14008 do_vfp_nsyn_opcode ("fstmdbd");
14009}
14010
14011static void
14012do_vfp_nsyn_pop (void)
14013{
14014 nsyn_insert_sp ();
14015 if (inst.operands[1].issingle)
22b5b651 14016 do_vfp_nsyn_opcode ("fldmias");
037e8744 14017 else
22b5b651 14018 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14019}
14020
14021/* Fix up Neon data-processing instructions, ORing in the correct bits for
14022 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14023
88714cb8
DG
14024static void
14025neon_dp_fixup (struct arm_it* insn)
037e8744 14026{
88714cb8
DG
14027 unsigned int i = insn->instruction;
14028 insn->is_neon = 1;
14029
037e8744
JB
14030 if (thumb_mode)
14031 {
14032 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14033 if (i & (1 << 24))
477330fc 14034 i |= 1 << 28;
5f4273c7 14035
037e8744 14036 i &= ~(1 << 24);
5f4273c7 14037
037e8744
JB
14038 i |= 0xef000000;
14039 }
14040 else
14041 i |= 0xf2000000;
5f4273c7 14042
88714cb8 14043 insn->instruction = i;
037e8744
JB
14044}
14045
14046/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14047 (0, 1, 2, 3). */
14048
14049static unsigned
14050neon_logbits (unsigned x)
14051{
14052 return ffs (x) - 4;
14053}
14054
14055#define LOW4(R) ((R) & 0xf)
14056#define HI1(R) (((R) >> 4) & 1)
14057
14058/* Encode insns with bit pattern:
14059
14060 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14061 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14062
037e8744
JB
14063 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14064 different meaning for some instruction. */
14065
14066static void
14067neon_three_same (int isquad, int ubit, int size)
14068{
14069 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14070 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14071 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14072 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14073 inst.instruction |= LOW4 (inst.operands[2].reg);
14074 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14075 inst.instruction |= (isquad != 0) << 6;
14076 inst.instruction |= (ubit != 0) << 24;
14077 if (size != -1)
14078 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14079
88714cb8 14080 neon_dp_fixup (&inst);
037e8744
JB
14081}
14082
14083/* Encode instructions of the form:
14084
14085 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14086 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14087
14088 Don't write size if SIZE == -1. */
14089
14090static void
14091neon_two_same (int qbit, int ubit, int size)
14092{
14093 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14094 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14095 inst.instruction |= LOW4 (inst.operands[1].reg);
14096 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14097 inst.instruction |= (qbit != 0) << 6;
14098 inst.instruction |= (ubit != 0) << 24;
14099
14100 if (size != -1)
14101 inst.instruction |= neon_logbits (size) << 18;
14102
88714cb8 14103 neon_dp_fixup (&inst);
5287ad62
JB
14104}
14105
14106/* Neon instruction encoders, in approximate order of appearance. */
14107
14108static void
14109do_neon_dyadic_i_su (void)
14110{
037e8744 14111 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14112 struct neon_type_el et = neon_check_type (3, rs,
14113 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14114 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14115}
14116
14117static void
14118do_neon_dyadic_i64_su (void)
14119{
037e8744 14120 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14121 struct neon_type_el et = neon_check_type (3, rs,
14122 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14123 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14124}
14125
14126static void
14127neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14128 unsigned immbits)
5287ad62
JB
14129{
14130 unsigned size = et.size >> 3;
14131 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14132 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14133 inst.instruction |= LOW4 (inst.operands[1].reg);
14134 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14135 inst.instruction |= (isquad != 0) << 6;
14136 inst.instruction |= immbits << 16;
14137 inst.instruction |= (size >> 3) << 7;
14138 inst.instruction |= (size & 0x7) << 19;
14139 if (write_ubit)
14140 inst.instruction |= (uval != 0) << 24;
14141
88714cb8 14142 neon_dp_fixup (&inst);
5287ad62
JB
14143}
14144
14145static void
14146do_neon_shl_imm (void)
14147{
14148 if (!inst.operands[2].isreg)
14149 {
037e8744 14150 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14151 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14152 int imm = inst.operands[2].imm;
14153
14154 constraint (imm < 0 || (unsigned)imm >= et.size,
14155 _("immediate out of range for shift"));
88714cb8 14156 NEON_ENCODE (IMMED, inst);
cb3b1e65 14157 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14158 }
14159 else
14160 {
037e8744 14161 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14162 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14163 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14164 unsigned int tmp;
14165
14166 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14167 vshl.xx Dd, Dm, Dn
14168 whereas other 3-register operations encoded by neon_three_same have
14169 syntax like:
14170 vadd.xx Dd, Dn, Dm
14171 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14172 here. */
627907b7
JB
14173 tmp = inst.operands[2].reg;
14174 inst.operands[2].reg = inst.operands[1].reg;
14175 inst.operands[1].reg = tmp;
88714cb8 14176 NEON_ENCODE (INTEGER, inst);
037e8744 14177 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14178 }
14179}
14180
14181static void
14182do_neon_qshl_imm (void)
14183{
14184 if (!inst.operands[2].isreg)
14185 {
037e8744 14186 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14187 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14188 int imm = inst.operands[2].imm;
627907b7 14189
cb3b1e65
JB
14190 constraint (imm < 0 || (unsigned)imm >= et.size,
14191 _("immediate out of range for shift"));
88714cb8 14192 NEON_ENCODE (IMMED, inst);
cb3b1e65 14193 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14194 }
14195 else
14196 {
037e8744 14197 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14198 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14199 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14200 unsigned int tmp;
14201
14202 /* See note in do_neon_shl_imm. */
14203 tmp = inst.operands[2].reg;
14204 inst.operands[2].reg = inst.operands[1].reg;
14205 inst.operands[1].reg = tmp;
88714cb8 14206 NEON_ENCODE (INTEGER, inst);
037e8744 14207 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14208 }
14209}
14210
627907b7
JB
14211static void
14212do_neon_rshl (void)
14213{
14214 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14215 struct neon_type_el et = neon_check_type (3, rs,
14216 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14217 unsigned int tmp;
14218
14219 tmp = inst.operands[2].reg;
14220 inst.operands[2].reg = inst.operands[1].reg;
14221 inst.operands[1].reg = tmp;
14222 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14223}
14224
5287ad62
JB
14225static int
14226neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14227{
036dc3f7
PB
14228 /* Handle .I8 pseudo-instructions. */
14229 if (size == 8)
5287ad62 14230 {
5287ad62 14231 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14232 FIXME is this the intended semantics? There doesn't seem much point in
14233 accepting .I8 if so. */
5287ad62
JB
14234 immediate |= immediate << 8;
14235 size = 16;
036dc3f7
PB
14236 }
14237
14238 if (size >= 32)
14239 {
14240 if (immediate == (immediate & 0x000000ff))
14241 {
14242 *immbits = immediate;
14243 return 0x1;
14244 }
14245 else if (immediate == (immediate & 0x0000ff00))
14246 {
14247 *immbits = immediate >> 8;
14248 return 0x3;
14249 }
14250 else if (immediate == (immediate & 0x00ff0000))
14251 {
14252 *immbits = immediate >> 16;
14253 return 0x5;
14254 }
14255 else if (immediate == (immediate & 0xff000000))
14256 {
14257 *immbits = immediate >> 24;
14258 return 0x7;
14259 }
14260 if ((immediate & 0xffff) != (immediate >> 16))
14261 goto bad_immediate;
14262 immediate &= 0xffff;
5287ad62
JB
14263 }
14264
14265 if (immediate == (immediate & 0x000000ff))
14266 {
14267 *immbits = immediate;
036dc3f7 14268 return 0x9;
5287ad62
JB
14269 }
14270 else if (immediate == (immediate & 0x0000ff00))
14271 {
14272 *immbits = immediate >> 8;
036dc3f7 14273 return 0xb;
5287ad62
JB
14274 }
14275
14276 bad_immediate:
dcbf9037 14277 first_error (_("immediate value out of range"));
5287ad62
JB
14278 return FAIL;
14279}
14280
5287ad62
JB
14281static void
14282do_neon_logic (void)
14283{
14284 if (inst.operands[2].present && inst.operands[2].isreg)
14285 {
037e8744 14286 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14287 neon_check_type (3, rs, N_IGNORE_TYPE);
14288 /* U bit and size field were set as part of the bitmask. */
88714cb8 14289 NEON_ENCODE (INTEGER, inst);
037e8744 14290 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14291 }
14292 else
14293 {
4316f0d2
DG
14294 const int three_ops_form = (inst.operands[2].present
14295 && !inst.operands[2].isreg);
14296 const int immoperand = (three_ops_form ? 2 : 1);
14297 enum neon_shape rs = (three_ops_form
14298 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14299 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14300 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14301 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14302 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14303 unsigned immbits;
14304 int cmode;
5f4273c7 14305
5287ad62 14306 if (et.type == NT_invtype)
477330fc 14307 return;
5f4273c7 14308
4316f0d2
DG
14309 if (three_ops_form)
14310 constraint (inst.operands[0].reg != inst.operands[1].reg,
14311 _("first and second operands shall be the same register"));
14312
88714cb8 14313 NEON_ENCODE (IMMED, inst);
5287ad62 14314
4316f0d2 14315 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14316 if (et.size == 64)
14317 {
14318 /* .i64 is a pseudo-op, so the immediate must be a repeating
14319 pattern. */
4316f0d2
DG
14320 if (immbits != (inst.operands[immoperand].regisimm ?
14321 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14322 {
14323 /* Set immbits to an invalid constant. */
14324 immbits = 0xdeadbeef;
14325 }
14326 }
14327
5287ad62 14328 switch (opcode)
477330fc
RM
14329 {
14330 case N_MNEM_vbic:
14331 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14332 break;
14333
14334 case N_MNEM_vorr:
14335 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14336 break;
14337
14338 case N_MNEM_vand:
14339 /* Pseudo-instruction for VBIC. */
14340 neon_invert_size (&immbits, 0, et.size);
14341 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14342 break;
14343
14344 case N_MNEM_vorn:
14345 /* Pseudo-instruction for VORR. */
14346 neon_invert_size (&immbits, 0, et.size);
14347 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14348 break;
14349
14350 default:
14351 abort ();
14352 }
5287ad62
JB
14353
14354 if (cmode == FAIL)
477330fc 14355 return;
5287ad62 14356
037e8744 14357 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14358 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14359 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14360 inst.instruction |= cmode << 8;
14361 neon_write_immbits (immbits);
5f4273c7 14362
88714cb8 14363 neon_dp_fixup (&inst);
5287ad62
JB
14364 }
14365}
14366
14367static void
14368do_neon_bitfield (void)
14369{
037e8744 14370 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14371 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14372 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14373}
14374
14375static void
dcbf9037 14376neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14377 unsigned destbits)
5287ad62 14378{
037e8744 14379 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14380 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14381 types | N_KEY);
5287ad62
JB
14382 if (et.type == NT_float)
14383 {
88714cb8 14384 NEON_ENCODE (FLOAT, inst);
037e8744 14385 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14386 }
14387 else
14388 {
88714cb8 14389 NEON_ENCODE (INTEGER, inst);
037e8744 14390 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14391 }
14392}
14393
14394static void
14395do_neon_dyadic_if_su (void)
14396{
dcbf9037 14397 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14398}
14399
14400static void
14401do_neon_dyadic_if_su_d (void)
14402{
14403 /* This version only allow D registers, but that constraint is enforced during
14404 operand parsing so we don't need to do anything extra here. */
dcbf9037 14405 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14406}
14407
5287ad62
JB
14408static void
14409do_neon_dyadic_if_i_d (void)
14410{
428e3f1f
PB
14411 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14412 affected if we specify unsigned args. */
14413 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14414}
14415
037e8744
JB
14416enum vfp_or_neon_is_neon_bits
14417{
14418 NEON_CHECK_CC = 1,
73924fbc
MGD
14419 NEON_CHECK_ARCH = 2,
14420 NEON_CHECK_ARCH8 = 4
037e8744
JB
14421};
14422
14423/* Call this function if an instruction which may have belonged to the VFP or
14424 Neon instruction sets, but turned out to be a Neon instruction (due to the
14425 operand types involved, etc.). We have to check and/or fix-up a couple of
14426 things:
14427
14428 - Make sure the user hasn't attempted to make a Neon instruction
14429 conditional.
14430 - Alter the value in the condition code field if necessary.
14431 - Make sure that the arch supports Neon instructions.
14432
14433 Which of these operations take place depends on bits from enum
14434 vfp_or_neon_is_neon_bits.
14435
14436 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14437 current instruction's condition is COND_ALWAYS, the condition field is
14438 changed to inst.uncond_value. This is necessary because instructions shared
14439 between VFP and Neon may be conditional for the VFP variants only, and the
14440 unconditional Neon version must have, e.g., 0xF in the condition field. */
14441
14442static int
14443vfp_or_neon_is_neon (unsigned check)
14444{
14445 /* Conditions are always legal in Thumb mode (IT blocks). */
14446 if (!thumb_mode && (check & NEON_CHECK_CC))
14447 {
14448 if (inst.cond != COND_ALWAYS)
477330fc
RM
14449 {
14450 first_error (_(BAD_COND));
14451 return FAIL;
14452 }
037e8744 14453 if (inst.uncond_value != -1)
477330fc 14454 inst.instruction |= inst.uncond_value << 28;
037e8744 14455 }
5f4273c7 14456
037e8744 14457 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14458 && !mark_feature_used (&fpu_neon_ext_v1))
14459 {
14460 first_error (_(BAD_FPU));
14461 return FAIL;
14462 }
14463
14464 if ((check & NEON_CHECK_ARCH8)
14465 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
14466 {
14467 first_error (_(BAD_FPU));
14468 return FAIL;
14469 }
5f4273c7 14470
037e8744
JB
14471 return SUCCESS;
14472}
14473
5287ad62
JB
14474static void
14475do_neon_addsub_if_i (void)
14476{
037e8744
JB
14477 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14478 return;
14479
14480 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14481 return;
14482
5287ad62
JB
14483 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14484 affected if we specify unsigned args. */
dcbf9037 14485 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
14486}
14487
14488/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14489 result to be:
14490 V<op> A,B (A is operand 0, B is operand 2)
14491 to mean:
14492 V<op> A,B,A
14493 not:
14494 V<op> A,B,B
14495 so handle that case specially. */
14496
14497static void
14498neon_exchange_operands (void)
14499{
14500 void *scratch = alloca (sizeof (inst.operands[0]));
14501 if (inst.operands[1].present)
14502 {
14503 /* Swap operands[1] and operands[2]. */
14504 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14505 inst.operands[1] = inst.operands[2];
14506 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
14507 }
14508 else
14509 {
14510 inst.operands[1] = inst.operands[2];
14511 inst.operands[2] = inst.operands[0];
14512 }
14513}
14514
14515static void
14516neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14517{
14518 if (inst.operands[2].isreg)
14519 {
14520 if (invert)
477330fc 14521 neon_exchange_operands ();
dcbf9037 14522 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
14523 }
14524 else
14525 {
037e8744 14526 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 14527 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14528 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 14529
88714cb8 14530 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14531 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14532 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14533 inst.instruction |= LOW4 (inst.operands[1].reg);
14534 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14535 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14536 inst.instruction |= (et.type == NT_float) << 10;
14537 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14538
88714cb8 14539 neon_dp_fixup (&inst);
5287ad62
JB
14540 }
14541}
14542
14543static void
14544do_neon_cmp (void)
14545{
14546 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
14547}
14548
14549static void
14550do_neon_cmp_inv (void)
14551{
14552 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
14553}
14554
14555static void
14556do_neon_ceq (void)
14557{
14558 neon_compare (N_IF_32, N_IF_32, FALSE);
14559}
14560
14561/* For multiply instructions, we have the possibility of 16-bit or 32-bit
14562 scalars, which are encoded in 5 bits, M : Rm.
14563 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
14564 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
14565 index in M. */
14566
14567static unsigned
14568neon_scalar_for_mul (unsigned scalar, unsigned elsize)
14569{
dcbf9037
JB
14570 unsigned regno = NEON_SCALAR_REG (scalar);
14571 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
14572
14573 switch (elsize)
14574 {
14575 case 16:
14576 if (regno > 7 || elno > 3)
477330fc 14577 goto bad_scalar;
5287ad62 14578 return regno | (elno << 3);
5f4273c7 14579
5287ad62
JB
14580 case 32:
14581 if (regno > 15 || elno > 1)
477330fc 14582 goto bad_scalar;
5287ad62
JB
14583 return regno | (elno << 4);
14584
14585 default:
14586 bad_scalar:
dcbf9037 14587 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
14588 }
14589
14590 return 0;
14591}
14592
14593/* Encode multiply / multiply-accumulate scalar instructions. */
14594
14595static void
14596neon_mul_mac (struct neon_type_el et, int ubit)
14597{
dcbf9037
JB
14598 unsigned scalar;
14599
14600 /* Give a more helpful error message if we have an invalid type. */
14601 if (et.type == NT_invtype)
14602 return;
5f4273c7 14603
dcbf9037 14604 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
14605 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14606 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14607 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14608 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14609 inst.instruction |= LOW4 (scalar);
14610 inst.instruction |= HI1 (scalar) << 5;
14611 inst.instruction |= (et.type == NT_float) << 8;
14612 inst.instruction |= neon_logbits (et.size) << 20;
14613 inst.instruction |= (ubit != 0) << 24;
14614
88714cb8 14615 neon_dp_fixup (&inst);
5287ad62
JB
14616}
14617
14618static void
14619do_neon_mac_maybe_scalar (void)
14620{
037e8744
JB
14621 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
14622 return;
14623
14624 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14625 return;
14626
5287ad62
JB
14627 if (inst.operands[2].isscalar)
14628 {
037e8744 14629 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 14630 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14631 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
88714cb8 14632 NEON_ENCODE (SCALAR, inst);
037e8744 14633 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
14634 }
14635 else
428e3f1f
PB
14636 {
14637 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14638 affected if we specify unsigned args. */
14639 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14640 }
5287ad62
JB
14641}
14642
62f3b8c8
PB
14643static void
14644do_neon_fmac (void)
14645{
14646 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
14647 return;
14648
14649 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14650 return;
14651
14652 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14653}
14654
5287ad62
JB
14655static void
14656do_neon_tst (void)
14657{
037e8744 14658 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14659 struct neon_type_el et = neon_check_type (3, rs,
14660 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 14661 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
14662}
14663
14664/* VMUL with 3 registers allows the P8 type. The scalar version supports the
14665 same types as the MAC equivalents. The polynomial type for this instruction
14666 is encoded the same as the integer type. */
14667
14668static void
14669do_neon_mul (void)
14670{
037e8744
JB
14671 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
14672 return;
14673
14674 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14675 return;
14676
5287ad62
JB
14677 if (inst.operands[2].isscalar)
14678 do_neon_mac_maybe_scalar ();
14679 else
dcbf9037 14680 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
14681}
14682
14683static void
14684do_neon_qdmulh (void)
14685{
14686 if (inst.operands[2].isscalar)
14687 {
037e8744 14688 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 14689 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14690 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 14691 NEON_ENCODE (SCALAR, inst);
037e8744 14692 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
14693 }
14694 else
14695 {
037e8744 14696 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14697 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14698 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 14699 NEON_ENCODE (INTEGER, inst);
5287ad62 14700 /* The U bit (rounding) comes from bit mask. */
037e8744 14701 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
14702 }
14703}
14704
14705static void
14706do_neon_fcmp_absolute (void)
14707{
037e8744 14708 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14709 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
14710 /* Size field comes from bit mask. */
037e8744 14711 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
14712}
14713
14714static void
14715do_neon_fcmp_absolute_inv (void)
14716{
14717 neon_exchange_operands ();
14718 do_neon_fcmp_absolute ();
14719}
14720
14721static void
14722do_neon_step (void)
14723{
037e8744 14724 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14725 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 14726 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14727}
14728
14729static void
14730do_neon_abs_neg (void)
14731{
037e8744
JB
14732 enum neon_shape rs;
14733 struct neon_type_el et;
5f4273c7 14734
037e8744
JB
14735 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
14736 return;
14737
14738 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14739 return;
14740
14741 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14742 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 14743
5287ad62
JB
14744 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14745 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14746 inst.instruction |= LOW4 (inst.operands[1].reg);
14747 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14748 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14749 inst.instruction |= (et.type == NT_float) << 10;
14750 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14751
88714cb8 14752 neon_dp_fixup (&inst);
5287ad62
JB
14753}
14754
14755static void
14756do_neon_sli (void)
14757{
037e8744 14758 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14759 struct neon_type_el et = neon_check_type (2, rs,
14760 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14761 int imm = inst.operands[2].imm;
14762 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 14763 _("immediate out of range for insert"));
037e8744 14764 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14765}
14766
14767static void
14768do_neon_sri (void)
14769{
037e8744 14770 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14771 struct neon_type_el et = neon_check_type (2, rs,
14772 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14773 int imm = inst.operands[2].imm;
14774 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 14775 _("immediate out of range for insert"));
037e8744 14776 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
14777}
14778
14779static void
14780do_neon_qshlu_imm (void)
14781{
037e8744 14782 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14783 struct neon_type_el et = neon_check_type (2, rs,
14784 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
14785 int imm = inst.operands[2].imm;
14786 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 14787 _("immediate out of range for shift"));
5287ad62
JB
14788 /* Only encodes the 'U present' variant of the instruction.
14789 In this case, signed types have OP (bit 8) set to 0.
14790 Unsigned types have OP set to 1. */
14791 inst.instruction |= (et.type == NT_unsigned) << 8;
14792 /* The rest of the bits are the same as other immediate shifts. */
037e8744 14793 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14794}
14795
14796static void
14797do_neon_qmovn (void)
14798{
14799 struct neon_type_el et = neon_check_type (2, NS_DQ,
14800 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14801 /* Saturating move where operands can be signed or unsigned, and the
14802 destination has the same signedness. */
88714cb8 14803 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14804 if (et.type == NT_unsigned)
14805 inst.instruction |= 0xc0;
14806 else
14807 inst.instruction |= 0x80;
14808 neon_two_same (0, 1, et.size / 2);
14809}
14810
14811static void
14812do_neon_qmovun (void)
14813{
14814 struct neon_type_el et = neon_check_type (2, NS_DQ,
14815 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14816 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 14817 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14818 neon_two_same (0, 1, et.size / 2);
14819}
14820
14821static void
14822do_neon_rshift_sat_narrow (void)
14823{
14824 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14825 or unsigned. If operands are unsigned, results must also be unsigned. */
14826 struct neon_type_el et = neon_check_type (2, NS_DQI,
14827 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14828 int imm = inst.operands[2].imm;
14829 /* This gets the bounds check, size encoding and immediate bits calculation
14830 right. */
14831 et.size /= 2;
5f4273c7 14832
5287ad62
JB
14833 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
14834 VQMOVN.I<size> <Dd>, <Qm>. */
14835 if (imm == 0)
14836 {
14837 inst.operands[2].present = 0;
14838 inst.instruction = N_MNEM_vqmovn;
14839 do_neon_qmovn ();
14840 return;
14841 }
5f4273c7 14842
5287ad62 14843 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 14844 _("immediate out of range"));
5287ad62
JB
14845 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
14846}
14847
14848static void
14849do_neon_rshift_sat_narrow_u (void)
14850{
14851 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14852 or unsigned. If operands are unsigned, results must also be unsigned. */
14853 struct neon_type_el et = neon_check_type (2, NS_DQI,
14854 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14855 int imm = inst.operands[2].imm;
14856 /* This gets the bounds check, size encoding and immediate bits calculation
14857 right. */
14858 et.size /= 2;
14859
14860 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
14861 VQMOVUN.I<size> <Dd>, <Qm>. */
14862 if (imm == 0)
14863 {
14864 inst.operands[2].present = 0;
14865 inst.instruction = N_MNEM_vqmovun;
14866 do_neon_qmovun ();
14867 return;
14868 }
14869
14870 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 14871 _("immediate out of range"));
5287ad62
JB
14872 /* FIXME: The manual is kind of unclear about what value U should have in
14873 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
14874 must be 1. */
14875 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
14876}
14877
14878static void
14879do_neon_movn (void)
14880{
14881 struct neon_type_el et = neon_check_type (2, NS_DQ,
14882 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 14883 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14884 neon_two_same (0, 1, et.size / 2);
14885}
14886
14887static void
14888do_neon_rshift_narrow (void)
14889{
14890 struct neon_type_el et = neon_check_type (2, NS_DQI,
14891 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
14892 int imm = inst.operands[2].imm;
14893 /* This gets the bounds check, size encoding and immediate bits calculation
14894 right. */
14895 et.size /= 2;
5f4273c7 14896
5287ad62
JB
14897 /* If immediate is zero then we are a pseudo-instruction for
14898 VMOVN.I<size> <Dd>, <Qm> */
14899 if (imm == 0)
14900 {
14901 inst.operands[2].present = 0;
14902 inst.instruction = N_MNEM_vmovn;
14903 do_neon_movn ();
14904 return;
14905 }
5f4273c7 14906
5287ad62 14907 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 14908 _("immediate out of range for narrowing operation"));
5287ad62
JB
14909 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
14910}
14911
14912static void
14913do_neon_shll (void)
14914{
14915 /* FIXME: Type checking when lengthening. */
14916 struct neon_type_el et = neon_check_type (2, NS_QDI,
14917 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
14918 unsigned imm = inst.operands[2].imm;
14919
14920 if (imm == et.size)
14921 {
14922 /* Maximum shift variant. */
88714cb8 14923 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14924 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14925 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14926 inst.instruction |= LOW4 (inst.operands[1].reg);
14927 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14928 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14929
88714cb8 14930 neon_dp_fixup (&inst);
5287ad62
JB
14931 }
14932 else
14933 {
14934 /* A more-specific type check for non-max versions. */
14935 et = neon_check_type (2, NS_QDI,
477330fc 14936 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 14937 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14938 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
14939 }
14940}
14941
037e8744 14942/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
14943 the current instruction is. */
14944
6b9a8b67
MGD
14945#define CVT_FLAVOUR_VAR \
14946 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
14947 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
14948 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
14949 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
14950 /* Half-precision conversions. */ \
14951 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
14952 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
14953 /* VFP instructions. */ \
14954 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
14955 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
14956 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
14957 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
14958 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
14959 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
14960 /* VFP instructions with bitshift. */ \
14961 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
14962 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
14963 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
14964 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
14965 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
14966 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
14967 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
14968 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
14969
14970#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
14971 neon_cvt_flavour_##C,
14972
14973/* The different types of conversions we can do. */
14974enum neon_cvt_flavour
14975{
14976 CVT_FLAVOUR_VAR
14977 neon_cvt_flavour_invalid,
14978 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
14979};
14980
14981#undef CVT_VAR
14982
14983static enum neon_cvt_flavour
14984get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 14985{
6b9a8b67
MGD
14986#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
14987 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
14988 if (et.type != NT_invtype) \
14989 { \
14990 inst.error = NULL; \
14991 return (neon_cvt_flavour_##C); \
5287ad62 14992 }
6b9a8b67 14993
5287ad62 14994 struct neon_type_el et;
037e8744 14995 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 14996 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
14997 /* The instruction versions which take an immediate take one register
14998 argument, which is extended to the width of the full register. Thus the
14999 "source" and "destination" registers must have the same width. Hack that
15000 here by making the size equal to the key (wider, in this case) operand. */
15001 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15002
6b9a8b67
MGD
15003 CVT_FLAVOUR_VAR;
15004
15005 return neon_cvt_flavour_invalid;
5287ad62
JB
15006#undef CVT_VAR
15007}
15008
7e8e6784
MGD
15009enum neon_cvt_mode
15010{
15011 neon_cvt_mode_a,
15012 neon_cvt_mode_n,
15013 neon_cvt_mode_p,
15014 neon_cvt_mode_m,
15015 neon_cvt_mode_z,
30bdf752
MGD
15016 neon_cvt_mode_x,
15017 neon_cvt_mode_r
7e8e6784
MGD
15018};
15019
037e8744
JB
15020/* Neon-syntax VFP conversions. */
15021
5287ad62 15022static void
6b9a8b67 15023do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15024{
037e8744 15025 const char *opname = 0;
5f4273c7 15026
037e8744 15027 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 15028 {
037e8744
JB
15029 /* Conversions with immediate bitshift. */
15030 const char *enc[] =
477330fc 15031 {
6b9a8b67
MGD
15032#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15033 CVT_FLAVOUR_VAR
15034 NULL
15035#undef CVT_VAR
477330fc 15036 };
037e8744 15037
6b9a8b67 15038 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15039 {
15040 opname = enc[flavour];
15041 constraint (inst.operands[0].reg != inst.operands[1].reg,
15042 _("operands 0 and 1 must be the same register"));
15043 inst.operands[1] = inst.operands[2];
15044 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15045 }
5287ad62
JB
15046 }
15047 else
15048 {
037e8744
JB
15049 /* Conversions without bitshift. */
15050 const char *enc[] =
477330fc 15051 {
6b9a8b67
MGD
15052#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15053 CVT_FLAVOUR_VAR
15054 NULL
15055#undef CVT_VAR
477330fc 15056 };
037e8744 15057
6b9a8b67 15058 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15059 opname = enc[flavour];
037e8744
JB
15060 }
15061
15062 if (opname)
15063 do_vfp_nsyn_opcode (opname);
15064}
15065
15066static void
15067do_vfp_nsyn_cvtz (void)
15068{
15069 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
6b9a8b67 15070 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15071 const char *enc[] =
15072 {
6b9a8b67
MGD
15073#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15074 CVT_FLAVOUR_VAR
15075 NULL
15076#undef CVT_VAR
037e8744
JB
15077 };
15078
6b9a8b67 15079 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15080 do_vfp_nsyn_opcode (enc[flavour]);
15081}
f31fef98 15082
037e8744 15083static void
bacebabc 15084do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15085 enum neon_cvt_mode mode)
15086{
15087 int sz, op;
15088 int rm;
15089
a715796b
TG
15090 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15091 D register operands. */
15092 if (flavour == neon_cvt_flavour_s32_f64
15093 || flavour == neon_cvt_flavour_u32_f64)
15094 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15095 _(BAD_FPU));
15096
7e8e6784
MGD
15097 set_it_insn_type (OUTSIDE_IT_INSN);
15098
15099 switch (flavour)
15100 {
15101 case neon_cvt_flavour_s32_f64:
15102 sz = 1;
827f64ff 15103 op = 1;
7e8e6784
MGD
15104 break;
15105 case neon_cvt_flavour_s32_f32:
15106 sz = 0;
15107 op = 1;
15108 break;
15109 case neon_cvt_flavour_u32_f64:
15110 sz = 1;
15111 op = 0;
15112 break;
15113 case neon_cvt_flavour_u32_f32:
15114 sz = 0;
15115 op = 0;
15116 break;
15117 default:
15118 first_error (_("invalid instruction shape"));
15119 return;
15120 }
15121
15122 switch (mode)
15123 {
15124 case neon_cvt_mode_a: rm = 0; break;
15125 case neon_cvt_mode_n: rm = 1; break;
15126 case neon_cvt_mode_p: rm = 2; break;
15127 case neon_cvt_mode_m: rm = 3; break;
15128 default: first_error (_("invalid rounding mode")); return;
15129 }
15130
15131 NEON_ENCODE (FPV8, inst);
15132 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15133 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15134 inst.instruction |= sz << 8;
15135 inst.instruction |= op << 7;
15136 inst.instruction |= rm << 16;
15137 inst.instruction |= 0xf0000000;
15138 inst.is_neon = TRUE;
15139}
15140
15141static void
15142do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15143{
15144 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 15145 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
6b9a8b67 15146 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15147
e3e535bc 15148 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15149 if (mode == neon_cvt_mode_z
e3e535bc 15150 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
bacebabc
RM
15151 && (flavour == neon_cvt_flavour_s32_f32
15152 || flavour == neon_cvt_flavour_u32_f32
15153 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15154 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15155 && (rs == NS_FD || rs == NS_FF))
15156 {
15157 do_vfp_nsyn_cvtz ();
15158 return;
15159 }
15160
037e8744 15161 /* VFP rather than Neon conversions. */
6b9a8b67 15162 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15163 {
7e8e6784
MGD
15164 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15165 do_vfp_nsyn_cvt (rs, flavour);
15166 else
15167 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15168
037e8744
JB
15169 return;
15170 }
15171
15172 switch (rs)
15173 {
15174 case NS_DDI:
15175 case NS_QQI:
15176 {
477330fc
RM
15177 unsigned immbits;
15178 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
35997600 15179
477330fc
RM
15180 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15181 return;
037e8744 15182
477330fc
RM
15183 /* Fixed-point conversion with #0 immediate is encoded as an
15184 integer conversion. */
15185 if (inst.operands[2].present && inst.operands[2].imm == 0)
15186 goto int_encode;
35997600 15187 immbits = 32 - inst.operands[2].imm;
477330fc
RM
15188 NEON_ENCODE (IMMED, inst);
15189 if (flavour != neon_cvt_flavour_invalid)
15190 inst.instruction |= enctab[flavour];
15191 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15192 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15193 inst.instruction |= LOW4 (inst.operands[1].reg);
15194 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15195 inst.instruction |= neon_quad (rs) << 6;
15196 inst.instruction |= 1 << 21;
15197 inst.instruction |= immbits << 16;
15198
15199 neon_dp_fixup (&inst);
037e8744
JB
15200 }
15201 break;
15202
15203 case NS_DD:
15204 case NS_QQ:
7e8e6784
MGD
15205 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15206 {
15207 NEON_ENCODE (FLOAT, inst);
15208 set_it_insn_type (OUTSIDE_IT_INSN);
15209
15210 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15211 return;
15212
15213 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15214 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15215 inst.instruction |= LOW4 (inst.operands[1].reg);
15216 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15217 inst.instruction |= neon_quad (rs) << 6;
15218 inst.instruction |= (flavour == neon_cvt_flavour_u32_f32) << 7;
15219 inst.instruction |= mode << 8;
15220 if (thumb_mode)
15221 inst.instruction |= 0xfc000000;
15222 else
15223 inst.instruction |= 0xf0000000;
15224 }
15225 else
15226 {
037e8744 15227 int_encode:
7e8e6784
MGD
15228 {
15229 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
037e8744 15230
7e8e6784 15231 NEON_ENCODE (INTEGER, inst);
037e8744 15232
7e8e6784
MGD
15233 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15234 return;
037e8744 15235
7e8e6784
MGD
15236 if (flavour != neon_cvt_flavour_invalid)
15237 inst.instruction |= enctab[flavour];
037e8744 15238
7e8e6784
MGD
15239 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15240 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15241 inst.instruction |= LOW4 (inst.operands[1].reg);
15242 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15243 inst.instruction |= neon_quad (rs) << 6;
15244 inst.instruction |= 2 << 18;
037e8744 15245
7e8e6784
MGD
15246 neon_dp_fixup (&inst);
15247 }
15248 }
15249 break;
037e8744 15250
8e79c3df
CM
15251 /* Half-precision conversions for Advanced SIMD -- neon. */
15252 case NS_QD:
15253 case NS_DQ:
15254
15255 if ((rs == NS_DQ)
15256 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15257 {
15258 as_bad (_("operand size must match register width"));
15259 break;
15260 }
15261
15262 if ((rs == NS_QD)
15263 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15264 {
15265 as_bad (_("operand size must match register width"));
15266 break;
15267 }
15268
15269 if (rs == NS_DQ)
477330fc 15270 inst.instruction = 0x3b60600;
8e79c3df
CM
15271 else
15272 inst.instruction = 0x3b60700;
15273
15274 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15275 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15276 inst.instruction |= LOW4 (inst.operands[1].reg);
15277 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15278 neon_dp_fixup (&inst);
8e79c3df
CM
15279 break;
15280
037e8744
JB
15281 default:
15282 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15283 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15284 do_vfp_nsyn_cvt (rs, flavour);
15285 else
15286 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15287 }
5287ad62
JB
15288}
15289
e3e535bc
NC
15290static void
15291do_neon_cvtr (void)
15292{
7e8e6784 15293 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15294}
15295
15296static void
15297do_neon_cvt (void)
15298{
7e8e6784
MGD
15299 do_neon_cvt_1 (neon_cvt_mode_z);
15300}
15301
15302static void
15303do_neon_cvta (void)
15304{
15305 do_neon_cvt_1 (neon_cvt_mode_a);
15306}
15307
15308static void
15309do_neon_cvtn (void)
15310{
15311 do_neon_cvt_1 (neon_cvt_mode_n);
15312}
15313
15314static void
15315do_neon_cvtp (void)
15316{
15317 do_neon_cvt_1 (neon_cvt_mode_p);
15318}
15319
15320static void
15321do_neon_cvtm (void)
15322{
15323 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15324}
15325
8e79c3df 15326static void
c70a8987 15327do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15328{
c70a8987
MGD
15329 if (is_double)
15330 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15331
c70a8987
MGD
15332 encode_arm_vfp_reg (inst.operands[0].reg,
15333 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15334 encode_arm_vfp_reg (inst.operands[1].reg,
15335 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15336 inst.instruction |= to ? 0x10000 : 0;
15337 inst.instruction |= t ? 0x80 : 0;
15338 inst.instruction |= is_double ? 0x100 : 0;
15339 do_vfp_cond_or_thumb ();
15340}
8e79c3df 15341
c70a8987
MGD
15342static void
15343do_neon_cvttb_1 (bfd_boolean t)
15344{
15345 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_DF, NS_NULL);
8e79c3df 15346
c70a8987
MGD
15347 if (rs == NS_NULL)
15348 return;
15349 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
15350 {
15351 inst.error = NULL;
15352 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
15353 }
15354 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
15355 {
15356 inst.error = NULL;
15357 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
15358 }
15359 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
15360 {
a715796b
TG
15361 /* The VCVTB and VCVTT instructions with D-register operands
15362 don't work for SP only targets. */
15363 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15364 _(BAD_FPU));
15365
c70a8987
MGD
15366 inst.error = NULL;
15367 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
15368 }
15369 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
15370 {
a715796b
TG
15371 /* The VCVTB and VCVTT instructions with D-register operands
15372 don't work for SP only targets. */
15373 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15374 _(BAD_FPU));
15375
c70a8987
MGD
15376 inst.error = NULL;
15377 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
15378 }
15379 else
15380 return;
15381}
15382
15383static void
15384do_neon_cvtb (void)
15385{
15386 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
15387}
15388
15389
15390static void
15391do_neon_cvtt (void)
15392{
c70a8987 15393 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
15394}
15395
5287ad62
JB
15396static void
15397neon_move_immediate (void)
15398{
037e8744
JB
15399 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
15400 struct neon_type_el et = neon_check_type (2, rs,
15401 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 15402 unsigned immlo, immhi = 0, immbits;
c96612cc 15403 int op, cmode, float_p;
5287ad62 15404
037e8744 15405 constraint (et.type == NT_invtype,
477330fc 15406 _("operand size must be specified for immediate VMOV"));
037e8744 15407
5287ad62
JB
15408 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
15409 op = (inst.instruction & (1 << 5)) != 0;
15410
15411 immlo = inst.operands[1].imm;
15412 if (inst.operands[1].regisimm)
15413 immhi = inst.operands[1].reg;
15414
15415 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 15416 _("immediate has bits set outside the operand size"));
5287ad62 15417
c96612cc
JB
15418 float_p = inst.operands[1].immisfloat;
15419
15420 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 15421 et.size, et.type)) == FAIL)
5287ad62
JB
15422 {
15423 /* Invert relevant bits only. */
15424 neon_invert_size (&immlo, &immhi, et.size);
15425 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
15426 with one or the other; those cases are caught by
15427 neon_cmode_for_move_imm. */
5287ad62 15428 op = !op;
c96612cc
JB
15429 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
15430 &op, et.size, et.type)) == FAIL)
477330fc
RM
15431 {
15432 first_error (_("immediate out of range"));
15433 return;
15434 }
5287ad62
JB
15435 }
15436
15437 inst.instruction &= ~(1 << 5);
15438 inst.instruction |= op << 5;
15439
15440 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15441 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 15442 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15443 inst.instruction |= cmode << 8;
15444
15445 neon_write_immbits (immbits);
15446}
15447
15448static void
15449do_neon_mvn (void)
15450{
15451 if (inst.operands[1].isreg)
15452 {
037e8744 15453 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 15454
88714cb8 15455 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15456 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15457 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15458 inst.instruction |= LOW4 (inst.operands[1].reg);
15459 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15460 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15461 }
15462 else
15463 {
88714cb8 15464 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15465 neon_move_immediate ();
15466 }
15467
88714cb8 15468 neon_dp_fixup (&inst);
5287ad62
JB
15469}
15470
15471/* Encode instructions of form:
15472
15473 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 15474 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
15475
15476static void
15477neon_mixed_length (struct neon_type_el et, unsigned size)
15478{
15479 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15480 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15481 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15482 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15483 inst.instruction |= LOW4 (inst.operands[2].reg);
15484 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15485 inst.instruction |= (et.type == NT_unsigned) << 24;
15486 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 15487
88714cb8 15488 neon_dp_fixup (&inst);
5287ad62
JB
15489}
15490
15491static void
15492do_neon_dyadic_long (void)
15493{
15494 /* FIXME: Type checking for lengthening op. */
15495 struct neon_type_el et = neon_check_type (3, NS_QDD,
15496 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
15497 neon_mixed_length (et, et.size);
15498}
15499
15500static void
15501do_neon_abal (void)
15502{
15503 struct neon_type_el et = neon_check_type (3, NS_QDD,
15504 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
15505 neon_mixed_length (et, et.size);
15506}
15507
15508static void
15509neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
15510{
15511 if (inst.operands[2].isscalar)
15512 {
dcbf9037 15513 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 15514 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 15515 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
15516 neon_mul_mac (et, et.type == NT_unsigned);
15517 }
15518 else
15519 {
15520 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 15521 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 15522 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15523 neon_mixed_length (et, et.size);
15524 }
15525}
15526
15527static void
15528do_neon_mac_maybe_scalar_long (void)
15529{
15530 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
15531}
15532
15533static void
15534do_neon_dyadic_wide (void)
15535{
15536 struct neon_type_el et = neon_check_type (3, NS_QQD,
15537 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
15538 neon_mixed_length (et, et.size);
15539}
15540
15541static void
15542do_neon_dyadic_narrow (void)
15543{
15544 struct neon_type_el et = neon_check_type (3, NS_QDD,
15545 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
15546 /* Operand sign is unimportant, and the U bit is part of the opcode,
15547 so force the operand type to integer. */
15548 et.type = NT_integer;
5287ad62
JB
15549 neon_mixed_length (et, et.size / 2);
15550}
15551
15552static void
15553do_neon_mul_sat_scalar_long (void)
15554{
15555 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
15556}
15557
15558static void
15559do_neon_vmull (void)
15560{
15561 if (inst.operands[2].isscalar)
15562 do_neon_mac_maybe_scalar_long ();
15563 else
15564 {
15565 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 15566 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 15567
5287ad62 15568 if (et.type == NT_poly)
477330fc 15569 NEON_ENCODE (POLY, inst);
5287ad62 15570 else
477330fc 15571 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
15572
15573 /* For polynomial encoding the U bit must be zero, and the size must
15574 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
15575 obviously, as 0b10). */
15576 if (et.size == 64)
15577 {
15578 /* Check we're on the correct architecture. */
15579 if (!mark_feature_used (&fpu_crypto_ext_armv8))
15580 inst.error =
15581 _("Instruction form not available on this architecture.");
15582
15583 et.size = 32;
15584 }
15585
5287ad62
JB
15586 neon_mixed_length (et, et.size);
15587 }
15588}
15589
15590static void
15591do_neon_ext (void)
15592{
037e8744 15593 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
15594 struct neon_type_el et = neon_check_type (3, rs,
15595 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15596 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
15597
15598 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
15599 _("shift out of range"));
5287ad62
JB
15600 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15601 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15602 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15603 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15604 inst.instruction |= LOW4 (inst.operands[2].reg);
15605 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 15606 inst.instruction |= neon_quad (rs) << 6;
5287ad62 15607 inst.instruction |= imm << 8;
5f4273c7 15608
88714cb8 15609 neon_dp_fixup (&inst);
5287ad62
JB
15610}
15611
15612static void
15613do_neon_rev (void)
15614{
037e8744 15615 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15616 struct neon_type_el et = neon_check_type (2, rs,
15617 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15618 unsigned op = (inst.instruction >> 7) & 3;
15619 /* N (width of reversed regions) is encoded as part of the bitmask. We
15620 extract it here to check the elements to be reversed are smaller.
15621 Otherwise we'd get a reserved instruction. */
15622 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 15623 gas_assert (elsize != 0);
5287ad62 15624 constraint (et.size >= elsize,
477330fc 15625 _("elements must be smaller than reversal region"));
037e8744 15626 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15627}
15628
15629static void
15630do_neon_dup (void)
15631{
15632 if (inst.operands[1].isscalar)
15633 {
037e8744 15634 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 15635 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15636 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 15637 unsigned sizebits = et.size >> 3;
dcbf9037 15638 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 15639 int logsize = neon_logbits (et.size);
dcbf9037 15640 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
15641
15642 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 15643 return;
037e8744 15644
88714cb8 15645 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
15646 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15647 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15648 inst.instruction |= LOW4 (dm);
15649 inst.instruction |= HI1 (dm) << 5;
037e8744 15650 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15651 inst.instruction |= x << 17;
15652 inst.instruction |= sizebits << 16;
5f4273c7 15653
88714cb8 15654 neon_dp_fixup (&inst);
5287ad62
JB
15655 }
15656 else
15657 {
037e8744
JB
15658 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
15659 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15660 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 15661 /* Duplicate ARM register to lanes of vector. */
88714cb8 15662 NEON_ENCODE (ARMREG, inst);
5287ad62 15663 switch (et.size)
477330fc
RM
15664 {
15665 case 8: inst.instruction |= 0x400000; break;
15666 case 16: inst.instruction |= 0x000020; break;
15667 case 32: inst.instruction |= 0x000000; break;
15668 default: break;
15669 }
5287ad62
JB
15670 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15671 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
15672 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 15673 inst.instruction |= neon_quad (rs) << 21;
5287ad62 15674 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 15675 variants, except for the condition field. */
037e8744 15676 do_vfp_cond_or_thumb ();
5287ad62
JB
15677 }
15678}
15679
15680/* VMOV has particularly many variations. It can be one of:
15681 0. VMOV<c><q> <Qd>, <Qm>
15682 1. VMOV<c><q> <Dd>, <Dm>
15683 (Register operations, which are VORR with Rm = Rn.)
15684 2. VMOV<c><q>.<dt> <Qd>, #<imm>
15685 3. VMOV<c><q>.<dt> <Dd>, #<imm>
15686 (Immediate loads.)
15687 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
15688 (ARM register to scalar.)
15689 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
15690 (Two ARM registers to vector.)
15691 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
15692 (Scalar to ARM register.)
15693 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
15694 (Vector to two ARM registers.)
037e8744
JB
15695 8. VMOV.F32 <Sd>, <Sm>
15696 9. VMOV.F64 <Dd>, <Dm>
15697 (VFP register moves.)
15698 10. VMOV.F32 <Sd>, #imm
15699 11. VMOV.F64 <Dd>, #imm
15700 (VFP float immediate load.)
15701 12. VMOV <Rd>, <Sm>
15702 (VFP single to ARM reg.)
15703 13. VMOV <Sd>, <Rm>
15704 (ARM reg to VFP single.)
15705 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
15706 (Two ARM regs to two VFP singles.)
15707 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
15708 (Two VFP singles to two ARM regs.)
5f4273c7 15709
037e8744
JB
15710 These cases can be disambiguated using neon_select_shape, except cases 1/9
15711 and 3/11 which depend on the operand type too.
5f4273c7 15712
5287ad62 15713 All the encoded bits are hardcoded by this function.
5f4273c7 15714
b7fc2769
JB
15715 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
15716 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 15717
5287ad62 15718 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 15719 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
15720
15721static void
15722do_neon_mov (void)
15723{
037e8744
JB
15724 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
15725 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
15726 NS_NULL);
15727 struct neon_type_el et;
15728 const char *ldconst = 0;
5287ad62 15729
037e8744 15730 switch (rs)
5287ad62 15731 {
037e8744
JB
15732 case NS_DD: /* case 1/9. */
15733 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15734 /* It is not an error here if no type is given. */
15735 inst.error = NULL;
15736 if (et.type == NT_float && et.size == 64)
477330fc
RM
15737 {
15738 do_vfp_nsyn_opcode ("fcpyd");
15739 break;
15740 }
037e8744 15741 /* fall through. */
5287ad62 15742
037e8744
JB
15743 case NS_QQ: /* case 0/1. */
15744 {
477330fc
RM
15745 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15746 return;
15747 /* The architecture manual I have doesn't explicitly state which
15748 value the U bit should have for register->register moves, but
15749 the equivalent VORR instruction has U = 0, so do that. */
15750 inst.instruction = 0x0200110;
15751 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15752 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15753 inst.instruction |= LOW4 (inst.operands[1].reg);
15754 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15755 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15756 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15757 inst.instruction |= neon_quad (rs) << 6;
15758
15759 neon_dp_fixup (&inst);
037e8744
JB
15760 }
15761 break;
5f4273c7 15762
037e8744
JB
15763 case NS_DI: /* case 3/11. */
15764 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15765 inst.error = NULL;
15766 if (et.type == NT_float && et.size == 64)
477330fc
RM
15767 {
15768 /* case 11 (fconstd). */
15769 ldconst = "fconstd";
15770 goto encode_fconstd;
15771 }
037e8744
JB
15772 /* fall through. */
15773
15774 case NS_QI: /* case 2/3. */
15775 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 15776 return;
037e8744
JB
15777 inst.instruction = 0x0800010;
15778 neon_move_immediate ();
88714cb8 15779 neon_dp_fixup (&inst);
5287ad62 15780 break;
5f4273c7 15781
037e8744
JB
15782 case NS_SR: /* case 4. */
15783 {
477330fc
RM
15784 unsigned bcdebits = 0;
15785 int logsize;
15786 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
15787 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 15788
05ac0ffb
JB
15789 /* .<size> is optional here, defaulting to .32. */
15790 if (inst.vectype.elems == 0
15791 && inst.operands[0].vectype.type == NT_invtype
15792 && inst.operands[1].vectype.type == NT_invtype)
15793 {
15794 inst.vectype.el[0].type = NT_untyped;
15795 inst.vectype.el[0].size = 32;
15796 inst.vectype.elems = 1;
15797 }
15798
477330fc
RM
15799 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
15800 logsize = neon_logbits (et.size);
15801
15802 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15803 _(BAD_FPU));
15804 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15805 && et.size != 32, _(BAD_FPU));
15806 constraint (et.type == NT_invtype, _("bad type for scalar"));
15807 constraint (x >= 64 / et.size, _("scalar index out of range"));
15808
15809 switch (et.size)
15810 {
15811 case 8: bcdebits = 0x8; break;
15812 case 16: bcdebits = 0x1; break;
15813 case 32: bcdebits = 0x0; break;
15814 default: ;
15815 }
15816
15817 bcdebits |= x << logsize;
15818
15819 inst.instruction = 0xe000b10;
15820 do_vfp_cond_or_thumb ();
15821 inst.instruction |= LOW4 (dn) << 16;
15822 inst.instruction |= HI1 (dn) << 7;
15823 inst.instruction |= inst.operands[1].reg << 12;
15824 inst.instruction |= (bcdebits & 3) << 5;
15825 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
15826 }
15827 break;
5f4273c7 15828
037e8744 15829 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 15830 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 15831 _(BAD_FPU));
b7fc2769 15832
037e8744
JB
15833 inst.instruction = 0xc400b10;
15834 do_vfp_cond_or_thumb ();
15835 inst.instruction |= LOW4 (inst.operands[0].reg);
15836 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
15837 inst.instruction |= inst.operands[1].reg << 12;
15838 inst.instruction |= inst.operands[2].reg << 16;
15839 break;
5f4273c7 15840
037e8744
JB
15841 case NS_RS: /* case 6. */
15842 {
477330fc
RM
15843 unsigned logsize;
15844 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
15845 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
15846 unsigned abcdebits = 0;
037e8744 15847
05ac0ffb
JB
15848 /* .<dt> is optional here, defaulting to .32. */
15849 if (inst.vectype.elems == 0
15850 && inst.operands[0].vectype.type == NT_invtype
15851 && inst.operands[1].vectype.type == NT_invtype)
15852 {
15853 inst.vectype.el[0].type = NT_untyped;
15854 inst.vectype.el[0].size = 32;
15855 inst.vectype.elems = 1;
15856 }
15857
91d6fa6a
NC
15858 et = neon_check_type (2, NS_NULL,
15859 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
15860 logsize = neon_logbits (et.size);
15861
15862 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15863 _(BAD_FPU));
15864 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15865 && et.size != 32, _(BAD_FPU));
15866 constraint (et.type == NT_invtype, _("bad type for scalar"));
15867 constraint (x >= 64 / et.size, _("scalar index out of range"));
15868
15869 switch (et.size)
15870 {
15871 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
15872 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
15873 case 32: abcdebits = 0x00; break;
15874 default: ;
15875 }
15876
15877 abcdebits |= x << logsize;
15878 inst.instruction = 0xe100b10;
15879 do_vfp_cond_or_thumb ();
15880 inst.instruction |= LOW4 (dn) << 16;
15881 inst.instruction |= HI1 (dn) << 7;
15882 inst.instruction |= inst.operands[0].reg << 12;
15883 inst.instruction |= (abcdebits & 3) << 5;
15884 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
15885 }
15886 break;
5f4273c7 15887
037e8744
JB
15888 case NS_RRD: /* case 7 (fmrrd). */
15889 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 15890 _(BAD_FPU));
037e8744
JB
15891
15892 inst.instruction = 0xc500b10;
15893 do_vfp_cond_or_thumb ();
15894 inst.instruction |= inst.operands[0].reg << 12;
15895 inst.instruction |= inst.operands[1].reg << 16;
15896 inst.instruction |= LOW4 (inst.operands[2].reg);
15897 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15898 break;
5f4273c7 15899
037e8744
JB
15900 case NS_FF: /* case 8 (fcpys). */
15901 do_vfp_nsyn_opcode ("fcpys");
15902 break;
5f4273c7 15903
037e8744
JB
15904 case NS_FI: /* case 10 (fconsts). */
15905 ldconst = "fconsts";
15906 encode_fconstd:
15907 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
15908 {
15909 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
15910 do_vfp_nsyn_opcode (ldconst);
15911 }
5287ad62 15912 else
477330fc 15913 first_error (_("immediate out of range"));
037e8744 15914 break;
5f4273c7 15915
037e8744
JB
15916 case NS_RF: /* case 12 (fmrs). */
15917 do_vfp_nsyn_opcode ("fmrs");
15918 break;
5f4273c7 15919
037e8744
JB
15920 case NS_FR: /* case 13 (fmsr). */
15921 do_vfp_nsyn_opcode ("fmsr");
15922 break;
5f4273c7 15923
037e8744
JB
15924 /* The encoders for the fmrrs and fmsrr instructions expect three operands
15925 (one of which is a list), but we have parsed four. Do some fiddling to
15926 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
15927 expect. */
15928 case NS_RRFF: /* case 14 (fmrrs). */
15929 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 15930 _("VFP registers must be adjacent"));
037e8744
JB
15931 inst.operands[2].imm = 2;
15932 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
15933 do_vfp_nsyn_opcode ("fmrrs");
15934 break;
5f4273c7 15935
037e8744
JB
15936 case NS_FFRR: /* case 15 (fmsrr). */
15937 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 15938 _("VFP registers must be adjacent"));
037e8744
JB
15939 inst.operands[1] = inst.operands[2];
15940 inst.operands[2] = inst.operands[3];
15941 inst.operands[0].imm = 2;
15942 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
15943 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 15944 break;
5f4273c7 15945
4c261dff
NC
15946 case NS_NULL:
15947 /* neon_select_shape has determined that the instruction
15948 shape is wrong and has already set the error message. */
15949 break;
15950
5287ad62
JB
15951 default:
15952 abort ();
15953 }
15954}
15955
15956static void
15957do_neon_rshift_round_imm (void)
15958{
037e8744 15959 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15960 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
15961 int imm = inst.operands[2].imm;
15962
15963 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
15964 if (imm == 0)
15965 {
15966 inst.operands[2].present = 0;
15967 do_neon_mov ();
15968 return;
15969 }
15970
15971 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15972 _("immediate out of range for shift"));
037e8744 15973 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 15974 et.size - imm);
5287ad62
JB
15975}
15976
15977static void
15978do_neon_movl (void)
15979{
15980 struct neon_type_el et = neon_check_type (2, NS_QD,
15981 N_EQK | N_DBL, N_SU_32 | N_KEY);
15982 unsigned sizebits = et.size >> 3;
15983 inst.instruction |= sizebits << 19;
15984 neon_two_same (0, et.type == NT_unsigned, -1);
15985}
15986
15987static void
15988do_neon_trn (void)
15989{
037e8744 15990 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15991 struct neon_type_el et = neon_check_type (2, rs,
15992 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 15993 NEON_ENCODE (INTEGER, inst);
037e8744 15994 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15995}
15996
15997static void
15998do_neon_zip_uzp (void)
15999{
037e8744 16000 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16001 struct neon_type_el et = neon_check_type (2, rs,
16002 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16003 if (rs == NS_DD && et.size == 32)
16004 {
16005 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16006 inst.instruction = N_MNEM_vtrn;
16007 do_neon_trn ();
16008 return;
16009 }
037e8744 16010 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16011}
16012
16013static void
16014do_neon_sat_abs_neg (void)
16015{
037e8744 16016 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16017 struct neon_type_el et = neon_check_type (2, rs,
16018 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16019 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16020}
16021
16022static void
16023do_neon_pair_long (void)
16024{
037e8744 16025 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16026 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16027 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16028 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16029 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16030}
16031
16032static void
16033do_neon_recip_est (void)
16034{
037e8744 16035 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16036 struct neon_type_el et = neon_check_type (2, rs,
16037 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
16038 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16039 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16040}
16041
16042static void
16043do_neon_cls (void)
16044{
037e8744 16045 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16046 struct neon_type_el et = neon_check_type (2, rs,
16047 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16048 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16049}
16050
16051static void
16052do_neon_clz (void)
16053{
037e8744 16054 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16055 struct neon_type_el et = neon_check_type (2, rs,
16056 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16057 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16058}
16059
16060static void
16061do_neon_cnt (void)
16062{
037e8744 16063 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16064 struct neon_type_el et = neon_check_type (2, rs,
16065 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16066 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16067}
16068
16069static void
16070do_neon_swp (void)
16071{
037e8744
JB
16072 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16073 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16074}
16075
16076static void
16077do_neon_tbl_tbx (void)
16078{
16079 unsigned listlenbits;
dcbf9037 16080 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16081
5287ad62
JB
16082 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16083 {
dcbf9037 16084 first_error (_("bad list length for table lookup"));
5287ad62
JB
16085 return;
16086 }
5f4273c7 16087
5287ad62
JB
16088 listlenbits = inst.operands[1].imm - 1;
16089 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16090 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16091 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16092 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16093 inst.instruction |= LOW4 (inst.operands[2].reg);
16094 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16095 inst.instruction |= listlenbits << 8;
5f4273c7 16096
88714cb8 16097 neon_dp_fixup (&inst);
5287ad62
JB
16098}
16099
16100static void
16101do_neon_ldm_stm (void)
16102{
16103 /* P, U and L bits are part of bitmask. */
16104 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16105 unsigned offsetbits = inst.operands[1].imm * 2;
16106
037e8744
JB
16107 if (inst.operands[1].issingle)
16108 {
16109 do_vfp_nsyn_ldm_stm (is_dbmode);
16110 return;
16111 }
16112
5287ad62 16113 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16114 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16115
16116 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16117 _("register list must contain at least 1 and at most 16 "
16118 "registers"));
5287ad62
JB
16119
16120 inst.instruction |= inst.operands[0].reg << 16;
16121 inst.instruction |= inst.operands[0].writeback << 21;
16122 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16123 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16124
16125 inst.instruction |= offsetbits;
5f4273c7 16126
037e8744 16127 do_vfp_cond_or_thumb ();
5287ad62
JB
16128}
16129
16130static void
16131do_neon_ldr_str (void)
16132{
5287ad62 16133 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16134
6844b2c2
MGD
16135 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16136 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16137 if (!is_ldr
6844b2c2 16138 && inst.operands[1].reg == REG_PC
ba86b375 16139 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16140 {
94dcf8bf 16141 if (thumb_mode)
6844b2c2 16142 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 16143 else if (warn_on_deprecated)
5c3696f8 16144 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
16145 }
16146
037e8744
JB
16147 if (inst.operands[0].issingle)
16148 {
cd2f129f 16149 if (is_ldr)
477330fc 16150 do_vfp_nsyn_opcode ("flds");
cd2f129f 16151 else
477330fc 16152 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
16153 }
16154 else
5287ad62 16155 {
cd2f129f 16156 if (is_ldr)
477330fc 16157 do_vfp_nsyn_opcode ("fldd");
5287ad62 16158 else
477330fc 16159 do_vfp_nsyn_opcode ("fstd");
5287ad62 16160 }
5287ad62
JB
16161}
16162
16163/* "interleave" version also handles non-interleaving register VLD1/VST1
16164 instructions. */
16165
16166static void
16167do_neon_ld_st_interleave (void)
16168{
037e8744 16169 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 16170 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
16171 unsigned alignbits = 0;
16172 unsigned idx;
16173 /* The bits in this table go:
16174 0: register stride of one (0) or two (1)
16175 1,2: register list length, minus one (1, 2, 3, 4).
16176 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
16177 We use -1 for invalid entries. */
16178 const int typetable[] =
16179 {
16180 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
16181 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
16182 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
16183 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
16184 };
16185 int typebits;
16186
dcbf9037
JB
16187 if (et.type == NT_invtype)
16188 return;
16189
5287ad62
JB
16190 if (inst.operands[1].immisalign)
16191 switch (inst.operands[1].imm >> 8)
16192 {
16193 case 64: alignbits = 1; break;
16194 case 128:
477330fc 16195 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 16196 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
16197 goto bad_alignment;
16198 alignbits = 2;
16199 break;
5287ad62 16200 case 256:
477330fc
RM
16201 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
16202 goto bad_alignment;
16203 alignbits = 3;
16204 break;
5287ad62
JB
16205 default:
16206 bad_alignment:
477330fc
RM
16207 first_error (_("bad alignment"));
16208 return;
5287ad62
JB
16209 }
16210
16211 inst.instruction |= alignbits << 4;
16212 inst.instruction |= neon_logbits (et.size) << 6;
16213
16214 /* Bits [4:6] of the immediate in a list specifier encode register stride
16215 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
16216 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
16217 up the right value for "type" in a table based on this value and the given
16218 list style, then stick it back. */
16219 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 16220 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
16221
16222 typebits = typetable[idx];
5f4273c7 16223
5287ad62 16224 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
16225 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
16226 _("bad element type for instruction"));
5287ad62
JB
16227
16228 inst.instruction &= ~0xf00;
16229 inst.instruction |= typebits << 8;
16230}
16231
16232/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
16233 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
16234 otherwise. The variable arguments are a list of pairs of legal (size, align)
16235 values, terminated with -1. */
16236
16237static int
16238neon_alignment_bit (int size, int align, int *do_align, ...)
16239{
16240 va_list ap;
16241 int result = FAIL, thissize, thisalign;
5f4273c7 16242
5287ad62
JB
16243 if (!inst.operands[1].immisalign)
16244 {
16245 *do_align = 0;
16246 return SUCCESS;
16247 }
5f4273c7 16248
5287ad62
JB
16249 va_start (ap, do_align);
16250
16251 do
16252 {
16253 thissize = va_arg (ap, int);
16254 if (thissize == -1)
477330fc 16255 break;
5287ad62
JB
16256 thisalign = va_arg (ap, int);
16257
16258 if (size == thissize && align == thisalign)
477330fc 16259 result = SUCCESS;
5287ad62
JB
16260 }
16261 while (result != SUCCESS);
16262
16263 va_end (ap);
16264
16265 if (result == SUCCESS)
16266 *do_align = 1;
16267 else
dcbf9037 16268 first_error (_("unsupported alignment for instruction"));
5f4273c7 16269
5287ad62
JB
16270 return result;
16271}
16272
16273static void
16274do_neon_ld_st_lane (void)
16275{
037e8744 16276 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
16277 int align_good, do_align = 0;
16278 int logsize = neon_logbits (et.size);
16279 int align = inst.operands[1].imm >> 8;
16280 int n = (inst.instruction >> 8) & 3;
16281 int max_el = 64 / et.size;
5f4273c7 16282
dcbf9037
JB
16283 if (et.type == NT_invtype)
16284 return;
5f4273c7 16285
5287ad62 16286 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 16287 _("bad list length"));
5287ad62 16288 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 16289 _("scalar index out of range"));
5287ad62 16290 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
16291 && et.size == 8,
16292 _("stride of 2 unavailable when element size is 8"));
5f4273c7 16293
5287ad62
JB
16294 switch (n)
16295 {
16296 case 0: /* VLD1 / VST1. */
16297 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
477330fc 16298 32, 32, -1);
5287ad62 16299 if (align_good == FAIL)
477330fc 16300 return;
5287ad62 16301 if (do_align)
477330fc
RM
16302 {
16303 unsigned alignbits = 0;
16304 switch (et.size)
16305 {
16306 case 16: alignbits = 0x1; break;
16307 case 32: alignbits = 0x3; break;
16308 default: ;
16309 }
16310 inst.instruction |= alignbits << 4;
16311 }
5287ad62
JB
16312 break;
16313
16314 case 1: /* VLD2 / VST2. */
16315 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
477330fc 16316 32, 64, -1);
5287ad62 16317 if (align_good == FAIL)
477330fc 16318 return;
5287ad62 16319 if (do_align)
477330fc 16320 inst.instruction |= 1 << 4;
5287ad62
JB
16321 break;
16322
16323 case 2: /* VLD3 / VST3. */
16324 constraint (inst.operands[1].immisalign,
477330fc 16325 _("can't use alignment with this instruction"));
5287ad62
JB
16326 break;
16327
16328 case 3: /* VLD4 / VST4. */
16329 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
477330fc 16330 16, 64, 32, 64, 32, 128, -1);
5287ad62 16331 if (align_good == FAIL)
477330fc 16332 return;
5287ad62 16333 if (do_align)
477330fc
RM
16334 {
16335 unsigned alignbits = 0;
16336 switch (et.size)
16337 {
16338 case 8: alignbits = 0x1; break;
16339 case 16: alignbits = 0x1; break;
16340 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
16341 default: ;
16342 }
16343 inst.instruction |= alignbits << 4;
16344 }
5287ad62
JB
16345 break;
16346
16347 default: ;
16348 }
16349
16350 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
16351 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16352 inst.instruction |= 1 << (4 + logsize);
5f4273c7 16353
5287ad62
JB
16354 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
16355 inst.instruction |= logsize << 10;
16356}
16357
16358/* Encode single n-element structure to all lanes VLD<n> instructions. */
16359
16360static void
16361do_neon_ld_dup (void)
16362{
037e8744 16363 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
16364 int align_good, do_align = 0;
16365
dcbf9037
JB
16366 if (et.type == NT_invtype)
16367 return;
16368
5287ad62
JB
16369 switch ((inst.instruction >> 8) & 3)
16370 {
16371 case 0: /* VLD1. */
9c2799c2 16372 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 16373 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
477330fc 16374 &do_align, 16, 16, 32, 32, -1);
5287ad62 16375 if (align_good == FAIL)
477330fc 16376 return;
5287ad62 16377 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
16378 {
16379 case 1: break;
16380 case 2: inst.instruction |= 1 << 5; break;
16381 default: first_error (_("bad list length")); return;
16382 }
5287ad62
JB
16383 inst.instruction |= neon_logbits (et.size) << 6;
16384 break;
16385
16386 case 1: /* VLD2. */
16387 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
477330fc 16388 &do_align, 8, 16, 16, 32, 32, 64, -1);
5287ad62 16389 if (align_good == FAIL)
477330fc 16390 return;
5287ad62 16391 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 16392 _("bad list length"));
5287ad62 16393 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16394 inst.instruction |= 1 << 5;
5287ad62
JB
16395 inst.instruction |= neon_logbits (et.size) << 6;
16396 break;
16397
16398 case 2: /* VLD3. */
16399 constraint (inst.operands[1].immisalign,
477330fc 16400 _("can't use alignment with this instruction"));
5287ad62 16401 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 16402 _("bad list length"));
5287ad62 16403 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16404 inst.instruction |= 1 << 5;
5287ad62
JB
16405 inst.instruction |= neon_logbits (et.size) << 6;
16406 break;
16407
16408 case 3: /* VLD4. */
16409 {
477330fc
RM
16410 int align = inst.operands[1].imm >> 8;
16411 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
16412 16, 64, 32, 64, 32, 128, -1);
16413 if (align_good == FAIL)
16414 return;
16415 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
16416 _("bad list length"));
16417 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16418 inst.instruction |= 1 << 5;
16419 if (et.size == 32 && align == 128)
16420 inst.instruction |= 0x3 << 6;
16421 else
16422 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
16423 }
16424 break;
16425
16426 default: ;
16427 }
16428
16429 inst.instruction |= do_align << 4;
16430}
16431
16432/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
16433 apart from bits [11:4]. */
16434
16435static void
16436do_neon_ldx_stx (void)
16437{
b1a769ed
DG
16438 if (inst.operands[1].isreg)
16439 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16440
5287ad62
JB
16441 switch (NEON_LANE (inst.operands[0].imm))
16442 {
16443 case NEON_INTERLEAVE_LANES:
88714cb8 16444 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
16445 do_neon_ld_st_interleave ();
16446 break;
5f4273c7 16447
5287ad62 16448 case NEON_ALL_LANES:
88714cb8 16449 NEON_ENCODE (DUP, inst);
2d51fb74
JB
16450 if (inst.instruction == N_INV)
16451 {
16452 first_error ("only loads support such operands");
16453 break;
16454 }
5287ad62
JB
16455 do_neon_ld_dup ();
16456 break;
5f4273c7 16457
5287ad62 16458 default:
88714cb8 16459 NEON_ENCODE (LANE, inst);
5287ad62
JB
16460 do_neon_ld_st_lane ();
16461 }
16462
16463 /* L bit comes from bit mask. */
16464 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16465 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16466 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 16467
5287ad62
JB
16468 if (inst.operands[1].postind)
16469 {
16470 int postreg = inst.operands[1].imm & 0xf;
16471 constraint (!inst.operands[1].immisreg,
477330fc 16472 _("post-index must be a register"));
5287ad62 16473 constraint (postreg == 0xd || postreg == 0xf,
477330fc 16474 _("bad register for post-index"));
5287ad62
JB
16475 inst.instruction |= postreg;
16476 }
4f2374c7 16477 else
5287ad62 16478 {
4f2374c7
WN
16479 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
16480 constraint (inst.reloc.exp.X_op != O_constant
16481 || inst.reloc.exp.X_add_number != 0,
16482 BAD_ADDR_MODE);
16483
16484 if (inst.operands[1].writeback)
16485 {
16486 inst.instruction |= 0xd;
16487 }
16488 else
16489 inst.instruction |= 0xf;
5287ad62 16490 }
5f4273c7 16491
5287ad62
JB
16492 if (thumb_mode)
16493 inst.instruction |= 0xf9000000;
16494 else
16495 inst.instruction |= 0xf4000000;
16496}
33399f07
MGD
16497
16498/* FP v8. */
16499static void
16500do_vfp_nsyn_fpv8 (enum neon_shape rs)
16501{
a715796b
TG
16502 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
16503 D register operands. */
16504 if (neon_shape_class[rs] == SC_DOUBLE)
16505 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16506 _(BAD_FPU));
16507
33399f07
MGD
16508 NEON_ENCODE (FPV8, inst);
16509
16510 if (rs == NS_FFF)
16511 do_vfp_sp_dyadic ();
16512 else
16513 do_vfp_dp_rd_rn_rm ();
16514
16515 if (rs == NS_DDD)
16516 inst.instruction |= 0x100;
16517
16518 inst.instruction |= 0xf0000000;
16519}
16520
16521static void
16522do_vsel (void)
16523{
16524 set_it_insn_type (OUTSIDE_IT_INSN);
16525
16526 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
16527 first_error (_("invalid instruction shape"));
16528}
16529
73924fbc
MGD
16530static void
16531do_vmaxnm (void)
16532{
16533 set_it_insn_type (OUTSIDE_IT_INSN);
16534
16535 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
16536 return;
16537
16538 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16539 return;
16540
16541 neon_dyadic_misc (NT_untyped, N_F32, 0);
16542}
16543
30bdf752
MGD
16544static void
16545do_vrint_1 (enum neon_cvt_mode mode)
16546{
16547 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_QQ, NS_NULL);
16548 struct neon_type_el et;
16549
16550 if (rs == NS_NULL)
16551 return;
16552
a715796b
TG
16553 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
16554 D register operands. */
16555 if (neon_shape_class[rs] == SC_DOUBLE)
16556 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16557 _(BAD_FPU));
16558
30bdf752
MGD
16559 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
16560 if (et.type != NT_invtype)
16561 {
16562 /* VFP encodings. */
16563 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
16564 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
16565 set_it_insn_type (OUTSIDE_IT_INSN);
16566
16567 NEON_ENCODE (FPV8, inst);
16568 if (rs == NS_FF)
16569 do_vfp_sp_monadic ();
16570 else
16571 do_vfp_dp_rd_rm ();
16572
16573 switch (mode)
16574 {
16575 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
16576 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
16577 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
16578 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
16579 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
16580 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
16581 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
16582 default: abort ();
16583 }
16584
16585 inst.instruction |= (rs == NS_DD) << 8;
16586 do_vfp_cond_or_thumb ();
16587 }
16588 else
16589 {
16590 /* Neon encodings (or something broken...). */
16591 inst.error = NULL;
16592 et = neon_check_type (2, rs, N_EQK, N_F32 | N_KEY);
16593
16594 if (et.type == NT_invtype)
16595 return;
16596
16597 set_it_insn_type (OUTSIDE_IT_INSN);
16598 NEON_ENCODE (FLOAT, inst);
16599
16600 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16601 return;
16602
16603 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16604 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16605 inst.instruction |= LOW4 (inst.operands[1].reg);
16606 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16607 inst.instruction |= neon_quad (rs) << 6;
16608 switch (mode)
16609 {
16610 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
16611 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
16612 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
16613 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
16614 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
16615 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
16616 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
16617 default: abort ();
16618 }
16619
16620 if (thumb_mode)
16621 inst.instruction |= 0xfc000000;
16622 else
16623 inst.instruction |= 0xf0000000;
16624 }
16625}
16626
16627static void
16628do_vrintx (void)
16629{
16630 do_vrint_1 (neon_cvt_mode_x);
16631}
16632
16633static void
16634do_vrintz (void)
16635{
16636 do_vrint_1 (neon_cvt_mode_z);
16637}
16638
16639static void
16640do_vrintr (void)
16641{
16642 do_vrint_1 (neon_cvt_mode_r);
16643}
16644
16645static void
16646do_vrinta (void)
16647{
16648 do_vrint_1 (neon_cvt_mode_a);
16649}
16650
16651static void
16652do_vrintn (void)
16653{
16654 do_vrint_1 (neon_cvt_mode_n);
16655}
16656
16657static void
16658do_vrintp (void)
16659{
16660 do_vrint_1 (neon_cvt_mode_p);
16661}
16662
16663static void
16664do_vrintm (void)
16665{
16666 do_vrint_1 (neon_cvt_mode_m);
16667}
16668
91ff7894
MGD
16669/* Crypto v1 instructions. */
16670static void
16671do_crypto_2op_1 (unsigned elttype, int op)
16672{
16673 set_it_insn_type (OUTSIDE_IT_INSN);
16674
16675 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
16676 == NT_invtype)
16677 return;
16678
16679 inst.error = NULL;
16680
16681 NEON_ENCODE (INTEGER, inst);
16682 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16683 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16684 inst.instruction |= LOW4 (inst.operands[1].reg);
16685 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16686 if (op != -1)
16687 inst.instruction |= op << 6;
16688
16689 if (thumb_mode)
16690 inst.instruction |= 0xfc000000;
16691 else
16692 inst.instruction |= 0xf0000000;
16693}
16694
48adcd8e
MGD
16695static void
16696do_crypto_3op_1 (int u, int op)
16697{
16698 set_it_insn_type (OUTSIDE_IT_INSN);
16699
16700 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
16701 N_32 | N_UNT | N_KEY).type == NT_invtype)
16702 return;
16703
16704 inst.error = NULL;
16705
16706 NEON_ENCODE (INTEGER, inst);
16707 neon_three_same (1, u, 8 << op);
16708}
16709
91ff7894
MGD
16710static void
16711do_aese (void)
16712{
16713 do_crypto_2op_1 (N_8, 0);
16714}
16715
16716static void
16717do_aesd (void)
16718{
16719 do_crypto_2op_1 (N_8, 1);
16720}
16721
16722static void
16723do_aesmc (void)
16724{
16725 do_crypto_2op_1 (N_8, 2);
16726}
16727
16728static void
16729do_aesimc (void)
16730{
16731 do_crypto_2op_1 (N_8, 3);
16732}
16733
48adcd8e
MGD
16734static void
16735do_sha1c (void)
16736{
16737 do_crypto_3op_1 (0, 0);
16738}
16739
16740static void
16741do_sha1p (void)
16742{
16743 do_crypto_3op_1 (0, 1);
16744}
16745
16746static void
16747do_sha1m (void)
16748{
16749 do_crypto_3op_1 (0, 2);
16750}
16751
16752static void
16753do_sha1su0 (void)
16754{
16755 do_crypto_3op_1 (0, 3);
16756}
91ff7894 16757
48adcd8e
MGD
16758static void
16759do_sha256h (void)
16760{
16761 do_crypto_3op_1 (1, 0);
16762}
16763
16764static void
16765do_sha256h2 (void)
16766{
16767 do_crypto_3op_1 (1, 1);
16768}
16769
16770static void
16771do_sha256su1 (void)
16772{
16773 do_crypto_3op_1 (1, 2);
16774}
3c9017d2
MGD
16775
16776static void
16777do_sha1h (void)
16778{
16779 do_crypto_2op_1 (N_32, -1);
16780}
16781
16782static void
16783do_sha1su1 (void)
16784{
16785 do_crypto_2op_1 (N_32, 0);
16786}
16787
16788static void
16789do_sha256su0 (void)
16790{
16791 do_crypto_2op_1 (N_32, 1);
16792}
dd5181d5
KT
16793
16794static void
16795do_crc32_1 (unsigned int poly, unsigned int sz)
16796{
16797 unsigned int Rd = inst.operands[0].reg;
16798 unsigned int Rn = inst.operands[1].reg;
16799 unsigned int Rm = inst.operands[2].reg;
16800
16801 set_it_insn_type (OUTSIDE_IT_INSN);
16802 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
16803 inst.instruction |= LOW4 (Rn) << 16;
16804 inst.instruction |= LOW4 (Rm);
16805 inst.instruction |= sz << (thumb_mode ? 4 : 21);
16806 inst.instruction |= poly << (thumb_mode ? 20 : 9);
16807
16808 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
16809 as_warn (UNPRED_REG ("r15"));
16810 if (thumb_mode && (Rd == REG_SP || Rn == REG_SP || Rm == REG_SP))
16811 as_warn (UNPRED_REG ("r13"));
16812}
16813
16814static void
16815do_crc32b (void)
16816{
16817 do_crc32_1 (0, 0);
16818}
16819
16820static void
16821do_crc32h (void)
16822{
16823 do_crc32_1 (0, 1);
16824}
16825
16826static void
16827do_crc32w (void)
16828{
16829 do_crc32_1 (0, 2);
16830}
16831
16832static void
16833do_crc32cb (void)
16834{
16835 do_crc32_1 (1, 0);
16836}
16837
16838static void
16839do_crc32ch (void)
16840{
16841 do_crc32_1 (1, 1);
16842}
16843
16844static void
16845do_crc32cw (void)
16846{
16847 do_crc32_1 (1, 2);
16848}
16849
5287ad62
JB
16850\f
16851/* Overall per-instruction processing. */
16852
16853/* We need to be able to fix up arbitrary expressions in some statements.
16854 This is so that we can handle symbols that are an arbitrary distance from
16855 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
16856 which returns part of an address in a form which will be valid for
16857 a data instruction. We do this by pushing the expression into a symbol
16858 in the expr_section, and creating a fix for that. */
16859
16860static void
16861fix_new_arm (fragS * frag,
16862 int where,
16863 short int size,
16864 expressionS * exp,
16865 int pc_rel,
16866 int reloc)
16867{
16868 fixS * new_fix;
16869
16870 switch (exp->X_op)
16871 {
16872 case O_constant:
6e7ce2cd
PB
16873 if (pc_rel)
16874 {
16875 /* Create an absolute valued symbol, so we have something to
477330fc
RM
16876 refer to in the object file. Unfortunately for us, gas's
16877 generic expression parsing will already have folded out
16878 any use of .set foo/.type foo %function that may have
16879 been used to set type information of the target location,
16880 that's being specified symbolically. We have to presume
16881 the user knows what they are doing. */
6e7ce2cd
PB
16882 char name[16 + 8];
16883 symbolS *symbol;
16884
16885 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
16886
16887 symbol = symbol_find_or_make (name);
16888 S_SET_SEGMENT (symbol, absolute_section);
16889 symbol_set_frag (symbol, &zero_address_frag);
16890 S_SET_VALUE (symbol, exp->X_add_number);
16891 exp->X_op = O_symbol;
16892 exp->X_add_symbol = symbol;
16893 exp->X_add_number = 0;
16894 }
16895 /* FALLTHROUGH */
5287ad62
JB
16896 case O_symbol:
16897 case O_add:
16898 case O_subtract:
21d799b5 16899 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 16900 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
16901 break;
16902
16903 default:
21d799b5 16904 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 16905 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
16906 break;
16907 }
16908
16909 /* Mark whether the fix is to a THUMB instruction, or an ARM
16910 instruction. */
16911 new_fix->tc_fix_data = thumb_mode;
16912}
16913
16914/* Create a frg for an instruction requiring relaxation. */
16915static void
16916output_relax_insn (void)
16917{
16918 char * to;
16919 symbolS *sym;
0110f2b8
PB
16920 int offset;
16921
6e1cb1a6
PB
16922 /* The size of the instruction is unknown, so tie the debug info to the
16923 start of the instruction. */
16924 dwarf2_emit_insn (0);
6e1cb1a6 16925
0110f2b8
PB
16926 switch (inst.reloc.exp.X_op)
16927 {
16928 case O_symbol:
16929 sym = inst.reloc.exp.X_add_symbol;
16930 offset = inst.reloc.exp.X_add_number;
16931 break;
16932 case O_constant:
16933 sym = NULL;
16934 offset = inst.reloc.exp.X_add_number;
16935 break;
16936 default:
16937 sym = make_expr_symbol (&inst.reloc.exp);
16938 offset = 0;
16939 break;
16940 }
16941 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
16942 inst.relax, sym, offset, NULL/*offset, opcode*/);
16943 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
16944}
16945
16946/* Write a 32-bit thumb instruction to buf. */
16947static void
16948put_thumb32_insn (char * buf, unsigned long insn)
16949{
16950 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
16951 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
16952}
16953
b99bd4ef 16954static void
c19d1205 16955output_inst (const char * str)
b99bd4ef 16956{
c19d1205 16957 char * to = NULL;
b99bd4ef 16958
c19d1205 16959 if (inst.error)
b99bd4ef 16960 {
c19d1205 16961 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
16962 return;
16963 }
5f4273c7
NC
16964 if (inst.relax)
16965 {
16966 output_relax_insn ();
0110f2b8 16967 return;
5f4273c7 16968 }
c19d1205
ZW
16969 if (inst.size == 0)
16970 return;
b99bd4ef 16971
c19d1205 16972 to = frag_more (inst.size);
8dc2430f
NC
16973 /* PR 9814: Record the thumb mode into the current frag so that we know
16974 what type of NOP padding to use, if necessary. We override any previous
16975 setting so that if the mode has changed then the NOPS that we use will
16976 match the encoding of the last instruction in the frag. */
cd000bff 16977 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
16978
16979 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 16980 {
9c2799c2 16981 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 16982 put_thumb32_insn (to, inst.instruction);
b99bd4ef 16983 }
c19d1205 16984 else if (inst.size > INSN_SIZE)
b99bd4ef 16985 {
9c2799c2 16986 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
16987 md_number_to_chars (to, inst.instruction, INSN_SIZE);
16988 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 16989 }
c19d1205
ZW
16990 else
16991 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 16992
c19d1205
ZW
16993 if (inst.reloc.type != BFD_RELOC_UNUSED)
16994 fix_new_arm (frag_now, to - frag_now->fr_literal,
16995 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
16996 inst.reloc.type);
b99bd4ef 16997
c19d1205 16998 dwarf2_emit_insn (inst.size);
c19d1205 16999}
b99bd4ef 17000
e07e6e58
NC
17001static char *
17002output_it_inst (int cond, int mask, char * to)
17003{
17004 unsigned long instruction = 0xbf00;
17005
17006 mask &= 0xf;
17007 instruction |= mask;
17008 instruction |= cond << 4;
17009
17010 if (to == NULL)
17011 {
17012 to = frag_more (2);
17013#ifdef OBJ_ELF
17014 dwarf2_emit_insn (2);
17015#endif
17016 }
17017
17018 md_number_to_chars (to, instruction, 2);
17019
17020 return to;
17021}
17022
c19d1205
ZW
17023/* Tag values used in struct asm_opcode's tag field. */
17024enum opcode_tag
17025{
17026 OT_unconditional, /* Instruction cannot be conditionalized.
17027 The ARM condition field is still 0xE. */
17028 OT_unconditionalF, /* Instruction cannot be conditionalized
17029 and carries 0xF in its ARM condition field. */
17030 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 17031 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
17032 suffix, others place 0xF where the condition field
17033 would be. */
c19d1205
ZW
17034 OT_cinfix3, /* Instruction takes a conditional infix,
17035 beginning at character index 3. (In
17036 unified mode, it becomes a suffix.) */
088fa78e
KH
17037 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
17038 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
17039 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
17040 character index 3, even in unified mode. Used for
17041 legacy instructions where suffix and infix forms
17042 may be ambiguous. */
c19d1205 17043 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 17044 suffix or an infix at character index 3. */
c19d1205
ZW
17045 OT_odd_infix_unc, /* This is the unconditional variant of an
17046 instruction that takes a conditional infix
17047 at an unusual position. In unified mode,
17048 this variant will accept a suffix. */
17049 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
17050 are the conditional variants of instructions that
17051 take conditional infixes in unusual positions.
17052 The infix appears at character index
17053 (tag - OT_odd_infix_0). These are not accepted
17054 in unified mode. */
17055};
b99bd4ef 17056
c19d1205
ZW
17057/* Subroutine of md_assemble, responsible for looking up the primary
17058 opcode from the mnemonic the user wrote. STR points to the
17059 beginning of the mnemonic.
17060
17061 This is not simply a hash table lookup, because of conditional
17062 variants. Most instructions have conditional variants, which are
17063 expressed with a _conditional affix_ to the mnemonic. If we were
17064 to encode each conditional variant as a literal string in the opcode
17065 table, it would have approximately 20,000 entries.
17066
17067 Most mnemonics take this affix as a suffix, and in unified syntax,
17068 'most' is upgraded to 'all'. However, in the divided syntax, some
17069 instructions take the affix as an infix, notably the s-variants of
17070 the arithmetic instructions. Of those instructions, all but six
17071 have the infix appear after the third character of the mnemonic.
17072
17073 Accordingly, the algorithm for looking up primary opcodes given
17074 an identifier is:
17075
17076 1. Look up the identifier in the opcode table.
17077 If we find a match, go to step U.
17078
17079 2. Look up the last two characters of the identifier in the
17080 conditions table. If we find a match, look up the first N-2
17081 characters of the identifier in the opcode table. If we
17082 find a match, go to step CE.
17083
17084 3. Look up the fourth and fifth characters of the identifier in
17085 the conditions table. If we find a match, extract those
17086 characters from the identifier, and look up the remaining
17087 characters in the opcode table. If we find a match, go
17088 to step CM.
17089
17090 4. Fail.
17091
17092 U. Examine the tag field of the opcode structure, in case this is
17093 one of the six instructions with its conditional infix in an
17094 unusual place. If it is, the tag tells us where to find the
17095 infix; look it up in the conditions table and set inst.cond
17096 accordingly. Otherwise, this is an unconditional instruction.
17097 Again set inst.cond accordingly. Return the opcode structure.
17098
17099 CE. Examine the tag field to make sure this is an instruction that
17100 should receive a conditional suffix. If it is not, fail.
17101 Otherwise, set inst.cond from the suffix we already looked up,
17102 and return the opcode structure.
17103
17104 CM. Examine the tag field to make sure this is an instruction that
17105 should receive a conditional infix after the third character.
17106 If it is not, fail. Otherwise, undo the edits to the current
17107 line of input and proceed as for case CE. */
17108
17109static const struct asm_opcode *
17110opcode_lookup (char **str)
17111{
17112 char *end, *base;
17113 char *affix;
17114 const struct asm_opcode *opcode;
17115 const struct asm_cond *cond;
e3cb604e 17116 char save[2];
c19d1205
ZW
17117
17118 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 17119 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 17120 for (base = end = *str; *end != '\0'; end++)
721a8186 17121 if (*end == ' ' || *end == '.')
c19d1205 17122 break;
b99bd4ef 17123
c19d1205 17124 if (end == base)
c921be7d 17125 return NULL;
b99bd4ef 17126
5287ad62 17127 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 17128 if (end[0] == '.')
b99bd4ef 17129 {
5287ad62 17130 int offset = 2;
5f4273c7 17131
267d2029 17132 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 17133 use. */
267d2029 17134 if (unified_syntax && end[1] == 'w')
c19d1205 17135 inst.size_req = 4;
267d2029 17136 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
17137 inst.size_req = 2;
17138 else
477330fc 17139 offset = 0;
5287ad62
JB
17140
17141 inst.vectype.elems = 0;
17142
17143 *str = end + offset;
b99bd4ef 17144
5f4273c7 17145 if (end[offset] == '.')
5287ad62 17146 {
267d2029 17147 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
17148 non-unified ARM syntax mode). */
17149 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 17150 return NULL;
477330fc 17151 }
5287ad62 17152 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 17153 return NULL;
b99bd4ef 17154 }
c19d1205
ZW
17155 else
17156 *str = end;
b99bd4ef 17157
c19d1205 17158 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 17159 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17160 end - base);
c19d1205 17161 if (opcode)
b99bd4ef 17162 {
c19d1205
ZW
17163 /* step U */
17164 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 17165 {
c19d1205
ZW
17166 inst.cond = COND_ALWAYS;
17167 return opcode;
b99bd4ef 17168 }
b99bd4ef 17169
278df34e 17170 if (warn_on_deprecated && unified_syntax)
5c3696f8 17171 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 17172 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 17173 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 17174 gas_assert (cond);
b99bd4ef 17175
c19d1205
ZW
17176 inst.cond = cond->value;
17177 return opcode;
17178 }
b99bd4ef 17179
c19d1205
ZW
17180 /* Cannot have a conditional suffix on a mnemonic of less than two
17181 characters. */
17182 if (end - base < 3)
c921be7d 17183 return NULL;
b99bd4ef 17184
c19d1205
ZW
17185 /* Look for suffixed mnemonic. */
17186 affix = end - 2;
21d799b5
NC
17187 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
17188 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17189 affix - base);
c19d1205
ZW
17190 if (opcode && cond)
17191 {
17192 /* step CE */
17193 switch (opcode->tag)
17194 {
e3cb604e
PB
17195 case OT_cinfix3_legacy:
17196 /* Ignore conditional suffixes matched on infix only mnemonics. */
17197 break;
17198
c19d1205 17199 case OT_cinfix3:
088fa78e 17200 case OT_cinfix3_deprecated:
c19d1205
ZW
17201 case OT_odd_infix_unc:
17202 if (!unified_syntax)
e3cb604e 17203 return 0;
c19d1205
ZW
17204 /* else fall through */
17205
17206 case OT_csuffix:
477330fc 17207 case OT_csuffixF:
c19d1205
ZW
17208 case OT_csuf_or_in3:
17209 inst.cond = cond->value;
17210 return opcode;
17211
17212 case OT_unconditional:
17213 case OT_unconditionalF:
dfa9f0d5 17214 if (thumb_mode)
c921be7d 17215 inst.cond = cond->value;
dfa9f0d5
PB
17216 else
17217 {
c921be7d 17218 /* Delayed diagnostic. */
dfa9f0d5
PB
17219 inst.error = BAD_COND;
17220 inst.cond = COND_ALWAYS;
17221 }
c19d1205 17222 return opcode;
b99bd4ef 17223
c19d1205 17224 default:
c921be7d 17225 return NULL;
c19d1205
ZW
17226 }
17227 }
b99bd4ef 17228
c19d1205
ZW
17229 /* Cannot have a usual-position infix on a mnemonic of less than
17230 six characters (five would be a suffix). */
17231 if (end - base < 6)
c921be7d 17232 return NULL;
b99bd4ef 17233
c19d1205
ZW
17234 /* Look for infixed mnemonic in the usual position. */
17235 affix = base + 3;
21d799b5 17236 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 17237 if (!cond)
c921be7d 17238 return NULL;
e3cb604e
PB
17239
17240 memcpy (save, affix, 2);
17241 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 17242 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17243 (end - base) - 2);
e3cb604e
PB
17244 memmove (affix + 2, affix, (end - affix) - 2);
17245 memcpy (affix, save, 2);
17246
088fa78e
KH
17247 if (opcode
17248 && (opcode->tag == OT_cinfix3
17249 || opcode->tag == OT_cinfix3_deprecated
17250 || opcode->tag == OT_csuf_or_in3
17251 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 17252 {
c921be7d 17253 /* Step CM. */
278df34e 17254 if (warn_on_deprecated && unified_syntax
088fa78e
KH
17255 && (opcode->tag == OT_cinfix3
17256 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 17257 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
17258
17259 inst.cond = cond->value;
17260 return opcode;
b99bd4ef
NC
17261 }
17262
c921be7d 17263 return NULL;
b99bd4ef
NC
17264}
17265
e07e6e58
NC
17266/* This function generates an initial IT instruction, leaving its block
17267 virtually open for the new instructions. Eventually,
17268 the mask will be updated by now_it_add_mask () each time
17269 a new instruction needs to be included in the IT block.
17270 Finally, the block is closed with close_automatic_it_block ().
17271 The block closure can be requested either from md_assemble (),
17272 a tencode (), or due to a label hook. */
17273
17274static void
17275new_automatic_it_block (int cond)
17276{
17277 now_it.state = AUTOMATIC_IT_BLOCK;
17278 now_it.mask = 0x18;
17279 now_it.cc = cond;
17280 now_it.block_length = 1;
cd000bff 17281 mapping_state (MAP_THUMB);
e07e6e58 17282 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
17283 now_it.warn_deprecated = FALSE;
17284 now_it.insn_cond = TRUE;
e07e6e58
NC
17285}
17286
17287/* Close an automatic IT block.
17288 See comments in new_automatic_it_block (). */
17289
17290static void
17291close_automatic_it_block (void)
17292{
17293 now_it.mask = 0x10;
17294 now_it.block_length = 0;
17295}
17296
17297/* Update the mask of the current automatically-generated IT
17298 instruction. See comments in new_automatic_it_block (). */
17299
17300static void
17301now_it_add_mask (int cond)
17302{
17303#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
17304#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 17305 | ((bitvalue) << (nbit)))
e07e6e58 17306 const int resulting_bit = (cond & 1);
c921be7d 17307
e07e6e58
NC
17308 now_it.mask &= 0xf;
17309 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17310 resulting_bit,
17311 (5 - now_it.block_length));
e07e6e58 17312 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17313 1,
17314 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
17315 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
17316
17317#undef CLEAR_BIT
17318#undef SET_BIT_VALUE
e07e6e58
NC
17319}
17320
17321/* The IT blocks handling machinery is accessed through the these functions:
17322 it_fsm_pre_encode () from md_assemble ()
17323 set_it_insn_type () optional, from the tencode functions
17324 set_it_insn_type_last () ditto
17325 in_it_block () ditto
17326 it_fsm_post_encode () from md_assemble ()
17327 force_automatic_it_block_close () from label habdling functions
17328
17329 Rationale:
17330 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
17331 initializing the IT insn type with a generic initial value depending
17332 on the inst.condition.
e07e6e58 17333 2) During the tencode function, two things may happen:
477330fc
RM
17334 a) The tencode function overrides the IT insn type by
17335 calling either set_it_insn_type (type) or set_it_insn_type_last ().
17336 b) The tencode function queries the IT block state by
17337 calling in_it_block () (i.e. to determine narrow/not narrow mode).
17338
17339 Both set_it_insn_type and in_it_block run the internal FSM state
17340 handling function (handle_it_state), because: a) setting the IT insn
17341 type may incur in an invalid state (exiting the function),
17342 and b) querying the state requires the FSM to be updated.
17343 Specifically we want to avoid creating an IT block for conditional
17344 branches, so it_fsm_pre_encode is actually a guess and we can't
17345 determine whether an IT block is required until the tencode () routine
17346 has decided what type of instruction this actually it.
17347 Because of this, if set_it_insn_type and in_it_block have to be used,
17348 set_it_insn_type has to be called first.
17349
17350 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
17351 determines the insn IT type depending on the inst.cond code.
17352 When a tencode () routine encodes an instruction that can be
17353 either outside an IT block, or, in the case of being inside, has to be
17354 the last one, set_it_insn_type_last () will determine the proper
17355 IT instruction type based on the inst.cond code. Otherwise,
17356 set_it_insn_type can be called for overriding that logic or
17357 for covering other cases.
17358
17359 Calling handle_it_state () may not transition the IT block state to
17360 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
17361 still queried. Instead, if the FSM determines that the state should
17362 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
17363 after the tencode () function: that's what it_fsm_post_encode () does.
17364
17365 Since in_it_block () calls the state handling function to get an
17366 updated state, an error may occur (due to invalid insns combination).
17367 In that case, inst.error is set.
17368 Therefore, inst.error has to be checked after the execution of
17369 the tencode () routine.
e07e6e58
NC
17370
17371 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
17372 any pending state change (if any) that didn't take place in
17373 handle_it_state () as explained above. */
e07e6e58
NC
17374
17375static void
17376it_fsm_pre_encode (void)
17377{
17378 if (inst.cond != COND_ALWAYS)
17379 inst.it_insn_type = INSIDE_IT_INSN;
17380 else
17381 inst.it_insn_type = OUTSIDE_IT_INSN;
17382
17383 now_it.state_handled = 0;
17384}
17385
17386/* IT state FSM handling function. */
17387
17388static int
17389handle_it_state (void)
17390{
17391 now_it.state_handled = 1;
5a01bb1d 17392 now_it.insn_cond = FALSE;
e07e6e58
NC
17393
17394 switch (now_it.state)
17395 {
17396 case OUTSIDE_IT_BLOCK:
17397 switch (inst.it_insn_type)
17398 {
17399 case OUTSIDE_IT_INSN:
17400 break;
17401
17402 case INSIDE_IT_INSN:
17403 case INSIDE_IT_LAST_INSN:
17404 if (thumb_mode == 0)
17405 {
c921be7d 17406 if (unified_syntax
e07e6e58
NC
17407 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
17408 as_tsktsk (_("Warning: conditional outside an IT block"\
17409 " for Thumb."));
17410 }
17411 else
17412 {
17413 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
17414 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
17415 {
17416 /* Automatically generate the IT instruction. */
17417 new_automatic_it_block (inst.cond);
17418 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
17419 close_automatic_it_block ();
17420 }
17421 else
17422 {
17423 inst.error = BAD_OUT_IT;
17424 return FAIL;
17425 }
17426 }
17427 break;
17428
17429 case IF_INSIDE_IT_LAST_INSN:
17430 case NEUTRAL_IT_INSN:
17431 break;
17432
17433 case IT_INSN:
17434 now_it.state = MANUAL_IT_BLOCK;
17435 now_it.block_length = 0;
17436 break;
17437 }
17438 break;
17439
17440 case AUTOMATIC_IT_BLOCK:
17441 /* Three things may happen now:
17442 a) We should increment current it block size;
17443 b) We should close current it block (closing insn or 4 insns);
17444 c) We should close current it block and start a new one (due
17445 to incompatible conditions or
17446 4 insns-length block reached). */
17447
17448 switch (inst.it_insn_type)
17449 {
17450 case OUTSIDE_IT_INSN:
17451 /* The closure of the block shall happen immediatelly,
17452 so any in_it_block () call reports the block as closed. */
17453 force_automatic_it_block_close ();
17454 break;
17455
17456 case INSIDE_IT_INSN:
17457 case INSIDE_IT_LAST_INSN:
17458 case IF_INSIDE_IT_LAST_INSN:
17459 now_it.block_length++;
17460
17461 if (now_it.block_length > 4
17462 || !now_it_compatible (inst.cond))
17463 {
17464 force_automatic_it_block_close ();
17465 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
17466 new_automatic_it_block (inst.cond);
17467 }
17468 else
17469 {
5a01bb1d 17470 now_it.insn_cond = TRUE;
e07e6e58
NC
17471 now_it_add_mask (inst.cond);
17472 }
17473
17474 if (now_it.state == AUTOMATIC_IT_BLOCK
17475 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
17476 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
17477 close_automatic_it_block ();
17478 break;
17479
17480 case NEUTRAL_IT_INSN:
17481 now_it.block_length++;
5a01bb1d 17482 now_it.insn_cond = TRUE;
e07e6e58
NC
17483
17484 if (now_it.block_length > 4)
17485 force_automatic_it_block_close ();
17486 else
17487 now_it_add_mask (now_it.cc & 1);
17488 break;
17489
17490 case IT_INSN:
17491 close_automatic_it_block ();
17492 now_it.state = MANUAL_IT_BLOCK;
17493 break;
17494 }
17495 break;
17496
17497 case MANUAL_IT_BLOCK:
17498 {
17499 /* Check conditional suffixes. */
17500 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
17501 int is_last;
17502 now_it.mask <<= 1;
17503 now_it.mask &= 0x1f;
17504 is_last = (now_it.mask == 0x10);
5a01bb1d 17505 now_it.insn_cond = TRUE;
e07e6e58
NC
17506
17507 switch (inst.it_insn_type)
17508 {
17509 case OUTSIDE_IT_INSN:
17510 inst.error = BAD_NOT_IT;
17511 return FAIL;
17512
17513 case INSIDE_IT_INSN:
17514 if (cond != inst.cond)
17515 {
17516 inst.error = BAD_IT_COND;
17517 return FAIL;
17518 }
17519 break;
17520
17521 case INSIDE_IT_LAST_INSN:
17522 case IF_INSIDE_IT_LAST_INSN:
17523 if (cond != inst.cond)
17524 {
17525 inst.error = BAD_IT_COND;
17526 return FAIL;
17527 }
17528 if (!is_last)
17529 {
17530 inst.error = BAD_BRANCH;
17531 return FAIL;
17532 }
17533 break;
17534
17535 case NEUTRAL_IT_INSN:
17536 /* The BKPT instruction is unconditional even in an IT block. */
17537 break;
17538
17539 case IT_INSN:
17540 inst.error = BAD_IT_IT;
17541 return FAIL;
17542 }
17543 }
17544 break;
17545 }
17546
17547 return SUCCESS;
17548}
17549
5a01bb1d
MGD
17550struct depr_insn_mask
17551{
17552 unsigned long pattern;
17553 unsigned long mask;
17554 const char* description;
17555};
17556
17557/* List of 16-bit instruction patterns deprecated in an IT block in
17558 ARMv8. */
17559static const struct depr_insn_mask depr_it_insns[] = {
17560 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
17561 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
17562 { 0xa000, 0xb800, N_("ADR") },
17563 { 0x4800, 0xf800, N_("Literal loads") },
17564 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
17565 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
17566 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
17567 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
17568 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
17569 { 0, 0, NULL }
17570};
17571
e07e6e58
NC
17572static void
17573it_fsm_post_encode (void)
17574{
17575 int is_last;
17576
17577 if (!now_it.state_handled)
17578 handle_it_state ();
17579
5a01bb1d
MGD
17580 if (now_it.insn_cond
17581 && !now_it.warn_deprecated
17582 && warn_on_deprecated
17583 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
17584 {
17585 if (inst.instruction >= 0x10000)
17586 {
5c3696f8 17587 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
5a01bb1d
MGD
17588 "deprecated in ARMv8"));
17589 now_it.warn_deprecated = TRUE;
17590 }
17591 else
17592 {
17593 const struct depr_insn_mask *p = depr_it_insns;
17594
17595 while (p->mask != 0)
17596 {
17597 if ((inst.instruction & p->mask) == p->pattern)
17598 {
5c3696f8 17599 as_tsktsk (_("IT blocks containing 16-bit Thumb instructions "
5a01bb1d
MGD
17600 "of the following class are deprecated in ARMv8: "
17601 "%s"), p->description);
17602 now_it.warn_deprecated = TRUE;
17603 break;
17604 }
17605
17606 ++p;
17607 }
17608 }
17609
17610 if (now_it.block_length > 1)
17611 {
5c3696f8 17612 as_tsktsk (_("IT blocks containing more than one conditional "
0a8897c7 17613 "instruction are deprecated in ARMv8"));
5a01bb1d
MGD
17614 now_it.warn_deprecated = TRUE;
17615 }
17616 }
17617
e07e6e58
NC
17618 is_last = (now_it.mask == 0x10);
17619 if (is_last)
17620 {
17621 now_it.state = OUTSIDE_IT_BLOCK;
17622 now_it.mask = 0;
17623 }
17624}
17625
17626static void
17627force_automatic_it_block_close (void)
17628{
17629 if (now_it.state == AUTOMATIC_IT_BLOCK)
17630 {
17631 close_automatic_it_block ();
17632 now_it.state = OUTSIDE_IT_BLOCK;
17633 now_it.mask = 0;
17634 }
17635}
17636
17637static int
17638in_it_block (void)
17639{
17640 if (!now_it.state_handled)
17641 handle_it_state ();
17642
17643 return now_it.state != OUTSIDE_IT_BLOCK;
17644}
17645
c19d1205
ZW
17646void
17647md_assemble (char *str)
b99bd4ef 17648{
c19d1205
ZW
17649 char *p = str;
17650 const struct asm_opcode * opcode;
b99bd4ef 17651
c19d1205
ZW
17652 /* Align the previous label if needed. */
17653 if (last_label_seen != NULL)
b99bd4ef 17654 {
c19d1205
ZW
17655 symbol_set_frag (last_label_seen, frag_now);
17656 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
17657 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
17658 }
17659
c19d1205
ZW
17660 memset (&inst, '\0', sizeof (inst));
17661 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 17662
c19d1205
ZW
17663 opcode = opcode_lookup (&p);
17664 if (!opcode)
b99bd4ef 17665 {
c19d1205 17666 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 17667 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 17668 if (! create_register_alias (str, p)
477330fc 17669 && ! create_neon_reg_alias (str, p))
c19d1205 17670 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 17671
b99bd4ef
NC
17672 return;
17673 }
17674
278df34e 17675 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 17676 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 17677
037e8744
JB
17678 /* The value which unconditional instructions should have in place of the
17679 condition field. */
17680 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
17681
c19d1205 17682 if (thumb_mode)
b99bd4ef 17683 {
e74cfd16 17684 arm_feature_set variant;
8f06b2d8
PB
17685
17686 variant = cpu_variant;
17687 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
17688 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
17689 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 17690 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
17691 if (!opcode->tvariant
17692 || (thumb_mode == 1
17693 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 17694 {
bf3eeda7 17695 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
b99bd4ef
NC
17696 return;
17697 }
c19d1205
ZW
17698 if (inst.cond != COND_ALWAYS && !unified_syntax
17699 && opcode->tencode != do_t_branch)
b99bd4ef 17700 {
c19d1205 17701 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
17702 return;
17703 }
17704
752d5da4 17705 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
076d447c 17706 {
7e806470 17707 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
752d5da4
NC
17708 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
17709 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
17710 {
17711 /* Two things are addressed here.
17712 1) Implicit require narrow instructions on Thumb-1.
17713 This avoids relaxation accidentally introducing Thumb-2
17714 instructions.
17715 2) Reject wide instructions in non Thumb-2 cores. */
17716 if (inst.size_req == 0)
17717 inst.size_req = 2;
17718 else if (inst.size_req == 4)
17719 {
bf3eeda7 17720 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
752d5da4
NC
17721 return;
17722 }
17723 }
076d447c
PB
17724 }
17725
c19d1205
ZW
17726 inst.instruction = opcode->tvalue;
17727
5be8be5d 17728 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
17729 {
17730 /* Prepare the it_insn_type for those encodings that don't set
17731 it. */
17732 it_fsm_pre_encode ();
c19d1205 17733
477330fc 17734 opcode->tencode ();
e07e6e58 17735
477330fc
RM
17736 it_fsm_post_encode ();
17737 }
e27ec89e 17738
0110f2b8 17739 if (!(inst.error || inst.relax))
b99bd4ef 17740 {
9c2799c2 17741 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
17742 inst.size = (inst.instruction > 0xffff ? 4 : 2);
17743 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 17744 {
c19d1205 17745 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
17746 return;
17747 }
17748 }
076d447c
PB
17749
17750 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 17751 instruction. */
9c2799c2 17752 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 17753
e74cfd16
PB
17754 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
17755 *opcode->tvariant);
ee065d83 17756 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 17757 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 17758 anything other than bl/blx and v6-M instructions.
3cfdb781
TG
17759 The impact of relaxable instructions will be considered later after we
17760 finish all relaxation. */
17761 if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
e07e6e58
NC
17762 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
17763 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
17764 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
17765 arm_ext_v6t2);
cd000bff 17766
88714cb8
DG
17767 check_neon_suffixes;
17768
cd000bff 17769 if (!inst.error)
c877a2f2
NC
17770 {
17771 mapping_state (MAP_THUMB);
17772 }
c19d1205 17773 }
3e9e4fcf 17774 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 17775 {
845b51d6
PB
17776 bfd_boolean is_bx;
17777
17778 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
17779 is_bx = (opcode->aencode == do_bx);
17780
c19d1205 17781 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
17782 if (!(is_bx && fix_v4bx)
17783 && !(opcode->avariant &&
17784 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 17785 {
bf3eeda7 17786 as_bad (_("selected processor does not support ARM mode `%s'"), str);
c19d1205 17787 return;
b99bd4ef 17788 }
c19d1205 17789 if (inst.size_req)
b99bd4ef 17790 {
c19d1205
ZW
17791 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
17792 return;
b99bd4ef
NC
17793 }
17794
c19d1205
ZW
17795 inst.instruction = opcode->avalue;
17796 if (opcode->tag == OT_unconditionalF)
17797 inst.instruction |= 0xF << 28;
17798 else
17799 inst.instruction |= inst.cond << 28;
17800 inst.size = INSN_SIZE;
5be8be5d 17801 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
17802 {
17803 it_fsm_pre_encode ();
17804 opcode->aencode ();
17805 it_fsm_post_encode ();
17806 }
ee065d83 17807 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 17808 on a hypothetical non-thumb v5 core. */
845b51d6 17809 if (is_bx)
e74cfd16 17810 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 17811 else
e74cfd16
PB
17812 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
17813 *opcode->avariant);
88714cb8
DG
17814
17815 check_neon_suffixes;
17816
cd000bff 17817 if (!inst.error)
c877a2f2
NC
17818 {
17819 mapping_state (MAP_ARM);
17820 }
b99bd4ef 17821 }
3e9e4fcf
JB
17822 else
17823 {
17824 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
17825 "-- `%s'"), str);
17826 return;
17827 }
c19d1205
ZW
17828 output_inst (str);
17829}
b99bd4ef 17830
e07e6e58
NC
17831static void
17832check_it_blocks_finished (void)
17833{
17834#ifdef OBJ_ELF
17835 asection *sect;
17836
17837 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
17838 if (seg_info (sect)->tc_segment_info_data.current_it.state
17839 == MANUAL_IT_BLOCK)
17840 {
17841 as_warn (_("section '%s' finished with an open IT block."),
17842 sect->name);
17843 }
17844#else
17845 if (now_it.state == MANUAL_IT_BLOCK)
17846 as_warn (_("file finished with an open IT block."));
17847#endif
17848}
17849
c19d1205
ZW
17850/* Various frobbings of labels and their addresses. */
17851
17852void
17853arm_start_line_hook (void)
17854{
17855 last_label_seen = NULL;
b99bd4ef
NC
17856}
17857
c19d1205
ZW
17858void
17859arm_frob_label (symbolS * sym)
b99bd4ef 17860{
c19d1205 17861 last_label_seen = sym;
b99bd4ef 17862
c19d1205 17863 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 17864
c19d1205
ZW
17865#if defined OBJ_COFF || defined OBJ_ELF
17866 ARM_SET_INTERWORK (sym, support_interwork);
17867#endif
b99bd4ef 17868
e07e6e58
NC
17869 force_automatic_it_block_close ();
17870
5f4273c7 17871 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
17872 as Thumb functions. This is because these labels, whilst
17873 they exist inside Thumb code, are not the entry points for
17874 possible ARM->Thumb calls. Also, these labels can be used
17875 as part of a computed goto or switch statement. eg gcc
17876 can generate code that looks like this:
b99bd4ef 17877
c19d1205
ZW
17878 ldr r2, [pc, .Laaa]
17879 lsl r3, r3, #2
17880 ldr r2, [r3, r2]
17881 mov pc, r2
b99bd4ef 17882
c19d1205
ZW
17883 .Lbbb: .word .Lxxx
17884 .Lccc: .word .Lyyy
17885 ..etc...
17886 .Laaa: .word Lbbb
b99bd4ef 17887
c19d1205
ZW
17888 The first instruction loads the address of the jump table.
17889 The second instruction converts a table index into a byte offset.
17890 The third instruction gets the jump address out of the table.
17891 The fourth instruction performs the jump.
b99bd4ef 17892
c19d1205
ZW
17893 If the address stored at .Laaa is that of a symbol which has the
17894 Thumb_Func bit set, then the linker will arrange for this address
17895 to have the bottom bit set, which in turn would mean that the
17896 address computation performed by the third instruction would end
17897 up with the bottom bit set. Since the ARM is capable of unaligned
17898 word loads, the instruction would then load the incorrect address
17899 out of the jump table, and chaos would ensue. */
17900 if (label_is_thumb_function_name
17901 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
17902 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 17903 {
c19d1205
ZW
17904 /* When the address of a Thumb function is taken the bottom
17905 bit of that address should be set. This will allow
17906 interworking between Arm and Thumb functions to work
17907 correctly. */
b99bd4ef 17908
c19d1205 17909 THUMB_SET_FUNC (sym, 1);
b99bd4ef 17910
c19d1205 17911 label_is_thumb_function_name = FALSE;
b99bd4ef 17912 }
07a53e5c 17913
07a53e5c 17914 dwarf2_emit_label (sym);
b99bd4ef
NC
17915}
17916
c921be7d 17917bfd_boolean
c19d1205 17918arm_data_in_code (void)
b99bd4ef 17919{
c19d1205 17920 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 17921 {
c19d1205
ZW
17922 *input_line_pointer = '/';
17923 input_line_pointer += 5;
17924 *input_line_pointer = 0;
c921be7d 17925 return TRUE;
b99bd4ef
NC
17926 }
17927
c921be7d 17928 return FALSE;
b99bd4ef
NC
17929}
17930
c19d1205
ZW
17931char *
17932arm_canonicalize_symbol_name (char * name)
b99bd4ef 17933{
c19d1205 17934 int len;
b99bd4ef 17935
c19d1205
ZW
17936 if (thumb_mode && (len = strlen (name)) > 5
17937 && streq (name + len - 5, "/data"))
17938 *(name + len - 5) = 0;
b99bd4ef 17939
c19d1205 17940 return name;
b99bd4ef 17941}
c19d1205
ZW
17942\f
17943/* Table of all register names defined by default. The user can
17944 define additional names with .req. Note that all register names
17945 should appear in both upper and lowercase variants. Some registers
17946 also have mixed-case names. */
b99bd4ef 17947
dcbf9037 17948#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 17949#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 17950#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
17951#define REGSET(p,t) \
17952 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
17953 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
17954 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
17955 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
17956#define REGSETH(p,t) \
17957 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
17958 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
17959 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
17960 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
17961#define REGSET2(p,t) \
17962 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
17963 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
17964 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
17965 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
17966#define SPLRBANK(base,bank,t) \
17967 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
17968 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
17969 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
17970 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
17971 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
17972 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 17973
c19d1205 17974static const struct reg_entry reg_names[] =
7ed4c4c5 17975{
c19d1205
ZW
17976 /* ARM integer registers. */
17977 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 17978
c19d1205
ZW
17979 /* ATPCS synonyms. */
17980 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
17981 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
17982 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 17983
c19d1205
ZW
17984 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
17985 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
17986 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 17987
c19d1205
ZW
17988 /* Well-known aliases. */
17989 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
17990 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
17991
17992 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
17993 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
17994
17995 /* Coprocessor numbers. */
17996 REGSET(p, CP), REGSET(P, CP),
17997
17998 /* Coprocessor register numbers. The "cr" variants are for backward
17999 compatibility. */
18000 REGSET(c, CN), REGSET(C, CN),
18001 REGSET(cr, CN), REGSET(CR, CN),
18002
90ec0d68
MGD
18003 /* ARM banked registers. */
18004 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
18005 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
18006 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
18007 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
18008 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
18009 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
18010 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
18011
18012 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
18013 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
18014 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
18015 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
18016 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 18017 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
18018 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
18019 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
18020
18021 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
18022 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
18023 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
18024 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
18025 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
18026 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
18027 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 18028 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
18029 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
18030
c19d1205
ZW
18031 /* FPA registers. */
18032 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
18033 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
18034
18035 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
18036 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
18037
18038 /* VFP SP registers. */
5287ad62
JB
18039 REGSET(s,VFS), REGSET(S,VFS),
18040 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
18041
18042 /* VFP DP Registers. */
5287ad62
JB
18043 REGSET(d,VFD), REGSET(D,VFD),
18044 /* Extra Neon DP registers. */
18045 REGSETH(d,VFD), REGSETH(D,VFD),
18046
18047 /* Neon QP registers. */
18048 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
18049
18050 /* VFP control registers. */
18051 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
18052 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
18053 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
18054 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
18055 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
18056 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
18057
18058 /* Maverick DSP coprocessor registers. */
18059 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
18060 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
18061
18062 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
18063 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
18064 REGDEF(dspsc,0,DSPSC),
18065
18066 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
18067 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
18068 REGDEF(DSPSC,0,DSPSC),
18069
18070 /* iWMMXt data registers - p0, c0-15. */
18071 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
18072
18073 /* iWMMXt control registers - p1, c0-3. */
18074 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
18075 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
18076 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
18077 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
18078
18079 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
18080 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
18081 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
18082 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
18083 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
18084
18085 /* XScale accumulator registers. */
18086 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
18087};
18088#undef REGDEF
18089#undef REGNUM
18090#undef REGSET
7ed4c4c5 18091
c19d1205
ZW
18092/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
18093 within psr_required_here. */
18094static const struct asm_psr psrs[] =
18095{
18096 /* Backward compatibility notation. Note that "all" is no longer
18097 truly all possible PSR bits. */
18098 {"all", PSR_c | PSR_f},
18099 {"flg", PSR_f},
18100 {"ctl", PSR_c},
18101
18102 /* Individual flags. */
18103 {"f", PSR_f},
18104 {"c", PSR_c},
18105 {"x", PSR_x},
18106 {"s", PSR_s},
59b42a0d 18107
c19d1205
ZW
18108 /* Combinations of flags. */
18109 {"fs", PSR_f | PSR_s},
18110 {"fx", PSR_f | PSR_x},
18111 {"fc", PSR_f | PSR_c},
18112 {"sf", PSR_s | PSR_f},
18113 {"sx", PSR_s | PSR_x},
18114 {"sc", PSR_s | PSR_c},
18115 {"xf", PSR_x | PSR_f},
18116 {"xs", PSR_x | PSR_s},
18117 {"xc", PSR_x | PSR_c},
18118 {"cf", PSR_c | PSR_f},
18119 {"cs", PSR_c | PSR_s},
18120 {"cx", PSR_c | PSR_x},
18121 {"fsx", PSR_f | PSR_s | PSR_x},
18122 {"fsc", PSR_f | PSR_s | PSR_c},
18123 {"fxs", PSR_f | PSR_x | PSR_s},
18124 {"fxc", PSR_f | PSR_x | PSR_c},
18125 {"fcs", PSR_f | PSR_c | PSR_s},
18126 {"fcx", PSR_f | PSR_c | PSR_x},
18127 {"sfx", PSR_s | PSR_f | PSR_x},
18128 {"sfc", PSR_s | PSR_f | PSR_c},
18129 {"sxf", PSR_s | PSR_x | PSR_f},
18130 {"sxc", PSR_s | PSR_x | PSR_c},
18131 {"scf", PSR_s | PSR_c | PSR_f},
18132 {"scx", PSR_s | PSR_c | PSR_x},
18133 {"xfs", PSR_x | PSR_f | PSR_s},
18134 {"xfc", PSR_x | PSR_f | PSR_c},
18135 {"xsf", PSR_x | PSR_s | PSR_f},
18136 {"xsc", PSR_x | PSR_s | PSR_c},
18137 {"xcf", PSR_x | PSR_c | PSR_f},
18138 {"xcs", PSR_x | PSR_c | PSR_s},
18139 {"cfs", PSR_c | PSR_f | PSR_s},
18140 {"cfx", PSR_c | PSR_f | PSR_x},
18141 {"csf", PSR_c | PSR_s | PSR_f},
18142 {"csx", PSR_c | PSR_s | PSR_x},
18143 {"cxf", PSR_c | PSR_x | PSR_f},
18144 {"cxs", PSR_c | PSR_x | PSR_s},
18145 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
18146 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
18147 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
18148 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
18149 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
18150 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
18151 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
18152 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
18153 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
18154 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
18155 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
18156 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
18157 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
18158 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
18159 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
18160 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
18161 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
18162 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
18163 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
18164 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
18165 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
18166 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
18167 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
18168 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
18169};
18170
62b3e311
PB
18171/* Table of V7M psr names. */
18172static const struct asm_psr v7m_psrs[] =
18173{
2b744c99
PB
18174 {"apsr", 0 }, {"APSR", 0 },
18175 {"iapsr", 1 }, {"IAPSR", 1 },
18176 {"eapsr", 2 }, {"EAPSR", 2 },
18177 {"psr", 3 }, {"PSR", 3 },
18178 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
18179 {"ipsr", 5 }, {"IPSR", 5 },
18180 {"epsr", 6 }, {"EPSR", 6 },
18181 {"iepsr", 7 }, {"IEPSR", 7 },
18182 {"msp", 8 }, {"MSP", 8 },
18183 {"psp", 9 }, {"PSP", 9 },
18184 {"primask", 16}, {"PRIMASK", 16},
18185 {"basepri", 17}, {"BASEPRI", 17},
00bbc0bd
NC
18186 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
18187 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
2b744c99
PB
18188 {"faultmask", 19}, {"FAULTMASK", 19},
18189 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
18190};
18191
c19d1205
ZW
18192/* Table of all shift-in-operand names. */
18193static const struct asm_shift_name shift_names [] =
b99bd4ef 18194{
c19d1205
ZW
18195 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
18196 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
18197 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
18198 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
18199 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
18200 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
18201};
b99bd4ef 18202
c19d1205
ZW
18203/* Table of all explicit relocation names. */
18204#ifdef OBJ_ELF
18205static struct reloc_entry reloc_names[] =
18206{
18207 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
18208 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
18209 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
18210 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
18211 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
18212 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
18213 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
18214 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
18215 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
18216 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 18217 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
18218 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
18219 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 18220 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 18221 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 18222 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 18223 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
477330fc 18224 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
18225};
18226#endif
b99bd4ef 18227
c19d1205
ZW
18228/* Table of all conditional affixes. 0xF is not defined as a condition code. */
18229static const struct asm_cond conds[] =
18230{
18231 {"eq", 0x0},
18232 {"ne", 0x1},
18233 {"cs", 0x2}, {"hs", 0x2},
18234 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
18235 {"mi", 0x4},
18236 {"pl", 0x5},
18237 {"vs", 0x6},
18238 {"vc", 0x7},
18239 {"hi", 0x8},
18240 {"ls", 0x9},
18241 {"ge", 0xa},
18242 {"lt", 0xb},
18243 {"gt", 0xc},
18244 {"le", 0xd},
18245 {"al", 0xe}
18246};
bfae80f2 18247
e797f7e0 18248#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
18249 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
18250 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 18251
62b3e311
PB
18252static struct asm_barrier_opt barrier_opt_names[] =
18253{
e797f7e0
MGD
18254 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
18255 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
18256 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
18257 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
18258 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
18259 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
18260 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
18261 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
18262 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
18263 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
18264 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
18265 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
18266 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
18267 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
18268 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
18269 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
18270};
18271
e797f7e0
MGD
18272#undef UL_BARRIER
18273
c19d1205
ZW
18274/* Table of ARM-format instructions. */
18275
18276/* Macros for gluing together operand strings. N.B. In all cases
18277 other than OPS0, the trailing OP_stop comes from default
18278 zero-initialization of the unspecified elements of the array. */
18279#define OPS0() { OP_stop, }
18280#define OPS1(a) { OP_##a, }
18281#define OPS2(a,b) { OP_##a,OP_##b, }
18282#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
18283#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
18284#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
18285#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
18286
5be8be5d
DG
18287/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
18288 This is useful when mixing operands for ARM and THUMB, i.e. using the
18289 MIX_ARM_THUMB_OPERANDS macro.
18290 In order to use these macros, prefix the number of operands with _
18291 e.g. _3. */
18292#define OPS_1(a) { a, }
18293#define OPS_2(a,b) { a,b, }
18294#define OPS_3(a,b,c) { a,b,c, }
18295#define OPS_4(a,b,c,d) { a,b,c,d, }
18296#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
18297#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
18298
c19d1205
ZW
18299/* These macros abstract out the exact format of the mnemonic table and
18300 save some repeated characters. */
18301
18302/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
18303#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18304 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 18305 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18306
18307/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
18308 a T_MNEM_xyz enumerator. */
18309#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18310 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18311#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18312 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
18313
18314/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
18315 infix after the third character. */
18316#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 18317 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 18318 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 18319#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 18320 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 18321 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18322#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18323 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 18324#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18325 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18326#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18327 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 18328#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18329 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 18330
c19d1205 18331/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
18332 field is still 0xE. Many of the Thumb variants can be executed
18333 conditionally, so this is checked separately. */
c19d1205 18334#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18335 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18336 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18337
dd5181d5
KT
18338/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
18339 Used by mnemonics that have very minimal differences in the encoding for
18340 ARM and Thumb variants and can be handled in a common function. */
18341#define TUEc(mnem, op, top, nops, ops, en) \
18342 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
18343 THUMB_VARIANT, do_##en, do_##en }
18344
c19d1205
ZW
18345/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
18346 condition code field. */
18347#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 18348 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18349 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18350
18351/* ARM-only variants of all the above. */
6a86118a 18352#define CE(mnem, op, nops, ops, ae) \
21d799b5 18353 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
18354
18355#define C3(mnem, op, nops, ops, ae) \
18356 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18357
e3cb604e
PB
18358/* Legacy mnemonics that always have conditional infix after the third
18359 character. */
18360#define CL(mnem, op, nops, ops, ae) \
21d799b5 18361 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
18362 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18363
8f06b2d8
PB
18364/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
18365#define cCE(mnem, op, nops, ops, ae) \
21d799b5 18366 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 18367
e3cb604e
PB
18368/* Legacy coprocessor instructions where conditional infix and conditional
18369 suffix are ambiguous. For consistency this includes all FPA instructions,
18370 not just the potentially ambiguous ones. */
18371#define cCL(mnem, op, nops, ops, ae) \
21d799b5 18372 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
18373 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
18374
18375/* Coprocessor, takes either a suffix or a position-3 infix
18376 (for an FPA corner case). */
18377#define C3E(mnem, op, nops, ops, ae) \
21d799b5 18378 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 18379 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 18380
6a86118a 18381#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
18382 { m1 #m2 m3, OPS##nops ops, \
18383 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
18384 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18385
18386#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
18387 xCM_ (m1, , m2, op, nops, ops, ae), \
18388 xCM_ (m1, eq, m2, op, nops, ops, ae), \
18389 xCM_ (m1, ne, m2, op, nops, ops, ae), \
18390 xCM_ (m1, cs, m2, op, nops, ops, ae), \
18391 xCM_ (m1, hs, m2, op, nops, ops, ae), \
18392 xCM_ (m1, cc, m2, op, nops, ops, ae), \
18393 xCM_ (m1, ul, m2, op, nops, ops, ae), \
18394 xCM_ (m1, lo, m2, op, nops, ops, ae), \
18395 xCM_ (m1, mi, m2, op, nops, ops, ae), \
18396 xCM_ (m1, pl, m2, op, nops, ops, ae), \
18397 xCM_ (m1, vs, m2, op, nops, ops, ae), \
18398 xCM_ (m1, vc, m2, op, nops, ops, ae), \
18399 xCM_ (m1, hi, m2, op, nops, ops, ae), \
18400 xCM_ (m1, ls, m2, op, nops, ops, ae), \
18401 xCM_ (m1, ge, m2, op, nops, ops, ae), \
18402 xCM_ (m1, lt, m2, op, nops, ops, ae), \
18403 xCM_ (m1, gt, m2, op, nops, ops, ae), \
18404 xCM_ (m1, le, m2, op, nops, ops, ae), \
18405 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
18406
18407#define UE(mnem, op, nops, ops, ae) \
18408 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
18409
18410#define UF(mnem, op, nops, ops, ae) \
18411 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
18412
5287ad62
JB
18413/* Neon data-processing. ARM versions are unconditional with cond=0xf.
18414 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
18415 use the same encoding function for each. */
18416#define NUF(mnem, op, nops, ops, enc) \
18417 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
18418 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18419
18420/* Neon data processing, version which indirects through neon_enc_tab for
18421 the various overloaded versions of opcodes. */
18422#define nUF(mnem, op, nops, ops, enc) \
21d799b5 18423 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
18424 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18425
18426/* Neon insn with conditional suffix for the ARM version, non-overloaded
18427 version. */
037e8744
JB
18428#define NCE_tag(mnem, op, nops, ops, enc, tag) \
18429 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
18430 THUMB_VARIANT, do_##enc, do_##enc }
18431
037e8744 18432#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 18433 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
18434
18435#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 18436 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 18437
5287ad62 18438/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 18439#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 18440 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
18441 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18442
037e8744 18443#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 18444 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
18445
18446#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 18447 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 18448
c19d1205
ZW
18449#define do_0 0
18450
c19d1205 18451static const struct asm_opcode insns[] =
bfae80f2 18452{
74db7efb
NC
18453#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
18454#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
18455 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
18456 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
18457 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
18458 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
18459 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
18460 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
18461 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
18462 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
18463 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
18464 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
18465 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
18466 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
18467 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
18468 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
18469 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
18470 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
18471
18472 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
18473 for setting PSR flag bits. They are obsolete in V6 and do not
18474 have Thumb equivalents. */
21d799b5
NC
18475 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
18476 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
18477 CL("tstp", 110f000, 2, (RR, SH), cmp),
18478 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
18479 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
18480 CL("cmpp", 150f000, 2, (RR, SH), cmp),
18481 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
18482 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
18483 CL("cmnp", 170f000, 2, (RR, SH), cmp),
18484
18485 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
18486 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
18487 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
18488 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
18489
18490 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
18491 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
18492 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
18493 OP_RRnpc),
18494 OP_ADDRGLDR),ldst, t_ldst),
18495 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
18496
18497 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18498 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18499 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18500 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18501 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18502 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18503
18504 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
18505 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
18506 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
18507 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 18508
c19d1205 18509 /* Pseudo ops. */
21d799b5 18510 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 18511 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 18512 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 18513 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
18514
18515 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
18516 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
18517 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
18518 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
18519 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
18520 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
18521 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
18522 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
18523 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
18524 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
18525 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
18526 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
18527 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 18528
16a4cf17 18529 /* These may simplify to neg. */
21d799b5
NC
18530 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
18531 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 18532
c921be7d
NC
18533#undef THUMB_VARIANT
18534#define THUMB_VARIANT & arm_ext_v6
18535
21d799b5 18536 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
18537
18538 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
18539#undef THUMB_VARIANT
18540#define THUMB_VARIANT & arm_ext_v6t2
18541
21d799b5
NC
18542 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
18543 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
18544 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 18545
5be8be5d
DG
18546 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
18547 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
18548 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
18549 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 18550
21d799b5
NC
18551 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18552 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 18553
21d799b5
NC
18554 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18555 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
18556
18557 /* V1 instructions with no Thumb analogue at all. */
21d799b5 18558 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
18559 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
18560
18561 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
18562 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
18563 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
18564 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
18565 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
18566 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
18567 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
18568 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
18569
c921be7d
NC
18570#undef ARM_VARIANT
18571#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
18572#undef THUMB_VARIANT
18573#define THUMB_VARIANT & arm_ext_v4t
18574
21d799b5
NC
18575 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
18576 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 18577
c921be7d
NC
18578#undef THUMB_VARIANT
18579#define THUMB_VARIANT & arm_ext_v6t2
18580
21d799b5 18581 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
18582 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
18583
18584 /* Generic coprocessor instructions. */
21d799b5
NC
18585 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
18586 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18587 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18588 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18589 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18590 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 18591 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 18592
c921be7d
NC
18593#undef ARM_VARIANT
18594#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
18595
21d799b5 18596 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
18597 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
18598
c921be7d
NC
18599#undef ARM_VARIANT
18600#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
18601#undef THUMB_VARIANT
18602#define THUMB_VARIANT & arm_ext_msr
18603
d2cd1205
JB
18604 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
18605 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 18606
c921be7d
NC
18607#undef ARM_VARIANT
18608#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
18609#undef THUMB_VARIANT
18610#define THUMB_VARIANT & arm_ext_v6t2
18611
21d799b5
NC
18612 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18613 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18614 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18615 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18616 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18617 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18618 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18619 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 18620
c921be7d
NC
18621#undef ARM_VARIANT
18622#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
18623#undef THUMB_VARIANT
18624#define THUMB_VARIANT & arm_ext_v4t
18625
5be8be5d
DG
18626 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18627 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18628 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18629 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
18630 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18631 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 18632
c921be7d
NC
18633#undef ARM_VARIANT
18634#define ARM_VARIANT & arm_ext_v4t_5
18635
c19d1205
ZW
18636 /* ARM Architecture 4T. */
18637 /* Note: bx (and blx) are required on V5, even if the processor does
18638 not support Thumb. */
21d799b5 18639 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 18640
c921be7d
NC
18641#undef ARM_VARIANT
18642#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
18643#undef THUMB_VARIANT
18644#define THUMB_VARIANT & arm_ext_v5t
18645
c19d1205
ZW
18646 /* Note: blx has 2 variants; the .value coded here is for
18647 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
18648 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
18649 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 18650
c921be7d
NC
18651#undef THUMB_VARIANT
18652#define THUMB_VARIANT & arm_ext_v6t2
18653
21d799b5
NC
18654 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
18655 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18656 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18657 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18658 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18659 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
18660 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
18661 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 18662
c921be7d 18663#undef ARM_VARIANT
74db7efb
NC
18664#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
18665#undef THUMB_VARIANT
18666#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 18667
21d799b5
NC
18668 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18669 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18670 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18671 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 18672
21d799b5
NC
18673 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18674 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 18675
21d799b5
NC
18676 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18677 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18678 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18679 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 18680
21d799b5
NC
18681 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18682 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18683 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18684 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 18685
21d799b5
NC
18686 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18687 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 18688
03ee1b7f
NC
18689 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18690 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18691 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18692 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 18693
c921be7d 18694#undef ARM_VARIANT
74db7efb
NC
18695#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
18696#undef THUMB_VARIANT
18697#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 18698
21d799b5 18699 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
18700 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
18701 ldrd, t_ldstd),
18702 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
18703 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 18704
21d799b5
NC
18705 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18706 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 18707
c921be7d
NC
18708#undef ARM_VARIANT
18709#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
18710
21d799b5 18711 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 18712
c921be7d
NC
18713#undef ARM_VARIANT
18714#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
18715#undef THUMB_VARIANT
18716#define THUMB_VARIANT & arm_ext_v6
18717
21d799b5
NC
18718 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
18719 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
18720 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18721 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18722 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18723 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18724 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18725 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18726 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18727 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 18728
c921be7d
NC
18729#undef THUMB_VARIANT
18730#define THUMB_VARIANT & arm_ext_v6t2
18731
5be8be5d
DG
18732 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
18733 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
18734 strex, t_strex),
21d799b5
NC
18735 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18736 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 18737
21d799b5
NC
18738 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
18739 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 18740
9e3c6df6 18741/* ARM V6 not included in V7M. */
c921be7d
NC
18742#undef THUMB_VARIANT
18743#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 18744 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 18745 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
18746 UF(rfeib, 9900a00, 1, (RRw), rfe),
18747 UF(rfeda, 8100a00, 1, (RRw), rfe),
18748 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
18749 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
18750 UF(rfefa, 8100a00, 1, (RRw), rfe),
18751 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
18752 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 18753 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
18754 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
18755 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 18756 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 18757 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 18758 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 18759 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 18760 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 18761 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c921be7d 18762
9e3c6df6
PB
18763/* ARM V6 not included in V7M (eg. integer SIMD). */
18764#undef THUMB_VARIANT
18765#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
18766 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
18767 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
18768 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
18769 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18770 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18771 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18772 /* Old name for QASX. */
74db7efb 18773 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 18774 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18775 /* Old name for QSAX. */
74db7efb 18776 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18777 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18778 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18779 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18780 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18781 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18782 /* Old name for SASX. */
74db7efb 18783 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18784 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18785 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 18786 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18787 /* Old name for SHASX. */
21d799b5 18788 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 18789 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18790 /* Old name for SHSAX. */
21d799b5
NC
18791 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18792 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18793 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18794 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18795 /* Old name for SSAX. */
74db7efb 18796 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18797 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18798 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18799 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18800 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18801 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18802 /* Old name for UASX. */
74db7efb 18803 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18804 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18805 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 18806 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18807 /* Old name for UHASX. */
21d799b5
NC
18808 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18809 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18810 /* Old name for UHSAX. */
21d799b5
NC
18811 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18812 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18813 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18814 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18815 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 18816 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18817 /* Old name for UQASX. */
21d799b5
NC
18818 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18819 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18820 /* Old name for UQSAX. */
21d799b5
NC
18821 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18822 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18823 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18824 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18825 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18826 /* Old name for USAX. */
74db7efb 18827 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 18828 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18829 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18830 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18831 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18832 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18833 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18834 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18835 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18836 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18837 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18838 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18839 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18840 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18841 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18842 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18843 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18844 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18845 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18846 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18847 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18848 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18849 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18850 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18851 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18852 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18853 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18854 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18855 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
18856 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
18857 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
18858 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18859 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18860 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 18861
c921be7d
NC
18862#undef ARM_VARIANT
18863#define ARM_VARIANT & arm_ext_v6k
18864#undef THUMB_VARIANT
18865#define THUMB_VARIANT & arm_ext_v6k
18866
21d799b5
NC
18867 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
18868 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
18869 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
18870 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 18871
c921be7d
NC
18872#undef THUMB_VARIANT
18873#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
18874 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
18875 ldrexd, t_ldrexd),
18876 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
18877 RRnpcb), strexd, t_strexd),
ebdca51a 18878
c921be7d
NC
18879#undef THUMB_VARIANT
18880#define THUMB_VARIANT & arm_ext_v6t2
5be8be5d
DG
18881 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
18882 rd_rn, rd_rn),
18883 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
18884 rd_rn, rd_rn),
18885 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 18886 strex, t_strexbh),
5be8be5d 18887 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 18888 strex, t_strexbh),
21d799b5 18889 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 18890
c921be7d 18891#undef ARM_VARIANT
f4c65163 18892#define ARM_VARIANT & arm_ext_sec
74db7efb 18893#undef THUMB_VARIANT
f4c65163 18894#define THUMB_VARIANT & arm_ext_sec
c921be7d 18895
21d799b5 18896 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 18897
90ec0d68
MGD
18898#undef ARM_VARIANT
18899#define ARM_VARIANT & arm_ext_virt
18900#undef THUMB_VARIANT
18901#define THUMB_VARIANT & arm_ext_virt
18902
18903 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
18904 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
18905
ddfded2f
MW
18906#undef ARM_VARIANT
18907#define ARM_VARIANT & arm_ext_pan
18908#undef THUMB_VARIANT
18909#define THUMB_VARIANT & arm_ext_pan
18910
18911 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
18912
c921be7d 18913#undef ARM_VARIANT
74db7efb 18914#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
18915#undef THUMB_VARIANT
18916#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 18917
21d799b5
NC
18918 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
18919 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
18920 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
18921 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 18922
21d799b5
NC
18923 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
18924 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
18925 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
18926 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 18927
5be8be5d
DG
18928 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
18929 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
18930 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
18931 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 18932
bf3eeda7 18933 /* Thumb-only instructions. */
74db7efb 18934#undef ARM_VARIANT
bf3eeda7
NS
18935#define ARM_VARIANT NULL
18936 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
18937 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
18938
18939 /* ARM does not really have an IT instruction, so always allow it.
18940 The opcode is copied from Thumb in order to allow warnings in
18941 -mimplicit-it=[never | arm] modes. */
18942#undef ARM_VARIANT
18943#define ARM_VARIANT & arm_ext_v1
18944
21d799b5
NC
18945 TUE("it", bf08, bf08, 1, (COND), it, t_it),
18946 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
18947 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
18948 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
18949 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
18950 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
18951 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
18952 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
18953 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
18954 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
18955 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
18956 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
18957 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
18958 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
18959 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 18960 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
18961 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
18962 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 18963
92e90b6e 18964 /* Thumb2 only instructions. */
c921be7d
NC
18965#undef ARM_VARIANT
18966#define ARM_VARIANT NULL
92e90b6e 18967
21d799b5
NC
18968 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
18969 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
18970 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
18971 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
18972 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
18973 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 18974
eea54501
MGD
18975 /* Hardware division instructions. */
18976#undef ARM_VARIANT
18977#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
18978#undef THUMB_VARIANT
18979#define THUMB_VARIANT & arm_ext_div
18980
eea54501
MGD
18981 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
18982 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 18983
7e806470 18984 /* ARM V6M/V7 instructions. */
c921be7d
NC
18985#undef ARM_VARIANT
18986#define ARM_VARIANT & arm_ext_barrier
18987#undef THUMB_VARIANT
18988#define THUMB_VARIANT & arm_ext_barrier
18989
ccb84d65
JB
18990 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
18991 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
18992 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 18993
62b3e311 18994 /* ARM V7 instructions. */
c921be7d
NC
18995#undef ARM_VARIANT
18996#define ARM_VARIANT & arm_ext_v7
18997#undef THUMB_VARIANT
18998#define THUMB_VARIANT & arm_ext_v7
18999
21d799b5
NC
19000 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
19001 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 19002
74db7efb 19003#undef ARM_VARIANT
60e5ef9f 19004#define ARM_VARIANT & arm_ext_mp
74db7efb 19005#undef THUMB_VARIANT
60e5ef9f
MGD
19006#define THUMB_VARIANT & arm_ext_mp
19007
19008 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
19009
53c4b28b
MGD
19010 /* AArchv8 instructions. */
19011#undef ARM_VARIANT
19012#define ARM_VARIANT & arm_ext_v8
19013#undef THUMB_VARIANT
19014#define THUMB_VARIANT & arm_ext_v8
19015
19016 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
8884b720 19017 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
4b8c8c02
RE
19018 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19019 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
9eb6c0f1 19020 ldrexd, t_ldrexd),
4b8c8c02
RE
19021 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
19022 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19023 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
19024 stlex, t_stlex),
19025 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
9eb6c0f1 19026 strexd, t_strexd),
4b8c8c02
RE
19027 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
19028 stlex, t_stlex),
19029 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
19030 stlex, t_stlex),
19031 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19032 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19033 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19034 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19035 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19036 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
53c4b28b 19037
8884b720 19038 /* ARMv8 T32 only. */
74db7efb 19039#undef ARM_VARIANT
b79f7053
MGD
19040#define ARM_VARIANT NULL
19041 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
19042 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
19043 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
19044
33399f07
MGD
19045 /* FP for ARMv8. */
19046#undef ARM_VARIANT
a715796b 19047#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 19048#undef THUMB_VARIANT
a715796b 19049#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
19050
19051 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
19052 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
19053 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
19054 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
19055 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
19056 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
19057 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
19058 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
19059 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
19060 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
19061 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
19062 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
19063 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
19064 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
19065 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
19066 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
19067 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 19068
91ff7894
MGD
19069 /* Crypto v1 extensions. */
19070#undef ARM_VARIANT
19071#define ARM_VARIANT & fpu_crypto_ext_armv8
19072#undef THUMB_VARIANT
19073#define THUMB_VARIANT & fpu_crypto_ext_armv8
19074
19075 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
19076 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
19077 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
19078 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
19079 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
19080 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
19081 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
19082 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
19083 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
19084 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
19085 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
19086 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
19087 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
19088 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 19089
dd5181d5 19090#undef ARM_VARIANT
74db7efb 19091#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
19092#undef THUMB_VARIANT
19093#define THUMB_VARIANT & crc_ext_armv8
19094 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
19095 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
19096 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
19097 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
19098 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
19099 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
19100
c921be7d
NC
19101#undef ARM_VARIANT
19102#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
19103#undef THUMB_VARIANT
19104#define THUMB_VARIANT NULL
c921be7d 19105
21d799b5
NC
19106 cCE("wfs", e200110, 1, (RR), rd),
19107 cCE("rfs", e300110, 1, (RR), rd),
19108 cCE("wfc", e400110, 1, (RR), rd),
19109 cCE("rfc", e500110, 1, (RR), rd),
19110
19111 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
19112 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
19113 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
19114 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
19115
19116 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
19117 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
19118 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
19119 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
19120
19121 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
19122 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
19123 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
19124 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
19125 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
19126 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
19127 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
19128 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
19129 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
19130 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
19131 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
19132 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
19133
19134 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
19135 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
19136 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
19137 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
19138 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
19139 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
19140 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
19141 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
19142 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
19143 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
19144 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
19145 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
19146
19147 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
19148 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
19149 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
19150 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
19151 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
19152 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
19153 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
19154 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
19155 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
19156 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
19157 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
19158 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
19159
19160 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
19161 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
19162 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
19163 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
19164 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
19165 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
19166 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
19167 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
19168 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
19169 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
19170 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
19171 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
19172
19173 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
19174 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
19175 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
19176 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
19177 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
19178 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
19179 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
19180 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
19181 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
19182 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
19183 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
19184 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
19185
19186 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
19187 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
19188 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
19189 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
19190 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
19191 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
19192 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
19193 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
19194 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
19195 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
19196 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
19197 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
19198
19199 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
19200 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
19201 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
19202 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
19203 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
19204 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
19205 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
19206 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
19207 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
19208 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
19209 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
19210 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
19211
19212 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
19213 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
19214 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
19215 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
19216 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
19217 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
19218 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
19219 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
19220 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
19221 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
19222 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
19223 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
19224
19225 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
19226 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
19227 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
19228 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
19229 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
19230 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
19231 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
19232 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
19233 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
19234 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
19235 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
19236 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
19237
19238 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
19239 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
19240 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
19241 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
19242 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
19243 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
19244 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
19245 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
19246 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
19247 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
19248 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
19249 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
19250
19251 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
19252 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
19253 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
19254 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
19255 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
19256 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
19257 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
19258 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
19259 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
19260 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
19261 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
19262 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
19263
19264 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
19265 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
19266 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
19267 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
19268 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
19269 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
19270 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
19271 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
19272 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
19273 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
19274 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
19275 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
19276
19277 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
19278 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
19279 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
19280 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
19281 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
19282 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
19283 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
19284 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
19285 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
19286 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
19287 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
19288 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
19289
19290 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
19291 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
19292 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
19293 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
19294 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
19295 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
19296 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
19297 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
19298 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
19299 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
19300 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
19301 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
19302
19303 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
19304 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
19305 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
19306 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
19307 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
19308 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
19309 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
19310 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
19311 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
19312 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
19313 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
19314 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
19315
19316 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
19317 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
19318 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
19319 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
19320 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
19321 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
19322 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
19323 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
19324 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
19325 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
19326 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
19327 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
19328
19329 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
19330 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
19331 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
19332 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
19333 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
19334 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19335 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19336 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19337 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
19338 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
19339 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
19340 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
19341
19342 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
19343 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
19344 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
19345 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
19346 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
19347 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19348 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19349 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19350 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
19351 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
19352 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
19353 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
19354
19355 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
19356 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
19357 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
19358 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
19359 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
19360 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19361 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19362 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19363 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
19364 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
19365 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
19366 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
19367
19368 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
19369 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
19370 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
19371 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
19372 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
19373 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19374 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19375 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19376 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
19377 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
19378 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
19379 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
19380
19381 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
19382 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
19383 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
19384 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
19385 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
19386 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19387 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19388 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19389 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
19390 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
19391 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
19392 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
19393
19394 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
19395 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
19396 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
19397 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
19398 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
19399 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19400 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19401 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19402 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
19403 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
19404 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
19405 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
19406
19407 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
19408 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
19409 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
19410 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
19411 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
19412 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19413 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19414 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19415 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
19416 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
19417 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
19418 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
19419
19420 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
19421 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
19422 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
19423 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
19424 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
19425 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19426 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19427 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19428 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
19429 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
19430 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
19431 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
19432
19433 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
19434 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
19435 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
19436 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
19437 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
19438 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19439 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19440 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19441 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
19442 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
19443 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
19444 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
19445
19446 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
19447 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
19448 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
19449 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
19450 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
19451 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19452 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19453 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19454 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
19455 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
19456 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
19457 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
19458
19459 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19460 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19461 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19462 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19463 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19464 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19465 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19466 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19467 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19468 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19469 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19470 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19471
19472 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19473 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19474 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19475 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19476 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19477 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19478 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19479 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19480 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19481 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19482 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19483 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19484
19485 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19486 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19487 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19488 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19489 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19490 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19491 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19492 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19493 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19494 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19495 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19496 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19497
19498 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
19499 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
19500 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
19501 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
19502
19503 cCL("flts", e000110, 2, (RF, RR), rn_rd),
19504 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
19505 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
19506 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
19507 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
19508 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
19509 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
19510 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
19511 cCL("flte", e080110, 2, (RF, RR), rn_rd),
19512 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
19513 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
19514 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 19515
c19d1205
ZW
19516 /* The implementation of the FIX instruction is broken on some
19517 assemblers, in that it accepts a precision specifier as well as a
19518 rounding specifier, despite the fact that this is meaningless.
19519 To be more compatible, we accept it as well, though of course it
19520 does not set any bits. */
21d799b5
NC
19521 cCE("fix", e100110, 2, (RR, RF), rd_rm),
19522 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
19523 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
19524 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
19525 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
19526 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
19527 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
19528 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
19529 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
19530 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
19531 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
19532 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
19533 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 19534
c19d1205 19535 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
19536#undef ARM_VARIANT
19537#define ARM_VARIANT & fpu_fpa_ext_v2
19538
21d799b5
NC
19539 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19540 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19541 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19542 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19543 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19544 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 19545
c921be7d
NC
19546#undef ARM_VARIANT
19547#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
19548
c19d1205 19549 /* Moves and type conversions. */
21d799b5
NC
19550 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
19551 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
19552 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
19553 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
19554 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
19555 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
19556 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
19557 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
19558 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
19559 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
19560 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
19561 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
19562 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
19563 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
19564
19565 /* Memory operations. */
21d799b5
NC
19566 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
19567 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
19568 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19569 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19570 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19571 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19572 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19573 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19574 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19575 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19576 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19577 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19578 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19579 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19580 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19581 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19582 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19583 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 19584
c19d1205 19585 /* Monadic operations. */
21d799b5
NC
19586 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
19587 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
19588 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
19589
19590 /* Dyadic operations. */
21d799b5
NC
19591 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19592 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19593 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19594 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19595 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19596 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19597 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19598 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19599 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 19600
c19d1205 19601 /* Comparisons. */
21d799b5
NC
19602 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
19603 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
19604 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
19605 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 19606
62f3b8c8
PB
19607 /* Double precision load/store are still present on single precision
19608 implementations. */
19609 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
19610 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
19611 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19612 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19613 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19614 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19615 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19616 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19617 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19618 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 19619
c921be7d
NC
19620#undef ARM_VARIANT
19621#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
19622
c19d1205 19623 /* Moves and type conversions. */
21d799b5
NC
19624 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19625 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
19626 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19627 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
19628 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
19629 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
19630 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
19631 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
19632 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
19633 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
19634 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19635 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
19636 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 19637
c19d1205 19638 /* Monadic operations. */
21d799b5
NC
19639 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19640 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19641 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
19642
19643 /* Dyadic operations. */
21d799b5
NC
19644 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19645 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19646 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19647 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19648 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19649 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19650 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19651 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19652 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 19653
c19d1205 19654 /* Comparisons. */
21d799b5
NC
19655 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19656 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
19657 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19658 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 19659
c921be7d
NC
19660#undef ARM_VARIANT
19661#define ARM_VARIANT & fpu_vfp_ext_v2
19662
21d799b5
NC
19663 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
19664 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
19665 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
19666 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 19667
037e8744
JB
19668/* Instructions which may belong to either the Neon or VFP instruction sets.
19669 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
19670#undef ARM_VARIANT
19671#define ARM_VARIANT & fpu_vfp_ext_v1xd
19672#undef THUMB_VARIANT
19673#define THUMB_VARIANT & fpu_vfp_ext_v1xd
19674
037e8744
JB
19675 /* These mnemonics are unique to VFP. */
19676 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
19677 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
19678 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19679 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19680 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
19681 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
19682 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
19683 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
19684 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
19685 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
19686
19687 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
19688 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
19689 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
19690 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 19691
21d799b5
NC
19692 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
19693 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
19694
19695 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
19696 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
19697
55881a11
MGD
19698 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19699 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19700 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19701 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19702 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19703 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
19704 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
19705 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 19706
5f1af56b 19707 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 19708 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
19709 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
19710 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 19711
037e8744
JB
19712
19713 /* NOTE: All VMOV encoding is special-cased! */
19714 NCE(vmov, 0, 1, (VMOV), neon_mov),
19715 NCE(vmovq, 0, 1, (VMOV), neon_mov),
19716
c921be7d
NC
19717#undef THUMB_VARIANT
19718#define THUMB_VARIANT & fpu_neon_ext_v1
19719#undef ARM_VARIANT
19720#define ARM_VARIANT & fpu_neon_ext_v1
19721
5287ad62
JB
19722 /* Data processing with three registers of the same length. */
19723 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
19724 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
19725 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
19726 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19727 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19728 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19729 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19730 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19731 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19732 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
19733 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
19734 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
19735 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
19736 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
19737 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
19738 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
19739 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
19740 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
19741 /* If not immediate, fall back to neon_dyadic_i64_su.
19742 shl_imm should accept I8 I16 I32 I64,
19743 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
19744 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
19745 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
19746 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
19747 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 19748 /* Logic ops, types optional & ignored. */
4316f0d2
DG
19749 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19750 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19751 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19752 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19753 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19754 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19755 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19756 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19757 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
19758 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
19759 /* Bitfield ops, untyped. */
19760 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19761 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19762 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19763 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19764 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19765 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19766 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
19767 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19768 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19769 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19770 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19771 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19772 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
19773 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
19774 back to neon_dyadic_if_su. */
21d799b5
NC
19775 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
19776 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
19777 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
19778 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
19779 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
19780 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
19781 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
19782 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 19783 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
19784 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
19785 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 19786 /* As above, D registers only. */
21d799b5
NC
19787 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
19788 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 19789 /* Int and float variants, signedness unimportant. */
21d799b5
NC
19790 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
19791 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
19792 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 19793 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
19794 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
19795 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
19796 /* vtst takes sizes 8, 16, 32. */
19797 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
19798 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
19799 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 19800 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 19801 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
19802 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19803 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
19804 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19805 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
19806 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
19807 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
19808 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
19809 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
19810 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
19811 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
19812 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
19813 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
19814 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
19815 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
19816 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
19817 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
19818
19819 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 19820 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
19821 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
19822
19823 /* Data processing with two registers and a shift amount. */
19824 /* Right shifts, and variants with rounding.
19825 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
19826 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
19827 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
19828 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
19829 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
19830 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
19831 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
19832 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
19833 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
19834 /* Shift and insert. Sizes accepted 8 16 32 64. */
19835 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
19836 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
19837 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
19838 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
19839 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
19840 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
19841 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
19842 /* Right shift immediate, saturating & narrowing, with rounding variants.
19843 Types accepted S16 S32 S64 U16 U32 U64. */
19844 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
19845 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
19846 /* As above, unsigned. Types accepted S16 S32 S64. */
19847 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
19848 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
19849 /* Right shift narrowing. Types accepted I16 I32 I64. */
19850 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
19851 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
19852 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 19853 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 19854 /* CVT with optional immediate for fixed-point variant. */
21d799b5 19855 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 19856
4316f0d2
DG
19857 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
19858 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
19859
19860 /* Data processing, three registers of different lengths. */
19861 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
19862 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
19863 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
19864 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
19865 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
19866 /* If not scalar, fall back to neon_dyadic_long.
19867 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
19868 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
19869 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
19870 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
19871 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
19872 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
19873 /* Dyadic, narrowing insns. Types I16 I32 I64. */
19874 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19875 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19876 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19877 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19878 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
19879 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
19880 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
19881 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
19882 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
19883 S16 S32 U16 U32. */
21d799b5 19884 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
19885
19886 /* Extract. Size 8. */
3b8d421e
PB
19887 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
19888 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
19889
19890 /* Two registers, miscellaneous. */
19891 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
19892 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
19893 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
19894 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
19895 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
19896 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
19897 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
19898 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
19899 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
19900 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
19901 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
19902 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
19903 /* VMOVN. Types I16 I32 I64. */
21d799b5 19904 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 19905 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 19906 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 19907 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 19908 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
19909 /* VZIP / VUZP. Sizes 8 16 32. */
19910 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
19911 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
19912 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
19913 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
19914 /* VQABS / VQNEG. Types S8 S16 S32. */
19915 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
19916 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
19917 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
19918 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
19919 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
19920 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
19921 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
19922 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
19923 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
19924 /* Reciprocal estimates. Types U32 F32. */
19925 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
19926 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
19927 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
19928 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
19929 /* VCLS. Types S8 S16 S32. */
19930 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
19931 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
19932 /* VCLZ. Types I8 I16 I32. */
19933 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
19934 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
19935 /* VCNT. Size 8. */
19936 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
19937 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
19938 /* Two address, untyped. */
19939 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
19940 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
19941 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
19942 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
19943 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
19944
19945 /* Table lookup. Size 8. */
19946 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
19947 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
19948
c921be7d
NC
19949#undef THUMB_VARIANT
19950#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
19951#undef ARM_VARIANT
19952#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
19953
5287ad62 19954 /* Neon element/structure load/store. */
21d799b5
NC
19955 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
19956 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
19957 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
19958 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
19959 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
19960 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
19961 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
19962 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 19963
c921be7d 19964#undef THUMB_VARIANT
74db7efb
NC
19965#define THUMB_VARIANT & fpu_vfp_ext_v3xd
19966#undef ARM_VARIANT
19967#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
19968 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
19969 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
19970 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
19971 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
19972 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
19973 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
19974 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
19975 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
19976 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
19977
74db7efb 19978#undef THUMB_VARIANT
c921be7d
NC
19979#define THUMB_VARIANT & fpu_vfp_ext_v3
19980#undef ARM_VARIANT
19981#define ARM_VARIANT & fpu_vfp_ext_v3
19982
21d799b5 19983 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 19984 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 19985 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 19986 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 19987 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 19988 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 19989 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 19990 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 19991 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 19992
74db7efb
NC
19993#undef ARM_VARIANT
19994#define ARM_VARIANT & fpu_vfp_ext_fma
19995#undef THUMB_VARIANT
19996#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
19997 /* Mnemonics shared by Neon and VFP. These are included in the
19998 VFP FMA variant; NEON and VFP FMA always includes the NEON
19999 FMA instructions. */
20000 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20001 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20002 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
20003 the v form should always be used. */
20004 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20005 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20006 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20007 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20008 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20009 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20010
5287ad62 20011#undef THUMB_VARIANT
c921be7d
NC
20012#undef ARM_VARIANT
20013#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
20014
21d799b5
NC
20015 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20016 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20017 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20018 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20019 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20020 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20021 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
20022 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 20023
c921be7d
NC
20024#undef ARM_VARIANT
20025#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
20026
21d799b5
NC
20027 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
20028 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
20029 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
20030 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
20031 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
20032 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
20033 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
20034 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
20035 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
20036 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20037 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20038 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20039 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20040 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20041 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
20042 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20043 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20044 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20045 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
20046 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
20047 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20048 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20049 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20050 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20051 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20052 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
20053 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
20054 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
20055 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
20056 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
20057 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
20058 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
20059 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
20060 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
20061 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
20062 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
20063 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
20064 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20065 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20066 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20067 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20068 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20069 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20070 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20071 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20072 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20073 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
20074 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20075 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20076 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20077 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20078 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20079 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20080 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20081 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20082 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20083 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20084 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20085 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20086 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20087 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20088 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20089 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20090 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20091 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20092 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20093 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20094 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20095 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20096 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20097 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20098 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20099 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20100 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20101 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20102 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20103 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20104 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20105 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20106 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20107 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20108 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20109 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20110 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20111 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20112 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20113 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20114 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20115 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
20116 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20117 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20118 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20119 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20120 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20121 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20122 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20123 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20124 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20125 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20126 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20127 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20128 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20129 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20130 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20131 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20132 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20133 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20134 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20135 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20136 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20137 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
20138 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20139 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20140 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20141 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20142 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20143 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20144 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20145 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20146 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20147 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20148 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20149 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20150 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20151 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20152 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20153 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20154 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20155 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20156 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20157 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20158 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20159 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20160 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20161 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20162 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20163 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20164 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20165 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20166 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20167 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20168 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20169 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
20170 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
20171 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
20172 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
20173 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
20174 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
20175 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20176 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20177 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20178 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
20179 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
20180 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
20181 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
20182 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
20183 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
20184 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20185 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20186 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20187 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20188 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 20189
c921be7d
NC
20190#undef ARM_VARIANT
20191#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
20192
21d799b5
NC
20193 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
20194 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
20195 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
20196 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
20197 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
20198 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
20199 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20200 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20201 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20202 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20203 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20204 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20205 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20206 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20207 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20208 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20209 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20210 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20211 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20212 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20213 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
20214 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20215 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20216 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20217 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20218 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20219 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20220 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20221 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20222 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20223 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20224 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20225 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20226 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20227 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20228 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20229 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20230 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20231 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20232 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20233 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20234 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20235 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20236 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20237 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20238 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20239 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20240 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20241 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20242 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20243 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20244 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20245 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20246 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20247 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20248 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20249 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 20250
c921be7d
NC
20251#undef ARM_VARIANT
20252#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
20253
21d799b5
NC
20254 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20255 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20256 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20257 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20258 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20259 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20260 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20261 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20262 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
20263 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
20264 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
20265 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
20266 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
20267 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
20268 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
20269 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
20270 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
20271 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
20272 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
20273 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
20274 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
20275 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
20276 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
20277 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
20278 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
20279 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
20280 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
20281 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
20282 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
20283 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
20284 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
20285 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
20286 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
20287 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
20288 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
20289 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
20290 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
20291 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
20292 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
20293 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
20294 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
20295 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
20296 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
20297 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
20298 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
20299 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
20300 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
20301 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
20302 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
20303 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
20304 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
20305 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
20306 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
20307 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
20308 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
20309 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
20310 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
20311 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
20312 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
20313 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
20314 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
20315 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
20316 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
20317 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
20318 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20319 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20320 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20321 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20322 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20323 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20324 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20325 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
20326 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
20327 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
20328 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
20329 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
20330};
20331#undef ARM_VARIANT
20332#undef THUMB_VARIANT
20333#undef TCE
c19d1205
ZW
20334#undef TUE
20335#undef TUF
20336#undef TCC
8f06b2d8 20337#undef cCE
e3cb604e
PB
20338#undef cCL
20339#undef C3E
c19d1205
ZW
20340#undef CE
20341#undef CM
20342#undef UE
20343#undef UF
20344#undef UT
5287ad62
JB
20345#undef NUF
20346#undef nUF
20347#undef NCE
20348#undef nCE
c19d1205
ZW
20349#undef OPS0
20350#undef OPS1
20351#undef OPS2
20352#undef OPS3
20353#undef OPS4
20354#undef OPS5
20355#undef OPS6
20356#undef do_0
20357\f
20358/* MD interface: bits in the object file. */
bfae80f2 20359
c19d1205
ZW
20360/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
20361 for use in the a.out file, and stores them in the array pointed to by buf.
20362 This knows about the endian-ness of the target machine and does
20363 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
20364 2 (short) and 4 (long) Floating numbers are put out as a series of
20365 LITTLENUMS (shorts, here at least). */
b99bd4ef 20366
c19d1205
ZW
20367void
20368md_number_to_chars (char * buf, valueT val, int n)
20369{
20370 if (target_big_endian)
20371 number_to_chars_bigendian (buf, val, n);
20372 else
20373 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
20374}
20375
c19d1205
ZW
20376static valueT
20377md_chars_to_number (char * buf, int n)
bfae80f2 20378{
c19d1205
ZW
20379 valueT result = 0;
20380 unsigned char * where = (unsigned char *) buf;
bfae80f2 20381
c19d1205 20382 if (target_big_endian)
b99bd4ef 20383 {
c19d1205
ZW
20384 while (n--)
20385 {
20386 result <<= 8;
20387 result |= (*where++ & 255);
20388 }
b99bd4ef 20389 }
c19d1205 20390 else
b99bd4ef 20391 {
c19d1205
ZW
20392 while (n--)
20393 {
20394 result <<= 8;
20395 result |= (where[n] & 255);
20396 }
bfae80f2 20397 }
b99bd4ef 20398
c19d1205 20399 return result;
bfae80f2 20400}
b99bd4ef 20401
c19d1205 20402/* MD interface: Sections. */
b99bd4ef 20403
fa94de6b
RM
20404/* Calculate the maximum variable size (i.e., excluding fr_fix)
20405 that an rs_machine_dependent frag may reach. */
20406
20407unsigned int
20408arm_frag_max_var (fragS *fragp)
20409{
20410 /* We only use rs_machine_dependent for variable-size Thumb instructions,
20411 which are either THUMB_SIZE (2) or INSN_SIZE (4).
20412
20413 Note that we generate relaxable instructions even for cases that don't
20414 really need it, like an immediate that's a trivial constant. So we're
20415 overestimating the instruction size for some of those cases. Rather
20416 than putting more intelligence here, it would probably be better to
20417 avoid generating a relaxation frag in the first place when it can be
20418 determined up front that a short instruction will suffice. */
20419
20420 gas_assert (fragp->fr_type == rs_machine_dependent);
20421 return INSN_SIZE;
20422}
20423
0110f2b8
PB
20424/* Estimate the size of a frag before relaxing. Assume everything fits in
20425 2 bytes. */
20426
c19d1205 20427int
0110f2b8 20428md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
20429 segT segtype ATTRIBUTE_UNUSED)
20430{
0110f2b8
PB
20431 fragp->fr_var = 2;
20432 return 2;
20433}
20434
20435/* Convert a machine dependent frag. */
20436
20437void
20438md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
20439{
20440 unsigned long insn;
20441 unsigned long old_op;
20442 char *buf;
20443 expressionS exp;
20444 fixS *fixp;
20445 int reloc_type;
20446 int pc_rel;
20447 int opcode;
20448
20449 buf = fragp->fr_literal + fragp->fr_fix;
20450
20451 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
20452 if (fragp->fr_symbol)
20453 {
0110f2b8
PB
20454 exp.X_op = O_symbol;
20455 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
20456 }
20457 else
20458 {
0110f2b8 20459 exp.X_op = O_constant;
5f4273c7 20460 }
0110f2b8
PB
20461 exp.X_add_number = fragp->fr_offset;
20462 opcode = fragp->fr_subtype;
20463 switch (opcode)
20464 {
20465 case T_MNEM_ldr_pc:
20466 case T_MNEM_ldr_pc2:
20467 case T_MNEM_ldr_sp:
20468 case T_MNEM_str_sp:
20469 case T_MNEM_ldr:
20470 case T_MNEM_ldrb:
20471 case T_MNEM_ldrh:
20472 case T_MNEM_str:
20473 case T_MNEM_strb:
20474 case T_MNEM_strh:
20475 if (fragp->fr_var == 4)
20476 {
5f4273c7 20477 insn = THUMB_OP32 (opcode);
0110f2b8
PB
20478 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
20479 {
20480 insn |= (old_op & 0x700) << 4;
20481 }
20482 else
20483 {
20484 insn |= (old_op & 7) << 12;
20485 insn |= (old_op & 0x38) << 13;
20486 }
20487 insn |= 0x00000c00;
20488 put_thumb32_insn (buf, insn);
20489 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
20490 }
20491 else
20492 {
20493 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
20494 }
20495 pc_rel = (opcode == T_MNEM_ldr_pc2);
20496 break;
20497 case T_MNEM_adr:
20498 if (fragp->fr_var == 4)
20499 {
20500 insn = THUMB_OP32 (opcode);
20501 insn |= (old_op & 0xf0) << 4;
20502 put_thumb32_insn (buf, insn);
20503 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
20504 }
20505 else
20506 {
20507 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20508 exp.X_add_number -= 4;
20509 }
20510 pc_rel = 1;
20511 break;
20512 case T_MNEM_mov:
20513 case T_MNEM_movs:
20514 case T_MNEM_cmp:
20515 case T_MNEM_cmn:
20516 if (fragp->fr_var == 4)
20517 {
20518 int r0off = (opcode == T_MNEM_mov
20519 || opcode == T_MNEM_movs) ? 0 : 8;
20520 insn = THUMB_OP32 (opcode);
20521 insn = (insn & 0xe1ffffff) | 0x10000000;
20522 insn |= (old_op & 0x700) << r0off;
20523 put_thumb32_insn (buf, insn);
20524 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
20525 }
20526 else
20527 {
20528 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
20529 }
20530 pc_rel = 0;
20531 break;
20532 case T_MNEM_b:
20533 if (fragp->fr_var == 4)
20534 {
20535 insn = THUMB_OP32(opcode);
20536 put_thumb32_insn (buf, insn);
20537 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
20538 }
20539 else
20540 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
20541 pc_rel = 1;
20542 break;
20543 case T_MNEM_bcond:
20544 if (fragp->fr_var == 4)
20545 {
20546 insn = THUMB_OP32(opcode);
20547 insn |= (old_op & 0xf00) << 14;
20548 put_thumb32_insn (buf, insn);
20549 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
20550 }
20551 else
20552 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
20553 pc_rel = 1;
20554 break;
20555 case T_MNEM_add_sp:
20556 case T_MNEM_add_pc:
20557 case T_MNEM_inc_sp:
20558 case T_MNEM_dec_sp:
20559 if (fragp->fr_var == 4)
20560 {
20561 /* ??? Choose between add and addw. */
20562 insn = THUMB_OP32 (opcode);
20563 insn |= (old_op & 0xf0) << 4;
20564 put_thumb32_insn (buf, insn);
16805f35
PB
20565 if (opcode == T_MNEM_add_pc)
20566 reloc_type = BFD_RELOC_ARM_T32_IMM12;
20567 else
20568 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
20569 }
20570 else
20571 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20572 pc_rel = 0;
20573 break;
20574
20575 case T_MNEM_addi:
20576 case T_MNEM_addis:
20577 case T_MNEM_subi:
20578 case T_MNEM_subis:
20579 if (fragp->fr_var == 4)
20580 {
20581 insn = THUMB_OP32 (opcode);
20582 insn |= (old_op & 0xf0) << 4;
20583 insn |= (old_op & 0xf) << 16;
20584 put_thumb32_insn (buf, insn);
16805f35
PB
20585 if (insn & (1 << 20))
20586 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
20587 else
20588 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
20589 }
20590 else
20591 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20592 pc_rel = 0;
20593 break;
20594 default:
5f4273c7 20595 abort ();
0110f2b8
PB
20596 }
20597 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 20598 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
20599 fixp->fx_file = fragp->fr_file;
20600 fixp->fx_line = fragp->fr_line;
20601 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
20602
20603 /* Set whether we use thumb-2 ISA based on final relaxation results. */
20604 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
20605 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
20606 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
20607}
20608
20609/* Return the size of a relaxable immediate operand instruction.
20610 SHIFT and SIZE specify the form of the allowable immediate. */
20611static int
20612relax_immediate (fragS *fragp, int size, int shift)
20613{
20614 offsetT offset;
20615 offsetT mask;
20616 offsetT low;
20617
20618 /* ??? Should be able to do better than this. */
20619 if (fragp->fr_symbol)
20620 return 4;
20621
20622 low = (1 << shift) - 1;
20623 mask = (1 << (shift + size)) - (1 << shift);
20624 offset = fragp->fr_offset;
20625 /* Force misaligned offsets to 32-bit variant. */
20626 if (offset & low)
5e77afaa 20627 return 4;
0110f2b8
PB
20628 if (offset & ~mask)
20629 return 4;
20630 return 2;
20631}
20632
5e77afaa
PB
20633/* Get the address of a symbol during relaxation. */
20634static addressT
5f4273c7 20635relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
20636{
20637 fragS *sym_frag;
20638 addressT addr;
20639 symbolS *sym;
20640
20641 sym = fragp->fr_symbol;
20642 sym_frag = symbol_get_frag (sym);
20643 know (S_GET_SEGMENT (sym) != absolute_section
20644 || sym_frag == &zero_address_frag);
20645 addr = S_GET_VALUE (sym) + fragp->fr_offset;
20646
20647 /* If frag has yet to be reached on this pass, assume it will
20648 move by STRETCH just as we did. If this is not so, it will
20649 be because some frag between grows, and that will force
20650 another pass. */
20651
20652 if (stretch != 0
20653 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
20654 {
20655 fragS *f;
20656
20657 /* Adjust stretch for any alignment frag. Note that if have
20658 been expanding the earlier code, the symbol may be
20659 defined in what appears to be an earlier frag. FIXME:
20660 This doesn't handle the fr_subtype field, which specifies
20661 a maximum number of bytes to skip when doing an
20662 alignment. */
20663 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
20664 {
20665 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
20666 {
20667 if (stretch < 0)
20668 stretch = - ((- stretch)
20669 & ~ ((1 << (int) f->fr_offset) - 1));
20670 else
20671 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
20672 if (stretch == 0)
20673 break;
20674 }
20675 }
20676 if (f != NULL)
20677 addr += stretch;
20678 }
5e77afaa
PB
20679
20680 return addr;
20681}
20682
0110f2b8
PB
20683/* Return the size of a relaxable adr pseudo-instruction or PC-relative
20684 load. */
20685static int
5e77afaa 20686relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
20687{
20688 addressT addr;
20689 offsetT val;
20690
20691 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
20692 if (fragp->fr_symbol == NULL
20693 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
20694 || sec != S_GET_SEGMENT (fragp->fr_symbol)
20695 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
20696 return 4;
20697
5f4273c7 20698 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
20699 addr = fragp->fr_address + fragp->fr_fix;
20700 addr = (addr + 4) & ~3;
5e77afaa 20701 /* Force misaligned targets to 32-bit variant. */
0110f2b8 20702 if (val & 3)
5e77afaa 20703 return 4;
0110f2b8
PB
20704 val -= addr;
20705 if (val < 0 || val > 1020)
20706 return 4;
20707 return 2;
20708}
20709
20710/* Return the size of a relaxable add/sub immediate instruction. */
20711static int
20712relax_addsub (fragS *fragp, asection *sec)
20713{
20714 char *buf;
20715 int op;
20716
20717 buf = fragp->fr_literal + fragp->fr_fix;
20718 op = bfd_get_16(sec->owner, buf);
20719 if ((op & 0xf) == ((op >> 4) & 0xf))
20720 return relax_immediate (fragp, 8, 0);
20721 else
20722 return relax_immediate (fragp, 3, 0);
20723}
20724
e83a675f
RE
20725/* Return TRUE iff the definition of symbol S could be pre-empted
20726 (overridden) at link or load time. */
20727static bfd_boolean
20728symbol_preemptible (symbolS *s)
20729{
20730 /* Weak symbols can always be pre-empted. */
20731 if (S_IS_WEAK (s))
20732 return TRUE;
20733
20734 /* Non-global symbols cannot be pre-empted. */
20735 if (! S_IS_EXTERNAL (s))
20736 return FALSE;
20737
20738#ifdef OBJ_ELF
20739 /* In ELF, a global symbol can be marked protected, or private. In that
20740 case it can't be pre-empted (other definitions in the same link unit
20741 would violate the ODR). */
20742 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
20743 return FALSE;
20744#endif
20745
20746 /* Other global symbols might be pre-empted. */
20747 return TRUE;
20748}
0110f2b8
PB
20749
20750/* Return the size of a relaxable branch instruction. BITS is the
20751 size of the offset field in the narrow instruction. */
20752
20753static int
5e77afaa 20754relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
20755{
20756 addressT addr;
20757 offsetT val;
20758 offsetT limit;
20759
20760 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 20761 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
20762 || sec != S_GET_SEGMENT (fragp->fr_symbol)
20763 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
20764 return 4;
20765
267bf995 20766#ifdef OBJ_ELF
e83a675f 20767 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
20768 if (S_IS_DEFINED (fragp->fr_symbol)
20769 && ARM_IS_FUNC (fragp->fr_symbol))
20770 return 4;
e83a675f 20771#endif
0d9b4b55 20772
e83a675f 20773 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 20774 return 4;
267bf995 20775
5f4273c7 20776 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
20777 addr = fragp->fr_address + fragp->fr_fix + 4;
20778 val -= addr;
20779
20780 /* Offset is a signed value *2 */
20781 limit = 1 << bits;
20782 if (val >= limit || val < -limit)
20783 return 4;
20784 return 2;
20785}
20786
20787
20788/* Relax a machine dependent frag. This returns the amount by which
20789 the current size of the frag should change. */
20790
20791int
5e77afaa 20792arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
20793{
20794 int oldsize;
20795 int newsize;
20796
20797 oldsize = fragp->fr_var;
20798 switch (fragp->fr_subtype)
20799 {
20800 case T_MNEM_ldr_pc2:
5f4273c7 20801 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
20802 break;
20803 case T_MNEM_ldr_pc:
20804 case T_MNEM_ldr_sp:
20805 case T_MNEM_str_sp:
5f4273c7 20806 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
20807 break;
20808 case T_MNEM_ldr:
20809 case T_MNEM_str:
5f4273c7 20810 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
20811 break;
20812 case T_MNEM_ldrh:
20813 case T_MNEM_strh:
5f4273c7 20814 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
20815 break;
20816 case T_MNEM_ldrb:
20817 case T_MNEM_strb:
5f4273c7 20818 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
20819 break;
20820 case T_MNEM_adr:
5f4273c7 20821 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
20822 break;
20823 case T_MNEM_mov:
20824 case T_MNEM_movs:
20825 case T_MNEM_cmp:
20826 case T_MNEM_cmn:
5f4273c7 20827 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
20828 break;
20829 case T_MNEM_b:
5f4273c7 20830 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
20831 break;
20832 case T_MNEM_bcond:
5f4273c7 20833 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
20834 break;
20835 case T_MNEM_add_sp:
20836 case T_MNEM_add_pc:
20837 newsize = relax_immediate (fragp, 8, 2);
20838 break;
20839 case T_MNEM_inc_sp:
20840 case T_MNEM_dec_sp:
20841 newsize = relax_immediate (fragp, 7, 2);
20842 break;
20843 case T_MNEM_addi:
20844 case T_MNEM_addis:
20845 case T_MNEM_subi:
20846 case T_MNEM_subis:
20847 newsize = relax_addsub (fragp, sec);
20848 break;
20849 default:
5f4273c7 20850 abort ();
0110f2b8 20851 }
5e77afaa
PB
20852
20853 fragp->fr_var = newsize;
20854 /* Freeze wide instructions that are at or before the same location as
20855 in the previous pass. This avoids infinite loops.
5f4273c7
NC
20856 Don't freeze them unconditionally because targets may be artificially
20857 misaligned by the expansion of preceding frags. */
5e77afaa 20858 if (stretch <= 0 && newsize > 2)
0110f2b8 20859 {
0110f2b8 20860 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 20861 frag_wane (fragp);
0110f2b8 20862 }
5e77afaa 20863
0110f2b8 20864 return newsize - oldsize;
c19d1205 20865}
b99bd4ef 20866
c19d1205 20867/* Round up a section size to the appropriate boundary. */
b99bd4ef 20868
c19d1205
ZW
20869valueT
20870md_section_align (segT segment ATTRIBUTE_UNUSED,
20871 valueT size)
20872{
f0927246
NC
20873#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
20874 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
20875 {
20876 /* For a.out, force the section size to be aligned. If we don't do
20877 this, BFD will align it for us, but it will not write out the
20878 final bytes of the section. This may be a bug in BFD, but it is
20879 easier to fix it here since that is how the other a.out targets
20880 work. */
20881 int align;
20882
20883 align = bfd_get_section_alignment (stdoutput, segment);
20884 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
20885 }
c19d1205 20886#endif
f0927246
NC
20887
20888 return size;
bfae80f2 20889}
b99bd4ef 20890
c19d1205
ZW
20891/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
20892 of an rs_align_code fragment. */
20893
20894void
20895arm_handle_align (fragS * fragP)
bfae80f2 20896{
e7495e45
NS
20897 static char const arm_noop[2][2][4] =
20898 {
20899 { /* ARMv1 */
20900 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
20901 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
20902 },
20903 { /* ARMv6k */
20904 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
20905 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
20906 },
20907 };
20908 static char const thumb_noop[2][2][2] =
20909 {
20910 { /* Thumb-1 */
20911 {0xc0, 0x46}, /* LE */
20912 {0x46, 0xc0}, /* BE */
20913 },
20914 { /* Thumb-2 */
20915 {0x00, 0xbf}, /* LE */
20916 {0xbf, 0x00} /* BE */
20917 }
20918 };
20919 static char const wide_thumb_noop[2][4] =
20920 { /* Wide Thumb-2 */
20921 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
20922 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
20923 };
c921be7d 20924
e7495e45 20925 unsigned bytes, fix, noop_size;
c19d1205
ZW
20926 char * p;
20927 const char * noop;
e7495e45 20928 const char *narrow_noop = NULL;
cd000bff
DJ
20929#ifdef OBJ_ELF
20930 enum mstate state;
20931#endif
bfae80f2 20932
c19d1205 20933 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
20934 return;
20935
c19d1205
ZW
20936 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
20937 p = fragP->fr_literal + fragP->fr_fix;
20938 fix = 0;
bfae80f2 20939
c19d1205
ZW
20940 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
20941 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 20942
cd000bff 20943 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 20944
cd000bff 20945 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 20946 {
7f78eb34
JW
20947 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
20948 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
20949 {
20950 narrow_noop = thumb_noop[1][target_big_endian];
20951 noop = wide_thumb_noop[target_big_endian];
20952 }
c19d1205 20953 else
e7495e45
NS
20954 noop = thumb_noop[0][target_big_endian];
20955 noop_size = 2;
cd000bff
DJ
20956#ifdef OBJ_ELF
20957 state = MAP_THUMB;
20958#endif
7ed4c4c5
NC
20959 }
20960 else
20961 {
7f78eb34
JW
20962 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
20963 ? selected_cpu : arm_arch_none,
20964 arm_ext_v6k) != 0]
e7495e45
NS
20965 [target_big_endian];
20966 noop_size = 4;
cd000bff
DJ
20967#ifdef OBJ_ELF
20968 state = MAP_ARM;
20969#endif
7ed4c4c5 20970 }
c921be7d 20971
e7495e45 20972 fragP->fr_var = noop_size;
c921be7d 20973
c19d1205 20974 if (bytes & (noop_size - 1))
7ed4c4c5 20975 {
c19d1205 20976 fix = bytes & (noop_size - 1);
cd000bff
DJ
20977#ifdef OBJ_ELF
20978 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
20979#endif
c19d1205
ZW
20980 memset (p, 0, fix);
20981 p += fix;
20982 bytes -= fix;
a737bd4d 20983 }
a737bd4d 20984
e7495e45
NS
20985 if (narrow_noop)
20986 {
20987 if (bytes & noop_size)
20988 {
20989 /* Insert a narrow noop. */
20990 memcpy (p, narrow_noop, noop_size);
20991 p += noop_size;
20992 bytes -= noop_size;
20993 fix += noop_size;
20994 }
20995
20996 /* Use wide noops for the remainder */
20997 noop_size = 4;
20998 }
20999
c19d1205 21000 while (bytes >= noop_size)
a737bd4d 21001 {
c19d1205
ZW
21002 memcpy (p, noop, noop_size);
21003 p += noop_size;
21004 bytes -= noop_size;
21005 fix += noop_size;
a737bd4d
NC
21006 }
21007
c19d1205 21008 fragP->fr_fix += fix;
a737bd4d
NC
21009}
21010
c19d1205
ZW
21011/* Called from md_do_align. Used to create an alignment
21012 frag in a code section. */
21013
21014void
21015arm_frag_align_code (int n, int max)
bfae80f2 21016{
c19d1205 21017 char * p;
7ed4c4c5 21018
c19d1205 21019 /* We assume that there will never be a requirement
6ec8e702 21020 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 21021 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
21022 {
21023 char err_msg[128];
21024
fa94de6b 21025 sprintf (err_msg,
477330fc
RM
21026 _("alignments greater than %d bytes not supported in .text sections."),
21027 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 21028 as_fatal ("%s", err_msg);
6ec8e702 21029 }
bfae80f2 21030
c19d1205
ZW
21031 p = frag_var (rs_align_code,
21032 MAX_MEM_FOR_RS_ALIGN_CODE,
21033 1,
21034 (relax_substateT) max,
21035 (symbolS *) NULL,
21036 (offsetT) n,
21037 (char *) NULL);
21038 *p = 0;
21039}
bfae80f2 21040
8dc2430f
NC
21041/* Perform target specific initialisation of a frag.
21042 Note - despite the name this initialisation is not done when the frag
21043 is created, but only when its type is assigned. A frag can be created
21044 and used a long time before its type is set, so beware of assuming that
21045 this initialisationis performed first. */
bfae80f2 21046
cd000bff
DJ
21047#ifndef OBJ_ELF
21048void
21049arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
21050{
21051 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 21052 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
21053}
21054
21055#else /* OBJ_ELF is defined. */
c19d1205 21056void
cd000bff 21057arm_init_frag (fragS * fragP, int max_chars)
c19d1205 21058{
8dc2430f
NC
21059 /* If the current ARM vs THUMB mode has not already
21060 been recorded into this frag then do so now. */
cd000bff 21061 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
cd000bff
DJ
21062 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
21063
f9c1b181
RL
21064 /* Record a mapping symbol for alignment frags. We will delete this
21065 later if the alignment ends up empty. */
21066 switch (fragP->fr_type)
21067 {
21068 case rs_align:
21069 case rs_align_test:
21070 case rs_fill:
21071 mapping_state_2 (MAP_DATA, max_chars);
21072 break;
21073 case rs_align_code:
21074 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
21075 break;
21076 default:
21077 break;
cd000bff 21078 }
bfae80f2
RE
21079}
21080
c19d1205
ZW
21081/* When we change sections we need to issue a new mapping symbol. */
21082
21083void
21084arm_elf_change_section (void)
bfae80f2 21085{
c19d1205
ZW
21086 /* Link an unlinked unwind index table section to the .text section. */
21087 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
21088 && elf_linked_to_section (now_seg) == NULL)
21089 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
21090}
21091
c19d1205
ZW
21092int
21093arm_elf_section_type (const char * str, size_t len)
e45d0630 21094{
c19d1205
ZW
21095 if (len == 5 && strncmp (str, "exidx", 5) == 0)
21096 return SHT_ARM_EXIDX;
e45d0630 21097
c19d1205
ZW
21098 return -1;
21099}
21100\f
21101/* Code to deal with unwinding tables. */
e45d0630 21102
c19d1205 21103static void add_unwind_adjustsp (offsetT);
e45d0630 21104
5f4273c7 21105/* Generate any deferred unwind frame offset. */
e45d0630 21106
bfae80f2 21107static void
c19d1205 21108flush_pending_unwind (void)
bfae80f2 21109{
c19d1205 21110 offsetT offset;
bfae80f2 21111
c19d1205
ZW
21112 offset = unwind.pending_offset;
21113 unwind.pending_offset = 0;
21114 if (offset != 0)
21115 add_unwind_adjustsp (offset);
bfae80f2
RE
21116}
21117
c19d1205
ZW
21118/* Add an opcode to this list for this function. Two-byte opcodes should
21119 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
21120 order. */
21121
bfae80f2 21122static void
c19d1205 21123add_unwind_opcode (valueT op, int length)
bfae80f2 21124{
c19d1205
ZW
21125 /* Add any deferred stack adjustment. */
21126 if (unwind.pending_offset)
21127 flush_pending_unwind ();
bfae80f2 21128
c19d1205 21129 unwind.sp_restored = 0;
bfae80f2 21130
c19d1205 21131 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 21132 {
c19d1205
ZW
21133 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
21134 if (unwind.opcodes)
21d799b5 21135 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
477330fc 21136 unwind.opcode_alloc);
c19d1205 21137 else
21d799b5 21138 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 21139 }
c19d1205 21140 while (length > 0)
bfae80f2 21141 {
c19d1205
ZW
21142 length--;
21143 unwind.opcodes[unwind.opcode_count] = op & 0xff;
21144 op >>= 8;
21145 unwind.opcode_count++;
bfae80f2 21146 }
bfae80f2
RE
21147}
21148
c19d1205
ZW
21149/* Add unwind opcodes to adjust the stack pointer. */
21150
bfae80f2 21151static void
c19d1205 21152add_unwind_adjustsp (offsetT offset)
bfae80f2 21153{
c19d1205 21154 valueT op;
bfae80f2 21155
c19d1205 21156 if (offset > 0x200)
bfae80f2 21157 {
c19d1205
ZW
21158 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
21159 char bytes[5];
21160 int n;
21161 valueT o;
bfae80f2 21162
c19d1205
ZW
21163 /* Long form: 0xb2, uleb128. */
21164 /* This might not fit in a word so add the individual bytes,
21165 remembering the list is built in reverse order. */
21166 o = (valueT) ((offset - 0x204) >> 2);
21167 if (o == 0)
21168 add_unwind_opcode (0, 1);
bfae80f2 21169
c19d1205
ZW
21170 /* Calculate the uleb128 encoding of the offset. */
21171 n = 0;
21172 while (o)
21173 {
21174 bytes[n] = o & 0x7f;
21175 o >>= 7;
21176 if (o)
21177 bytes[n] |= 0x80;
21178 n++;
21179 }
21180 /* Add the insn. */
21181 for (; n; n--)
21182 add_unwind_opcode (bytes[n - 1], 1);
21183 add_unwind_opcode (0xb2, 1);
21184 }
21185 else if (offset > 0x100)
bfae80f2 21186 {
c19d1205
ZW
21187 /* Two short opcodes. */
21188 add_unwind_opcode (0x3f, 1);
21189 op = (offset - 0x104) >> 2;
21190 add_unwind_opcode (op, 1);
bfae80f2 21191 }
c19d1205
ZW
21192 else if (offset > 0)
21193 {
21194 /* Short opcode. */
21195 op = (offset - 4) >> 2;
21196 add_unwind_opcode (op, 1);
21197 }
21198 else if (offset < 0)
bfae80f2 21199 {
c19d1205
ZW
21200 offset = -offset;
21201 while (offset > 0x100)
bfae80f2 21202 {
c19d1205
ZW
21203 add_unwind_opcode (0x7f, 1);
21204 offset -= 0x100;
bfae80f2 21205 }
c19d1205
ZW
21206 op = ((offset - 4) >> 2) | 0x40;
21207 add_unwind_opcode (op, 1);
bfae80f2 21208 }
bfae80f2
RE
21209}
21210
c19d1205
ZW
21211/* Finish the list of unwind opcodes for this function. */
21212static void
21213finish_unwind_opcodes (void)
bfae80f2 21214{
c19d1205 21215 valueT op;
bfae80f2 21216
c19d1205 21217 if (unwind.fp_used)
bfae80f2 21218 {
708587a4 21219 /* Adjust sp as necessary. */
c19d1205
ZW
21220 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
21221 flush_pending_unwind ();
bfae80f2 21222
c19d1205
ZW
21223 /* After restoring sp from the frame pointer. */
21224 op = 0x90 | unwind.fp_reg;
21225 add_unwind_opcode (op, 1);
21226 }
21227 else
21228 flush_pending_unwind ();
bfae80f2
RE
21229}
21230
bfae80f2 21231
c19d1205
ZW
21232/* Start an exception table entry. If idx is nonzero this is an index table
21233 entry. */
bfae80f2
RE
21234
21235static void
c19d1205 21236start_unwind_section (const segT text_seg, int idx)
bfae80f2 21237{
c19d1205
ZW
21238 const char * text_name;
21239 const char * prefix;
21240 const char * prefix_once;
21241 const char * group_name;
21242 size_t prefix_len;
21243 size_t text_len;
21244 char * sec_name;
21245 size_t sec_name_len;
21246 int type;
21247 int flags;
21248 int linkonce;
bfae80f2 21249
c19d1205 21250 if (idx)
bfae80f2 21251 {
c19d1205
ZW
21252 prefix = ELF_STRING_ARM_unwind;
21253 prefix_once = ELF_STRING_ARM_unwind_once;
21254 type = SHT_ARM_EXIDX;
bfae80f2 21255 }
c19d1205 21256 else
bfae80f2 21257 {
c19d1205
ZW
21258 prefix = ELF_STRING_ARM_unwind_info;
21259 prefix_once = ELF_STRING_ARM_unwind_info_once;
21260 type = SHT_PROGBITS;
bfae80f2
RE
21261 }
21262
c19d1205
ZW
21263 text_name = segment_name (text_seg);
21264 if (streq (text_name, ".text"))
21265 text_name = "";
21266
21267 if (strncmp (text_name, ".gnu.linkonce.t.",
21268 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 21269 {
c19d1205
ZW
21270 prefix = prefix_once;
21271 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
21272 }
21273
c19d1205
ZW
21274 prefix_len = strlen (prefix);
21275 text_len = strlen (text_name);
21276 sec_name_len = prefix_len + text_len;
21d799b5 21277 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
21278 memcpy (sec_name, prefix, prefix_len);
21279 memcpy (sec_name + prefix_len, text_name, text_len);
21280 sec_name[prefix_len + text_len] = '\0';
bfae80f2 21281
c19d1205
ZW
21282 flags = SHF_ALLOC;
21283 linkonce = 0;
21284 group_name = 0;
bfae80f2 21285
c19d1205
ZW
21286 /* Handle COMDAT group. */
21287 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 21288 {
c19d1205
ZW
21289 group_name = elf_group_name (text_seg);
21290 if (group_name == NULL)
21291 {
bd3ba5d1 21292 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
21293 segment_name (text_seg));
21294 ignore_rest_of_line ();
21295 return;
21296 }
21297 flags |= SHF_GROUP;
21298 linkonce = 1;
bfae80f2
RE
21299 }
21300
c19d1205 21301 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 21302
5f4273c7 21303 /* Set the section link for index tables. */
c19d1205
ZW
21304 if (idx)
21305 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
21306}
21307
bfae80f2 21308
c19d1205
ZW
21309/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
21310 personality routine data. Returns zero, or the index table value for
cad0da33 21311 an inline entry. */
c19d1205
ZW
21312
21313static valueT
21314create_unwind_entry (int have_data)
bfae80f2 21315{
c19d1205
ZW
21316 int size;
21317 addressT where;
21318 char *ptr;
21319 /* The current word of data. */
21320 valueT data;
21321 /* The number of bytes left in this word. */
21322 int n;
bfae80f2 21323
c19d1205 21324 finish_unwind_opcodes ();
bfae80f2 21325
c19d1205
ZW
21326 /* Remember the current text section. */
21327 unwind.saved_seg = now_seg;
21328 unwind.saved_subseg = now_subseg;
bfae80f2 21329
c19d1205 21330 start_unwind_section (now_seg, 0);
bfae80f2 21331
c19d1205 21332 if (unwind.personality_routine == NULL)
bfae80f2 21333 {
c19d1205
ZW
21334 if (unwind.personality_index == -2)
21335 {
21336 if (have_data)
5f4273c7 21337 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
21338 return 1; /* EXIDX_CANTUNWIND. */
21339 }
bfae80f2 21340
c19d1205
ZW
21341 /* Use a default personality routine if none is specified. */
21342 if (unwind.personality_index == -1)
21343 {
21344 if (unwind.opcode_count > 3)
21345 unwind.personality_index = 1;
21346 else
21347 unwind.personality_index = 0;
21348 }
bfae80f2 21349
c19d1205
ZW
21350 /* Space for the personality routine entry. */
21351 if (unwind.personality_index == 0)
21352 {
21353 if (unwind.opcode_count > 3)
21354 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 21355
c19d1205
ZW
21356 if (!have_data)
21357 {
21358 /* All the data is inline in the index table. */
21359 data = 0x80;
21360 n = 3;
21361 while (unwind.opcode_count > 0)
21362 {
21363 unwind.opcode_count--;
21364 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
21365 n--;
21366 }
bfae80f2 21367
c19d1205
ZW
21368 /* Pad with "finish" opcodes. */
21369 while (n--)
21370 data = (data << 8) | 0xb0;
bfae80f2 21371
c19d1205
ZW
21372 return data;
21373 }
21374 size = 0;
21375 }
21376 else
21377 /* We get two opcodes "free" in the first word. */
21378 size = unwind.opcode_count - 2;
21379 }
21380 else
5011093d 21381 {
cad0da33
NC
21382 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
21383 if (unwind.personality_index != -1)
21384 {
21385 as_bad (_("attempt to recreate an unwind entry"));
21386 return 1;
21387 }
5011093d
NC
21388
21389 /* An extra byte is required for the opcode count. */
21390 size = unwind.opcode_count + 1;
21391 }
bfae80f2 21392
c19d1205
ZW
21393 size = (size + 3) >> 2;
21394 if (size > 0xff)
21395 as_bad (_("too many unwind opcodes"));
bfae80f2 21396
c19d1205
ZW
21397 frag_align (2, 0, 0);
21398 record_alignment (now_seg, 2);
21399 unwind.table_entry = expr_build_dot ();
21400
21401 /* Allocate the table entry. */
21402 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
21403 /* PR 13449: Zero the table entries in case some of them are not used. */
21404 memset (ptr, 0, (size << 2) + 4);
c19d1205 21405 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 21406
c19d1205 21407 switch (unwind.personality_index)
bfae80f2 21408 {
c19d1205
ZW
21409 case -1:
21410 /* ??? Should this be a PLT generating relocation? */
21411 /* Custom personality routine. */
21412 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
21413 BFD_RELOC_ARM_PREL31);
bfae80f2 21414
c19d1205
ZW
21415 where += 4;
21416 ptr += 4;
bfae80f2 21417
c19d1205 21418 /* Set the first byte to the number of additional words. */
5011093d 21419 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
21420 n = 3;
21421 break;
bfae80f2 21422
c19d1205
ZW
21423 /* ABI defined personality routines. */
21424 case 0:
21425 /* Three opcodes bytes are packed into the first word. */
21426 data = 0x80;
21427 n = 3;
21428 break;
bfae80f2 21429
c19d1205
ZW
21430 case 1:
21431 case 2:
21432 /* The size and first two opcode bytes go in the first word. */
21433 data = ((0x80 + unwind.personality_index) << 8) | size;
21434 n = 2;
21435 break;
bfae80f2 21436
c19d1205
ZW
21437 default:
21438 /* Should never happen. */
21439 abort ();
21440 }
bfae80f2 21441
c19d1205
ZW
21442 /* Pack the opcodes into words (MSB first), reversing the list at the same
21443 time. */
21444 while (unwind.opcode_count > 0)
21445 {
21446 if (n == 0)
21447 {
21448 md_number_to_chars (ptr, data, 4);
21449 ptr += 4;
21450 n = 4;
21451 data = 0;
21452 }
21453 unwind.opcode_count--;
21454 n--;
21455 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
21456 }
21457
21458 /* Finish off the last word. */
21459 if (n < 4)
21460 {
21461 /* Pad with "finish" opcodes. */
21462 while (n--)
21463 data = (data << 8) | 0xb0;
21464
21465 md_number_to_chars (ptr, data, 4);
21466 }
21467
21468 if (!have_data)
21469 {
21470 /* Add an empty descriptor if there is no user-specified data. */
21471 ptr = frag_more (4);
21472 md_number_to_chars (ptr, 0, 4);
21473 }
21474
21475 return 0;
bfae80f2
RE
21476}
21477
f0927246
NC
21478
21479/* Initialize the DWARF-2 unwind information for this procedure. */
21480
21481void
21482tc_arm_frame_initial_instructions (void)
21483{
21484 cfi_add_CFA_def_cfa (REG_SP, 0);
21485}
21486#endif /* OBJ_ELF */
21487
c19d1205
ZW
21488/* Convert REGNAME to a DWARF-2 register number. */
21489
21490int
1df69f4f 21491tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 21492{
1df69f4f 21493 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
21494 if (reg != FAIL)
21495 return reg;
c19d1205 21496
1f5afe1c
NC
21497 /* PR 16694: Allow VFP registers as well. */
21498 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
21499 if (reg != FAIL)
21500 return 64 + reg;
c19d1205 21501
1f5afe1c
NC
21502 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
21503 if (reg != FAIL)
21504 return reg + 256;
21505
21506 return -1;
bfae80f2
RE
21507}
21508
f0927246 21509#ifdef TE_PE
c19d1205 21510void
f0927246 21511tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 21512{
91d6fa6a 21513 expressionS exp;
bfae80f2 21514
91d6fa6a
NC
21515 exp.X_op = O_secrel;
21516 exp.X_add_symbol = symbol;
21517 exp.X_add_number = 0;
21518 emit_expr (&exp, size);
f0927246
NC
21519}
21520#endif
bfae80f2 21521
c19d1205 21522/* MD interface: Symbol and relocation handling. */
bfae80f2 21523
2fc8bdac
ZW
21524/* Return the address within the segment that a PC-relative fixup is
21525 relative to. For ARM, PC-relative fixups applied to instructions
21526 are generally relative to the location of the fixup plus 8 bytes.
21527 Thumb branches are offset by 4, and Thumb loads relative to PC
21528 require special handling. */
bfae80f2 21529
c19d1205 21530long
2fc8bdac 21531md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 21532{
2fc8bdac
ZW
21533 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
21534
21535 /* If this is pc-relative and we are going to emit a relocation
21536 then we just want to put out any pipeline compensation that the linker
53baae48
NC
21537 will need. Otherwise we want to use the calculated base.
21538 For WinCE we skip the bias for externals as well, since this
21539 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 21540 if (fixP->fx_pcrel
2fc8bdac 21541 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
21542 || (arm_force_relocation (fixP)
21543#ifdef TE_WINCE
21544 && !S_IS_EXTERNAL (fixP->fx_addsy)
21545#endif
21546 )))
2fc8bdac 21547 base = 0;
bfae80f2 21548
267bf995 21549
c19d1205 21550 switch (fixP->fx_r_type)
bfae80f2 21551 {
2fc8bdac
ZW
21552 /* PC relative addressing on the Thumb is slightly odd as the
21553 bottom two bits of the PC are forced to zero for the
21554 calculation. This happens *after* application of the
21555 pipeline offset. However, Thumb adrl already adjusts for
21556 this, so we need not do it again. */
c19d1205 21557 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 21558 return base & ~3;
c19d1205
ZW
21559
21560 case BFD_RELOC_ARM_THUMB_OFFSET:
21561 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 21562 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 21563 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 21564 return (base + 4) & ~3;
c19d1205 21565
2fc8bdac
ZW
21566 /* Thumb branches are simply offset by +4. */
21567 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21568 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21569 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21570 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 21571 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 21572 return base + 4;
bfae80f2 21573
267bf995 21574 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
21575 if (fixP->fx_addsy
21576 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21577 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 21578 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
21579 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21580 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
21581 return base + 4;
21582
00adf2d4
JB
21583 /* BLX is like branches above, but forces the low two bits of PC to
21584 zero. */
486499d0
CL
21585 case BFD_RELOC_THUMB_PCREL_BLX:
21586 if (fixP->fx_addsy
21587 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21588 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
21589 && THUMB_IS_FUNC (fixP->fx_addsy)
21590 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21591 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
21592 return (base + 4) & ~3;
21593
2fc8bdac
ZW
21594 /* ARM mode branches are offset by +8. However, the Windows CE
21595 loader expects the relocation not to take this into account. */
267bf995 21596 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
21597 if (fixP->fx_addsy
21598 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21599 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
21600 && ARM_IS_FUNC (fixP->fx_addsy)
21601 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21602 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 21603 return base + 8;
267bf995 21604
486499d0
CL
21605 case BFD_RELOC_ARM_PCREL_CALL:
21606 if (fixP->fx_addsy
21607 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21608 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
21609 && THUMB_IS_FUNC (fixP->fx_addsy)
21610 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21611 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 21612 return base + 8;
267bf995 21613
2fc8bdac 21614 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 21615 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 21616 case BFD_RELOC_ARM_PLT32:
c19d1205 21617#ifdef TE_WINCE
5f4273c7 21618 /* When handling fixups immediately, because we have already
477330fc 21619 discovered the value of a symbol, or the address of the frag involved
53baae48 21620 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
21621 see fixup_segment() in write.c
21622 The S_IS_EXTERNAL test handles the case of global symbols.
21623 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
21624 if (fixP->fx_pcrel
21625 && fixP->fx_addsy != NULL
21626 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21627 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
21628 return base + 8;
2fc8bdac 21629 return base;
c19d1205 21630#else
2fc8bdac 21631 return base + 8;
c19d1205 21632#endif
2fc8bdac 21633
267bf995 21634
2fc8bdac
ZW
21635 /* ARM mode loads relative to PC are also offset by +8. Unlike
21636 branches, the Windows CE loader *does* expect the relocation
21637 to take this into account. */
21638 case BFD_RELOC_ARM_OFFSET_IMM:
21639 case BFD_RELOC_ARM_OFFSET_IMM8:
21640 case BFD_RELOC_ARM_HWLITERAL:
21641 case BFD_RELOC_ARM_LITERAL:
21642 case BFD_RELOC_ARM_CP_OFF_IMM:
21643 return base + 8;
21644
21645
21646 /* Other PC-relative relocations are un-offset. */
21647 default:
21648 return base;
21649 }
bfae80f2
RE
21650}
21651
8b2d793c
NC
21652static bfd_boolean flag_warn_syms = TRUE;
21653
ae8714c2
NC
21654bfd_boolean
21655arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 21656{
8b2d793c
NC
21657 /* PR 18347 - Warn if the user attempts to create a symbol with the same
21658 name as an ARM instruction. Whilst strictly speaking it is allowed, it
21659 does mean that the resulting code might be very confusing to the reader.
21660 Also this warning can be triggered if the user omits an operand before
21661 an immediate address, eg:
21662
21663 LDR =foo
21664
21665 GAS treats this as an assignment of the value of the symbol foo to a
21666 symbol LDR, and so (without this code) it will not issue any kind of
21667 warning or error message.
21668
21669 Note - ARM instructions are case-insensitive but the strings in the hash
21670 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
21671 lower case too. */
21672 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
21673 {
21674 char * nbuf = strdup (name);
21675 char * p;
21676
21677 for (p = nbuf; *p; p++)
21678 *p = TOLOWER (*p);
21679 if (hash_find (arm_ops_hsh, nbuf) != NULL)
21680 {
21681 static struct hash_control * already_warned = NULL;
21682
21683 if (already_warned == NULL)
21684 already_warned = hash_new ();
21685 /* Only warn about the symbol once. To keep the code
21686 simple we let hash_insert do the lookup for us. */
21687 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 21688 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
21689 }
21690 else
21691 free (nbuf);
21692 }
21693
ae8714c2
NC
21694 return FALSE;
21695}
21696
21697/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
21698 Otherwise we have no need to default values of symbols. */
21699
21700symbolS *
21701md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
21702{
21703#ifdef OBJ_ELF
21704 if (name[0] == '_' && name[1] == 'G'
21705 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
21706 {
21707 if (!GOT_symbol)
21708 {
21709 if (symbol_find (name))
21710 as_bad (_("GOT already in the symbol table"));
21711
21712 GOT_symbol = symbol_new (name, undefined_section,
21713 (valueT) 0, & zero_address_frag);
21714 }
21715
21716 return GOT_symbol;
21717 }
21718#endif
21719
c921be7d 21720 return NULL;
bfae80f2
RE
21721}
21722
55cf6793 21723/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
21724 computed as two separate immediate values, added together. We
21725 already know that this value cannot be computed by just one ARM
21726 instruction. */
21727
21728static unsigned int
21729validate_immediate_twopart (unsigned int val,
21730 unsigned int * highpart)
bfae80f2 21731{
c19d1205
ZW
21732 unsigned int a;
21733 unsigned int i;
bfae80f2 21734
c19d1205
ZW
21735 for (i = 0; i < 32; i += 2)
21736 if (((a = rotate_left (val, i)) & 0xff) != 0)
21737 {
21738 if (a & 0xff00)
21739 {
21740 if (a & ~ 0xffff)
21741 continue;
21742 * highpart = (a >> 8) | ((i + 24) << 7);
21743 }
21744 else if (a & 0xff0000)
21745 {
21746 if (a & 0xff000000)
21747 continue;
21748 * highpart = (a >> 16) | ((i + 16) << 7);
21749 }
21750 else
21751 {
9c2799c2 21752 gas_assert (a & 0xff000000);
c19d1205
ZW
21753 * highpart = (a >> 24) | ((i + 8) << 7);
21754 }
bfae80f2 21755
c19d1205
ZW
21756 return (a & 0xff) | (i << 7);
21757 }
bfae80f2 21758
c19d1205 21759 return FAIL;
bfae80f2
RE
21760}
21761
c19d1205
ZW
21762static int
21763validate_offset_imm (unsigned int val, int hwse)
21764{
21765 if ((hwse && val > 255) || val > 4095)
21766 return FAIL;
21767 return val;
21768}
bfae80f2 21769
55cf6793 21770/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
21771 negative immediate constant by altering the instruction. A bit of
21772 a hack really.
21773 MOV <-> MVN
21774 AND <-> BIC
21775 ADC <-> SBC
21776 by inverting the second operand, and
21777 ADD <-> SUB
21778 CMP <-> CMN
21779 by negating the second operand. */
bfae80f2 21780
c19d1205
ZW
21781static int
21782negate_data_op (unsigned long * instruction,
21783 unsigned long value)
bfae80f2 21784{
c19d1205
ZW
21785 int op, new_inst;
21786 unsigned long negated, inverted;
bfae80f2 21787
c19d1205
ZW
21788 negated = encode_arm_immediate (-value);
21789 inverted = encode_arm_immediate (~value);
bfae80f2 21790
c19d1205
ZW
21791 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
21792 switch (op)
bfae80f2 21793 {
c19d1205
ZW
21794 /* First negates. */
21795 case OPCODE_SUB: /* ADD <-> SUB */
21796 new_inst = OPCODE_ADD;
21797 value = negated;
21798 break;
bfae80f2 21799
c19d1205
ZW
21800 case OPCODE_ADD:
21801 new_inst = OPCODE_SUB;
21802 value = negated;
21803 break;
bfae80f2 21804
c19d1205
ZW
21805 case OPCODE_CMP: /* CMP <-> CMN */
21806 new_inst = OPCODE_CMN;
21807 value = negated;
21808 break;
bfae80f2 21809
c19d1205
ZW
21810 case OPCODE_CMN:
21811 new_inst = OPCODE_CMP;
21812 value = negated;
21813 break;
bfae80f2 21814
c19d1205
ZW
21815 /* Now Inverted ops. */
21816 case OPCODE_MOV: /* MOV <-> MVN */
21817 new_inst = OPCODE_MVN;
21818 value = inverted;
21819 break;
bfae80f2 21820
c19d1205
ZW
21821 case OPCODE_MVN:
21822 new_inst = OPCODE_MOV;
21823 value = inverted;
21824 break;
bfae80f2 21825
c19d1205
ZW
21826 case OPCODE_AND: /* AND <-> BIC */
21827 new_inst = OPCODE_BIC;
21828 value = inverted;
21829 break;
bfae80f2 21830
c19d1205
ZW
21831 case OPCODE_BIC:
21832 new_inst = OPCODE_AND;
21833 value = inverted;
21834 break;
bfae80f2 21835
c19d1205
ZW
21836 case OPCODE_ADC: /* ADC <-> SBC */
21837 new_inst = OPCODE_SBC;
21838 value = inverted;
21839 break;
bfae80f2 21840
c19d1205
ZW
21841 case OPCODE_SBC:
21842 new_inst = OPCODE_ADC;
21843 value = inverted;
21844 break;
bfae80f2 21845
c19d1205
ZW
21846 /* We cannot do anything. */
21847 default:
21848 return FAIL;
b99bd4ef
NC
21849 }
21850
c19d1205
ZW
21851 if (value == (unsigned) FAIL)
21852 return FAIL;
21853
21854 *instruction &= OPCODE_MASK;
21855 *instruction |= new_inst << DATA_OP_SHIFT;
21856 return value;
b99bd4ef
NC
21857}
21858
ef8d22e6
PB
21859/* Like negate_data_op, but for Thumb-2. */
21860
21861static unsigned int
16dd5e42 21862thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
21863{
21864 int op, new_inst;
21865 int rd;
16dd5e42 21866 unsigned int negated, inverted;
ef8d22e6
PB
21867
21868 negated = encode_thumb32_immediate (-value);
21869 inverted = encode_thumb32_immediate (~value);
21870
21871 rd = (*instruction >> 8) & 0xf;
21872 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
21873 switch (op)
21874 {
21875 /* ADD <-> SUB. Includes CMP <-> CMN. */
21876 case T2_OPCODE_SUB:
21877 new_inst = T2_OPCODE_ADD;
21878 value = negated;
21879 break;
21880
21881 case T2_OPCODE_ADD:
21882 new_inst = T2_OPCODE_SUB;
21883 value = negated;
21884 break;
21885
21886 /* ORR <-> ORN. Includes MOV <-> MVN. */
21887 case T2_OPCODE_ORR:
21888 new_inst = T2_OPCODE_ORN;
21889 value = inverted;
21890 break;
21891
21892 case T2_OPCODE_ORN:
21893 new_inst = T2_OPCODE_ORR;
21894 value = inverted;
21895 break;
21896
21897 /* AND <-> BIC. TST has no inverted equivalent. */
21898 case T2_OPCODE_AND:
21899 new_inst = T2_OPCODE_BIC;
21900 if (rd == 15)
21901 value = FAIL;
21902 else
21903 value = inverted;
21904 break;
21905
21906 case T2_OPCODE_BIC:
21907 new_inst = T2_OPCODE_AND;
21908 value = inverted;
21909 break;
21910
21911 /* ADC <-> SBC */
21912 case T2_OPCODE_ADC:
21913 new_inst = T2_OPCODE_SBC;
21914 value = inverted;
21915 break;
21916
21917 case T2_OPCODE_SBC:
21918 new_inst = T2_OPCODE_ADC;
21919 value = inverted;
21920 break;
21921
21922 /* We cannot do anything. */
21923 default:
21924 return FAIL;
21925 }
21926
16dd5e42 21927 if (value == (unsigned int)FAIL)
ef8d22e6
PB
21928 return FAIL;
21929
21930 *instruction &= T2_OPCODE_MASK;
21931 *instruction |= new_inst << T2_DATA_OP_SHIFT;
21932 return value;
21933}
21934
8f06b2d8
PB
21935/* Read a 32-bit thumb instruction from buf. */
21936static unsigned long
21937get_thumb32_insn (char * buf)
21938{
21939 unsigned long insn;
21940 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
21941 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21942
21943 return insn;
21944}
21945
a8bc6c78
PB
21946
21947/* We usually want to set the low bit on the address of thumb function
21948 symbols. In particular .word foo - . should have the low bit set.
21949 Generic code tries to fold the difference of two symbols to
21950 a constant. Prevent this and force a relocation when the first symbols
21951 is a thumb function. */
c921be7d
NC
21952
21953bfd_boolean
a8bc6c78
PB
21954arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
21955{
21956 if (op == O_subtract
21957 && l->X_op == O_symbol
21958 && r->X_op == O_symbol
21959 && THUMB_IS_FUNC (l->X_add_symbol))
21960 {
21961 l->X_op = O_subtract;
21962 l->X_op_symbol = r->X_add_symbol;
21963 l->X_add_number -= r->X_add_number;
c921be7d 21964 return TRUE;
a8bc6c78 21965 }
c921be7d 21966
a8bc6c78 21967 /* Process as normal. */
c921be7d 21968 return FALSE;
a8bc6c78
PB
21969}
21970
4a42ebbc
RR
21971/* Encode Thumb2 unconditional branches and calls. The encoding
21972 for the 2 are identical for the immediate values. */
21973
21974static void
21975encode_thumb2_b_bl_offset (char * buf, offsetT value)
21976{
21977#define T2I1I2MASK ((1 << 13) | (1 << 11))
21978 offsetT newval;
21979 offsetT newval2;
21980 addressT S, I1, I2, lo, hi;
21981
21982 S = (value >> 24) & 0x01;
21983 I1 = (value >> 23) & 0x01;
21984 I2 = (value >> 22) & 0x01;
21985 hi = (value >> 12) & 0x3ff;
fa94de6b 21986 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
21987 newval = md_chars_to_number (buf, THUMB_SIZE);
21988 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21989 newval |= (S << 10) | hi;
21990 newval2 &= ~T2I1I2MASK;
21991 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
21992 md_number_to_chars (buf, newval, THUMB_SIZE);
21993 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
21994}
21995
c19d1205 21996void
55cf6793 21997md_apply_fix (fixS * fixP,
c19d1205
ZW
21998 valueT * valP,
21999 segT seg)
22000{
22001 offsetT value = * valP;
22002 offsetT newval;
22003 unsigned int newimm;
22004 unsigned long temp;
22005 int sign;
22006 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 22007
9c2799c2 22008 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 22009
c19d1205 22010 /* Note whether this will delete the relocation. */
4962c51a 22011
c19d1205
ZW
22012 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
22013 fixP->fx_done = 1;
b99bd4ef 22014
adbaf948 22015 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 22016 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
22017 for emit_reloc. */
22018 value &= 0xffffffff;
22019 value ^= 0x80000000;
5f4273c7 22020 value -= 0x80000000;
adbaf948
ZW
22021
22022 *valP = value;
c19d1205 22023 fixP->fx_addnumber = value;
b99bd4ef 22024
adbaf948
ZW
22025 /* Same treatment for fixP->fx_offset. */
22026 fixP->fx_offset &= 0xffffffff;
22027 fixP->fx_offset ^= 0x80000000;
22028 fixP->fx_offset -= 0x80000000;
22029
c19d1205 22030 switch (fixP->fx_r_type)
b99bd4ef 22031 {
c19d1205
ZW
22032 case BFD_RELOC_NONE:
22033 /* This will need to go in the object file. */
22034 fixP->fx_done = 0;
22035 break;
b99bd4ef 22036
c19d1205
ZW
22037 case BFD_RELOC_ARM_IMMEDIATE:
22038 /* We claim that this fixup has been processed here,
22039 even if in fact we generate an error because we do
22040 not have a reloc for it, so tc_gen_reloc will reject it. */
22041 fixP->fx_done = 1;
b99bd4ef 22042
77db8e2e 22043 if (fixP->fx_addsy)
b99bd4ef 22044 {
77db8e2e 22045 const char *msg = 0;
b99bd4ef 22046
77db8e2e
NC
22047 if (! S_IS_DEFINED (fixP->fx_addsy))
22048 msg = _("undefined symbol %s used as an immediate value");
22049 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22050 msg = _("symbol %s is in a different section");
22051 else if (S_IS_WEAK (fixP->fx_addsy))
22052 msg = _("symbol %s is weak and may be overridden later");
22053
22054 if (msg)
22055 {
22056 as_bad_where (fixP->fx_file, fixP->fx_line,
22057 msg, S_GET_NAME (fixP->fx_addsy));
22058 break;
22059 }
42e5fcbf
AS
22060 }
22061
c19d1205
ZW
22062 temp = md_chars_to_number (buf, INSN_SIZE);
22063
5e73442d
SL
22064 /* If the offset is negative, we should use encoding A2 for ADR. */
22065 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
22066 newimm = negate_data_op (&temp, value);
22067 else
22068 {
22069 newimm = encode_arm_immediate (value);
22070
22071 /* If the instruction will fail, see if we can fix things up by
22072 changing the opcode. */
22073 if (newimm == (unsigned int) FAIL)
22074 newimm = negate_data_op (&temp, value);
22075 }
22076
22077 if (newimm == (unsigned int) FAIL)
b99bd4ef 22078 {
c19d1205
ZW
22079 as_bad_where (fixP->fx_file, fixP->fx_line,
22080 _("invalid constant (%lx) after fixup"),
22081 (unsigned long) value);
22082 break;
b99bd4ef 22083 }
b99bd4ef 22084
c19d1205
ZW
22085 newimm |= (temp & 0xfffff000);
22086 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
22087 break;
b99bd4ef 22088
c19d1205
ZW
22089 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22090 {
22091 unsigned int highpart = 0;
22092 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 22093
77db8e2e 22094 if (fixP->fx_addsy)
42e5fcbf 22095 {
77db8e2e 22096 const char *msg = 0;
42e5fcbf 22097
77db8e2e
NC
22098 if (! S_IS_DEFINED (fixP->fx_addsy))
22099 msg = _("undefined symbol %s used as an immediate value");
22100 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22101 msg = _("symbol %s is in a different section");
22102 else if (S_IS_WEAK (fixP->fx_addsy))
22103 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 22104
77db8e2e
NC
22105 if (msg)
22106 {
22107 as_bad_where (fixP->fx_file, fixP->fx_line,
22108 msg, S_GET_NAME (fixP->fx_addsy));
22109 break;
22110 }
22111 }
fa94de6b 22112
c19d1205
ZW
22113 newimm = encode_arm_immediate (value);
22114 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 22115
c19d1205
ZW
22116 /* If the instruction will fail, see if we can fix things up by
22117 changing the opcode. */
22118 if (newimm == (unsigned int) FAIL
22119 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
22120 {
22121 /* No ? OK - try using two ADD instructions to generate
22122 the value. */
22123 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 22124
c19d1205
ZW
22125 /* Yes - then make sure that the second instruction is
22126 also an add. */
22127 if (newimm != (unsigned int) FAIL)
22128 newinsn = temp;
22129 /* Still No ? Try using a negated value. */
22130 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
22131 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
22132 /* Otherwise - give up. */
22133 else
22134 {
22135 as_bad_where (fixP->fx_file, fixP->fx_line,
22136 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
22137 (long) value);
22138 break;
22139 }
b99bd4ef 22140
c19d1205
ZW
22141 /* Replace the first operand in the 2nd instruction (which
22142 is the PC) with the destination register. We have
22143 already added in the PC in the first instruction and we
22144 do not want to do it again. */
22145 newinsn &= ~ 0xf0000;
22146 newinsn |= ((newinsn & 0x0f000) << 4);
22147 }
b99bd4ef 22148
c19d1205
ZW
22149 newimm |= (temp & 0xfffff000);
22150 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 22151
c19d1205
ZW
22152 highpart |= (newinsn & 0xfffff000);
22153 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
22154 }
22155 break;
b99bd4ef 22156
c19d1205 22157 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
22158 if (!fixP->fx_done && seg->use_rela_p)
22159 value = 0;
22160
c19d1205 22161 case BFD_RELOC_ARM_LITERAL:
26d97720 22162 sign = value > 0;
b99bd4ef 22163
c19d1205
ZW
22164 if (value < 0)
22165 value = - value;
b99bd4ef 22166
c19d1205 22167 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 22168 {
c19d1205
ZW
22169 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
22170 as_bad_where (fixP->fx_file, fixP->fx_line,
22171 _("invalid literal constant: pool needs to be closer"));
22172 else
22173 as_bad_where (fixP->fx_file, fixP->fx_line,
22174 _("bad immediate value for offset (%ld)"),
22175 (long) value);
22176 break;
f03698e6
RE
22177 }
22178
c19d1205 22179 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
22180 if (value == 0)
22181 newval &= 0xfffff000;
22182 else
22183 {
22184 newval &= 0xff7ff000;
22185 newval |= value | (sign ? INDEX_UP : 0);
22186 }
c19d1205
ZW
22187 md_number_to_chars (buf, newval, INSN_SIZE);
22188 break;
b99bd4ef 22189
c19d1205
ZW
22190 case BFD_RELOC_ARM_OFFSET_IMM8:
22191 case BFD_RELOC_ARM_HWLITERAL:
26d97720 22192 sign = value > 0;
b99bd4ef 22193
c19d1205
ZW
22194 if (value < 0)
22195 value = - value;
b99bd4ef 22196
c19d1205 22197 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 22198 {
c19d1205
ZW
22199 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
22200 as_bad_where (fixP->fx_file, fixP->fx_line,
22201 _("invalid literal constant: pool needs to be closer"));
22202 else
427d0db6
RM
22203 as_bad_where (fixP->fx_file, fixP->fx_line,
22204 _("bad immediate value for 8-bit offset (%ld)"),
22205 (long) value);
c19d1205 22206 break;
b99bd4ef
NC
22207 }
22208
c19d1205 22209 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
22210 if (value == 0)
22211 newval &= 0xfffff0f0;
22212 else
22213 {
22214 newval &= 0xff7ff0f0;
22215 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
22216 }
c19d1205
ZW
22217 md_number_to_chars (buf, newval, INSN_SIZE);
22218 break;
b99bd4ef 22219
c19d1205
ZW
22220 case BFD_RELOC_ARM_T32_OFFSET_U8:
22221 if (value < 0 || value > 1020 || value % 4 != 0)
22222 as_bad_where (fixP->fx_file, fixP->fx_line,
22223 _("bad immediate value for offset (%ld)"), (long) value);
22224 value /= 4;
b99bd4ef 22225
c19d1205 22226 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
22227 newval |= value;
22228 md_number_to_chars (buf+2, newval, THUMB_SIZE);
22229 break;
b99bd4ef 22230
c19d1205
ZW
22231 case BFD_RELOC_ARM_T32_OFFSET_IMM:
22232 /* This is a complicated relocation used for all varieties of Thumb32
22233 load/store instruction with immediate offset:
22234
22235 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 22236 *4, optional writeback(W)
c19d1205
ZW
22237 (doubleword load/store)
22238
22239 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
22240 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
22241 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
22242 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
22243 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
22244
22245 Uppercase letters indicate bits that are already encoded at
22246 this point. Lowercase letters are our problem. For the
22247 second block of instructions, the secondary opcode nybble
22248 (bits 8..11) is present, and bit 23 is zero, even if this is
22249 a PC-relative operation. */
22250 newval = md_chars_to_number (buf, THUMB_SIZE);
22251 newval <<= 16;
22252 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 22253
c19d1205 22254 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 22255 {
c19d1205
ZW
22256 /* Doubleword load/store: 8-bit offset, scaled by 4. */
22257 if (value >= 0)
22258 newval |= (1 << 23);
22259 else
22260 value = -value;
22261 if (value % 4 != 0)
22262 {
22263 as_bad_where (fixP->fx_file, fixP->fx_line,
22264 _("offset not a multiple of 4"));
22265 break;
22266 }
22267 value /= 4;
216d22bc 22268 if (value > 0xff)
c19d1205
ZW
22269 {
22270 as_bad_where (fixP->fx_file, fixP->fx_line,
22271 _("offset out of range"));
22272 break;
22273 }
22274 newval &= ~0xff;
b99bd4ef 22275 }
c19d1205 22276 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 22277 {
c19d1205
ZW
22278 /* PC-relative, 12-bit offset. */
22279 if (value >= 0)
22280 newval |= (1 << 23);
22281 else
22282 value = -value;
216d22bc 22283 if (value > 0xfff)
c19d1205
ZW
22284 {
22285 as_bad_where (fixP->fx_file, fixP->fx_line,
22286 _("offset out of range"));
22287 break;
22288 }
22289 newval &= ~0xfff;
b99bd4ef 22290 }
c19d1205 22291 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 22292 {
c19d1205
ZW
22293 /* Writeback: 8-bit, +/- offset. */
22294 if (value >= 0)
22295 newval |= (1 << 9);
22296 else
22297 value = -value;
216d22bc 22298 if (value > 0xff)
c19d1205
ZW
22299 {
22300 as_bad_where (fixP->fx_file, fixP->fx_line,
22301 _("offset out of range"));
22302 break;
22303 }
22304 newval &= ~0xff;
b99bd4ef 22305 }
c19d1205 22306 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 22307 {
c19d1205 22308 /* T-instruction: positive 8-bit offset. */
216d22bc 22309 if (value < 0 || value > 0xff)
b99bd4ef 22310 {
c19d1205
ZW
22311 as_bad_where (fixP->fx_file, fixP->fx_line,
22312 _("offset out of range"));
22313 break;
b99bd4ef 22314 }
c19d1205
ZW
22315 newval &= ~0xff;
22316 newval |= value;
b99bd4ef
NC
22317 }
22318 else
b99bd4ef 22319 {
c19d1205
ZW
22320 /* Positive 12-bit or negative 8-bit offset. */
22321 int limit;
22322 if (value >= 0)
b99bd4ef 22323 {
c19d1205
ZW
22324 newval |= (1 << 23);
22325 limit = 0xfff;
22326 }
22327 else
22328 {
22329 value = -value;
22330 limit = 0xff;
22331 }
22332 if (value > limit)
22333 {
22334 as_bad_where (fixP->fx_file, fixP->fx_line,
22335 _("offset out of range"));
22336 break;
b99bd4ef 22337 }
c19d1205 22338 newval &= ~limit;
b99bd4ef 22339 }
b99bd4ef 22340
c19d1205
ZW
22341 newval |= value;
22342 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
22343 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
22344 break;
404ff6b5 22345
c19d1205
ZW
22346 case BFD_RELOC_ARM_SHIFT_IMM:
22347 newval = md_chars_to_number (buf, INSN_SIZE);
22348 if (((unsigned long) value) > 32
22349 || (value == 32
22350 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
22351 {
22352 as_bad_where (fixP->fx_file, fixP->fx_line,
22353 _("shift expression is too large"));
22354 break;
22355 }
404ff6b5 22356
c19d1205
ZW
22357 if (value == 0)
22358 /* Shifts of zero must be done as lsl. */
22359 newval &= ~0x60;
22360 else if (value == 32)
22361 value = 0;
22362 newval &= 0xfffff07f;
22363 newval |= (value & 0x1f) << 7;
22364 md_number_to_chars (buf, newval, INSN_SIZE);
22365 break;
404ff6b5 22366
c19d1205 22367 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 22368 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 22369 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 22370 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
22371 /* We claim that this fixup has been processed here,
22372 even if in fact we generate an error because we do
22373 not have a reloc for it, so tc_gen_reloc will reject it. */
22374 fixP->fx_done = 1;
404ff6b5 22375
c19d1205
ZW
22376 if (fixP->fx_addsy
22377 && ! S_IS_DEFINED (fixP->fx_addsy))
22378 {
22379 as_bad_where (fixP->fx_file, fixP->fx_line,
22380 _("undefined symbol %s used as an immediate value"),
22381 S_GET_NAME (fixP->fx_addsy));
22382 break;
22383 }
404ff6b5 22384
c19d1205
ZW
22385 newval = md_chars_to_number (buf, THUMB_SIZE);
22386 newval <<= 16;
22387 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 22388
16805f35
PB
22389 newimm = FAIL;
22390 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
22391 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
22392 {
22393 newimm = encode_thumb32_immediate (value);
22394 if (newimm == (unsigned int) FAIL)
22395 newimm = thumb32_negate_data_op (&newval, value);
22396 }
16805f35
PB
22397 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
22398 && newimm == (unsigned int) FAIL)
92e90b6e 22399 {
16805f35
PB
22400 /* Turn add/sum into addw/subw. */
22401 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
22402 newval = (newval & 0xfeffffff) | 0x02000000;
40f246e3
NC
22403 /* No flat 12-bit imm encoding for addsw/subsw. */
22404 if ((newval & 0x00100000) == 0)
e9f89963 22405 {
40f246e3
NC
22406 /* 12 bit immediate for addw/subw. */
22407 if (value < 0)
22408 {
22409 value = -value;
22410 newval ^= 0x00a00000;
22411 }
22412 if (value > 0xfff)
22413 newimm = (unsigned int) FAIL;
22414 else
22415 newimm = value;
e9f89963 22416 }
92e90b6e 22417 }
cc8a6dd0 22418
c19d1205 22419 if (newimm == (unsigned int)FAIL)
3631a3c8 22420 {
c19d1205
ZW
22421 as_bad_where (fixP->fx_file, fixP->fx_line,
22422 _("invalid constant (%lx) after fixup"),
22423 (unsigned long) value);
22424 break;
3631a3c8
NC
22425 }
22426
c19d1205
ZW
22427 newval |= (newimm & 0x800) << 15;
22428 newval |= (newimm & 0x700) << 4;
22429 newval |= (newimm & 0x0ff);
cc8a6dd0 22430
c19d1205
ZW
22431 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
22432 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
22433 break;
a737bd4d 22434
3eb17e6b 22435 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
22436 if (((unsigned long) value) > 0xffff)
22437 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 22438 _("invalid smc expression"));
2fc8bdac 22439 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
22440 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
22441 md_number_to_chars (buf, newval, INSN_SIZE);
22442 break;
a737bd4d 22443
90ec0d68
MGD
22444 case BFD_RELOC_ARM_HVC:
22445 if (((unsigned long) value) > 0xffff)
22446 as_bad_where (fixP->fx_file, fixP->fx_line,
22447 _("invalid hvc expression"));
22448 newval = md_chars_to_number (buf, INSN_SIZE);
22449 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
22450 md_number_to_chars (buf, newval, INSN_SIZE);
22451 break;
22452
c19d1205 22453 case BFD_RELOC_ARM_SWI:
adbaf948 22454 if (fixP->tc_fix_data != 0)
c19d1205
ZW
22455 {
22456 if (((unsigned long) value) > 0xff)
22457 as_bad_where (fixP->fx_file, fixP->fx_line,
22458 _("invalid swi expression"));
2fc8bdac 22459 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
22460 newval |= value;
22461 md_number_to_chars (buf, newval, THUMB_SIZE);
22462 }
22463 else
22464 {
22465 if (((unsigned long) value) > 0x00ffffff)
22466 as_bad_where (fixP->fx_file, fixP->fx_line,
22467 _("invalid swi expression"));
2fc8bdac 22468 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
22469 newval |= value;
22470 md_number_to_chars (buf, newval, INSN_SIZE);
22471 }
22472 break;
a737bd4d 22473
c19d1205
ZW
22474 case BFD_RELOC_ARM_MULTI:
22475 if (((unsigned long) value) > 0xffff)
22476 as_bad_where (fixP->fx_file, fixP->fx_line,
22477 _("invalid expression in load/store multiple"));
22478 newval = value | md_chars_to_number (buf, INSN_SIZE);
22479 md_number_to_chars (buf, newval, INSN_SIZE);
22480 break;
a737bd4d 22481
c19d1205 22482#ifdef OBJ_ELF
39b41c9c 22483 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
22484
22485 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22486 && fixP->fx_addsy
34e77a92 22487 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22488 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22489 && THUMB_IS_FUNC (fixP->fx_addsy))
22490 /* Flip the bl to blx. This is a simple flip
22491 bit here because we generate PCREL_CALL for
22492 unconditional bls. */
22493 {
22494 newval = md_chars_to_number (buf, INSN_SIZE);
22495 newval = newval | 0x10000000;
22496 md_number_to_chars (buf, newval, INSN_SIZE);
22497 temp = 1;
22498 fixP->fx_done = 1;
22499 }
39b41c9c
PB
22500 else
22501 temp = 3;
22502 goto arm_branch_common;
22503
22504 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
22505 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22506 && fixP->fx_addsy
34e77a92 22507 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22508 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22509 && THUMB_IS_FUNC (fixP->fx_addsy))
22510 {
22511 /* This would map to a bl<cond>, b<cond>,
22512 b<always> to a Thumb function. We
22513 need to force a relocation for this particular
22514 case. */
22515 newval = md_chars_to_number (buf, INSN_SIZE);
22516 fixP->fx_done = 0;
22517 }
22518
2fc8bdac 22519 case BFD_RELOC_ARM_PLT32:
c19d1205 22520#endif
39b41c9c
PB
22521 case BFD_RELOC_ARM_PCREL_BRANCH:
22522 temp = 3;
22523 goto arm_branch_common;
a737bd4d 22524
39b41c9c 22525 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 22526
39b41c9c 22527 temp = 1;
267bf995
RR
22528 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22529 && fixP->fx_addsy
34e77a92 22530 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22531 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22532 && ARM_IS_FUNC (fixP->fx_addsy))
22533 {
22534 /* Flip the blx to a bl and warn. */
22535 const char *name = S_GET_NAME (fixP->fx_addsy);
22536 newval = 0xeb000000;
22537 as_warn_where (fixP->fx_file, fixP->fx_line,
22538 _("blx to '%s' an ARM ISA state function changed to bl"),
22539 name);
22540 md_number_to_chars (buf, newval, INSN_SIZE);
22541 temp = 3;
22542 fixP->fx_done = 1;
22543 }
22544
22545#ifdef OBJ_ELF
22546 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 22547 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
22548#endif
22549
39b41c9c 22550 arm_branch_common:
c19d1205 22551 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
22552 instruction, in a 24 bit, signed field. Bits 26 through 32 either
22553 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
22554 also be be clear. */
22555 if (value & temp)
c19d1205 22556 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
22557 _("misaligned branch destination"));
22558 if ((value & (offsetT)0xfe000000) != (offsetT)0
22559 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 22560 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 22561
2fc8bdac 22562 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 22563 {
2fc8bdac
ZW
22564 newval = md_chars_to_number (buf, INSN_SIZE);
22565 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
22566 /* Set the H bit on BLX instructions. */
22567 if (temp == 1)
22568 {
22569 if (value & 2)
22570 newval |= 0x01000000;
22571 else
22572 newval &= ~0x01000000;
22573 }
2fc8bdac 22574 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 22575 }
c19d1205 22576 break;
a737bd4d 22577
25fe350b
MS
22578 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
22579 /* CBZ can only branch forward. */
a737bd4d 22580
738755b0 22581 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
22582 (which, strictly speaking, are prohibited) will be turned into
22583 no-ops.
738755b0
MS
22584
22585 FIXME: It may be better to remove the instruction completely and
22586 perform relaxation. */
22587 if (value == -2)
2fc8bdac
ZW
22588 {
22589 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 22590 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
22591 md_number_to_chars (buf, newval, THUMB_SIZE);
22592 }
738755b0
MS
22593 else
22594 {
22595 if (value & ~0x7e)
08f10d51 22596 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 22597
477330fc 22598 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
22599 {
22600 newval = md_chars_to_number (buf, THUMB_SIZE);
22601 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
22602 md_number_to_chars (buf, newval, THUMB_SIZE);
22603 }
22604 }
c19d1205 22605 break;
a737bd4d 22606
c19d1205 22607 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 22608 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 22609 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 22610
2fc8bdac
ZW
22611 if (fixP->fx_done || !seg->use_rela_p)
22612 {
22613 newval = md_chars_to_number (buf, THUMB_SIZE);
22614 newval |= (value & 0x1ff) >> 1;
22615 md_number_to_chars (buf, newval, THUMB_SIZE);
22616 }
c19d1205 22617 break;
a737bd4d 22618
c19d1205 22619 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 22620 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 22621 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 22622
2fc8bdac
ZW
22623 if (fixP->fx_done || !seg->use_rela_p)
22624 {
22625 newval = md_chars_to_number (buf, THUMB_SIZE);
22626 newval |= (value & 0xfff) >> 1;
22627 md_number_to_chars (buf, newval, THUMB_SIZE);
22628 }
c19d1205 22629 break;
a737bd4d 22630
c19d1205 22631 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
22632 if (fixP->fx_addsy
22633 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22634 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22635 && ARM_IS_FUNC (fixP->fx_addsy)
22636 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22637 {
22638 /* Force a relocation for a branch 20 bits wide. */
22639 fixP->fx_done = 0;
22640 }
08f10d51 22641 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
22642 as_bad_where (fixP->fx_file, fixP->fx_line,
22643 _("conditional branch out of range"));
404ff6b5 22644
2fc8bdac
ZW
22645 if (fixP->fx_done || !seg->use_rela_p)
22646 {
22647 offsetT newval2;
22648 addressT S, J1, J2, lo, hi;
404ff6b5 22649
2fc8bdac
ZW
22650 S = (value & 0x00100000) >> 20;
22651 J2 = (value & 0x00080000) >> 19;
22652 J1 = (value & 0x00040000) >> 18;
22653 hi = (value & 0x0003f000) >> 12;
22654 lo = (value & 0x00000ffe) >> 1;
6c43fab6 22655
2fc8bdac
ZW
22656 newval = md_chars_to_number (buf, THUMB_SIZE);
22657 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22658 newval |= (S << 10) | hi;
22659 newval2 |= (J1 << 13) | (J2 << 11) | lo;
22660 md_number_to_chars (buf, newval, THUMB_SIZE);
22661 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22662 }
c19d1205 22663 break;
6c43fab6 22664
c19d1205 22665 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
22666 /* If there is a blx from a thumb state function to
22667 another thumb function flip this to a bl and warn
22668 about it. */
22669
22670 if (fixP->fx_addsy
34e77a92 22671 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22672 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22673 && THUMB_IS_FUNC (fixP->fx_addsy))
22674 {
22675 const char *name = S_GET_NAME (fixP->fx_addsy);
22676 as_warn_where (fixP->fx_file, fixP->fx_line,
22677 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
22678 name);
22679 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22680 newval = newval | 0x1000;
22681 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
22682 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
22683 fixP->fx_done = 1;
22684 }
22685
22686
22687 goto thumb_bl_common;
22688
c19d1205 22689 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
22690 /* A bl from Thumb state ISA to an internal ARM state function
22691 is converted to a blx. */
22692 if (fixP->fx_addsy
22693 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22694 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22695 && ARM_IS_FUNC (fixP->fx_addsy)
22696 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22697 {
22698 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22699 newval = newval & ~0x1000;
22700 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
22701 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
22702 fixP->fx_done = 1;
22703 }
22704
22705 thumb_bl_common:
22706
2fc8bdac
ZW
22707 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
22708 /* For a BLX instruction, make sure that the relocation is rounded up
22709 to a word boundary. This follows the semantics of the instruction
22710 which specifies that bit 1 of the target address will come from bit
22711 1 of the base address. */
d406f3e4
JB
22712 value = (value + 3) & ~ 3;
22713
22714#ifdef OBJ_ELF
22715 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
22716 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
22717 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
22718#endif
404ff6b5 22719
2b2f5df9
NC
22720 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
22721 {
22722 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
22723 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
22724 else if ((value & ~0x1ffffff)
22725 && ((value & ~0x1ffffff) != ~0x1ffffff))
22726 as_bad_where (fixP->fx_file, fixP->fx_line,
22727 _("Thumb2 branch out of range"));
22728 }
4a42ebbc
RR
22729
22730 if (fixP->fx_done || !seg->use_rela_p)
22731 encode_thumb2_b_bl_offset (buf, value);
22732
c19d1205 22733 break;
404ff6b5 22734
c19d1205 22735 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
22736 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
22737 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 22738
2fc8bdac 22739 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 22740 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 22741
2fc8bdac 22742 break;
a737bd4d 22743
2fc8bdac
ZW
22744 case BFD_RELOC_8:
22745 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 22746 *buf = value;
c19d1205 22747 break;
a737bd4d 22748
c19d1205 22749 case BFD_RELOC_16:
2fc8bdac 22750 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 22751 md_number_to_chars (buf, value, 2);
c19d1205 22752 break;
a737bd4d 22753
c19d1205 22754#ifdef OBJ_ELF
0855e32b
NS
22755 case BFD_RELOC_ARM_TLS_CALL:
22756 case BFD_RELOC_ARM_THM_TLS_CALL:
22757 case BFD_RELOC_ARM_TLS_DESCSEQ:
22758 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 22759 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
22760 case BFD_RELOC_ARM_TLS_GD32:
22761 case BFD_RELOC_ARM_TLS_LE32:
22762 case BFD_RELOC_ARM_TLS_IE32:
22763 case BFD_RELOC_ARM_TLS_LDM32:
22764 case BFD_RELOC_ARM_TLS_LDO32:
22765 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 22766 break;
6c43fab6 22767
c19d1205
ZW
22768 case BFD_RELOC_ARM_GOT32:
22769 case BFD_RELOC_ARM_GOTOFF:
c19d1205 22770 break;
b43420e6
NC
22771
22772 case BFD_RELOC_ARM_GOT_PREL:
22773 if (fixP->fx_done || !seg->use_rela_p)
477330fc 22774 md_number_to_chars (buf, value, 4);
b43420e6
NC
22775 break;
22776
9a6f4e97
NS
22777 case BFD_RELOC_ARM_TARGET2:
22778 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
22779 addend here for REL targets, because it won't be written out
22780 during reloc processing later. */
9a6f4e97
NS
22781 if (fixP->fx_done || !seg->use_rela_p)
22782 md_number_to_chars (buf, fixP->fx_offset, 4);
22783 break;
c19d1205 22784#endif
6c43fab6 22785
c19d1205
ZW
22786 case BFD_RELOC_RVA:
22787 case BFD_RELOC_32:
22788 case BFD_RELOC_ARM_TARGET1:
22789 case BFD_RELOC_ARM_ROSEGREL32:
22790 case BFD_RELOC_ARM_SBREL32:
22791 case BFD_RELOC_32_PCREL:
f0927246
NC
22792#ifdef TE_PE
22793 case BFD_RELOC_32_SECREL:
22794#endif
2fc8bdac 22795 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
22796#ifdef TE_WINCE
22797 /* For WinCE we only do this for pcrel fixups. */
22798 if (fixP->fx_done || fixP->fx_pcrel)
22799#endif
22800 md_number_to_chars (buf, value, 4);
c19d1205 22801 break;
6c43fab6 22802
c19d1205
ZW
22803#ifdef OBJ_ELF
22804 case BFD_RELOC_ARM_PREL31:
2fc8bdac 22805 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
22806 {
22807 newval = md_chars_to_number (buf, 4) & 0x80000000;
22808 if ((value ^ (value >> 1)) & 0x40000000)
22809 {
22810 as_bad_where (fixP->fx_file, fixP->fx_line,
22811 _("rel31 relocation overflow"));
22812 }
22813 newval |= value & 0x7fffffff;
22814 md_number_to_chars (buf, newval, 4);
22815 }
22816 break;
c19d1205 22817#endif
a737bd4d 22818
c19d1205 22819 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 22820 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
22821 if (value < -1023 || value > 1023 || (value & 3))
22822 as_bad_where (fixP->fx_file, fixP->fx_line,
22823 _("co-processor offset out of range"));
22824 cp_off_common:
26d97720 22825 sign = value > 0;
c19d1205
ZW
22826 if (value < 0)
22827 value = -value;
8f06b2d8
PB
22828 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22829 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
22830 newval = md_chars_to_number (buf, INSN_SIZE);
22831 else
22832 newval = get_thumb32_insn (buf);
26d97720
NS
22833 if (value == 0)
22834 newval &= 0xffffff00;
22835 else
22836 {
22837 newval &= 0xff7fff00;
22838 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
22839 }
8f06b2d8
PB
22840 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22841 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
22842 md_number_to_chars (buf, newval, INSN_SIZE);
22843 else
22844 put_thumb32_insn (buf, newval);
c19d1205 22845 break;
a737bd4d 22846
c19d1205 22847 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 22848 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
22849 if (value < -255 || value > 255)
22850 as_bad_where (fixP->fx_file, fixP->fx_line,
22851 _("co-processor offset out of range"));
df7849c5 22852 value *= 4;
c19d1205 22853 goto cp_off_common;
6c43fab6 22854
c19d1205
ZW
22855 case BFD_RELOC_ARM_THUMB_OFFSET:
22856 newval = md_chars_to_number (buf, THUMB_SIZE);
22857 /* Exactly what ranges, and where the offset is inserted depends
22858 on the type of instruction, we can establish this from the
22859 top 4 bits. */
22860 switch (newval >> 12)
22861 {
22862 case 4: /* PC load. */
22863 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
22864 forced to zero for these loads; md_pcrel_from has already
22865 compensated for this. */
22866 if (value & 3)
22867 as_bad_where (fixP->fx_file, fixP->fx_line,
22868 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
22869 (((unsigned long) fixP->fx_frag->fr_address
22870 + (unsigned long) fixP->fx_where) & ~3)
22871 + (unsigned long) value);
a737bd4d 22872
c19d1205
ZW
22873 if (value & ~0x3fc)
22874 as_bad_where (fixP->fx_file, fixP->fx_line,
22875 _("invalid offset, value too big (0x%08lX)"),
22876 (long) value);
a737bd4d 22877
c19d1205
ZW
22878 newval |= value >> 2;
22879 break;
a737bd4d 22880
c19d1205
ZW
22881 case 9: /* SP load/store. */
22882 if (value & ~0x3fc)
22883 as_bad_where (fixP->fx_file, fixP->fx_line,
22884 _("invalid offset, value too big (0x%08lX)"),
22885 (long) value);
22886 newval |= value >> 2;
22887 break;
6c43fab6 22888
c19d1205
ZW
22889 case 6: /* Word load/store. */
22890 if (value & ~0x7c)
22891 as_bad_where (fixP->fx_file, fixP->fx_line,
22892 _("invalid offset, value too big (0x%08lX)"),
22893 (long) value);
22894 newval |= value << 4; /* 6 - 2. */
22895 break;
a737bd4d 22896
c19d1205
ZW
22897 case 7: /* Byte load/store. */
22898 if (value & ~0x1f)
22899 as_bad_where (fixP->fx_file, fixP->fx_line,
22900 _("invalid offset, value too big (0x%08lX)"),
22901 (long) value);
22902 newval |= value << 6;
22903 break;
a737bd4d 22904
c19d1205
ZW
22905 case 8: /* Halfword load/store. */
22906 if (value & ~0x3e)
22907 as_bad_where (fixP->fx_file, fixP->fx_line,
22908 _("invalid offset, value too big (0x%08lX)"),
22909 (long) value);
22910 newval |= value << 5; /* 6 - 1. */
22911 break;
a737bd4d 22912
c19d1205
ZW
22913 default:
22914 as_bad_where (fixP->fx_file, fixP->fx_line,
22915 "Unable to process relocation for thumb opcode: %lx",
22916 (unsigned long) newval);
22917 break;
22918 }
22919 md_number_to_chars (buf, newval, THUMB_SIZE);
22920 break;
a737bd4d 22921
c19d1205
ZW
22922 case BFD_RELOC_ARM_THUMB_ADD:
22923 /* This is a complicated relocation, since we use it for all of
22924 the following immediate relocations:
a737bd4d 22925
c19d1205
ZW
22926 3bit ADD/SUB
22927 8bit ADD/SUB
22928 9bit ADD/SUB SP word-aligned
22929 10bit ADD PC/SP word-aligned
a737bd4d 22930
c19d1205
ZW
22931 The type of instruction being processed is encoded in the
22932 instruction field:
a737bd4d 22933
c19d1205
ZW
22934 0x8000 SUB
22935 0x00F0 Rd
22936 0x000F Rs
22937 */
22938 newval = md_chars_to_number (buf, THUMB_SIZE);
22939 {
22940 int rd = (newval >> 4) & 0xf;
22941 int rs = newval & 0xf;
22942 int subtract = !!(newval & 0x8000);
a737bd4d 22943
c19d1205
ZW
22944 /* Check for HI regs, only very restricted cases allowed:
22945 Adjusting SP, and using PC or SP to get an address. */
22946 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
22947 || (rs > 7 && rs != REG_SP && rs != REG_PC))
22948 as_bad_where (fixP->fx_file, fixP->fx_line,
22949 _("invalid Hi register with immediate"));
a737bd4d 22950
c19d1205
ZW
22951 /* If value is negative, choose the opposite instruction. */
22952 if (value < 0)
22953 {
22954 value = -value;
22955 subtract = !subtract;
22956 if (value < 0)
22957 as_bad_where (fixP->fx_file, fixP->fx_line,
22958 _("immediate value out of range"));
22959 }
a737bd4d 22960
c19d1205
ZW
22961 if (rd == REG_SP)
22962 {
22963 if (value & ~0x1fc)
22964 as_bad_where (fixP->fx_file, fixP->fx_line,
22965 _("invalid immediate for stack address calculation"));
22966 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
22967 newval |= value >> 2;
22968 }
22969 else if (rs == REG_PC || rs == REG_SP)
22970 {
22971 if (subtract || value & ~0x3fc)
22972 as_bad_where (fixP->fx_file, fixP->fx_line,
22973 _("invalid immediate for address calculation (value = 0x%08lX)"),
22974 (unsigned long) value);
22975 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
22976 newval |= rd << 8;
22977 newval |= value >> 2;
22978 }
22979 else if (rs == rd)
22980 {
22981 if (value & ~0xff)
22982 as_bad_where (fixP->fx_file, fixP->fx_line,
22983 _("immediate value out of range"));
22984 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
22985 newval |= (rd << 8) | value;
22986 }
22987 else
22988 {
22989 if (value & ~0x7)
22990 as_bad_where (fixP->fx_file, fixP->fx_line,
22991 _("immediate value out of range"));
22992 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
22993 newval |= rd | (rs << 3) | (value << 6);
22994 }
22995 }
22996 md_number_to_chars (buf, newval, THUMB_SIZE);
22997 break;
a737bd4d 22998
c19d1205
ZW
22999 case BFD_RELOC_ARM_THUMB_IMM:
23000 newval = md_chars_to_number (buf, THUMB_SIZE);
23001 if (value < 0 || value > 255)
23002 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 23003 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
23004 (long) value);
23005 newval |= value;
23006 md_number_to_chars (buf, newval, THUMB_SIZE);
23007 break;
a737bd4d 23008
c19d1205
ZW
23009 case BFD_RELOC_ARM_THUMB_SHIFT:
23010 /* 5bit shift value (0..32). LSL cannot take 32. */
23011 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
23012 temp = newval & 0xf800;
23013 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
23014 as_bad_where (fixP->fx_file, fixP->fx_line,
23015 _("invalid shift value: %ld"), (long) value);
23016 /* Shifts of zero must be encoded as LSL. */
23017 if (value == 0)
23018 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
23019 /* Shifts of 32 are encoded as zero. */
23020 else if (value == 32)
23021 value = 0;
23022 newval |= value << 6;
23023 md_number_to_chars (buf, newval, THUMB_SIZE);
23024 break;
a737bd4d 23025
c19d1205
ZW
23026 case BFD_RELOC_VTABLE_INHERIT:
23027 case BFD_RELOC_VTABLE_ENTRY:
23028 fixP->fx_done = 0;
23029 return;
6c43fab6 23030
b6895b4f
PB
23031 case BFD_RELOC_ARM_MOVW:
23032 case BFD_RELOC_ARM_MOVT:
23033 case BFD_RELOC_ARM_THUMB_MOVW:
23034 case BFD_RELOC_ARM_THUMB_MOVT:
23035 if (fixP->fx_done || !seg->use_rela_p)
23036 {
23037 /* REL format relocations are limited to a 16-bit addend. */
23038 if (!fixP->fx_done)
23039 {
39623e12 23040 if (value < -0x8000 || value > 0x7fff)
b6895b4f 23041 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 23042 _("offset out of range"));
b6895b4f
PB
23043 }
23044 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23045 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23046 {
23047 value >>= 16;
23048 }
23049
23050 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23051 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23052 {
23053 newval = get_thumb32_insn (buf);
23054 newval &= 0xfbf08f00;
23055 newval |= (value & 0xf000) << 4;
23056 newval |= (value & 0x0800) << 15;
23057 newval |= (value & 0x0700) << 4;
23058 newval |= (value & 0x00ff);
23059 put_thumb32_insn (buf, newval);
23060 }
23061 else
23062 {
23063 newval = md_chars_to_number (buf, 4);
23064 newval &= 0xfff0f000;
23065 newval |= value & 0x0fff;
23066 newval |= (value & 0xf000) << 4;
23067 md_number_to_chars (buf, newval, 4);
23068 }
23069 }
23070 return;
23071
4962c51a
MS
23072 case BFD_RELOC_ARM_ALU_PC_G0_NC:
23073 case BFD_RELOC_ARM_ALU_PC_G0:
23074 case BFD_RELOC_ARM_ALU_PC_G1_NC:
23075 case BFD_RELOC_ARM_ALU_PC_G1:
23076 case BFD_RELOC_ARM_ALU_PC_G2:
23077 case BFD_RELOC_ARM_ALU_SB_G0_NC:
23078 case BFD_RELOC_ARM_ALU_SB_G0:
23079 case BFD_RELOC_ARM_ALU_SB_G1_NC:
23080 case BFD_RELOC_ARM_ALU_SB_G1:
23081 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 23082 gas_assert (!fixP->fx_done);
4962c51a
MS
23083 if (!seg->use_rela_p)
23084 {
477330fc
RM
23085 bfd_vma insn;
23086 bfd_vma encoded_addend;
23087 bfd_vma addend_abs = abs (value);
23088
23089 /* Check that the absolute value of the addend can be
23090 expressed as an 8-bit constant plus a rotation. */
23091 encoded_addend = encode_arm_immediate (addend_abs);
23092 if (encoded_addend == (unsigned int) FAIL)
4962c51a 23093 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23094 _("the offset 0x%08lX is not representable"),
23095 (unsigned long) addend_abs);
23096
23097 /* Extract the instruction. */
23098 insn = md_chars_to_number (buf, INSN_SIZE);
23099
23100 /* If the addend is positive, use an ADD instruction.
23101 Otherwise use a SUB. Take care not to destroy the S bit. */
23102 insn &= 0xff1fffff;
23103 if (value < 0)
23104 insn |= 1 << 22;
23105 else
23106 insn |= 1 << 23;
23107
23108 /* Place the encoded addend into the first 12 bits of the
23109 instruction. */
23110 insn &= 0xfffff000;
23111 insn |= encoded_addend;
23112
23113 /* Update the instruction. */
23114 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
23115 }
23116 break;
23117
23118 case BFD_RELOC_ARM_LDR_PC_G0:
23119 case BFD_RELOC_ARM_LDR_PC_G1:
23120 case BFD_RELOC_ARM_LDR_PC_G2:
23121 case BFD_RELOC_ARM_LDR_SB_G0:
23122 case BFD_RELOC_ARM_LDR_SB_G1:
23123 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 23124 gas_assert (!fixP->fx_done);
4962c51a 23125 if (!seg->use_rela_p)
477330fc
RM
23126 {
23127 bfd_vma insn;
23128 bfd_vma addend_abs = abs (value);
4962c51a 23129
477330fc
RM
23130 /* Check that the absolute value of the addend can be
23131 encoded in 12 bits. */
23132 if (addend_abs >= 0x1000)
4962c51a 23133 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23134 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
23135 (unsigned long) addend_abs);
23136
23137 /* Extract the instruction. */
23138 insn = md_chars_to_number (buf, INSN_SIZE);
23139
23140 /* If the addend is negative, clear bit 23 of the instruction.
23141 Otherwise set it. */
23142 if (value < 0)
23143 insn &= ~(1 << 23);
23144 else
23145 insn |= 1 << 23;
23146
23147 /* Place the absolute value of the addend into the first 12 bits
23148 of the instruction. */
23149 insn &= 0xfffff000;
23150 insn |= addend_abs;
23151
23152 /* Update the instruction. */
23153 md_number_to_chars (buf, insn, INSN_SIZE);
23154 }
4962c51a
MS
23155 break;
23156
23157 case BFD_RELOC_ARM_LDRS_PC_G0:
23158 case BFD_RELOC_ARM_LDRS_PC_G1:
23159 case BFD_RELOC_ARM_LDRS_PC_G2:
23160 case BFD_RELOC_ARM_LDRS_SB_G0:
23161 case BFD_RELOC_ARM_LDRS_SB_G1:
23162 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 23163 gas_assert (!fixP->fx_done);
4962c51a 23164 if (!seg->use_rela_p)
477330fc
RM
23165 {
23166 bfd_vma insn;
23167 bfd_vma addend_abs = abs (value);
4962c51a 23168
477330fc
RM
23169 /* Check that the absolute value of the addend can be
23170 encoded in 8 bits. */
23171 if (addend_abs >= 0x100)
4962c51a 23172 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23173 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
23174 (unsigned long) addend_abs);
23175
23176 /* Extract the instruction. */
23177 insn = md_chars_to_number (buf, INSN_SIZE);
23178
23179 /* If the addend is negative, clear bit 23 of the instruction.
23180 Otherwise set it. */
23181 if (value < 0)
23182 insn &= ~(1 << 23);
23183 else
23184 insn |= 1 << 23;
23185
23186 /* Place the first four bits of the absolute value of the addend
23187 into the first 4 bits of the instruction, and the remaining
23188 four into bits 8 .. 11. */
23189 insn &= 0xfffff0f0;
23190 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
23191
23192 /* Update the instruction. */
23193 md_number_to_chars (buf, insn, INSN_SIZE);
23194 }
4962c51a
MS
23195 break;
23196
23197 case BFD_RELOC_ARM_LDC_PC_G0:
23198 case BFD_RELOC_ARM_LDC_PC_G1:
23199 case BFD_RELOC_ARM_LDC_PC_G2:
23200 case BFD_RELOC_ARM_LDC_SB_G0:
23201 case BFD_RELOC_ARM_LDC_SB_G1:
23202 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 23203 gas_assert (!fixP->fx_done);
4962c51a 23204 if (!seg->use_rela_p)
477330fc
RM
23205 {
23206 bfd_vma insn;
23207 bfd_vma addend_abs = abs (value);
4962c51a 23208
477330fc
RM
23209 /* Check that the absolute value of the addend is a multiple of
23210 four and, when divided by four, fits in 8 bits. */
23211 if (addend_abs & 0x3)
4962c51a 23212 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23213 _("bad offset 0x%08lX (must be word-aligned)"),
23214 (unsigned long) addend_abs);
4962c51a 23215
477330fc 23216 if ((addend_abs >> 2) > 0xff)
4962c51a 23217 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23218 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
23219 (unsigned long) addend_abs);
23220
23221 /* Extract the instruction. */
23222 insn = md_chars_to_number (buf, INSN_SIZE);
23223
23224 /* If the addend is negative, clear bit 23 of the instruction.
23225 Otherwise set it. */
23226 if (value < 0)
23227 insn &= ~(1 << 23);
23228 else
23229 insn |= 1 << 23;
23230
23231 /* Place the addend (divided by four) into the first eight
23232 bits of the instruction. */
23233 insn &= 0xfffffff0;
23234 insn |= addend_abs >> 2;
23235
23236 /* Update the instruction. */
23237 md_number_to_chars (buf, insn, INSN_SIZE);
23238 }
4962c51a
MS
23239 break;
23240
845b51d6
PB
23241 case BFD_RELOC_ARM_V4BX:
23242 /* This will need to go in the object file. */
23243 fixP->fx_done = 0;
23244 break;
23245
c19d1205
ZW
23246 case BFD_RELOC_UNUSED:
23247 default:
23248 as_bad_where (fixP->fx_file, fixP->fx_line,
23249 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
23250 }
6c43fab6
RE
23251}
23252
c19d1205
ZW
23253/* Translate internal representation of relocation info to BFD target
23254 format. */
a737bd4d 23255
c19d1205 23256arelent *
00a97672 23257tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 23258{
c19d1205
ZW
23259 arelent * reloc;
23260 bfd_reloc_code_real_type code;
a737bd4d 23261
21d799b5 23262 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 23263
21d799b5 23264 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
23265 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
23266 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 23267
2fc8bdac 23268 if (fixp->fx_pcrel)
00a97672
RS
23269 {
23270 if (section->use_rela_p)
23271 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
23272 else
23273 fixp->fx_offset = reloc->address;
23274 }
c19d1205 23275 reloc->addend = fixp->fx_offset;
a737bd4d 23276
c19d1205 23277 switch (fixp->fx_r_type)
a737bd4d 23278 {
c19d1205
ZW
23279 case BFD_RELOC_8:
23280 if (fixp->fx_pcrel)
23281 {
23282 code = BFD_RELOC_8_PCREL;
23283 break;
23284 }
a737bd4d 23285
c19d1205
ZW
23286 case BFD_RELOC_16:
23287 if (fixp->fx_pcrel)
23288 {
23289 code = BFD_RELOC_16_PCREL;
23290 break;
23291 }
6c43fab6 23292
c19d1205
ZW
23293 case BFD_RELOC_32:
23294 if (fixp->fx_pcrel)
23295 {
23296 code = BFD_RELOC_32_PCREL;
23297 break;
23298 }
a737bd4d 23299
b6895b4f
PB
23300 case BFD_RELOC_ARM_MOVW:
23301 if (fixp->fx_pcrel)
23302 {
23303 code = BFD_RELOC_ARM_MOVW_PCREL;
23304 break;
23305 }
23306
23307 case BFD_RELOC_ARM_MOVT:
23308 if (fixp->fx_pcrel)
23309 {
23310 code = BFD_RELOC_ARM_MOVT_PCREL;
23311 break;
23312 }
23313
23314 case BFD_RELOC_ARM_THUMB_MOVW:
23315 if (fixp->fx_pcrel)
23316 {
23317 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
23318 break;
23319 }
23320
23321 case BFD_RELOC_ARM_THUMB_MOVT:
23322 if (fixp->fx_pcrel)
23323 {
23324 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
23325 break;
23326 }
23327
c19d1205
ZW
23328 case BFD_RELOC_NONE:
23329 case BFD_RELOC_ARM_PCREL_BRANCH:
23330 case BFD_RELOC_ARM_PCREL_BLX:
23331 case BFD_RELOC_RVA:
23332 case BFD_RELOC_THUMB_PCREL_BRANCH7:
23333 case BFD_RELOC_THUMB_PCREL_BRANCH9:
23334 case BFD_RELOC_THUMB_PCREL_BRANCH12:
23335 case BFD_RELOC_THUMB_PCREL_BRANCH20:
23336 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23337 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
23338 case BFD_RELOC_VTABLE_ENTRY:
23339 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
23340#ifdef TE_PE
23341 case BFD_RELOC_32_SECREL:
23342#endif
c19d1205
ZW
23343 code = fixp->fx_r_type;
23344 break;
a737bd4d 23345
00adf2d4
JB
23346 case BFD_RELOC_THUMB_PCREL_BLX:
23347#ifdef OBJ_ELF
23348 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
23349 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
23350 else
23351#endif
23352 code = BFD_RELOC_THUMB_PCREL_BLX;
23353 break;
23354
c19d1205
ZW
23355 case BFD_RELOC_ARM_LITERAL:
23356 case BFD_RELOC_ARM_HWLITERAL:
23357 /* If this is called then the a literal has
23358 been referenced across a section boundary. */
23359 as_bad_where (fixp->fx_file, fixp->fx_line,
23360 _("literal referenced across section boundary"));
23361 return NULL;
a737bd4d 23362
c19d1205 23363#ifdef OBJ_ELF
0855e32b
NS
23364 case BFD_RELOC_ARM_TLS_CALL:
23365 case BFD_RELOC_ARM_THM_TLS_CALL:
23366 case BFD_RELOC_ARM_TLS_DESCSEQ:
23367 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
23368 case BFD_RELOC_ARM_GOT32:
23369 case BFD_RELOC_ARM_GOTOFF:
b43420e6 23370 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
23371 case BFD_RELOC_ARM_PLT32:
23372 case BFD_RELOC_ARM_TARGET1:
23373 case BFD_RELOC_ARM_ROSEGREL32:
23374 case BFD_RELOC_ARM_SBREL32:
23375 case BFD_RELOC_ARM_PREL31:
23376 case BFD_RELOC_ARM_TARGET2:
23377 case BFD_RELOC_ARM_TLS_LE32:
23378 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
23379 case BFD_RELOC_ARM_PCREL_CALL:
23380 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
23381 case BFD_RELOC_ARM_ALU_PC_G0_NC:
23382 case BFD_RELOC_ARM_ALU_PC_G0:
23383 case BFD_RELOC_ARM_ALU_PC_G1_NC:
23384 case BFD_RELOC_ARM_ALU_PC_G1:
23385 case BFD_RELOC_ARM_ALU_PC_G2:
23386 case BFD_RELOC_ARM_LDR_PC_G0:
23387 case BFD_RELOC_ARM_LDR_PC_G1:
23388 case BFD_RELOC_ARM_LDR_PC_G2:
23389 case BFD_RELOC_ARM_LDRS_PC_G0:
23390 case BFD_RELOC_ARM_LDRS_PC_G1:
23391 case BFD_RELOC_ARM_LDRS_PC_G2:
23392 case BFD_RELOC_ARM_LDC_PC_G0:
23393 case BFD_RELOC_ARM_LDC_PC_G1:
23394 case BFD_RELOC_ARM_LDC_PC_G2:
23395 case BFD_RELOC_ARM_ALU_SB_G0_NC:
23396 case BFD_RELOC_ARM_ALU_SB_G0:
23397 case BFD_RELOC_ARM_ALU_SB_G1_NC:
23398 case BFD_RELOC_ARM_ALU_SB_G1:
23399 case BFD_RELOC_ARM_ALU_SB_G2:
23400 case BFD_RELOC_ARM_LDR_SB_G0:
23401 case BFD_RELOC_ARM_LDR_SB_G1:
23402 case BFD_RELOC_ARM_LDR_SB_G2:
23403 case BFD_RELOC_ARM_LDRS_SB_G0:
23404 case BFD_RELOC_ARM_LDRS_SB_G1:
23405 case BFD_RELOC_ARM_LDRS_SB_G2:
23406 case BFD_RELOC_ARM_LDC_SB_G0:
23407 case BFD_RELOC_ARM_LDC_SB_G1:
23408 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 23409 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
23410 code = fixp->fx_r_type;
23411 break;
a737bd4d 23412
0855e32b 23413 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
23414 case BFD_RELOC_ARM_TLS_GD32:
23415 case BFD_RELOC_ARM_TLS_IE32:
23416 case BFD_RELOC_ARM_TLS_LDM32:
23417 /* BFD will include the symbol's address in the addend.
23418 But we don't want that, so subtract it out again here. */
23419 if (!S_IS_COMMON (fixp->fx_addsy))
23420 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
23421 code = fixp->fx_r_type;
23422 break;
23423#endif
a737bd4d 23424
c19d1205
ZW
23425 case BFD_RELOC_ARM_IMMEDIATE:
23426 as_bad_where (fixp->fx_file, fixp->fx_line,
23427 _("internal relocation (type: IMMEDIATE) not fixed up"));
23428 return NULL;
a737bd4d 23429
c19d1205
ZW
23430 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
23431 as_bad_where (fixp->fx_file, fixp->fx_line,
23432 _("ADRL used for a symbol not defined in the same file"));
23433 return NULL;
a737bd4d 23434
c19d1205 23435 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
23436 if (section->use_rela_p)
23437 {
23438 code = fixp->fx_r_type;
23439 break;
23440 }
23441
c19d1205
ZW
23442 if (fixp->fx_addsy != NULL
23443 && !S_IS_DEFINED (fixp->fx_addsy)
23444 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 23445 {
c19d1205
ZW
23446 as_bad_where (fixp->fx_file, fixp->fx_line,
23447 _("undefined local label `%s'"),
23448 S_GET_NAME (fixp->fx_addsy));
23449 return NULL;
a737bd4d
NC
23450 }
23451
c19d1205
ZW
23452 as_bad_where (fixp->fx_file, fixp->fx_line,
23453 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
23454 return NULL;
a737bd4d 23455
c19d1205
ZW
23456 default:
23457 {
23458 char * type;
6c43fab6 23459
c19d1205
ZW
23460 switch (fixp->fx_r_type)
23461 {
23462 case BFD_RELOC_NONE: type = "NONE"; break;
23463 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
23464 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 23465 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
23466 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
23467 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
23468 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 23469 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 23470 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
23471 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
23472 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
23473 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
23474 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
23475 default: type = _("<unknown>"); break;
23476 }
23477 as_bad_where (fixp->fx_file, fixp->fx_line,
23478 _("cannot represent %s relocation in this object file format"),
23479 type);
23480 return NULL;
23481 }
a737bd4d 23482 }
6c43fab6 23483
c19d1205
ZW
23484#ifdef OBJ_ELF
23485 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
23486 && GOT_symbol
23487 && fixp->fx_addsy == GOT_symbol)
23488 {
23489 code = BFD_RELOC_ARM_GOTPC;
23490 reloc->addend = fixp->fx_offset = reloc->address;
23491 }
23492#endif
6c43fab6 23493
c19d1205 23494 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 23495
c19d1205
ZW
23496 if (reloc->howto == NULL)
23497 {
23498 as_bad_where (fixp->fx_file, fixp->fx_line,
23499 _("cannot represent %s relocation in this object file format"),
23500 bfd_get_reloc_code_name (code));
23501 return NULL;
23502 }
6c43fab6 23503
c19d1205
ZW
23504 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
23505 vtable entry to be used in the relocation's section offset. */
23506 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
23507 reloc->address = fixp->fx_offset;
6c43fab6 23508
c19d1205 23509 return reloc;
6c43fab6
RE
23510}
23511
c19d1205 23512/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 23513
c19d1205
ZW
23514void
23515cons_fix_new_arm (fragS * frag,
23516 int where,
23517 int size,
62ebcb5c
AM
23518 expressionS * exp,
23519 bfd_reloc_code_real_type reloc)
6c43fab6 23520{
c19d1205 23521 int pcrel = 0;
6c43fab6 23522
c19d1205
ZW
23523 /* Pick a reloc.
23524 FIXME: @@ Should look at CPU word size. */
23525 switch (size)
23526 {
23527 case 1:
62ebcb5c 23528 reloc = BFD_RELOC_8;
c19d1205
ZW
23529 break;
23530 case 2:
62ebcb5c 23531 reloc = BFD_RELOC_16;
c19d1205
ZW
23532 break;
23533 case 4:
23534 default:
62ebcb5c 23535 reloc = BFD_RELOC_32;
c19d1205
ZW
23536 break;
23537 case 8:
62ebcb5c 23538 reloc = BFD_RELOC_64;
c19d1205
ZW
23539 break;
23540 }
6c43fab6 23541
f0927246
NC
23542#ifdef TE_PE
23543 if (exp->X_op == O_secrel)
23544 {
23545 exp->X_op = O_symbol;
62ebcb5c 23546 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
23547 }
23548#endif
23549
62ebcb5c 23550 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 23551}
6c43fab6 23552
4343666d 23553#if defined (OBJ_COFF)
c19d1205
ZW
23554void
23555arm_validate_fix (fixS * fixP)
6c43fab6 23556{
c19d1205
ZW
23557 /* If the destination of the branch is a defined symbol which does not have
23558 the THUMB_FUNC attribute, then we must be calling a function which has
23559 the (interfacearm) attribute. We look for the Thumb entry point to that
23560 function and change the branch to refer to that function instead. */
23561 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
23562 && fixP->fx_addsy != NULL
23563 && S_IS_DEFINED (fixP->fx_addsy)
23564 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 23565 {
c19d1205 23566 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 23567 }
c19d1205
ZW
23568}
23569#endif
6c43fab6 23570
267bf995 23571
c19d1205
ZW
23572int
23573arm_force_relocation (struct fix * fixp)
23574{
23575#if defined (OBJ_COFF) && defined (TE_PE)
23576 if (fixp->fx_r_type == BFD_RELOC_RVA)
23577 return 1;
23578#endif
6c43fab6 23579
267bf995
RR
23580 /* In case we have a call or a branch to a function in ARM ISA mode from
23581 a thumb function or vice-versa force the relocation. These relocations
23582 are cleared off for some cores that might have blx and simple transformations
23583 are possible. */
23584
23585#ifdef OBJ_ELF
23586 switch (fixp->fx_r_type)
23587 {
23588 case BFD_RELOC_ARM_PCREL_JUMP:
23589 case BFD_RELOC_ARM_PCREL_CALL:
23590 case BFD_RELOC_THUMB_PCREL_BLX:
23591 if (THUMB_IS_FUNC (fixp->fx_addsy))
23592 return 1;
23593 break;
23594
23595 case BFD_RELOC_ARM_PCREL_BLX:
23596 case BFD_RELOC_THUMB_PCREL_BRANCH25:
23597 case BFD_RELOC_THUMB_PCREL_BRANCH20:
23598 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23599 if (ARM_IS_FUNC (fixp->fx_addsy))
23600 return 1;
23601 break;
23602
23603 default:
23604 break;
23605 }
23606#endif
23607
b5884301
PB
23608 /* Resolve these relocations even if the symbol is extern or weak.
23609 Technically this is probably wrong due to symbol preemption.
23610 In practice these relocations do not have enough range to be useful
23611 at dynamic link time, and some code (e.g. in the Linux kernel)
23612 expects these references to be resolved. */
c19d1205
ZW
23613 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
23614 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 23615 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 23616 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
23617 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23618 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
23619 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 23620 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
23621 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23622 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
23623 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
23624 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
23625 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
23626 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 23627 return 0;
a737bd4d 23628
4962c51a
MS
23629 /* Always leave these relocations for the linker. */
23630 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
23631 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
23632 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
23633 return 1;
23634
f0291e4c
PB
23635 /* Always generate relocations against function symbols. */
23636 if (fixp->fx_r_type == BFD_RELOC_32
23637 && fixp->fx_addsy
23638 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
23639 return 1;
23640
c19d1205 23641 return generic_force_reloc (fixp);
404ff6b5
AH
23642}
23643
0ffdc86c 23644#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
23645/* Relocations against function names must be left unadjusted,
23646 so that the linker can use this information to generate interworking
23647 stubs. The MIPS version of this function
c19d1205
ZW
23648 also prevents relocations that are mips-16 specific, but I do not
23649 know why it does this.
404ff6b5 23650
c19d1205
ZW
23651 FIXME:
23652 There is one other problem that ought to be addressed here, but
23653 which currently is not: Taking the address of a label (rather
23654 than a function) and then later jumping to that address. Such
23655 addresses also ought to have their bottom bit set (assuming that
23656 they reside in Thumb code), but at the moment they will not. */
404ff6b5 23657
c19d1205
ZW
23658bfd_boolean
23659arm_fix_adjustable (fixS * fixP)
404ff6b5 23660{
c19d1205
ZW
23661 if (fixP->fx_addsy == NULL)
23662 return 1;
404ff6b5 23663
e28387c3
PB
23664 /* Preserve relocations against symbols with function type. */
23665 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 23666 return FALSE;
e28387c3 23667
c19d1205
ZW
23668 if (THUMB_IS_FUNC (fixP->fx_addsy)
23669 && fixP->fx_subsy == NULL)
c921be7d 23670 return FALSE;
a737bd4d 23671
c19d1205
ZW
23672 /* We need the symbol name for the VTABLE entries. */
23673 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
23674 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 23675 return FALSE;
404ff6b5 23676
c19d1205
ZW
23677 /* Don't allow symbols to be discarded on GOT related relocs. */
23678 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
23679 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
23680 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
23681 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
23682 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
23683 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
23684 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
23685 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
23686 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
23687 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
23688 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
23689 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
23690 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 23691 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 23692 return FALSE;
a737bd4d 23693
4962c51a
MS
23694 /* Similarly for group relocations. */
23695 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
23696 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
23697 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 23698 return FALSE;
4962c51a 23699
79947c54
CD
23700 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
23701 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
23702 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23703 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
23704 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
23705 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23706 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
23707 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
23708 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 23709 return FALSE;
79947c54 23710
c921be7d 23711 return TRUE;
a737bd4d 23712}
0ffdc86c
NC
23713#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
23714
23715#ifdef OBJ_ELF
404ff6b5 23716
c19d1205
ZW
23717const char *
23718elf32_arm_target_format (void)
404ff6b5 23719{
c19d1205
ZW
23720#ifdef TE_SYMBIAN
23721 return (target_big_endian
23722 ? "elf32-bigarm-symbian"
23723 : "elf32-littlearm-symbian");
23724#elif defined (TE_VXWORKS)
23725 return (target_big_endian
23726 ? "elf32-bigarm-vxworks"
23727 : "elf32-littlearm-vxworks");
b38cadfb
NC
23728#elif defined (TE_NACL)
23729 return (target_big_endian
23730 ? "elf32-bigarm-nacl"
23731 : "elf32-littlearm-nacl");
c19d1205
ZW
23732#else
23733 if (target_big_endian)
23734 return "elf32-bigarm";
23735 else
23736 return "elf32-littlearm";
23737#endif
404ff6b5
AH
23738}
23739
c19d1205
ZW
23740void
23741armelf_frob_symbol (symbolS * symp,
23742 int * puntp)
404ff6b5 23743{
c19d1205
ZW
23744 elf_frob_symbol (symp, puntp);
23745}
23746#endif
404ff6b5 23747
c19d1205 23748/* MD interface: Finalization. */
a737bd4d 23749
c19d1205
ZW
23750void
23751arm_cleanup (void)
23752{
23753 literal_pool * pool;
a737bd4d 23754
e07e6e58
NC
23755 /* Ensure that all the IT blocks are properly closed. */
23756 check_it_blocks_finished ();
23757
c19d1205
ZW
23758 for (pool = list_of_pools; pool; pool = pool->next)
23759 {
5f4273c7 23760 /* Put it at the end of the relevant section. */
c19d1205
ZW
23761 subseg_set (pool->section, pool->sub_section);
23762#ifdef OBJ_ELF
23763 arm_elf_change_section ();
23764#endif
23765 s_ltorg (0);
23766 }
404ff6b5
AH
23767}
23768
cd000bff
DJ
23769#ifdef OBJ_ELF
23770/* Remove any excess mapping symbols generated for alignment frags in
23771 SEC. We may have created a mapping symbol before a zero byte
23772 alignment; remove it if there's a mapping symbol after the
23773 alignment. */
23774static void
23775check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
23776 void *dummy ATTRIBUTE_UNUSED)
23777{
23778 segment_info_type *seginfo = seg_info (sec);
23779 fragS *fragp;
23780
23781 if (seginfo == NULL || seginfo->frchainP == NULL)
23782 return;
23783
23784 for (fragp = seginfo->frchainP->frch_root;
23785 fragp != NULL;
23786 fragp = fragp->fr_next)
23787 {
23788 symbolS *sym = fragp->tc_frag_data.last_map;
23789 fragS *next = fragp->fr_next;
23790
23791 /* Variable-sized frags have been converted to fixed size by
23792 this point. But if this was variable-sized to start with,
23793 there will be a fixed-size frag after it. So don't handle
23794 next == NULL. */
23795 if (sym == NULL || next == NULL)
23796 continue;
23797
23798 if (S_GET_VALUE (sym) < next->fr_address)
23799 /* Not at the end of this frag. */
23800 continue;
23801 know (S_GET_VALUE (sym) == next->fr_address);
23802
23803 do
23804 {
23805 if (next->tc_frag_data.first_map != NULL)
23806 {
23807 /* Next frag starts with a mapping symbol. Discard this
23808 one. */
23809 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
23810 break;
23811 }
23812
23813 if (next->fr_next == NULL)
23814 {
23815 /* This mapping symbol is at the end of the section. Discard
23816 it. */
23817 know (next->fr_fix == 0 && next->fr_var == 0);
23818 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
23819 break;
23820 }
23821
23822 /* As long as we have empty frags without any mapping symbols,
23823 keep looking. */
23824 /* If the next frag is non-empty and does not start with a
23825 mapping symbol, then this mapping symbol is required. */
23826 if (next->fr_address != next->fr_next->fr_address)
23827 break;
23828
23829 next = next->fr_next;
23830 }
23831 while (next != NULL);
23832 }
23833}
23834#endif
23835
c19d1205
ZW
23836/* Adjust the symbol table. This marks Thumb symbols as distinct from
23837 ARM ones. */
404ff6b5 23838
c19d1205
ZW
23839void
23840arm_adjust_symtab (void)
404ff6b5 23841{
c19d1205
ZW
23842#ifdef OBJ_COFF
23843 symbolS * sym;
404ff6b5 23844
c19d1205
ZW
23845 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
23846 {
23847 if (ARM_IS_THUMB (sym))
23848 {
23849 if (THUMB_IS_FUNC (sym))
23850 {
23851 /* Mark the symbol as a Thumb function. */
23852 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
23853 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
23854 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 23855
c19d1205
ZW
23856 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
23857 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
23858 else
23859 as_bad (_("%s: unexpected function type: %d"),
23860 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
23861 }
23862 else switch (S_GET_STORAGE_CLASS (sym))
23863 {
23864 case C_EXT:
23865 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
23866 break;
23867 case C_STAT:
23868 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
23869 break;
23870 case C_LABEL:
23871 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
23872 break;
23873 default:
23874 /* Do nothing. */
23875 break;
23876 }
23877 }
a737bd4d 23878
c19d1205
ZW
23879 if (ARM_IS_INTERWORK (sym))
23880 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 23881 }
c19d1205
ZW
23882#endif
23883#ifdef OBJ_ELF
23884 symbolS * sym;
23885 char bind;
404ff6b5 23886
c19d1205 23887 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 23888 {
c19d1205
ZW
23889 if (ARM_IS_THUMB (sym))
23890 {
23891 elf_symbol_type * elf_sym;
404ff6b5 23892
c19d1205
ZW
23893 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
23894 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 23895
b0796911
PB
23896 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
23897 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
23898 {
23899 /* If it's a .thumb_func, declare it as so,
23900 otherwise tag label as .code 16. */
23901 if (THUMB_IS_FUNC (sym))
35fc36a8
RS
23902 elf_sym->internal_elf_sym.st_target_internal
23903 = ST_BRANCH_TO_THUMB;
3ba67470 23904 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
23905 elf_sym->internal_elf_sym.st_info =
23906 ELF_ST_INFO (bind, STT_ARM_16BIT);
23907 }
23908 }
23909 }
cd000bff
DJ
23910
23911 /* Remove any overlapping mapping symbols generated by alignment frags. */
23912 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
23913 /* Now do generic ELF adjustments. */
23914 elf_adjust_symtab ();
c19d1205 23915#endif
404ff6b5
AH
23916}
23917
c19d1205 23918/* MD interface: Initialization. */
404ff6b5 23919
a737bd4d 23920static void
c19d1205 23921set_constant_flonums (void)
a737bd4d 23922{
c19d1205 23923 int i;
404ff6b5 23924
c19d1205
ZW
23925 for (i = 0; i < NUM_FLOAT_VALS; i++)
23926 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
23927 abort ();
a737bd4d 23928}
404ff6b5 23929
3e9e4fcf
JB
23930/* Auto-select Thumb mode if it's the only available instruction set for the
23931 given architecture. */
23932
23933static void
23934autoselect_thumb_from_cpu_variant (void)
23935{
23936 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
23937 opcode_select (16);
23938}
23939
c19d1205
ZW
23940void
23941md_begin (void)
a737bd4d 23942{
c19d1205
ZW
23943 unsigned mach;
23944 unsigned int i;
404ff6b5 23945
c19d1205
ZW
23946 if ( (arm_ops_hsh = hash_new ()) == NULL
23947 || (arm_cond_hsh = hash_new ()) == NULL
23948 || (arm_shift_hsh = hash_new ()) == NULL
23949 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 23950 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 23951 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
23952 || (arm_reloc_hsh = hash_new ()) == NULL
23953 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
23954 as_fatal (_("virtual memory exhausted"));
23955
23956 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 23957 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 23958 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 23959 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 23960 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 23961 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 23962 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 23963 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 23964 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 23965 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 23966 (void *) (v7m_psrs + i));
c19d1205 23967 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 23968 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
23969 for (i = 0;
23970 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
23971 i++)
d3ce72d0 23972 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 23973 (void *) (barrier_opt_names + i));
c19d1205 23974#ifdef OBJ_ELF
3da1d841
NC
23975 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
23976 {
23977 struct reloc_entry * entry = reloc_names + i;
23978
23979 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
23980 /* This makes encode_branch() use the EABI versions of this relocation. */
23981 entry->reloc = BFD_RELOC_UNUSED;
23982
23983 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
23984 }
c19d1205
ZW
23985#endif
23986
23987 set_constant_flonums ();
404ff6b5 23988
c19d1205
ZW
23989 /* Set the cpu variant based on the command-line options. We prefer
23990 -mcpu= over -march= if both are set (as for GCC); and we prefer
23991 -mfpu= over any other way of setting the floating point unit.
23992 Use of legacy options with new options are faulted. */
e74cfd16 23993 if (legacy_cpu)
404ff6b5 23994 {
e74cfd16 23995 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
23996 as_bad (_("use of old and new-style options to set CPU type"));
23997
23998 mcpu_cpu_opt = legacy_cpu;
404ff6b5 23999 }
e74cfd16 24000 else if (!mcpu_cpu_opt)
c19d1205 24001 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 24002
e74cfd16 24003 if (legacy_fpu)
c19d1205 24004 {
e74cfd16 24005 if (mfpu_opt)
c19d1205 24006 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
24007
24008 mfpu_opt = legacy_fpu;
24009 }
e74cfd16 24010 else if (!mfpu_opt)
03b1477f 24011 {
45eb4c1b
NS
24012#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
24013 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
24014 /* Some environments specify a default FPU. If they don't, infer it
24015 from the processor. */
e74cfd16 24016 if (mcpu_fpu_opt)
03b1477f
RE
24017 mfpu_opt = mcpu_fpu_opt;
24018 else
24019 mfpu_opt = march_fpu_opt;
39c2da32 24020#else
e74cfd16 24021 mfpu_opt = &fpu_default;
39c2da32 24022#endif
03b1477f
RE
24023 }
24024
e74cfd16 24025 if (!mfpu_opt)
03b1477f 24026 {
493cb6ef 24027 if (mcpu_cpu_opt != NULL)
e74cfd16 24028 mfpu_opt = &fpu_default;
493cb6ef 24029 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 24030 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 24031 else
e74cfd16 24032 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
24033 }
24034
ee065d83 24035#ifdef CPU_DEFAULT
e74cfd16 24036 if (!mcpu_cpu_opt)
ee065d83 24037 {
e74cfd16
PB
24038 mcpu_cpu_opt = &cpu_default;
24039 selected_cpu = cpu_default;
ee065d83 24040 }
73f43896
NC
24041 else if (no_cpu_selected ())
24042 selected_cpu = cpu_default;
e74cfd16
PB
24043#else
24044 if (mcpu_cpu_opt)
24045 selected_cpu = *mcpu_cpu_opt;
ee065d83 24046 else
e74cfd16 24047 mcpu_cpu_opt = &arm_arch_any;
ee065d83 24048#endif
03b1477f 24049
e74cfd16 24050 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 24051
3e9e4fcf
JB
24052 autoselect_thumb_from_cpu_variant ();
24053
e74cfd16 24054 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 24055
f17c130b 24056#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 24057 {
7cc69913
NC
24058 unsigned int flags = 0;
24059
24060#if defined OBJ_ELF
24061 flags = meabi_flags;
d507cf36
PB
24062
24063 switch (meabi_flags)
33a392fb 24064 {
d507cf36 24065 case EF_ARM_EABI_UNKNOWN:
7cc69913 24066#endif
d507cf36
PB
24067 /* Set the flags in the private structure. */
24068 if (uses_apcs_26) flags |= F_APCS26;
24069 if (support_interwork) flags |= F_INTERWORK;
24070 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 24071 if (pic_code) flags |= F_PIC;
e74cfd16 24072 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
24073 flags |= F_SOFT_FLOAT;
24074
d507cf36
PB
24075 switch (mfloat_abi_opt)
24076 {
24077 case ARM_FLOAT_ABI_SOFT:
24078 case ARM_FLOAT_ABI_SOFTFP:
24079 flags |= F_SOFT_FLOAT;
24080 break;
33a392fb 24081
d507cf36
PB
24082 case ARM_FLOAT_ABI_HARD:
24083 if (flags & F_SOFT_FLOAT)
24084 as_bad (_("hard-float conflicts with specified fpu"));
24085 break;
24086 }
03b1477f 24087
e74cfd16
PB
24088 /* Using pure-endian doubles (even if soft-float). */
24089 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 24090 flags |= F_VFP_FLOAT;
f17c130b 24091
fde78edd 24092#if defined OBJ_ELF
e74cfd16 24093 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 24094 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
24095 break;
24096
8cb51566 24097 case EF_ARM_EABI_VER4:
3a4a14e9 24098 case EF_ARM_EABI_VER5:
c19d1205 24099 /* No additional flags to set. */
d507cf36
PB
24100 break;
24101
24102 default:
24103 abort ();
24104 }
7cc69913 24105#endif
b99bd4ef
NC
24106 bfd_set_private_flags (stdoutput, flags);
24107
24108 /* We have run out flags in the COFF header to encode the
24109 status of ATPCS support, so instead we create a dummy,
c19d1205 24110 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
24111 if (atpcs)
24112 {
24113 asection * sec;
24114
24115 sec = bfd_make_section (stdoutput, ".arm.atpcs");
24116
24117 if (sec != NULL)
24118 {
24119 bfd_set_section_flags
24120 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
24121 bfd_set_section_size (stdoutput, sec, 0);
24122 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
24123 }
24124 }
7cc69913 24125 }
f17c130b 24126#endif
b99bd4ef
NC
24127
24128 /* Record the CPU type as well. */
2d447fca
JM
24129 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
24130 mach = bfd_mach_arm_iWMMXt2;
24131 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 24132 mach = bfd_mach_arm_iWMMXt;
e74cfd16 24133 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 24134 mach = bfd_mach_arm_XScale;
e74cfd16 24135 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 24136 mach = bfd_mach_arm_ep9312;
e74cfd16 24137 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 24138 mach = bfd_mach_arm_5TE;
e74cfd16 24139 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 24140 {
e74cfd16 24141 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
24142 mach = bfd_mach_arm_5T;
24143 else
24144 mach = bfd_mach_arm_5;
24145 }
e74cfd16 24146 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 24147 {
e74cfd16 24148 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
24149 mach = bfd_mach_arm_4T;
24150 else
24151 mach = bfd_mach_arm_4;
24152 }
e74cfd16 24153 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 24154 mach = bfd_mach_arm_3M;
e74cfd16
PB
24155 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
24156 mach = bfd_mach_arm_3;
24157 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
24158 mach = bfd_mach_arm_2a;
24159 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
24160 mach = bfd_mach_arm_2;
24161 else
24162 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
24163
24164 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
24165}
24166
c19d1205 24167/* Command line processing. */
b99bd4ef 24168
c19d1205
ZW
24169/* md_parse_option
24170 Invocation line includes a switch not recognized by the base assembler.
24171 See if it's a processor-specific option.
b99bd4ef 24172
c19d1205
ZW
24173 This routine is somewhat complicated by the need for backwards
24174 compatibility (since older releases of gcc can't be changed).
24175 The new options try to make the interface as compatible as
24176 possible with GCC.
b99bd4ef 24177
c19d1205 24178 New options (supported) are:
b99bd4ef 24179
c19d1205
ZW
24180 -mcpu=<cpu name> Assemble for selected processor
24181 -march=<architecture name> Assemble for selected architecture
24182 -mfpu=<fpu architecture> Assemble for selected FPU.
24183 -EB/-mbig-endian Big-endian
24184 -EL/-mlittle-endian Little-endian
24185 -k Generate PIC code
24186 -mthumb Start in Thumb mode
24187 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 24188
278df34e 24189 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 24190 -m[no-]warn-syms Warn when symbols match instructions
267bf995 24191
c19d1205 24192 For now we will also provide support for:
b99bd4ef 24193
c19d1205
ZW
24194 -mapcs-32 32-bit Program counter
24195 -mapcs-26 26-bit Program counter
24196 -macps-float Floats passed in FP registers
24197 -mapcs-reentrant Reentrant code
24198 -matpcs
24199 (sometime these will probably be replaced with -mapcs=<list of options>
24200 and -matpcs=<list of options>)
b99bd4ef 24201
c19d1205
ZW
24202 The remaining options are only supported for back-wards compatibility.
24203 Cpu variants, the arm part is optional:
24204 -m[arm]1 Currently not supported.
24205 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
24206 -m[arm]3 Arm 3 processor
24207 -m[arm]6[xx], Arm 6 processors
24208 -m[arm]7[xx][t][[d]m] Arm 7 processors
24209 -m[arm]8[10] Arm 8 processors
24210 -m[arm]9[20][tdmi] Arm 9 processors
24211 -mstrongarm[110[0]] StrongARM processors
24212 -mxscale XScale processors
24213 -m[arm]v[2345[t[e]]] Arm architectures
24214 -mall All (except the ARM1)
24215 FP variants:
24216 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
24217 -mfpe-old (No float load/store multiples)
24218 -mvfpxd VFP Single precision
24219 -mvfp All VFP
24220 -mno-fpu Disable all floating point instructions
b99bd4ef 24221
c19d1205
ZW
24222 The following CPU names are recognized:
24223 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
24224 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
24225 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
24226 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
24227 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
24228 arm10t arm10e, arm1020t, arm1020e, arm10200e,
24229 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 24230
c19d1205 24231 */
b99bd4ef 24232
c19d1205 24233const char * md_shortopts = "m:k";
b99bd4ef 24234
c19d1205
ZW
24235#ifdef ARM_BI_ENDIAN
24236#define OPTION_EB (OPTION_MD_BASE + 0)
24237#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 24238#else
c19d1205
ZW
24239#if TARGET_BYTES_BIG_ENDIAN
24240#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 24241#else
c19d1205
ZW
24242#define OPTION_EL (OPTION_MD_BASE + 1)
24243#endif
b99bd4ef 24244#endif
845b51d6 24245#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 24246
c19d1205 24247struct option md_longopts[] =
b99bd4ef 24248{
c19d1205
ZW
24249#ifdef OPTION_EB
24250 {"EB", no_argument, NULL, OPTION_EB},
24251#endif
24252#ifdef OPTION_EL
24253 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 24254#endif
845b51d6 24255 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
24256 {NULL, no_argument, NULL, 0}
24257};
b99bd4ef 24258
8b2d793c 24259
c19d1205 24260size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 24261
c19d1205 24262struct arm_option_table
b99bd4ef 24263{
c19d1205
ZW
24264 char *option; /* Option name to match. */
24265 char *help; /* Help information. */
24266 int *var; /* Variable to change. */
24267 int value; /* What to change it to. */
24268 char *deprecated; /* If non-null, print this message. */
24269};
b99bd4ef 24270
c19d1205
ZW
24271struct arm_option_table arm_opts[] =
24272{
24273 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
24274 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
24275 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
24276 &support_interwork, 1, NULL},
24277 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
24278 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
24279 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
24280 1, NULL},
24281 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
24282 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
24283 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
24284 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
24285 NULL},
b99bd4ef 24286
c19d1205
ZW
24287 /* These are recognized by the assembler, but have no affect on code. */
24288 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
24289 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
24290
24291 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
24292 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
24293 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
24294 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
24295 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
24296 {NULL, NULL, NULL, 0, NULL}
24297};
24298
24299struct arm_legacy_option_table
24300{
24301 char *option; /* Option name to match. */
24302 const arm_feature_set **var; /* Variable to change. */
24303 const arm_feature_set value; /* What to change it to. */
24304 char *deprecated; /* If non-null, print this message. */
24305};
b99bd4ef 24306
e74cfd16
PB
24307const struct arm_legacy_option_table arm_legacy_opts[] =
24308{
c19d1205
ZW
24309 /* DON'T add any new processors to this list -- we want the whole list
24310 to go away... Add them to the processors table instead. */
e74cfd16
PB
24311 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
24312 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
24313 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
24314 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
24315 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
24316 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
24317 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
24318 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
24319 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
24320 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
24321 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
24322 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
24323 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
24324 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
24325 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
24326 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
24327 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
24328 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
24329 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
24330 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
24331 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
24332 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
24333 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
24334 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
24335 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
24336 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
24337 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
24338 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
24339 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
24340 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
24341 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
24342 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
24343 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
24344 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
24345 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
24346 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
24347 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
24348 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
24349 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
24350 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
24351 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
24352 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
24353 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
24354 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
24355 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
24356 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
24357 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
24358 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
24359 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
24360 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
24361 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
24362 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
24363 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
24364 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
24365 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
24366 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
24367 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
24368 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
24369 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
24370 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
24371 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
24372 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
24373 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
24374 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
24375 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
24376 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
24377 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
24378 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
24379 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
24380 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 24381 N_("use -mcpu=strongarm110")},
e74cfd16 24382 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 24383 N_("use -mcpu=strongarm1100")},
e74cfd16 24384 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 24385 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
24386 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
24387 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
24388 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 24389
c19d1205 24390 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
24391 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
24392 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
24393 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
24394 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
24395 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
24396 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
24397 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
24398 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
24399 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
24400 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
24401 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
24402 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
24403 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
24404 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
24405 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
24406 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
24407 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
24408 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 24409
c19d1205 24410 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
24411 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
24412 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
24413 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
24414 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 24415 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 24416
e74cfd16 24417 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 24418};
7ed4c4c5 24419
c19d1205 24420struct arm_cpu_option_table
7ed4c4c5 24421{
c19d1205 24422 char *name;
f3bad469 24423 size_t name_len;
e74cfd16 24424 const arm_feature_set value;
c19d1205
ZW
24425 /* For some CPUs we assume an FPU unless the user explicitly sets
24426 -mfpu=... */
e74cfd16 24427 const arm_feature_set default_fpu;
ee065d83
PB
24428 /* The canonical name of the CPU, or NULL to use NAME converted to upper
24429 case. */
24430 const char *canonical_name;
c19d1205 24431};
7ed4c4c5 24432
c19d1205
ZW
24433/* This list should, at a minimum, contain all the cpu names
24434 recognized by GCC. */
f3bad469 24435#define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
e74cfd16 24436static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 24437{
f3bad469
MGD
24438 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
24439 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
24440 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
24441 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
24442 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
24443 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24444 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24445 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24446 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24447 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24448 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24449 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
24450 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24451 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
24452 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24453 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
24454 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24455 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24456 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24457 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24458 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24459 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24460 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24461 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24462 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24463 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24464 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24465 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24466 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24467 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24468 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24469 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24470 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24471 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24472 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24473 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24474 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24475 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24476 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24477 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
24478 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24479 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24480 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24481 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24482 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24483 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
c19d1205
ZW
24484 /* For V5 or later processors we default to using VFP; but the user
24485 should really set the FPU type explicitly. */
f3bad469
MGD
24486 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
24487 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24488 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
24489 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
24490 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
24491 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
24492 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
24493 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24494 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
24495 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
24496 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24497 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24498 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
24499 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
24500 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24501 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
24502 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
24503 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24504 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24505 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
24506 "ARM1026EJ-S"),
24507 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
24508 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24509 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24510 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24511 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24512 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24513 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
24514 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
24515 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
24516 "ARM1136JF-S"),
24517 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
24518 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
24519 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
24520 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
24521 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
24522 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL),
24523 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL),
24524 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
24525 FPU_NONE, "Cortex-A5"),
c9fb6e58 24526 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469
MGD
24527 "Cortex-A7"),
24528 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
823d2571 24529 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 24530 | FPU_NEON_EXT_V1),
f3bad469
MGD
24531 "Cortex-A8"),
24532 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
823d2571 24533 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 24534 | FPU_NEON_EXT_V1),
f3bad469 24535 "Cortex-A9"),
c9fb6e58 24536 ARM_CPU_OPT ("cortex-a12", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
63a4bc21 24537 "Cortex-A12"),
c9fb6e58 24538 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469 24539 "Cortex-A15"),
d7adf960
KT
24540 ARM_CPU_OPT ("cortex-a17", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
24541 "Cortex-A17"),
92eb40d9 24542 ARM_CPU_OPT ("cortex-a53", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 24543 "Cortex-A53"),
92eb40d9 24544 ARM_CPU_OPT ("cortex-a57", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 24545 "Cortex-A57"),
b19f47ad
JW
24546 ARM_CPU_OPT ("cortex-a72", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24547 "Cortex-A72"),
f3bad469
MGD
24548 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
24549 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
24550 "Cortex-R4F"),
24551 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
24552 FPU_NONE, "Cortex-R5"),
70a8bc5b 24553 ARM_CPU_OPT ("cortex-r7", ARM_ARCH_V7R_IDIV,
24554 FPU_ARCH_VFP_V3D16,
24555 "Cortex-R7"),
a715796b 24556 ARM_CPU_OPT ("cortex-m7", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M7"),
f3bad469
MGD
24557 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
24558 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
24559 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
24560 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
ce32bd10 24561 ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"),
246496bb
EM
24562 ARM_CPU_OPT ("exynos-m1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24563 "Samsung " \
24564 "Exynos M1"),
c19d1205 24565 /* ??? XSCALE is really an architecture. */
f3bad469 24566 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 24567 /* ??? iwmmxt is not a processor. */
f3bad469
MGD
24568 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
24569 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
24570 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 24571 /* Maverick */
823d2571 24572 ARM_CPU_OPT ("ep9312", ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
da4339ed
NC
24573 FPU_ARCH_MAVERICK, "ARM920T"),
24574 /* Marvell processors. */
823d2571
TG
24575 ARM_CPU_OPT ("marvell-pj4", ARM_FEATURE_CORE_LOW (ARM_AEXT_V7A | ARM_EXT_MP
24576 | ARM_EXT_SEC),
477330fc 24577 FPU_ARCH_VFP_V3D16, NULL),
823d2571
TG
24578 ARM_CPU_OPT ("marvell-whitney", ARM_FEATURE_CORE_LOW (ARM_AEXT_V7A | ARM_EXT_MP
24579 | ARM_EXT_SEC),
4347085a 24580 FPU_ARCH_NEON_VFP_V4, NULL),
ea0d6bb9
PT
24581 /* APM X-Gene family. */
24582 ARM_CPU_OPT ("xgene1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24583 "APM X-Gene 1"),
24584 ARM_CPU_OPT ("xgene2", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24585 "APM X-Gene 2"),
da4339ed 24586
f3bad469 24587 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 24588};
f3bad469 24589#undef ARM_CPU_OPT
7ed4c4c5 24590
c19d1205 24591struct arm_arch_option_table
7ed4c4c5 24592{
c19d1205 24593 char *name;
f3bad469 24594 size_t name_len;
e74cfd16
PB
24595 const arm_feature_set value;
24596 const arm_feature_set default_fpu;
c19d1205 24597};
7ed4c4c5 24598
c19d1205
ZW
24599/* This list should, at a minimum, contain all the architecture names
24600 recognized by GCC. */
f3bad469 24601#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
e74cfd16 24602static const struct arm_arch_option_table arm_archs[] =
c19d1205 24603{
f3bad469
MGD
24604 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
24605 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
24606 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
24607 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
24608 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
24609 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
24610 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
24611 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
24612 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
24613 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
24614 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
24615 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
24616 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
24617 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
24618 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
24619 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
24620 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
24621 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
24622 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
24623 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
24624 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
24625 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP),
24626 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
24627 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
24628 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
24629 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP),
24630 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
24631 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
24632 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
24633 /* The official spelling of the ARMv7 profile variants is the dashed form.
24634 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 24635 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 24636 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
24637 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
24638 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
24639 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
24640 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
24641 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
24642 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
bca38921 24643 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
f3bad469
MGD
24644 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
24645 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
24646 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
24647 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 24648};
f3bad469 24649#undef ARM_ARCH_OPT
7ed4c4c5 24650
69133863
MGD
24651/* ISA extensions in the co-processor and main instruction set space. */
24652struct arm_option_extension_value_table
c19d1205
ZW
24653{
24654 char *name;
f3bad469 24655 size_t name_len;
5a70a223
JB
24656 const arm_feature_set merge_value;
24657 const arm_feature_set clear_value;
69133863 24658 const arm_feature_set allowed_archs;
c19d1205 24659};
7ed4c4c5 24660
69133863
MGD
24661/* The following table must be in alphabetical order with a NULL last entry.
24662 */
5a70a223 24663#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, AA }
69133863 24664static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 24665{
823d2571
TG
24666 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
24667 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 24668 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
24669 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
24670 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
24671 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
24672 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
24673 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
24674 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
24675 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A | ARM_EXT_V7R)),
24676 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
24677 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ANY),
24678 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
24679 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ANY),
24680 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
24681 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ANY),
24682 ARM_EXT_OPT ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
24683 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
24684 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A | ARM_EXT_V7R)),
bca38921 24685 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
823d2571
TG
24686 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
24687 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
24688 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
24689 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
24690 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
24691 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
24692 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
24693 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
24694 ARM_EXT_OPT ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
24695 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
24696 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V7A)),
24697 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
24698 | ARM_EXT_DIV),
24699 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
24700 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
24701 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
24702 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ANY),
5a70a223 24703 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE }
69133863 24704};
f3bad469 24705#undef ARM_EXT_OPT
69133863
MGD
24706
24707/* ISA floating-point and Advanced SIMD extensions. */
24708struct arm_option_fpu_value_table
24709{
24710 char *name;
24711 const arm_feature_set value;
c19d1205 24712};
7ed4c4c5 24713
c19d1205
ZW
24714/* This list should, at a minimum, contain all the fpu names
24715 recognized by GCC. */
69133863 24716static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
24717{
24718 {"softfpa", FPU_NONE},
24719 {"fpe", FPU_ARCH_FPE},
24720 {"fpe2", FPU_ARCH_FPE},
24721 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
24722 {"fpa", FPU_ARCH_FPA},
24723 {"fpa10", FPU_ARCH_FPA},
24724 {"fpa11", FPU_ARCH_FPA},
24725 {"arm7500fe", FPU_ARCH_FPA},
24726 {"softvfp", FPU_ARCH_VFP},
24727 {"softvfp+vfp", FPU_ARCH_VFP_V2},
24728 {"vfp", FPU_ARCH_VFP_V2},
24729 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 24730 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
24731 {"vfp10", FPU_ARCH_VFP_V2},
24732 {"vfp10-r0", FPU_ARCH_VFP_V1},
24733 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
24734 {"vfpv2", FPU_ARCH_VFP_V2},
24735 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 24736 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 24737 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
24738 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
24739 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
24740 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
24741 {"arm1020t", FPU_ARCH_VFP_V1},
24742 {"arm1020e", FPU_ARCH_VFP_V2},
24743 {"arm1136jfs", FPU_ARCH_VFP_V2},
24744 {"arm1136jf-s", FPU_ARCH_VFP_V2},
24745 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 24746 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 24747 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
24748 {"vfpv4", FPU_ARCH_VFP_V4},
24749 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 24750 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
24751 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
24752 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 24753 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
24754 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
24755 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
24756 {"crypto-neon-fp-armv8",
24757 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
e74cfd16
PB
24758 {NULL, ARM_ARCH_NONE}
24759};
24760
24761struct arm_option_value_table
24762{
24763 char *name;
24764 long value;
c19d1205 24765};
7ed4c4c5 24766
e74cfd16 24767static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
24768{
24769 {"hard", ARM_FLOAT_ABI_HARD},
24770 {"softfp", ARM_FLOAT_ABI_SOFTFP},
24771 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 24772 {NULL, 0}
c19d1205 24773};
7ed4c4c5 24774
c19d1205 24775#ifdef OBJ_ELF
3a4a14e9 24776/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 24777static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
24778{
24779 {"gnu", EF_ARM_EABI_UNKNOWN},
24780 {"4", EF_ARM_EABI_VER4},
3a4a14e9 24781 {"5", EF_ARM_EABI_VER5},
e74cfd16 24782 {NULL, 0}
c19d1205
ZW
24783};
24784#endif
7ed4c4c5 24785
c19d1205
ZW
24786struct arm_long_option_table
24787{
24788 char * option; /* Substring to match. */
24789 char * help; /* Help information. */
24790 int (* func) (char * subopt); /* Function to decode sub-option. */
24791 char * deprecated; /* If non-null, print this message. */
24792};
7ed4c4c5 24793
c921be7d 24794static bfd_boolean
f3bad469 24795arm_parse_extension (char *str, const arm_feature_set **opt_p)
7ed4c4c5 24796{
21d799b5
NC
24797 arm_feature_set *ext_set = (arm_feature_set *)
24798 xmalloc (sizeof (arm_feature_set));
e74cfd16 24799
69133863 24800 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
24801 extensions being added before being removed. We achieve this by having
24802 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 24803 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 24804 or removing it (0) and only allowing it to change in the order
69133863
MGD
24805 -1 -> 1 -> 0. */
24806 const struct arm_option_extension_value_table * opt = NULL;
24807 int adding_value = -1;
24808
e74cfd16
PB
24809 /* Copy the feature set, so that we can modify it. */
24810 *ext_set = **opt_p;
24811 *opt_p = ext_set;
24812
c19d1205 24813 while (str != NULL && *str != 0)
7ed4c4c5 24814 {
f3bad469
MGD
24815 char *ext;
24816 size_t len;
7ed4c4c5 24817
c19d1205
ZW
24818 if (*str != '+')
24819 {
24820 as_bad (_("invalid architectural extension"));
c921be7d 24821 return FALSE;
c19d1205 24822 }
7ed4c4c5 24823
c19d1205
ZW
24824 str++;
24825 ext = strchr (str, '+');
7ed4c4c5 24826
c19d1205 24827 if (ext != NULL)
f3bad469 24828 len = ext - str;
c19d1205 24829 else
f3bad469 24830 len = strlen (str);
7ed4c4c5 24831
f3bad469 24832 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
24833 {
24834 if (adding_value != 0)
24835 {
24836 adding_value = 0;
24837 opt = arm_extensions;
24838 }
24839
f3bad469 24840 len -= 2;
69133863
MGD
24841 str += 2;
24842 }
f3bad469 24843 else if (len > 0)
69133863
MGD
24844 {
24845 if (adding_value == -1)
24846 {
24847 adding_value = 1;
24848 opt = arm_extensions;
24849 }
24850 else if (adding_value != 1)
24851 {
24852 as_bad (_("must specify extensions to add before specifying "
24853 "those to remove"));
24854 return FALSE;
24855 }
24856 }
24857
f3bad469 24858 if (len == 0)
c19d1205
ZW
24859 {
24860 as_bad (_("missing architectural extension"));
c921be7d 24861 return FALSE;
c19d1205 24862 }
7ed4c4c5 24863
69133863
MGD
24864 gas_assert (adding_value != -1);
24865 gas_assert (opt != NULL);
24866
24867 /* Scan over the options table trying to find an exact match. */
24868 for (; opt->name != NULL; opt++)
f3bad469 24869 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 24870 {
69133863
MGD
24871 /* Check we can apply the extension to this architecture. */
24872 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
24873 {
24874 as_bad (_("extension does not apply to the base architecture"));
24875 return FALSE;
24876 }
24877
24878 /* Add or remove the extension. */
24879 if (adding_value)
5a70a223 24880 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 24881 else
5a70a223 24882 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 24883
c19d1205
ZW
24884 break;
24885 }
7ed4c4c5 24886
c19d1205
ZW
24887 if (opt->name == NULL)
24888 {
69133863
MGD
24889 /* Did we fail to find an extension because it wasn't specified in
24890 alphabetical order, or because it does not exist? */
24891
24892 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 24893 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
24894 break;
24895
24896 if (opt->name == NULL)
24897 as_bad (_("unknown architectural extension `%s'"), str);
24898 else
24899 as_bad (_("architectural extensions must be specified in "
24900 "alphabetical order"));
24901
c921be7d 24902 return FALSE;
c19d1205 24903 }
69133863
MGD
24904 else
24905 {
24906 /* We should skip the extension we've just matched the next time
24907 round. */
24908 opt++;
24909 }
7ed4c4c5 24910
c19d1205
ZW
24911 str = ext;
24912 };
7ed4c4c5 24913
c921be7d 24914 return TRUE;
c19d1205 24915}
7ed4c4c5 24916
c921be7d 24917static bfd_boolean
f3bad469 24918arm_parse_cpu (char *str)
7ed4c4c5 24919{
f3bad469
MGD
24920 const struct arm_cpu_option_table *opt;
24921 char *ext = strchr (str, '+');
24922 size_t len;
7ed4c4c5 24923
c19d1205 24924 if (ext != NULL)
f3bad469 24925 len = ext - str;
7ed4c4c5 24926 else
f3bad469 24927 len = strlen (str);
7ed4c4c5 24928
f3bad469 24929 if (len == 0)
7ed4c4c5 24930 {
c19d1205 24931 as_bad (_("missing cpu name `%s'"), str);
c921be7d 24932 return FALSE;
7ed4c4c5
NC
24933 }
24934
c19d1205 24935 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 24936 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 24937 {
e74cfd16
PB
24938 mcpu_cpu_opt = &opt->value;
24939 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 24940 if (opt->canonical_name)
5f4273c7 24941 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
24942 else
24943 {
f3bad469 24944 size_t i;
c921be7d 24945
f3bad469 24946 for (i = 0; i < len; i++)
ee065d83
PB
24947 selected_cpu_name[i] = TOUPPER (opt->name[i]);
24948 selected_cpu_name[i] = 0;
24949 }
7ed4c4c5 24950
c19d1205
ZW
24951 if (ext != NULL)
24952 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 24953
c921be7d 24954 return TRUE;
c19d1205 24955 }
7ed4c4c5 24956
c19d1205 24957 as_bad (_("unknown cpu `%s'"), str);
c921be7d 24958 return FALSE;
7ed4c4c5
NC
24959}
24960
c921be7d 24961static bfd_boolean
f3bad469 24962arm_parse_arch (char *str)
7ed4c4c5 24963{
e74cfd16 24964 const struct arm_arch_option_table *opt;
c19d1205 24965 char *ext = strchr (str, '+');
f3bad469 24966 size_t len;
7ed4c4c5 24967
c19d1205 24968 if (ext != NULL)
f3bad469 24969 len = ext - str;
7ed4c4c5 24970 else
f3bad469 24971 len = strlen (str);
7ed4c4c5 24972
f3bad469 24973 if (len == 0)
7ed4c4c5 24974 {
c19d1205 24975 as_bad (_("missing architecture name `%s'"), str);
c921be7d 24976 return FALSE;
7ed4c4c5
NC
24977 }
24978
c19d1205 24979 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 24980 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 24981 {
e74cfd16
PB
24982 march_cpu_opt = &opt->value;
24983 march_fpu_opt = &opt->default_fpu;
5f4273c7 24984 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 24985
c19d1205
ZW
24986 if (ext != NULL)
24987 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 24988
c921be7d 24989 return TRUE;
c19d1205
ZW
24990 }
24991
24992 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 24993 return FALSE;
7ed4c4c5 24994}
eb043451 24995
c921be7d 24996static bfd_boolean
c19d1205
ZW
24997arm_parse_fpu (char * str)
24998{
69133863 24999 const struct arm_option_fpu_value_table * opt;
b99bd4ef 25000
c19d1205
ZW
25001 for (opt = arm_fpus; opt->name != NULL; opt++)
25002 if (streq (opt->name, str))
25003 {
e74cfd16 25004 mfpu_opt = &opt->value;
c921be7d 25005 return TRUE;
c19d1205 25006 }
b99bd4ef 25007
c19d1205 25008 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 25009 return FALSE;
c19d1205
ZW
25010}
25011
c921be7d 25012static bfd_boolean
c19d1205 25013arm_parse_float_abi (char * str)
b99bd4ef 25014{
e74cfd16 25015 const struct arm_option_value_table * opt;
b99bd4ef 25016
c19d1205
ZW
25017 for (opt = arm_float_abis; opt->name != NULL; opt++)
25018 if (streq (opt->name, str))
25019 {
25020 mfloat_abi_opt = opt->value;
c921be7d 25021 return TRUE;
c19d1205 25022 }
cc8a6dd0 25023
c19d1205 25024 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 25025 return FALSE;
c19d1205 25026}
b99bd4ef 25027
c19d1205 25028#ifdef OBJ_ELF
c921be7d 25029static bfd_boolean
c19d1205
ZW
25030arm_parse_eabi (char * str)
25031{
e74cfd16 25032 const struct arm_option_value_table *opt;
cc8a6dd0 25033
c19d1205
ZW
25034 for (opt = arm_eabis; opt->name != NULL; opt++)
25035 if (streq (opt->name, str))
25036 {
25037 meabi_flags = opt->value;
c921be7d 25038 return TRUE;
c19d1205
ZW
25039 }
25040 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 25041 return FALSE;
c19d1205
ZW
25042}
25043#endif
cc8a6dd0 25044
c921be7d 25045static bfd_boolean
e07e6e58
NC
25046arm_parse_it_mode (char * str)
25047{
c921be7d 25048 bfd_boolean ret = TRUE;
e07e6e58
NC
25049
25050 if (streq ("arm", str))
25051 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
25052 else if (streq ("thumb", str))
25053 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
25054 else if (streq ("always", str))
25055 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
25056 else if (streq ("never", str))
25057 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
25058 else
25059 {
25060 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 25061 "arm, thumb, always, or never."), str);
c921be7d 25062 ret = FALSE;
e07e6e58
NC
25063 }
25064
25065 return ret;
25066}
25067
2e6976a8
DG
25068static bfd_boolean
25069arm_ccs_mode (char * unused ATTRIBUTE_UNUSED)
25070{
25071 codecomposer_syntax = TRUE;
25072 arm_comment_chars[0] = ';';
25073 arm_line_separator_chars[0] = 0;
25074 return TRUE;
25075}
25076
c19d1205
ZW
25077struct arm_long_option_table arm_long_opts[] =
25078{
25079 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
25080 arm_parse_cpu, NULL},
25081 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
25082 arm_parse_arch, NULL},
25083 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
25084 arm_parse_fpu, NULL},
25085 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
25086 arm_parse_float_abi, NULL},
25087#ifdef OBJ_ELF
7fac0536 25088 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
25089 arm_parse_eabi, NULL},
25090#endif
e07e6e58
NC
25091 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
25092 arm_parse_it_mode, NULL},
2e6976a8
DG
25093 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
25094 arm_ccs_mode, NULL},
c19d1205
ZW
25095 {NULL, NULL, 0, NULL}
25096};
cc8a6dd0 25097
c19d1205
ZW
25098int
25099md_parse_option (int c, char * arg)
25100{
25101 struct arm_option_table *opt;
e74cfd16 25102 const struct arm_legacy_option_table *fopt;
c19d1205 25103 struct arm_long_option_table *lopt;
b99bd4ef 25104
c19d1205 25105 switch (c)
b99bd4ef 25106 {
c19d1205
ZW
25107#ifdef OPTION_EB
25108 case OPTION_EB:
25109 target_big_endian = 1;
25110 break;
25111#endif
cc8a6dd0 25112
c19d1205
ZW
25113#ifdef OPTION_EL
25114 case OPTION_EL:
25115 target_big_endian = 0;
25116 break;
25117#endif
b99bd4ef 25118
845b51d6
PB
25119 case OPTION_FIX_V4BX:
25120 fix_v4bx = TRUE;
25121 break;
25122
c19d1205
ZW
25123 case 'a':
25124 /* Listing option. Just ignore these, we don't support additional
25125 ones. */
25126 return 0;
b99bd4ef 25127
c19d1205
ZW
25128 default:
25129 for (opt = arm_opts; opt->option != NULL; opt++)
25130 {
25131 if (c == opt->option[0]
25132 && ((arg == NULL && opt->option[1] == 0)
25133 || streq (arg, opt->option + 1)))
25134 {
c19d1205 25135 /* If the option is deprecated, tell the user. */
278df34e 25136 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
25137 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
25138 arg ? arg : "", _(opt->deprecated));
b99bd4ef 25139
c19d1205
ZW
25140 if (opt->var != NULL)
25141 *opt->var = opt->value;
cc8a6dd0 25142
c19d1205
ZW
25143 return 1;
25144 }
25145 }
b99bd4ef 25146
e74cfd16
PB
25147 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
25148 {
25149 if (c == fopt->option[0]
25150 && ((arg == NULL && fopt->option[1] == 0)
25151 || streq (arg, fopt->option + 1)))
25152 {
e74cfd16 25153 /* If the option is deprecated, tell the user. */
278df34e 25154 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
25155 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
25156 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
25157
25158 if (fopt->var != NULL)
25159 *fopt->var = &fopt->value;
25160
25161 return 1;
25162 }
25163 }
25164
c19d1205
ZW
25165 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
25166 {
25167 /* These options are expected to have an argument. */
25168 if (c == lopt->option[0]
25169 && arg != NULL
25170 && strncmp (arg, lopt->option + 1,
25171 strlen (lopt->option + 1)) == 0)
25172 {
c19d1205 25173 /* If the option is deprecated, tell the user. */
278df34e 25174 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
25175 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
25176 _(lopt->deprecated));
b99bd4ef 25177
c19d1205
ZW
25178 /* Call the sup-option parser. */
25179 return lopt->func (arg + strlen (lopt->option) - 1);
25180 }
25181 }
a737bd4d 25182
c19d1205
ZW
25183 return 0;
25184 }
a394c00f 25185
c19d1205
ZW
25186 return 1;
25187}
a394c00f 25188
c19d1205
ZW
25189void
25190md_show_usage (FILE * fp)
a394c00f 25191{
c19d1205
ZW
25192 struct arm_option_table *opt;
25193 struct arm_long_option_table *lopt;
a394c00f 25194
c19d1205 25195 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 25196
c19d1205
ZW
25197 for (opt = arm_opts; opt->option != NULL; opt++)
25198 if (opt->help != NULL)
25199 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 25200
c19d1205
ZW
25201 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
25202 if (lopt->help != NULL)
25203 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 25204
c19d1205
ZW
25205#ifdef OPTION_EB
25206 fprintf (fp, _("\
25207 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
25208#endif
25209
c19d1205
ZW
25210#ifdef OPTION_EL
25211 fprintf (fp, _("\
25212 -EL assemble code for a little-endian cpu\n"));
a737bd4d 25213#endif
845b51d6
PB
25214
25215 fprintf (fp, _("\
25216 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 25217}
ee065d83
PB
25218
25219
25220#ifdef OBJ_ELF
62b3e311
PB
25221typedef struct
25222{
25223 int val;
25224 arm_feature_set flags;
25225} cpu_arch_ver_table;
25226
25227/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
25228 least features first. */
25229static const cpu_arch_ver_table cpu_arch_ver[] =
25230{
25231 {1, ARM_ARCH_V4},
25232 {2, ARM_ARCH_V4T},
25233 {3, ARM_ARCH_V5},
ee3c0378 25234 {3, ARM_ARCH_V5T},
62b3e311
PB
25235 {4, ARM_ARCH_V5TE},
25236 {5, ARM_ARCH_V5TEJ},
25237 {6, ARM_ARCH_V6},
7e806470 25238 {9, ARM_ARCH_V6K},
f4c65163 25239 {7, ARM_ARCH_V6Z},
91e22acd 25240 {11, ARM_ARCH_V6M},
b2a5fbdc 25241 {12, ARM_ARCH_V6SM},
7e806470 25242 {8, ARM_ARCH_V6T2},
c9fb6e58 25243 {10, ARM_ARCH_V7VE},
62b3e311
PB
25244 {10, ARM_ARCH_V7R},
25245 {10, ARM_ARCH_V7M},
bca38921 25246 {14, ARM_ARCH_V8A},
62b3e311
PB
25247 {0, ARM_ARCH_NONE}
25248};
25249
ee3c0378
AS
25250/* Set an attribute if it has not already been set by the user. */
25251static void
25252aeabi_set_attribute_int (int tag, int value)
25253{
25254 if (tag < 1
25255 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
25256 || !attributes_set_explicitly[tag])
25257 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
25258}
25259
25260static void
25261aeabi_set_attribute_string (int tag, const char *value)
25262{
25263 if (tag < 1
25264 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
25265 || !attributes_set_explicitly[tag])
25266 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
25267}
25268
ee065d83 25269/* Set the public EABI object attributes. */
3cfdb781 25270void
ee065d83
PB
25271aeabi_set_public_attributes (void)
25272{
25273 int arch;
69239280 25274 char profile;
90ec0d68 25275 int virt_sec = 0;
bca38921 25276 int fp16_optional = 0;
e74cfd16 25277 arm_feature_set flags;
62b3e311
PB
25278 arm_feature_set tmp;
25279 const cpu_arch_ver_table *p;
ee065d83
PB
25280
25281 /* Choose the architecture based on the capabilities of the requested cpu
25282 (if any) and/or the instructions actually used. */
e74cfd16
PB
25283 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
25284 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
25285 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
ddd7f988
RE
25286
25287 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
25288 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
25289
25290 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
25291 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
25292
7f78eb34
JW
25293 selected_cpu = flags;
25294
ddd7f988 25295 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
25296 if (object_arch)
25297 {
25298 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
25299 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
25300 }
25301
251665fc
MGD
25302 /* We need to make sure that the attributes do not identify us as v6S-M
25303 when the only v6S-M feature in use is the Operating System Extensions. */
25304 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
25305 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
477330fc 25306 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
251665fc 25307
62b3e311
PB
25308 tmp = flags;
25309 arch = 0;
25310 for (p = cpu_arch_ver; p->val; p++)
25311 {
25312 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
25313 {
25314 arch = p->val;
25315 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
25316 }
25317 }
ee065d83 25318
9e3c6df6
PB
25319 /* The table lookup above finds the last architecture to contribute
25320 a new feature. Unfortunately, Tag13 is a subset of the union of
25321 v6T2 and v7-M, so it is never seen as contributing a new feature.
25322 We can not search for the last entry which is entirely used,
25323 because if no CPU is specified we build up only those flags
25324 actually used. Perhaps we should separate out the specified
25325 and implicit cases. Avoid taking this path for -march=all by
25326 checking for contradictory v7-A / v7-M features. */
25327 if (arch == 10
25328 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
25329 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
25330 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
25331 arch = 13;
25332
ee065d83
PB
25333 /* Tag_CPU_name. */
25334 if (selected_cpu_name[0])
25335 {
91d6fa6a 25336 char *q;
ee065d83 25337
91d6fa6a
NC
25338 q = selected_cpu_name;
25339 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
25340 {
25341 int i;
5f4273c7 25342
91d6fa6a
NC
25343 q += 4;
25344 for (i = 0; q[i]; i++)
25345 q[i] = TOUPPER (q[i]);
ee065d83 25346 }
91d6fa6a 25347 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 25348 }
62f3b8c8 25349
ee065d83 25350 /* Tag_CPU_arch. */
ee3c0378 25351 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 25352
62b3e311
PB
25353 /* Tag_CPU_arch_profile. */
25354 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
69239280 25355 profile = 'A';
62b3e311 25356 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
69239280 25357 profile = 'R';
7e806470 25358 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
69239280
MGD
25359 profile = 'M';
25360 else
25361 profile = '\0';
25362
25363 if (profile != '\0')
25364 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 25365
ee065d83 25366 /* Tag_ARM_ISA_use. */
ee3c0378
AS
25367 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
25368 || arch == 0)
25369 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 25370
ee065d83 25371 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
25372 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
25373 || arch == 0)
25374 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
25375 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
62f3b8c8 25376
ee065d83 25377 /* Tag_VFP_arch. */
a715796b
TG
25378 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
25379 aeabi_set_attribute_int (Tag_VFP_arch,
25380 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
25381 ? 7 : 8);
bca38921 25382 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
25383 aeabi_set_attribute_int (Tag_VFP_arch,
25384 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
25385 ? 5 : 6);
25386 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
25387 {
25388 fp16_optional = 1;
25389 aeabi_set_attribute_int (Tag_VFP_arch, 3);
25390 }
ada65aa3 25391 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
25392 {
25393 aeabi_set_attribute_int (Tag_VFP_arch, 4);
25394 fp16_optional = 1;
25395 }
ee3c0378
AS
25396 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
25397 aeabi_set_attribute_int (Tag_VFP_arch, 2);
25398 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 25399 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 25400 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 25401
4547cb56
NC
25402 /* Tag_ABI_HardFP_use. */
25403 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
25404 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
25405 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
25406
ee065d83 25407 /* Tag_WMMX_arch. */
ee3c0378
AS
25408 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
25409 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
25410 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
25411 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 25412
ee3c0378 25413 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
bca38921
MGD
25414 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
25415 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
25416 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
25417 {
25418 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
25419 {
25420 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
25421 }
25422 else
25423 {
25424 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
25425 fp16_optional = 1;
25426 }
25427 }
fa94de6b 25428
ee3c0378 25429 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 25430 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 25431 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 25432
69239280
MGD
25433 /* Tag_DIV_use.
25434
25435 We set Tag_DIV_use to two when integer divide instructions have been used
25436 in ARM state, or when Thumb integer divide instructions have been used,
25437 but we have no architecture profile set, nor have we any ARM instructions.
25438
bca38921
MGD
25439 For ARMv8 we set the tag to 0 as integer divide is implied by the base
25440 architecture.
25441
69239280 25442 For new architectures we will have to check these tests. */
bca38921
MGD
25443 gas_assert (arch <= TAG_CPU_ARCH_V8);
25444 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8))
25445 aeabi_set_attribute_int (Tag_DIV_use, 0);
25446 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
25447 || (profile == '\0'
25448 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
25449 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 25450 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
25451
25452 /* Tag_MP_extension_use. */
25453 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
25454 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
25455
25456 /* Tag Virtualization_use. */
25457 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
25458 virt_sec |= 1;
25459 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
25460 virt_sec |= 2;
25461 if (virt_sec != 0)
25462 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
25463}
25464
104d59d1 25465/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
25466void
25467arm_md_end (void)
25468{
ee065d83
PB
25469 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
25470 return;
25471
25472 aeabi_set_public_attributes ();
ee065d83 25473}
8463be01 25474#endif /* OBJ_ELF */
ee065d83
PB
25475
25476
25477/* Parse a .cpu directive. */
25478
25479static void
25480s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
25481{
e74cfd16 25482 const struct arm_cpu_option_table *opt;
ee065d83
PB
25483 char *name;
25484 char saved_char;
25485
25486 name = input_line_pointer;
5f4273c7 25487 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
25488 input_line_pointer++;
25489 saved_char = *input_line_pointer;
25490 *input_line_pointer = 0;
25491
25492 /* Skip the first "all" entry. */
25493 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
25494 if (streq (opt->name, name))
25495 {
e74cfd16
PB
25496 mcpu_cpu_opt = &opt->value;
25497 selected_cpu = opt->value;
ee065d83 25498 if (opt->canonical_name)
5f4273c7 25499 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
25500 else
25501 {
25502 int i;
25503 for (i = 0; opt->name[i]; i++)
25504 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 25505
ee065d83
PB
25506 selected_cpu_name[i] = 0;
25507 }
e74cfd16 25508 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
25509 *input_line_pointer = saved_char;
25510 demand_empty_rest_of_line ();
25511 return;
25512 }
25513 as_bad (_("unknown cpu `%s'"), name);
25514 *input_line_pointer = saved_char;
25515 ignore_rest_of_line ();
25516}
25517
25518
25519/* Parse a .arch directive. */
25520
25521static void
25522s_arm_arch (int ignored ATTRIBUTE_UNUSED)
25523{
e74cfd16 25524 const struct arm_arch_option_table *opt;
ee065d83
PB
25525 char saved_char;
25526 char *name;
25527
25528 name = input_line_pointer;
5f4273c7 25529 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
25530 input_line_pointer++;
25531 saved_char = *input_line_pointer;
25532 *input_line_pointer = 0;
25533
25534 /* Skip the first "all" entry. */
25535 for (opt = arm_archs + 1; opt->name != NULL; opt++)
25536 if (streq (opt->name, name))
25537 {
e74cfd16
PB
25538 mcpu_cpu_opt = &opt->value;
25539 selected_cpu = opt->value;
5f4273c7 25540 strcpy (selected_cpu_name, opt->name);
e74cfd16 25541 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
25542 *input_line_pointer = saved_char;
25543 demand_empty_rest_of_line ();
25544 return;
25545 }
25546
25547 as_bad (_("unknown architecture `%s'\n"), name);
25548 *input_line_pointer = saved_char;
25549 ignore_rest_of_line ();
25550}
25551
25552
7a1d4c38
PB
25553/* Parse a .object_arch directive. */
25554
25555static void
25556s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
25557{
25558 const struct arm_arch_option_table *opt;
25559 char saved_char;
25560 char *name;
25561
25562 name = input_line_pointer;
5f4273c7 25563 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
25564 input_line_pointer++;
25565 saved_char = *input_line_pointer;
25566 *input_line_pointer = 0;
25567
25568 /* Skip the first "all" entry. */
25569 for (opt = arm_archs + 1; opt->name != NULL; opt++)
25570 if (streq (opt->name, name))
25571 {
25572 object_arch = &opt->value;
25573 *input_line_pointer = saved_char;
25574 demand_empty_rest_of_line ();
25575 return;
25576 }
25577
25578 as_bad (_("unknown architecture `%s'\n"), name);
25579 *input_line_pointer = saved_char;
25580 ignore_rest_of_line ();
25581}
25582
69133863
MGD
25583/* Parse a .arch_extension directive. */
25584
25585static void
25586s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
25587{
25588 const struct arm_option_extension_value_table *opt;
25589 char saved_char;
25590 char *name;
25591 int adding_value = 1;
25592
25593 name = input_line_pointer;
25594 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
25595 input_line_pointer++;
25596 saved_char = *input_line_pointer;
25597 *input_line_pointer = 0;
25598
25599 if (strlen (name) >= 2
25600 && strncmp (name, "no", 2) == 0)
25601 {
25602 adding_value = 0;
25603 name += 2;
25604 }
25605
25606 for (opt = arm_extensions; opt->name != NULL; opt++)
25607 if (streq (opt->name, name))
25608 {
25609 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
25610 {
25611 as_bad (_("architectural extension `%s' is not allowed for the "
25612 "current base architecture"), name);
25613 break;
25614 }
25615
25616 if (adding_value)
5a70a223
JB
25617 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu,
25618 opt->merge_value);
69133863 25619 else
5a70a223 25620 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->clear_value);
69133863
MGD
25621
25622 mcpu_cpu_opt = &selected_cpu;
25623 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
25624 *input_line_pointer = saved_char;
25625 demand_empty_rest_of_line ();
25626 return;
25627 }
25628
25629 if (opt->name == NULL)
e673710a 25630 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
25631
25632 *input_line_pointer = saved_char;
25633 ignore_rest_of_line ();
25634}
25635
ee065d83
PB
25636/* Parse a .fpu directive. */
25637
25638static void
25639s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
25640{
69133863 25641 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
25642 char saved_char;
25643 char *name;
25644
25645 name = input_line_pointer;
5f4273c7 25646 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
25647 input_line_pointer++;
25648 saved_char = *input_line_pointer;
25649 *input_line_pointer = 0;
5f4273c7 25650
ee065d83
PB
25651 for (opt = arm_fpus; opt->name != NULL; opt++)
25652 if (streq (opt->name, name))
25653 {
e74cfd16
PB
25654 mfpu_opt = &opt->value;
25655 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
25656 *input_line_pointer = saved_char;
25657 demand_empty_rest_of_line ();
25658 return;
25659 }
25660
25661 as_bad (_("unknown floating point format `%s'\n"), name);
25662 *input_line_pointer = saved_char;
25663 ignore_rest_of_line ();
25664}
ee065d83 25665
794ba86a 25666/* Copy symbol information. */
f31fef98 25667
794ba86a
DJ
25668void
25669arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
25670{
25671 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
25672}
e04befd0 25673
f31fef98 25674#ifdef OBJ_ELF
e04befd0
AS
25675/* Given a symbolic attribute NAME, return the proper integer value.
25676 Returns -1 if the attribute is not known. */
f31fef98 25677
e04befd0
AS
25678int
25679arm_convert_symbolic_attribute (const char *name)
25680{
f31fef98
NC
25681 static const struct
25682 {
25683 const char * name;
25684 const int tag;
25685 }
25686 attribute_table[] =
25687 {
25688 /* When you modify this table you should
25689 also modify the list in doc/c-arm.texi. */
e04befd0 25690#define T(tag) {#tag, tag}
f31fef98
NC
25691 T (Tag_CPU_raw_name),
25692 T (Tag_CPU_name),
25693 T (Tag_CPU_arch),
25694 T (Tag_CPU_arch_profile),
25695 T (Tag_ARM_ISA_use),
25696 T (Tag_THUMB_ISA_use),
75375b3e 25697 T (Tag_FP_arch),
f31fef98
NC
25698 T (Tag_VFP_arch),
25699 T (Tag_WMMX_arch),
25700 T (Tag_Advanced_SIMD_arch),
25701 T (Tag_PCS_config),
25702 T (Tag_ABI_PCS_R9_use),
25703 T (Tag_ABI_PCS_RW_data),
25704 T (Tag_ABI_PCS_RO_data),
25705 T (Tag_ABI_PCS_GOT_use),
25706 T (Tag_ABI_PCS_wchar_t),
25707 T (Tag_ABI_FP_rounding),
25708 T (Tag_ABI_FP_denormal),
25709 T (Tag_ABI_FP_exceptions),
25710 T (Tag_ABI_FP_user_exceptions),
25711 T (Tag_ABI_FP_number_model),
75375b3e 25712 T (Tag_ABI_align_needed),
f31fef98 25713 T (Tag_ABI_align8_needed),
75375b3e 25714 T (Tag_ABI_align_preserved),
f31fef98
NC
25715 T (Tag_ABI_align8_preserved),
25716 T (Tag_ABI_enum_size),
25717 T (Tag_ABI_HardFP_use),
25718 T (Tag_ABI_VFP_args),
25719 T (Tag_ABI_WMMX_args),
25720 T (Tag_ABI_optimization_goals),
25721 T (Tag_ABI_FP_optimization_goals),
25722 T (Tag_compatibility),
25723 T (Tag_CPU_unaligned_access),
75375b3e 25724 T (Tag_FP_HP_extension),
f31fef98
NC
25725 T (Tag_VFP_HP_extension),
25726 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
25727 T (Tag_MPextension_use),
25728 T (Tag_DIV_use),
f31fef98
NC
25729 T (Tag_nodefaults),
25730 T (Tag_also_compatible_with),
25731 T (Tag_conformance),
25732 T (Tag_T2EE_use),
25733 T (Tag_Virtualization_use),
cd21e546 25734 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 25735#undef T
f31fef98 25736 };
e04befd0
AS
25737 unsigned int i;
25738
25739 if (name == NULL)
25740 return -1;
25741
f31fef98 25742 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 25743 if (streq (name, attribute_table[i].name))
e04befd0
AS
25744 return attribute_table[i].tag;
25745
25746 return -1;
25747}
267bf995
RR
25748
25749
93ef582d
NC
25750/* Apply sym value for relocations only in the case that they are for
25751 local symbols in the same segment as the fixup and you have the
25752 respective architectural feature for blx and simple switches. */
267bf995 25753int
93ef582d 25754arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
25755{
25756 if (fixP->fx_addsy
25757 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
25758 /* PR 17444: If the local symbol is in a different section then a reloc
25759 will always be generated for it, so applying the symbol value now
25760 will result in a double offset being stored in the relocation. */
25761 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 25762 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
25763 {
25764 switch (fixP->fx_r_type)
25765 {
25766 case BFD_RELOC_ARM_PCREL_BLX:
25767 case BFD_RELOC_THUMB_PCREL_BRANCH23:
25768 if (ARM_IS_FUNC (fixP->fx_addsy))
25769 return 1;
25770 break;
25771
25772 case BFD_RELOC_ARM_PCREL_CALL:
25773 case BFD_RELOC_THUMB_PCREL_BLX:
25774 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 25775 return 1;
267bf995
RR
25776 break;
25777
25778 default:
25779 break;
25780 }
25781
25782 }
25783 return 0;
25784}
f31fef98 25785#endif /* OBJ_ELF */
This page took 2.971668 seconds and 4 git commands to generate.