]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
Add support for converting VLDR <reg>,=<constant> to a VMOV instruction when appropriate.
[thirdparty/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);
d6b4b13e
MW
262static const arm_feature_set fpu_neon_ext_v8_1 =
263 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8 | FPU_NEON_EXT_RDMA);
e74cfd16 264
33a392fb 265static int mfloat_abi_opt = -1;
e74cfd16
PB
266/* Record user cpu selection for object attributes. */
267static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
268/* Must be long enough to hold any of the names in arm_cpus. */
269static char selected_cpu_name[16];
8d67f500 270
aacf0b33
KT
271extern FLONUM_TYPE generic_floating_point_number;
272
8d67f500
NC
273/* Return if no cpu was selected on command-line. */
274static bfd_boolean
275no_cpu_selected (void)
276{
823d2571 277 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
278}
279
7cc69913 280#ifdef OBJ_ELF
deeaaff8
DJ
281# ifdef EABI_DEFAULT
282static int meabi_flags = EABI_DEFAULT;
283# else
d507cf36 284static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 285# endif
e1da3f5b 286
ee3c0378
AS
287static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
288
e1da3f5b 289bfd_boolean
5f4273c7 290arm_is_eabi (void)
e1da3f5b
PB
291{
292 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
293}
7cc69913 294#endif
b99bd4ef 295
b99bd4ef 296#ifdef OBJ_ELF
c19d1205 297/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
298symbolS * GOT_symbol;
299#endif
300
b99bd4ef
NC
301/* 0: assemble for ARM,
302 1: assemble for Thumb,
303 2: assemble for Thumb even though target CPU does not support thumb
304 instructions. */
305static int thumb_mode = 0;
8dc2430f
NC
306/* A value distinct from the possible values for thumb_mode that we
307 can use to record whether thumb_mode has been copied into the
308 tc_frag_data field of a frag. */
309#define MODE_RECORDED (1 << 4)
b99bd4ef 310
e07e6e58
NC
311/* Specifies the intrinsic IT insn behavior mode. */
312enum implicit_it_mode
313{
314 IMPLICIT_IT_MODE_NEVER = 0x00,
315 IMPLICIT_IT_MODE_ARM = 0x01,
316 IMPLICIT_IT_MODE_THUMB = 0x02,
317 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
318};
319static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
320
c19d1205
ZW
321/* If unified_syntax is true, we are processing the new unified
322 ARM/Thumb syntax. Important differences from the old ARM mode:
323
324 - Immediate operands do not require a # prefix.
325 - Conditional affixes always appear at the end of the
326 instruction. (For backward compatibility, those instructions
327 that formerly had them in the middle, continue to accept them
328 there.)
329 - The IT instruction may appear, and if it does is validated
330 against subsequent conditional affixes. It does not generate
331 machine code.
332
333 Important differences from the old Thumb mode:
334
335 - Immediate operands do not require a # prefix.
336 - Most of the V6T2 instructions are only available in unified mode.
337 - The .N and .W suffixes are recognized and honored (it is an error
338 if they cannot be honored).
339 - All instructions set the flags if and only if they have an 's' affix.
340 - Conditional affixes may be used. They are validated against
341 preceding IT instructions. Unlike ARM mode, you cannot use a
342 conditional affix except in the scope of an IT instruction. */
343
344static bfd_boolean unified_syntax = FALSE;
b99bd4ef 345
bacebabc
RM
346/* An immediate operand can start with #, and ld*, st*, pld operands
347 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
348 before a [, which can appear as the first operand for pld.
349 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
350const char arm_symbol_chars[] = "#[]{}";
bacebabc 351
5287ad62
JB
352enum neon_el_type
353{
dcbf9037 354 NT_invtype,
5287ad62
JB
355 NT_untyped,
356 NT_integer,
357 NT_float,
358 NT_poly,
359 NT_signed,
dcbf9037 360 NT_unsigned
5287ad62
JB
361};
362
363struct neon_type_el
364{
365 enum neon_el_type type;
366 unsigned size;
367};
368
369#define NEON_MAX_TYPE_ELS 4
370
371struct neon_type
372{
373 struct neon_type_el el[NEON_MAX_TYPE_ELS];
374 unsigned elems;
375};
376
e07e6e58
NC
377enum it_instruction_type
378{
379 OUTSIDE_IT_INSN,
380 INSIDE_IT_INSN,
381 INSIDE_IT_LAST_INSN,
382 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 383 if inside, should be the last one. */
e07e6e58 384 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 385 i.e. BKPT and NOP. */
e07e6e58
NC
386 IT_INSN /* The IT insn has been parsed. */
387};
388
ad6cec43
MGD
389/* The maximum number of operands we need. */
390#define ARM_IT_MAX_OPERANDS 6
391
b99bd4ef
NC
392struct arm_it
393{
c19d1205 394 const char * error;
b99bd4ef 395 unsigned long instruction;
c19d1205
ZW
396 int size;
397 int size_req;
398 int cond;
037e8744
JB
399 /* "uncond_value" is set to the value in place of the conditional field in
400 unconditional versions of the instruction, or -1 if nothing is
401 appropriate. */
402 int uncond_value;
5287ad62 403 struct neon_type vectype;
88714cb8
DG
404 /* This does not indicate an actual NEON instruction, only that
405 the mnemonic accepts neon-style type suffixes. */
406 int is_neon;
0110f2b8
PB
407 /* Set to the opcode if the instruction needs relaxation.
408 Zero if the instruction is not relaxed. */
409 unsigned long relax;
b99bd4ef
NC
410 struct
411 {
412 bfd_reloc_code_real_type type;
c19d1205
ZW
413 expressionS exp;
414 int pc_rel;
b99bd4ef 415 } reloc;
b99bd4ef 416
e07e6e58
NC
417 enum it_instruction_type it_insn_type;
418
c19d1205
ZW
419 struct
420 {
421 unsigned reg;
ca3f61f7 422 signed int imm;
dcbf9037 423 struct neon_type_el vectype;
ca3f61f7
NC
424 unsigned present : 1; /* Operand present. */
425 unsigned isreg : 1; /* Operand was a register. */
426 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
427 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
428 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 429 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
430 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
431 instructions. This allows us to disambiguate ARM <-> vector insns. */
432 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 433 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 434 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 435 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
436 unsigned hasreloc : 1; /* Operand has relocation suffix. */
437 unsigned writeback : 1; /* Operand has trailing ! */
438 unsigned preind : 1; /* Preindexed address. */
439 unsigned postind : 1; /* Postindexed address. */
440 unsigned negative : 1; /* Index register was negated. */
441 unsigned shifted : 1; /* Shift applied to operation. */
442 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 443 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
444};
445
c19d1205 446static struct arm_it inst;
b99bd4ef
NC
447
448#define NUM_FLOAT_VALS 8
449
05d2d07e 450const char * fp_const[] =
b99bd4ef
NC
451{
452 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
453};
454
c19d1205 455/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
456#define MAX_LITTLENUMS 6
457
458LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
459
460#define FAIL (-1)
461#define SUCCESS (0)
462
463#define SUFF_S 1
464#define SUFF_D 2
465#define SUFF_E 3
466#define SUFF_P 4
467
c19d1205
ZW
468#define CP_T_X 0x00008000
469#define CP_T_Y 0x00400000
b99bd4ef 470
c19d1205
ZW
471#define CONDS_BIT 0x00100000
472#define LOAD_BIT 0x00100000
b99bd4ef
NC
473
474#define DOUBLE_LOAD_FLAG 0x00000001
475
476struct asm_cond
477{
d3ce72d0 478 const char * template_name;
c921be7d 479 unsigned long value;
b99bd4ef
NC
480};
481
c19d1205 482#define COND_ALWAYS 0xE
b99bd4ef 483
b99bd4ef
NC
484struct asm_psr
485{
d3ce72d0 486 const char * template_name;
c921be7d 487 unsigned long field;
b99bd4ef
NC
488};
489
62b3e311
PB
490struct asm_barrier_opt
491{
e797f7e0
MGD
492 const char * template_name;
493 unsigned long value;
494 const arm_feature_set arch;
62b3e311
PB
495};
496
2d2255b5 497/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
498#define SPSR_BIT (1 << 22)
499
c19d1205
ZW
500/* The individual PSR flag bits. */
501#define PSR_c (1 << 16)
502#define PSR_x (1 << 17)
503#define PSR_s (1 << 18)
504#define PSR_f (1 << 19)
b99bd4ef 505
c19d1205 506struct reloc_entry
bfae80f2 507{
c921be7d
NC
508 char * name;
509 bfd_reloc_code_real_type reloc;
bfae80f2
RE
510};
511
5287ad62 512enum vfp_reg_pos
bfae80f2 513{
5287ad62
JB
514 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
515 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
516};
517
518enum vfp_ldstm_type
519{
520 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
521};
522
dcbf9037
JB
523/* Bits for DEFINED field in neon_typed_alias. */
524#define NTA_HASTYPE 1
525#define NTA_HASINDEX 2
526
527struct neon_typed_alias
528{
c921be7d
NC
529 unsigned char defined;
530 unsigned char index;
531 struct neon_type_el eltype;
dcbf9037
JB
532};
533
c19d1205
ZW
534/* ARM register categories. This includes coprocessor numbers and various
535 architecture extensions' registers. */
536enum arm_reg_type
bfae80f2 537{
c19d1205
ZW
538 REG_TYPE_RN,
539 REG_TYPE_CP,
540 REG_TYPE_CN,
541 REG_TYPE_FN,
542 REG_TYPE_VFS,
543 REG_TYPE_VFD,
5287ad62 544 REG_TYPE_NQ,
037e8744 545 REG_TYPE_VFSD,
5287ad62 546 REG_TYPE_NDQ,
037e8744 547 REG_TYPE_NSDQ,
c19d1205
ZW
548 REG_TYPE_VFC,
549 REG_TYPE_MVF,
550 REG_TYPE_MVD,
551 REG_TYPE_MVFX,
552 REG_TYPE_MVDX,
553 REG_TYPE_MVAX,
554 REG_TYPE_DSPSC,
555 REG_TYPE_MMXWR,
556 REG_TYPE_MMXWC,
557 REG_TYPE_MMXWCG,
558 REG_TYPE_XSCALE,
90ec0d68 559 REG_TYPE_RNB
bfae80f2
RE
560};
561
dcbf9037
JB
562/* Structure for a hash table entry for a register.
563 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
564 information which states whether a vector type or index is specified (for a
565 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
566struct reg_entry
567{
c921be7d 568 const char * name;
90ec0d68 569 unsigned int number;
c921be7d
NC
570 unsigned char type;
571 unsigned char builtin;
572 struct neon_typed_alias * neon;
6c43fab6
RE
573};
574
c19d1205 575/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 576const char * const reg_expected_msgs[] =
c19d1205
ZW
577{
578 N_("ARM register expected"),
579 N_("bad or missing co-processor number"),
580 N_("co-processor register expected"),
581 N_("FPA register expected"),
582 N_("VFP single precision register expected"),
5287ad62
JB
583 N_("VFP/Neon double precision register expected"),
584 N_("Neon quad precision register expected"),
037e8744 585 N_("VFP single or double precision register expected"),
5287ad62 586 N_("Neon double or quad precision register expected"),
037e8744 587 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
588 N_("VFP system register expected"),
589 N_("Maverick MVF register expected"),
590 N_("Maverick MVD register expected"),
591 N_("Maverick MVFX register expected"),
592 N_("Maverick MVDX register expected"),
593 N_("Maverick MVAX register expected"),
594 N_("Maverick DSPSC register expected"),
595 N_("iWMMXt data register expected"),
596 N_("iWMMXt control register expected"),
597 N_("iWMMXt scalar register expected"),
598 N_("XScale accumulator register expected"),
6c43fab6
RE
599};
600
c19d1205 601/* Some well known registers that we refer to directly elsewhere. */
bd340a04 602#define REG_R12 12
c19d1205
ZW
603#define REG_SP 13
604#define REG_LR 14
605#define REG_PC 15
404ff6b5 606
b99bd4ef
NC
607/* ARM instructions take 4bytes in the object file, Thumb instructions
608 take 2: */
c19d1205 609#define INSN_SIZE 4
b99bd4ef
NC
610
611struct asm_opcode
612{
613 /* Basic string to match. */
d3ce72d0 614 const char * template_name;
c19d1205
ZW
615
616 /* Parameters to instruction. */
5be8be5d 617 unsigned int operands[8];
c19d1205
ZW
618
619 /* Conditional tag - see opcode_lookup. */
620 unsigned int tag : 4;
b99bd4ef
NC
621
622 /* Basic instruction code. */
c19d1205 623 unsigned int avalue : 28;
b99bd4ef 624
c19d1205
ZW
625 /* Thumb-format instruction code. */
626 unsigned int tvalue;
b99bd4ef 627
90e4755a 628 /* Which architecture variant provides this instruction. */
c921be7d
NC
629 const arm_feature_set * avariant;
630 const arm_feature_set * tvariant;
c19d1205
ZW
631
632 /* Function to call to encode instruction in ARM format. */
633 void (* aencode) (void);
b99bd4ef 634
c19d1205
ZW
635 /* Function to call to encode instruction in Thumb format. */
636 void (* tencode) (void);
b99bd4ef
NC
637};
638
a737bd4d
NC
639/* Defines for various bits that we will want to toggle. */
640#define INST_IMMEDIATE 0x02000000
641#define OFFSET_REG 0x02000000
c19d1205 642#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
643#define SHIFT_BY_REG 0x00000010
644#define PRE_INDEX 0x01000000
645#define INDEX_UP 0x00800000
646#define WRITE_BACK 0x00200000
647#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 648#define CPSI_MMOD 0x00020000
90e4755a 649
a737bd4d
NC
650#define LITERAL_MASK 0xf000f000
651#define OPCODE_MASK 0xfe1fffff
652#define V4_STR_BIT 0x00000020
8335d6aa 653#define VLDR_VMOV_SAME 0x0040f000
90e4755a 654
efd81785
PB
655#define T2_SUBS_PC_LR 0xf3de8f00
656
a737bd4d 657#define DATA_OP_SHIFT 21
90e4755a 658
ef8d22e6
PB
659#define T2_OPCODE_MASK 0xfe1fffff
660#define T2_DATA_OP_SHIFT 21
661
6530b175
NC
662#define A_COND_MASK 0xf0000000
663#define A_PUSH_POP_OP_MASK 0x0fff0000
664
665/* Opcodes for pushing/poping registers to/from the stack. */
666#define A1_OPCODE_PUSH 0x092d0000
667#define A2_OPCODE_PUSH 0x052d0004
668#define A2_OPCODE_POP 0x049d0004
669
a737bd4d
NC
670/* Codes to distinguish the arithmetic instructions. */
671#define OPCODE_AND 0
672#define OPCODE_EOR 1
673#define OPCODE_SUB 2
674#define OPCODE_RSB 3
675#define OPCODE_ADD 4
676#define OPCODE_ADC 5
677#define OPCODE_SBC 6
678#define OPCODE_RSC 7
679#define OPCODE_TST 8
680#define OPCODE_TEQ 9
681#define OPCODE_CMP 10
682#define OPCODE_CMN 11
683#define OPCODE_ORR 12
684#define OPCODE_MOV 13
685#define OPCODE_BIC 14
686#define OPCODE_MVN 15
90e4755a 687
ef8d22e6
PB
688#define T2_OPCODE_AND 0
689#define T2_OPCODE_BIC 1
690#define T2_OPCODE_ORR 2
691#define T2_OPCODE_ORN 3
692#define T2_OPCODE_EOR 4
693#define T2_OPCODE_ADD 8
694#define T2_OPCODE_ADC 10
695#define T2_OPCODE_SBC 11
696#define T2_OPCODE_SUB 13
697#define T2_OPCODE_RSB 14
698
a737bd4d
NC
699#define T_OPCODE_MUL 0x4340
700#define T_OPCODE_TST 0x4200
701#define T_OPCODE_CMN 0x42c0
702#define T_OPCODE_NEG 0x4240
703#define T_OPCODE_MVN 0x43c0
90e4755a 704
a737bd4d
NC
705#define T_OPCODE_ADD_R3 0x1800
706#define T_OPCODE_SUB_R3 0x1a00
707#define T_OPCODE_ADD_HI 0x4400
708#define T_OPCODE_ADD_ST 0xb000
709#define T_OPCODE_SUB_ST 0xb080
710#define T_OPCODE_ADD_SP 0xa800
711#define T_OPCODE_ADD_PC 0xa000
712#define T_OPCODE_ADD_I8 0x3000
713#define T_OPCODE_SUB_I8 0x3800
714#define T_OPCODE_ADD_I3 0x1c00
715#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 716
a737bd4d
NC
717#define T_OPCODE_ASR_R 0x4100
718#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
719#define T_OPCODE_LSR_R 0x40c0
720#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
721#define T_OPCODE_ASR_I 0x1000
722#define T_OPCODE_LSL_I 0x0000
723#define T_OPCODE_LSR_I 0x0800
b99bd4ef 724
a737bd4d
NC
725#define T_OPCODE_MOV_I8 0x2000
726#define T_OPCODE_CMP_I8 0x2800
727#define T_OPCODE_CMP_LR 0x4280
728#define T_OPCODE_MOV_HR 0x4600
729#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 730
a737bd4d
NC
731#define T_OPCODE_LDR_PC 0x4800
732#define T_OPCODE_LDR_SP 0x9800
733#define T_OPCODE_STR_SP 0x9000
734#define T_OPCODE_LDR_IW 0x6800
735#define T_OPCODE_STR_IW 0x6000
736#define T_OPCODE_LDR_IH 0x8800
737#define T_OPCODE_STR_IH 0x8000
738#define T_OPCODE_LDR_IB 0x7800
739#define T_OPCODE_STR_IB 0x7000
740#define T_OPCODE_LDR_RW 0x5800
741#define T_OPCODE_STR_RW 0x5000
742#define T_OPCODE_LDR_RH 0x5a00
743#define T_OPCODE_STR_RH 0x5200
744#define T_OPCODE_LDR_RB 0x5c00
745#define T_OPCODE_STR_RB 0x5400
c9b604bd 746
a737bd4d
NC
747#define T_OPCODE_PUSH 0xb400
748#define T_OPCODE_POP 0xbc00
b99bd4ef 749
2fc8bdac 750#define T_OPCODE_BRANCH 0xe000
b99bd4ef 751
a737bd4d 752#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 753#define THUMB_PP_PC_LR 0x0100
c19d1205 754#define THUMB_LOAD_BIT 0x0800
53365c0d 755#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
756
757#define BAD_ARGS _("bad arguments to instruction")
fdfde340 758#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
759#define BAD_PC _("r15 not allowed here")
760#define BAD_COND _("instruction cannot be conditional")
761#define BAD_OVERLAP _("registers may not be the same")
762#define BAD_HIREG _("lo register required")
763#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 764#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
765#define BAD_BRANCH _("branch must be last instruction in IT block")
766#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 767#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
768#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
769#define BAD_IT_COND _("incorrect condition in IT block")
770#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 771#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
772#define BAD_PC_ADDRESSING \
773 _("cannot use register index with PC-relative addressing")
774#define BAD_PC_WRITEBACK \
775 _("cannot use writeback with PC-relative addressing")
08f10d51 776#define BAD_RANGE _("branch out of range")
dd5181d5 777#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
c19d1205 778
c921be7d
NC
779static struct hash_control * arm_ops_hsh;
780static struct hash_control * arm_cond_hsh;
781static struct hash_control * arm_shift_hsh;
782static struct hash_control * arm_psr_hsh;
783static struct hash_control * arm_v7m_psr_hsh;
784static struct hash_control * arm_reg_hsh;
785static struct hash_control * arm_reloc_hsh;
786static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 787
b99bd4ef
NC
788/* Stuff needed to resolve the label ambiguity
789 As:
790 ...
791 label: <insn>
792 may differ from:
793 ...
794 label:
5f4273c7 795 <insn> */
b99bd4ef
NC
796
797symbolS * last_label_seen;
b34976b6 798static int label_is_thumb_function_name = FALSE;
e07e6e58 799
3d0c9500
NC
800/* Literal pool structure. Held on a per-section
801 and per-sub-section basis. */
a737bd4d 802
c19d1205 803#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 804typedef struct literal_pool
b99bd4ef 805{
c921be7d
NC
806 expressionS literals [MAX_LITERAL_POOL_SIZE];
807 unsigned int next_free_entry;
808 unsigned int id;
809 symbolS * symbol;
810 segT section;
811 subsegT sub_section;
a8040cf2
NC
812#ifdef OBJ_ELF
813 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
814#endif
c921be7d 815 struct literal_pool * next;
8335d6aa 816 unsigned int alignment;
3d0c9500 817} literal_pool;
b99bd4ef 818
3d0c9500
NC
819/* Pointer to a linked list of literal pools. */
820literal_pool * list_of_pools = NULL;
e27ec89e 821
2e6976a8
DG
822typedef enum asmfunc_states
823{
824 OUTSIDE_ASMFUNC,
825 WAITING_ASMFUNC_NAME,
826 WAITING_ENDASMFUNC
827} asmfunc_states;
828
829static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
830
e07e6e58
NC
831#ifdef OBJ_ELF
832# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
833#else
834static struct current_it now_it;
835#endif
836
837static inline int
838now_it_compatible (int cond)
839{
840 return (cond & ~1) == (now_it.cc & ~1);
841}
842
843static inline int
844conditional_insn (void)
845{
846 return inst.cond != COND_ALWAYS;
847}
848
849static int in_it_block (void);
850
851static int handle_it_state (void);
852
853static void force_automatic_it_block_close (void);
854
c921be7d
NC
855static void it_fsm_post_encode (void);
856
e07e6e58
NC
857#define set_it_insn_type(type) \
858 do \
859 { \
860 inst.it_insn_type = type; \
861 if (handle_it_state () == FAIL) \
477330fc 862 return; \
e07e6e58
NC
863 } \
864 while (0)
865
c921be7d
NC
866#define set_it_insn_type_nonvoid(type, failret) \
867 do \
868 { \
869 inst.it_insn_type = type; \
870 if (handle_it_state () == FAIL) \
477330fc 871 return failret; \
c921be7d
NC
872 } \
873 while(0)
874
e07e6e58
NC
875#define set_it_insn_type_last() \
876 do \
877 { \
878 if (inst.cond == COND_ALWAYS) \
477330fc 879 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 880 else \
477330fc 881 set_it_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
882 } \
883 while (0)
884
c19d1205 885/* Pure syntax. */
b99bd4ef 886
c19d1205
ZW
887/* This array holds the chars that always start a comment. If the
888 pre-processor is disabled, these aren't very useful. */
2e6976a8 889char arm_comment_chars[] = "@";
3d0c9500 890
c19d1205
ZW
891/* This array holds the chars that only start a comment at the beginning of
892 a line. If the line seems to have the form '# 123 filename'
893 .line and .file directives will appear in the pre-processed output. */
894/* Note that input_file.c hand checks for '#' at the beginning of the
895 first line of the input file. This is because the compiler outputs
896 #NO_APP at the beginning of its output. */
897/* Also note that comments like this one will always work. */
898const char line_comment_chars[] = "#";
3d0c9500 899
2e6976a8 900char arm_line_separator_chars[] = ";";
b99bd4ef 901
c19d1205
ZW
902/* Chars that can be used to separate mant
903 from exp in floating point numbers. */
904const char EXP_CHARS[] = "eE";
3d0c9500 905
c19d1205
ZW
906/* Chars that mean this number is a floating point constant. */
907/* As in 0f12.456 */
908/* or 0d1.2345e12 */
b99bd4ef 909
c19d1205 910const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 911
c19d1205
ZW
912/* Prefix characters that indicate the start of an immediate
913 value. */
914#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 915
c19d1205
ZW
916/* Separator character handling. */
917
918#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
919
920static inline int
921skip_past_char (char ** str, char c)
922{
8ab8155f
NC
923 /* PR gas/14987: Allow for whitespace before the expected character. */
924 skip_whitespace (*str);
427d0db6 925
c19d1205
ZW
926 if (**str == c)
927 {
928 (*str)++;
929 return SUCCESS;
3d0c9500 930 }
c19d1205
ZW
931 else
932 return FAIL;
933}
c921be7d 934
c19d1205 935#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 936
c19d1205
ZW
937/* Arithmetic expressions (possibly involving symbols). */
938
939/* Return TRUE if anything in the expression is a bignum. */
940
941static int
942walk_no_bignums (symbolS * sp)
943{
944 if (symbol_get_value_expression (sp)->X_op == O_big)
945 return 1;
946
947 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 948 {
c19d1205
ZW
949 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
950 || (symbol_get_value_expression (sp)->X_op_symbol
951 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
952 }
953
c19d1205 954 return 0;
3d0c9500
NC
955}
956
c19d1205
ZW
957static int in_my_get_expression = 0;
958
959/* Third argument to my_get_expression. */
960#define GE_NO_PREFIX 0
961#define GE_IMM_PREFIX 1
962#define GE_OPT_PREFIX 2
5287ad62
JB
963/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
964 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
965#define GE_OPT_PREFIX_BIG 3
a737bd4d 966
b99bd4ef 967static int
c19d1205 968my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 969{
c19d1205
ZW
970 char * save_in;
971 segT seg;
b99bd4ef 972
c19d1205
ZW
973 /* In unified syntax, all prefixes are optional. */
974 if (unified_syntax)
5287ad62 975 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 976 : GE_OPT_PREFIX;
b99bd4ef 977
c19d1205 978 switch (prefix_mode)
b99bd4ef 979 {
c19d1205
ZW
980 case GE_NO_PREFIX: break;
981 case GE_IMM_PREFIX:
982 if (!is_immediate_prefix (**str))
983 {
984 inst.error = _("immediate expression requires a # prefix");
985 return FAIL;
986 }
987 (*str)++;
988 break;
989 case GE_OPT_PREFIX:
5287ad62 990 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
991 if (is_immediate_prefix (**str))
992 (*str)++;
993 break;
994 default: abort ();
995 }
b99bd4ef 996
c19d1205 997 memset (ep, 0, sizeof (expressionS));
b99bd4ef 998
c19d1205
ZW
999 save_in = input_line_pointer;
1000 input_line_pointer = *str;
1001 in_my_get_expression = 1;
1002 seg = expression (ep);
1003 in_my_get_expression = 0;
1004
f86adc07 1005 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1006 {
f86adc07 1007 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1008 *str = input_line_pointer;
1009 input_line_pointer = save_in;
1010 if (inst.error == NULL)
f86adc07
NS
1011 inst.error = (ep->X_op == O_absent
1012 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1013 return 1;
1014 }
b99bd4ef 1015
c19d1205
ZW
1016#ifdef OBJ_AOUT
1017 if (seg != absolute_section
1018 && seg != text_section
1019 && seg != data_section
1020 && seg != bss_section
1021 && seg != undefined_section)
1022 {
1023 inst.error = _("bad segment");
1024 *str = input_line_pointer;
1025 input_line_pointer = save_in;
1026 return 1;
b99bd4ef 1027 }
87975d2a
AM
1028#else
1029 (void) seg;
c19d1205 1030#endif
b99bd4ef 1031
c19d1205
ZW
1032 /* Get rid of any bignums now, so that we don't generate an error for which
1033 we can't establish a line number later on. Big numbers are never valid
1034 in instructions, which is where this routine is always called. */
5287ad62
JB
1035 if (prefix_mode != GE_OPT_PREFIX_BIG
1036 && (ep->X_op == O_big
477330fc 1037 || (ep->X_add_symbol
5287ad62 1038 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1039 || (ep->X_op_symbol
5287ad62 1040 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1041 {
1042 inst.error = _("invalid constant");
1043 *str = input_line_pointer;
1044 input_line_pointer = save_in;
1045 return 1;
1046 }
b99bd4ef 1047
c19d1205
ZW
1048 *str = input_line_pointer;
1049 input_line_pointer = save_in;
1050 return 0;
b99bd4ef
NC
1051}
1052
c19d1205
ZW
1053/* Turn a string in input_line_pointer into a floating point constant
1054 of type TYPE, and store the appropriate bytes in *LITP. The number
1055 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1056 returned, or NULL on OK.
b99bd4ef 1057
c19d1205
ZW
1058 Note that fp constants aren't represent in the normal way on the ARM.
1059 In big endian mode, things are as expected. However, in little endian
1060 mode fp constants are big-endian word-wise, and little-endian byte-wise
1061 within the words. For example, (double) 1.1 in big endian mode is
1062 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1063 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1064
c19d1205 1065 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1066
c19d1205
ZW
1067char *
1068md_atof (int type, char * litP, int * sizeP)
1069{
1070 int prec;
1071 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1072 char *t;
1073 int i;
b99bd4ef 1074
c19d1205
ZW
1075 switch (type)
1076 {
1077 case 'f':
1078 case 'F':
1079 case 's':
1080 case 'S':
1081 prec = 2;
1082 break;
b99bd4ef 1083
c19d1205
ZW
1084 case 'd':
1085 case 'D':
1086 case 'r':
1087 case 'R':
1088 prec = 4;
1089 break;
b99bd4ef 1090
c19d1205
ZW
1091 case 'x':
1092 case 'X':
499ac353 1093 prec = 5;
c19d1205 1094 break;
b99bd4ef 1095
c19d1205
ZW
1096 case 'p':
1097 case 'P':
499ac353 1098 prec = 5;
c19d1205 1099 break;
a737bd4d 1100
c19d1205
ZW
1101 default:
1102 *sizeP = 0;
499ac353 1103 return _("Unrecognized or unsupported floating point constant");
c19d1205 1104 }
b99bd4ef 1105
c19d1205
ZW
1106 t = atof_ieee (input_line_pointer, type, words);
1107 if (t)
1108 input_line_pointer = t;
499ac353 1109 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1110
c19d1205
ZW
1111 if (target_big_endian)
1112 {
1113 for (i = 0; i < prec; i++)
1114 {
499ac353
NC
1115 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1116 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1117 }
1118 }
1119 else
1120 {
e74cfd16 1121 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1122 for (i = prec - 1; i >= 0; i--)
1123 {
499ac353
NC
1124 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1125 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1126 }
1127 else
1128 /* For a 4 byte float the order of elements in `words' is 1 0.
1129 For an 8 byte float the order is 1 0 3 2. */
1130 for (i = 0; i < prec; i += 2)
1131 {
499ac353
NC
1132 md_number_to_chars (litP, (valueT) words[i + 1],
1133 sizeof (LITTLENUM_TYPE));
1134 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1135 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1136 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1137 }
1138 }
b99bd4ef 1139
499ac353 1140 return NULL;
c19d1205 1141}
b99bd4ef 1142
c19d1205
ZW
1143/* We handle all bad expressions here, so that we can report the faulty
1144 instruction in the error message. */
1145void
91d6fa6a 1146md_operand (expressionS * exp)
c19d1205
ZW
1147{
1148 if (in_my_get_expression)
91d6fa6a 1149 exp->X_op = O_illegal;
b99bd4ef
NC
1150}
1151
c19d1205 1152/* Immediate values. */
b99bd4ef 1153
c19d1205
ZW
1154/* Generic immediate-value read function for use in directives.
1155 Accepts anything that 'expression' can fold to a constant.
1156 *val receives the number. */
1157#ifdef OBJ_ELF
1158static int
1159immediate_for_directive (int *val)
b99bd4ef 1160{
c19d1205
ZW
1161 expressionS exp;
1162 exp.X_op = O_illegal;
b99bd4ef 1163
c19d1205
ZW
1164 if (is_immediate_prefix (*input_line_pointer))
1165 {
1166 input_line_pointer++;
1167 expression (&exp);
1168 }
b99bd4ef 1169
c19d1205
ZW
1170 if (exp.X_op != O_constant)
1171 {
1172 as_bad (_("expected #constant"));
1173 ignore_rest_of_line ();
1174 return FAIL;
1175 }
1176 *val = exp.X_add_number;
1177 return SUCCESS;
b99bd4ef 1178}
c19d1205 1179#endif
b99bd4ef 1180
c19d1205 1181/* Register parsing. */
b99bd4ef 1182
c19d1205
ZW
1183/* Generic register parser. CCP points to what should be the
1184 beginning of a register name. If it is indeed a valid register
1185 name, advance CCP over it and return the reg_entry structure;
1186 otherwise return NULL. Does not issue diagnostics. */
1187
1188static struct reg_entry *
1189arm_reg_parse_multi (char **ccp)
b99bd4ef 1190{
c19d1205
ZW
1191 char *start = *ccp;
1192 char *p;
1193 struct reg_entry *reg;
b99bd4ef 1194
477330fc
RM
1195 skip_whitespace (start);
1196
c19d1205
ZW
1197#ifdef REGISTER_PREFIX
1198 if (*start != REGISTER_PREFIX)
01cfc07f 1199 return NULL;
c19d1205
ZW
1200 start++;
1201#endif
1202#ifdef OPTIONAL_REGISTER_PREFIX
1203 if (*start == OPTIONAL_REGISTER_PREFIX)
1204 start++;
1205#endif
b99bd4ef 1206
c19d1205
ZW
1207 p = start;
1208 if (!ISALPHA (*p) || !is_name_beginner (*p))
1209 return NULL;
b99bd4ef 1210
c19d1205
ZW
1211 do
1212 p++;
1213 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1214
1215 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1216
1217 if (!reg)
1218 return NULL;
1219
1220 *ccp = p;
1221 return reg;
b99bd4ef
NC
1222}
1223
1224static int
dcbf9037 1225arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1226 enum arm_reg_type type)
b99bd4ef 1227{
c19d1205
ZW
1228 /* Alternative syntaxes are accepted for a few register classes. */
1229 switch (type)
1230 {
1231 case REG_TYPE_MVF:
1232 case REG_TYPE_MVD:
1233 case REG_TYPE_MVFX:
1234 case REG_TYPE_MVDX:
1235 /* Generic coprocessor register names are allowed for these. */
79134647 1236 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1237 return reg->number;
1238 break;
69b97547 1239
c19d1205
ZW
1240 case REG_TYPE_CP:
1241 /* For backward compatibility, a bare number is valid here. */
1242 {
1243 unsigned long processor = strtoul (start, ccp, 10);
1244 if (*ccp != start && processor <= 15)
1245 return processor;
1246 }
6057a28f 1247
c19d1205
ZW
1248 case REG_TYPE_MMXWC:
1249 /* WC includes WCG. ??? I'm not sure this is true for all
1250 instructions that take WC registers. */
79134647 1251 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1252 return reg->number;
6057a28f 1253 break;
c19d1205 1254
6057a28f 1255 default:
c19d1205 1256 break;
6057a28f
NC
1257 }
1258
dcbf9037
JB
1259 return FAIL;
1260}
1261
1262/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1263 return value is the register number or FAIL. */
1264
1265static int
1266arm_reg_parse (char **ccp, enum arm_reg_type type)
1267{
1268 char *start = *ccp;
1269 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1270 int ret;
1271
1272 /* Do not allow a scalar (reg+index) to parse as a register. */
1273 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1274 return FAIL;
1275
1276 if (reg && reg->type == type)
1277 return reg->number;
1278
1279 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1280 return ret;
1281
c19d1205
ZW
1282 *ccp = start;
1283 return FAIL;
1284}
69b97547 1285
dcbf9037
JB
1286/* Parse a Neon type specifier. *STR should point at the leading '.'
1287 character. Does no verification at this stage that the type fits the opcode
1288 properly. E.g.,
1289
1290 .i32.i32.s16
1291 .s32.f32
1292 .u16
1293
1294 Can all be legally parsed by this function.
1295
1296 Fills in neon_type struct pointer with parsed information, and updates STR
1297 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1298 type, FAIL if not. */
1299
1300static int
1301parse_neon_type (struct neon_type *type, char **str)
1302{
1303 char *ptr = *str;
1304
1305 if (type)
1306 type->elems = 0;
1307
1308 while (type->elems < NEON_MAX_TYPE_ELS)
1309 {
1310 enum neon_el_type thistype = NT_untyped;
1311 unsigned thissize = -1u;
1312
1313 if (*ptr != '.')
1314 break;
1315
1316 ptr++;
1317
1318 /* Just a size without an explicit type. */
1319 if (ISDIGIT (*ptr))
1320 goto parsesize;
1321
1322 switch (TOLOWER (*ptr))
1323 {
1324 case 'i': thistype = NT_integer; break;
1325 case 'f': thistype = NT_float; break;
1326 case 'p': thistype = NT_poly; break;
1327 case 's': thistype = NT_signed; break;
1328 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1329 case 'd':
1330 thistype = NT_float;
1331 thissize = 64;
1332 ptr++;
1333 goto done;
dcbf9037
JB
1334 default:
1335 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1336 return FAIL;
1337 }
1338
1339 ptr++;
1340
1341 /* .f is an abbreviation for .f32. */
1342 if (thistype == NT_float && !ISDIGIT (*ptr))
1343 thissize = 32;
1344 else
1345 {
1346 parsesize:
1347 thissize = strtoul (ptr, &ptr, 10);
1348
1349 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1350 && thissize != 64)
1351 {
1352 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1353 return FAIL;
1354 }
1355 }
1356
037e8744 1357 done:
dcbf9037 1358 if (type)
477330fc
RM
1359 {
1360 type->el[type->elems].type = thistype;
dcbf9037
JB
1361 type->el[type->elems].size = thissize;
1362 type->elems++;
1363 }
1364 }
1365
1366 /* Empty/missing type is not a successful parse. */
1367 if (type->elems == 0)
1368 return FAIL;
1369
1370 *str = ptr;
1371
1372 return SUCCESS;
1373}
1374
1375/* Errors may be set multiple times during parsing or bit encoding
1376 (particularly in the Neon bits), but usually the earliest error which is set
1377 will be the most meaningful. Avoid overwriting it with later (cascading)
1378 errors by calling this function. */
1379
1380static void
1381first_error (const char *err)
1382{
1383 if (!inst.error)
1384 inst.error = err;
1385}
1386
1387/* Parse a single type, e.g. ".s32", leading period included. */
1388static int
1389parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1390{
1391 char *str = *ccp;
1392 struct neon_type optype;
1393
1394 if (*str == '.')
1395 {
1396 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1397 {
1398 if (optype.elems == 1)
1399 *vectype = optype.el[0];
1400 else
1401 {
1402 first_error (_("only one type should be specified for operand"));
1403 return FAIL;
1404 }
1405 }
dcbf9037 1406 else
477330fc
RM
1407 {
1408 first_error (_("vector type expected"));
1409 return FAIL;
1410 }
dcbf9037
JB
1411 }
1412 else
1413 return FAIL;
5f4273c7 1414
dcbf9037 1415 *ccp = str;
5f4273c7 1416
dcbf9037
JB
1417 return SUCCESS;
1418}
1419
1420/* Special meanings for indices (which have a range of 0-7), which will fit into
1421 a 4-bit integer. */
1422
1423#define NEON_ALL_LANES 15
1424#define NEON_INTERLEAVE_LANES 14
1425
1426/* Parse either a register or a scalar, with an optional type. Return the
1427 register number, and optionally fill in the actual type of the register
1428 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1429 type/index information in *TYPEINFO. */
1430
1431static int
1432parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1433 enum arm_reg_type *rtype,
1434 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1435{
1436 char *str = *ccp;
1437 struct reg_entry *reg = arm_reg_parse_multi (&str);
1438 struct neon_typed_alias atype;
1439 struct neon_type_el parsetype;
1440
1441 atype.defined = 0;
1442 atype.index = -1;
1443 atype.eltype.type = NT_invtype;
1444 atype.eltype.size = -1;
1445
1446 /* Try alternate syntax for some types of register. Note these are mutually
1447 exclusive with the Neon syntax extensions. */
1448 if (reg == NULL)
1449 {
1450 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1451 if (altreg != FAIL)
477330fc 1452 *ccp = str;
dcbf9037 1453 if (typeinfo)
477330fc 1454 *typeinfo = atype;
dcbf9037
JB
1455 return altreg;
1456 }
1457
037e8744
JB
1458 /* Undo polymorphism when a set of register types may be accepted. */
1459 if ((type == REG_TYPE_NDQ
1460 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1461 || (type == REG_TYPE_VFSD
477330fc 1462 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1463 || (type == REG_TYPE_NSDQ
477330fc
RM
1464 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1465 || reg->type == REG_TYPE_NQ))
f512f76f
NC
1466 || (type == REG_TYPE_MMXWC
1467 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1468 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1469
1470 if (type != reg->type)
1471 return FAIL;
1472
1473 if (reg->neon)
1474 atype = *reg->neon;
5f4273c7 1475
dcbf9037
JB
1476 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1477 {
1478 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1479 {
1480 first_error (_("can't redefine type for operand"));
1481 return FAIL;
1482 }
dcbf9037
JB
1483 atype.defined |= NTA_HASTYPE;
1484 atype.eltype = parsetype;
1485 }
5f4273c7 1486
dcbf9037
JB
1487 if (skip_past_char (&str, '[') == SUCCESS)
1488 {
1489 if (type != REG_TYPE_VFD)
477330fc
RM
1490 {
1491 first_error (_("only D registers may be indexed"));
1492 return FAIL;
1493 }
5f4273c7 1494
dcbf9037 1495 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1496 {
1497 first_error (_("can't change index for operand"));
1498 return FAIL;
1499 }
dcbf9037
JB
1500
1501 atype.defined |= NTA_HASINDEX;
1502
1503 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1504 atype.index = NEON_ALL_LANES;
dcbf9037 1505 else
477330fc
RM
1506 {
1507 expressionS exp;
dcbf9037 1508
477330fc 1509 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1510
477330fc
RM
1511 if (exp.X_op != O_constant)
1512 {
1513 first_error (_("constant expression required"));
1514 return FAIL;
1515 }
dcbf9037 1516
477330fc
RM
1517 if (skip_past_char (&str, ']') == FAIL)
1518 return FAIL;
dcbf9037 1519
477330fc
RM
1520 atype.index = exp.X_add_number;
1521 }
dcbf9037 1522 }
5f4273c7 1523
dcbf9037
JB
1524 if (typeinfo)
1525 *typeinfo = atype;
5f4273c7 1526
dcbf9037
JB
1527 if (rtype)
1528 *rtype = type;
5f4273c7 1529
dcbf9037 1530 *ccp = str;
5f4273c7 1531
dcbf9037
JB
1532 return reg->number;
1533}
1534
1535/* Like arm_reg_parse, but allow allow the following extra features:
1536 - If RTYPE is non-zero, return the (possibly restricted) type of the
1537 register (e.g. Neon double or quad reg when either has been requested).
1538 - If this is a Neon vector type with additional type information, fill
1539 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1540 This function will fault on encountering a scalar. */
dcbf9037
JB
1541
1542static int
1543arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1544 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1545{
1546 struct neon_typed_alias atype;
1547 char *str = *ccp;
1548 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1549
1550 if (reg == FAIL)
1551 return FAIL;
1552
0855e32b
NS
1553 /* Do not allow regname(... to parse as a register. */
1554 if (*str == '(')
1555 return FAIL;
1556
dcbf9037
JB
1557 /* Do not allow a scalar (reg+index) to parse as a register. */
1558 if ((atype.defined & NTA_HASINDEX) != 0)
1559 {
1560 first_error (_("register operand expected, but got scalar"));
1561 return FAIL;
1562 }
1563
1564 if (vectype)
1565 *vectype = atype.eltype;
1566
1567 *ccp = str;
1568
1569 return reg;
1570}
1571
1572#define NEON_SCALAR_REG(X) ((X) >> 4)
1573#define NEON_SCALAR_INDEX(X) ((X) & 15)
1574
5287ad62
JB
1575/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1576 have enough information to be able to do a good job bounds-checking. So, we
1577 just do easy checks here, and do further checks later. */
1578
1579static int
dcbf9037 1580parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1581{
dcbf9037 1582 int reg;
5287ad62 1583 char *str = *ccp;
dcbf9037 1584 struct neon_typed_alias atype;
5f4273c7 1585
dcbf9037 1586 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1587
dcbf9037 1588 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1589 return FAIL;
5f4273c7 1590
dcbf9037 1591 if (atype.index == NEON_ALL_LANES)
5287ad62 1592 {
dcbf9037 1593 first_error (_("scalar must have an index"));
5287ad62
JB
1594 return FAIL;
1595 }
dcbf9037 1596 else if (atype.index >= 64 / elsize)
5287ad62 1597 {
dcbf9037 1598 first_error (_("scalar index out of range"));
5287ad62
JB
1599 return FAIL;
1600 }
5f4273c7 1601
dcbf9037
JB
1602 if (type)
1603 *type = atype.eltype;
5f4273c7 1604
5287ad62 1605 *ccp = str;
5f4273c7 1606
dcbf9037 1607 return reg * 16 + atype.index;
5287ad62
JB
1608}
1609
c19d1205 1610/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1611
c19d1205
ZW
1612static long
1613parse_reg_list (char ** strp)
1614{
1615 char * str = * strp;
1616 long range = 0;
1617 int another_range;
a737bd4d 1618
c19d1205
ZW
1619 /* We come back here if we get ranges concatenated by '+' or '|'. */
1620 do
6057a28f 1621 {
477330fc
RM
1622 skip_whitespace (str);
1623
c19d1205 1624 another_range = 0;
a737bd4d 1625
c19d1205
ZW
1626 if (*str == '{')
1627 {
1628 int in_range = 0;
1629 int cur_reg = -1;
a737bd4d 1630
c19d1205
ZW
1631 str++;
1632 do
1633 {
1634 int reg;
6057a28f 1635
dcbf9037 1636 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1637 {
dcbf9037 1638 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1639 return FAIL;
1640 }
a737bd4d 1641
c19d1205
ZW
1642 if (in_range)
1643 {
1644 int i;
a737bd4d 1645
c19d1205
ZW
1646 if (reg <= cur_reg)
1647 {
dcbf9037 1648 first_error (_("bad range in register list"));
c19d1205
ZW
1649 return FAIL;
1650 }
40a18ebd 1651
c19d1205
ZW
1652 for (i = cur_reg + 1; i < reg; i++)
1653 {
1654 if (range & (1 << i))
1655 as_tsktsk
1656 (_("Warning: duplicated register (r%d) in register list"),
1657 i);
1658 else
1659 range |= 1 << i;
1660 }
1661 in_range = 0;
1662 }
a737bd4d 1663
c19d1205
ZW
1664 if (range & (1 << reg))
1665 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1666 reg);
1667 else if (reg <= cur_reg)
1668 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1669
c19d1205
ZW
1670 range |= 1 << reg;
1671 cur_reg = reg;
1672 }
1673 while (skip_past_comma (&str) != FAIL
1674 || (in_range = 1, *str++ == '-'));
1675 str--;
a737bd4d 1676
d996d970 1677 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1678 {
dcbf9037 1679 first_error (_("missing `}'"));
c19d1205
ZW
1680 return FAIL;
1681 }
1682 }
1683 else
1684 {
91d6fa6a 1685 expressionS exp;
40a18ebd 1686
91d6fa6a 1687 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1688 return FAIL;
40a18ebd 1689
91d6fa6a 1690 if (exp.X_op == O_constant)
c19d1205 1691 {
91d6fa6a
NC
1692 if (exp.X_add_number
1693 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1694 {
1695 inst.error = _("invalid register mask");
1696 return FAIL;
1697 }
a737bd4d 1698
91d6fa6a 1699 if ((range & exp.X_add_number) != 0)
c19d1205 1700 {
91d6fa6a 1701 int regno = range & exp.X_add_number;
a737bd4d 1702
c19d1205
ZW
1703 regno &= -regno;
1704 regno = (1 << regno) - 1;
1705 as_tsktsk
1706 (_("Warning: duplicated register (r%d) in register list"),
1707 regno);
1708 }
a737bd4d 1709
91d6fa6a 1710 range |= exp.X_add_number;
c19d1205
ZW
1711 }
1712 else
1713 {
1714 if (inst.reloc.type != 0)
1715 {
1716 inst.error = _("expression too complex");
1717 return FAIL;
1718 }
a737bd4d 1719
91d6fa6a 1720 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1721 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1722 inst.reloc.pc_rel = 0;
1723 }
1724 }
a737bd4d 1725
c19d1205
ZW
1726 if (*str == '|' || *str == '+')
1727 {
1728 str++;
1729 another_range = 1;
1730 }
a737bd4d 1731 }
c19d1205 1732 while (another_range);
a737bd4d 1733
c19d1205
ZW
1734 *strp = str;
1735 return range;
a737bd4d
NC
1736}
1737
5287ad62
JB
1738/* Types of registers in a list. */
1739
1740enum reg_list_els
1741{
1742 REGLIST_VFP_S,
1743 REGLIST_VFP_D,
1744 REGLIST_NEON_D
1745};
1746
c19d1205
ZW
1747/* Parse a VFP register list. If the string is invalid return FAIL.
1748 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1749 register. Parses registers of type ETYPE.
1750 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1751 - Q registers can be used to specify pairs of D registers
1752 - { } can be omitted from around a singleton register list
477330fc
RM
1753 FIXME: This is not implemented, as it would require backtracking in
1754 some cases, e.g.:
1755 vtbl.8 d3,d4,d5
1756 This could be done (the meaning isn't really ambiguous), but doesn't
1757 fit in well with the current parsing framework.
dcbf9037
JB
1758 - 32 D registers may be used (also true for VFPv3).
1759 FIXME: Types are ignored in these register lists, which is probably a
1760 bug. */
6057a28f 1761
c19d1205 1762static int
037e8744 1763parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1764{
037e8744 1765 char *str = *ccp;
c19d1205
ZW
1766 int base_reg;
1767 int new_base;
21d799b5 1768 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1769 int max_regs = 0;
c19d1205
ZW
1770 int count = 0;
1771 int warned = 0;
1772 unsigned long mask = 0;
a737bd4d 1773 int i;
6057a28f 1774
477330fc 1775 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1776 {
1777 inst.error = _("expecting {");
1778 return FAIL;
1779 }
6057a28f 1780
5287ad62 1781 switch (etype)
c19d1205 1782 {
5287ad62 1783 case REGLIST_VFP_S:
c19d1205
ZW
1784 regtype = REG_TYPE_VFS;
1785 max_regs = 32;
5287ad62 1786 break;
5f4273c7 1787
5287ad62
JB
1788 case REGLIST_VFP_D:
1789 regtype = REG_TYPE_VFD;
b7fc2769 1790 break;
5f4273c7 1791
b7fc2769
JB
1792 case REGLIST_NEON_D:
1793 regtype = REG_TYPE_NDQ;
1794 break;
1795 }
1796
1797 if (etype != REGLIST_VFP_S)
1798 {
b1cc4aeb
PB
1799 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1800 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1801 {
1802 max_regs = 32;
1803 if (thumb_mode)
1804 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1805 fpu_vfp_ext_d32);
1806 else
1807 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1808 fpu_vfp_ext_d32);
1809 }
5287ad62 1810 else
477330fc 1811 max_regs = 16;
c19d1205 1812 }
6057a28f 1813
c19d1205 1814 base_reg = max_regs;
a737bd4d 1815
c19d1205
ZW
1816 do
1817 {
5287ad62 1818 int setmask = 1, addregs = 1;
dcbf9037 1819
037e8744 1820 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1821
c19d1205 1822 if (new_base == FAIL)
a737bd4d 1823 {
dcbf9037 1824 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1825 return FAIL;
1826 }
5f4273c7 1827
b7fc2769 1828 if (new_base >= max_regs)
477330fc
RM
1829 {
1830 first_error (_("register out of range in list"));
1831 return FAIL;
1832 }
5f4273c7 1833
5287ad62
JB
1834 /* Note: a value of 2 * n is returned for the register Q<n>. */
1835 if (regtype == REG_TYPE_NQ)
477330fc
RM
1836 {
1837 setmask = 3;
1838 addregs = 2;
1839 }
5287ad62 1840
c19d1205
ZW
1841 if (new_base < base_reg)
1842 base_reg = new_base;
a737bd4d 1843
5287ad62 1844 if (mask & (setmask << new_base))
c19d1205 1845 {
dcbf9037 1846 first_error (_("invalid register list"));
c19d1205 1847 return FAIL;
a737bd4d 1848 }
a737bd4d 1849
c19d1205
ZW
1850 if ((mask >> new_base) != 0 && ! warned)
1851 {
1852 as_tsktsk (_("register list not in ascending order"));
1853 warned = 1;
1854 }
0bbf2aa4 1855
5287ad62
JB
1856 mask |= setmask << new_base;
1857 count += addregs;
0bbf2aa4 1858
037e8744 1859 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1860 {
1861 int high_range;
0bbf2aa4 1862
037e8744 1863 str++;
0bbf2aa4 1864
037e8744 1865 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1866 == FAIL)
c19d1205
ZW
1867 {
1868 inst.error = gettext (reg_expected_msgs[regtype]);
1869 return FAIL;
1870 }
0bbf2aa4 1871
477330fc
RM
1872 if (high_range >= max_regs)
1873 {
1874 first_error (_("register out of range in list"));
1875 return FAIL;
1876 }
b7fc2769 1877
477330fc
RM
1878 if (regtype == REG_TYPE_NQ)
1879 high_range = high_range + 1;
5287ad62 1880
c19d1205
ZW
1881 if (high_range <= new_base)
1882 {
1883 inst.error = _("register range not in ascending order");
1884 return FAIL;
1885 }
0bbf2aa4 1886
5287ad62 1887 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1888 {
5287ad62 1889 if (mask & (setmask << new_base))
0bbf2aa4 1890 {
c19d1205
ZW
1891 inst.error = _("invalid register list");
1892 return FAIL;
0bbf2aa4 1893 }
c19d1205 1894
5287ad62
JB
1895 mask |= setmask << new_base;
1896 count += addregs;
0bbf2aa4 1897 }
0bbf2aa4 1898 }
0bbf2aa4 1899 }
037e8744 1900 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1901
037e8744 1902 str++;
0bbf2aa4 1903
c19d1205
ZW
1904 /* Sanity check -- should have raised a parse error above. */
1905 if (count == 0 || count > max_regs)
1906 abort ();
1907
1908 *pbase = base_reg;
1909
1910 /* Final test -- the registers must be consecutive. */
1911 mask >>= base_reg;
1912 for (i = 0; i < count; i++)
1913 {
1914 if ((mask & (1u << i)) == 0)
1915 {
1916 inst.error = _("non-contiguous register range");
1917 return FAIL;
1918 }
1919 }
1920
037e8744
JB
1921 *ccp = str;
1922
c19d1205 1923 return count;
b99bd4ef
NC
1924}
1925
dcbf9037
JB
1926/* True if two alias types are the same. */
1927
c921be7d 1928static bfd_boolean
dcbf9037
JB
1929neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1930{
1931 if (!a && !b)
c921be7d 1932 return TRUE;
5f4273c7 1933
dcbf9037 1934 if (!a || !b)
c921be7d 1935 return FALSE;
dcbf9037
JB
1936
1937 if (a->defined != b->defined)
c921be7d 1938 return FALSE;
5f4273c7 1939
dcbf9037
JB
1940 if ((a->defined & NTA_HASTYPE) != 0
1941 && (a->eltype.type != b->eltype.type
477330fc 1942 || a->eltype.size != b->eltype.size))
c921be7d 1943 return FALSE;
dcbf9037
JB
1944
1945 if ((a->defined & NTA_HASINDEX) != 0
1946 && (a->index != b->index))
c921be7d 1947 return FALSE;
5f4273c7 1948
c921be7d 1949 return TRUE;
dcbf9037
JB
1950}
1951
5287ad62
JB
1952/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1953 The base register is put in *PBASE.
dcbf9037 1954 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1955 the return value.
1956 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1957 Bits [6:5] encode the list length (minus one).
1958 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1959
5287ad62 1960#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1961#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1962#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1963
1964static int
dcbf9037 1965parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 1966 struct neon_type_el *eltype)
5287ad62
JB
1967{
1968 char *ptr = *str;
1969 int base_reg = -1;
1970 int reg_incr = -1;
1971 int count = 0;
1972 int lane = -1;
1973 int leading_brace = 0;
1974 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
1975 const char *const incr_error = _("register stride must be 1 or 2");
1976 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1977 struct neon_typed_alias firsttype;
5f4273c7 1978
5287ad62
JB
1979 if (skip_past_char (&ptr, '{') == SUCCESS)
1980 leading_brace = 1;
5f4273c7 1981
5287ad62
JB
1982 do
1983 {
dcbf9037
JB
1984 struct neon_typed_alias atype;
1985 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1986
5287ad62 1987 if (getreg == FAIL)
477330fc
RM
1988 {
1989 first_error (_(reg_expected_msgs[rtype]));
1990 return FAIL;
1991 }
5f4273c7 1992
5287ad62 1993 if (base_reg == -1)
477330fc
RM
1994 {
1995 base_reg = getreg;
1996 if (rtype == REG_TYPE_NQ)
1997 {
1998 reg_incr = 1;
1999 }
2000 firsttype = atype;
2001 }
5287ad62 2002 else if (reg_incr == -1)
477330fc
RM
2003 {
2004 reg_incr = getreg - base_reg;
2005 if (reg_incr < 1 || reg_incr > 2)
2006 {
2007 first_error (_(incr_error));
2008 return FAIL;
2009 }
2010 }
5287ad62 2011 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2012 {
2013 first_error (_(incr_error));
2014 return FAIL;
2015 }
dcbf9037 2016
c921be7d 2017 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2018 {
2019 first_error (_(type_error));
2020 return FAIL;
2021 }
5f4273c7 2022
5287ad62 2023 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2024 modes. */
5287ad62 2025 if (ptr[0] == '-')
477330fc
RM
2026 {
2027 struct neon_typed_alias htype;
2028 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2029 if (lane == -1)
2030 lane = NEON_INTERLEAVE_LANES;
2031 else if (lane != NEON_INTERLEAVE_LANES)
2032 {
2033 first_error (_(type_error));
2034 return FAIL;
2035 }
2036 if (reg_incr == -1)
2037 reg_incr = 1;
2038 else if (reg_incr != 1)
2039 {
2040 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2041 return FAIL;
2042 }
2043 ptr++;
2044 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2045 if (hireg == FAIL)
2046 {
2047 first_error (_(reg_expected_msgs[rtype]));
2048 return FAIL;
2049 }
2050 if (! neon_alias_types_same (&htype, &firsttype))
2051 {
2052 first_error (_(type_error));
2053 return FAIL;
2054 }
2055 count += hireg + dregs - getreg;
2056 continue;
2057 }
5f4273c7 2058
5287ad62
JB
2059 /* If we're using Q registers, we can't use [] or [n] syntax. */
2060 if (rtype == REG_TYPE_NQ)
477330fc
RM
2061 {
2062 count += 2;
2063 continue;
2064 }
5f4273c7 2065
dcbf9037 2066 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2067 {
2068 if (lane == -1)
2069 lane = atype.index;
2070 else if (lane != atype.index)
2071 {
2072 first_error (_(type_error));
2073 return FAIL;
2074 }
2075 }
5287ad62 2076 else if (lane == -1)
477330fc 2077 lane = NEON_INTERLEAVE_LANES;
5287ad62 2078 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2079 {
2080 first_error (_(type_error));
2081 return FAIL;
2082 }
5287ad62
JB
2083 count++;
2084 }
2085 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2086
5287ad62
JB
2087 /* No lane set by [x]. We must be interleaving structures. */
2088 if (lane == -1)
2089 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2090
5287ad62
JB
2091 /* Sanity check. */
2092 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2093 || (count > 1 && reg_incr == -1))
2094 {
dcbf9037 2095 first_error (_("error parsing element/structure list"));
5287ad62
JB
2096 return FAIL;
2097 }
2098
2099 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2100 {
dcbf9037 2101 first_error (_("expected }"));
5287ad62
JB
2102 return FAIL;
2103 }
5f4273c7 2104
5287ad62
JB
2105 if (reg_incr == -1)
2106 reg_incr = 1;
2107
dcbf9037
JB
2108 if (eltype)
2109 *eltype = firsttype.eltype;
2110
5287ad62
JB
2111 *pbase = base_reg;
2112 *str = ptr;
5f4273c7 2113
5287ad62
JB
2114 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2115}
2116
c19d1205
ZW
2117/* Parse an explicit relocation suffix on an expression. This is
2118 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2119 arm_reloc_hsh contains no entries, so this function can only
2120 succeed if there is no () after the word. Returns -1 on error,
2121 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2122
c19d1205
ZW
2123static int
2124parse_reloc (char **str)
b99bd4ef 2125{
c19d1205
ZW
2126 struct reloc_entry *r;
2127 char *p, *q;
b99bd4ef 2128
c19d1205
ZW
2129 if (**str != '(')
2130 return BFD_RELOC_UNUSED;
b99bd4ef 2131
c19d1205
ZW
2132 p = *str + 1;
2133 q = p;
2134
2135 while (*q && *q != ')' && *q != ',')
2136 q++;
2137 if (*q != ')')
2138 return -1;
2139
21d799b5
NC
2140 if ((r = (struct reloc_entry *)
2141 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2142 return -1;
2143
2144 *str = q + 1;
2145 return r->reloc;
b99bd4ef
NC
2146}
2147
c19d1205
ZW
2148/* Directives: register aliases. */
2149
dcbf9037 2150static struct reg_entry *
90ec0d68 2151insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2152{
d3ce72d0 2153 struct reg_entry *new_reg;
c19d1205 2154 const char *name;
b99bd4ef 2155
d3ce72d0 2156 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2157 {
d3ce72d0 2158 if (new_reg->builtin)
c19d1205 2159 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2160
c19d1205
ZW
2161 /* Only warn about a redefinition if it's not defined as the
2162 same register. */
d3ce72d0 2163 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2164 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2165
d929913e 2166 return NULL;
c19d1205 2167 }
b99bd4ef 2168
c19d1205 2169 name = xstrdup (str);
d3ce72d0 2170 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
b99bd4ef 2171
d3ce72d0
NC
2172 new_reg->name = name;
2173 new_reg->number = number;
2174 new_reg->type = type;
2175 new_reg->builtin = FALSE;
2176 new_reg->neon = NULL;
b99bd4ef 2177
d3ce72d0 2178 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2179 abort ();
5f4273c7 2180
d3ce72d0 2181 return new_reg;
dcbf9037
JB
2182}
2183
2184static void
2185insert_neon_reg_alias (char *str, int number, int type,
477330fc 2186 struct neon_typed_alias *atype)
dcbf9037
JB
2187{
2188 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2189
dcbf9037
JB
2190 if (!reg)
2191 {
2192 first_error (_("attempt to redefine typed alias"));
2193 return;
2194 }
5f4273c7 2195
dcbf9037
JB
2196 if (atype)
2197 {
21d799b5 2198 reg->neon = (struct neon_typed_alias *)
477330fc 2199 xmalloc (sizeof (struct neon_typed_alias));
dcbf9037
JB
2200 *reg->neon = *atype;
2201 }
c19d1205 2202}
b99bd4ef 2203
c19d1205 2204/* Look for the .req directive. This is of the form:
b99bd4ef 2205
c19d1205 2206 new_register_name .req existing_register_name
b99bd4ef 2207
c19d1205 2208 If we find one, or if it looks sufficiently like one that we want to
d929913e 2209 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2210
d929913e 2211static bfd_boolean
c19d1205
ZW
2212create_register_alias (char * newname, char *p)
2213{
2214 struct reg_entry *old;
2215 char *oldname, *nbuf;
2216 size_t nlen;
b99bd4ef 2217
c19d1205
ZW
2218 /* The input scrubber ensures that whitespace after the mnemonic is
2219 collapsed to single spaces. */
2220 oldname = p;
2221 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2222 return FALSE;
b99bd4ef 2223
c19d1205
ZW
2224 oldname += 6;
2225 if (*oldname == '\0')
d929913e 2226 return FALSE;
b99bd4ef 2227
21d799b5 2228 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2229 if (!old)
b99bd4ef 2230 {
c19d1205 2231 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2232 return TRUE;
b99bd4ef
NC
2233 }
2234
c19d1205
ZW
2235 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2236 the desired alias name, and p points to its end. If not, then
2237 the desired alias name is in the global original_case_string. */
2238#ifdef TC_CASE_SENSITIVE
2239 nlen = p - newname;
2240#else
2241 newname = original_case_string;
2242 nlen = strlen (newname);
2243#endif
b99bd4ef 2244
21d799b5 2245 nbuf = (char *) alloca (nlen + 1);
c19d1205
ZW
2246 memcpy (nbuf, newname, nlen);
2247 nbuf[nlen] = '\0';
b99bd4ef 2248
c19d1205
ZW
2249 /* Create aliases under the new name as stated; an all-lowercase
2250 version of the new name; and an all-uppercase version of the new
2251 name. */
d929913e
NC
2252 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2253 {
2254 for (p = nbuf; *p; p++)
2255 *p = TOUPPER (*p);
c19d1205 2256
d929913e
NC
2257 if (strncmp (nbuf, newname, nlen))
2258 {
2259 /* If this attempt to create an additional alias fails, do not bother
2260 trying to create the all-lower case alias. We will fail and issue
2261 a second, duplicate error message. This situation arises when the
2262 programmer does something like:
2263 foo .req r0
2264 Foo .req r1
2265 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2266 the artificial FOO alias because it has already been created by the
d929913e
NC
2267 first .req. */
2268 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2269 return TRUE;
2270 }
c19d1205 2271
d929913e
NC
2272 for (p = nbuf; *p; p++)
2273 *p = TOLOWER (*p);
c19d1205 2274
d929913e
NC
2275 if (strncmp (nbuf, newname, nlen))
2276 insert_reg_alias (nbuf, old->number, old->type);
2277 }
c19d1205 2278
d929913e 2279 return TRUE;
b99bd4ef
NC
2280}
2281
dcbf9037
JB
2282/* Create a Neon typed/indexed register alias using directives, e.g.:
2283 X .dn d5.s32[1]
2284 Y .qn 6.s16
2285 Z .dn d7
2286 T .dn Z[0]
2287 These typed registers can be used instead of the types specified after the
2288 Neon mnemonic, so long as all operands given have types. Types can also be
2289 specified directly, e.g.:
5f4273c7 2290 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2291
c921be7d 2292static bfd_boolean
dcbf9037
JB
2293create_neon_reg_alias (char *newname, char *p)
2294{
2295 enum arm_reg_type basetype;
2296 struct reg_entry *basereg;
2297 struct reg_entry mybasereg;
2298 struct neon_type ntype;
2299 struct neon_typed_alias typeinfo;
12d6b0b7 2300 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2301 int namelen;
5f4273c7 2302
dcbf9037
JB
2303 typeinfo.defined = 0;
2304 typeinfo.eltype.type = NT_invtype;
2305 typeinfo.eltype.size = -1;
2306 typeinfo.index = -1;
5f4273c7 2307
dcbf9037 2308 nameend = p;
5f4273c7 2309
dcbf9037
JB
2310 if (strncmp (p, " .dn ", 5) == 0)
2311 basetype = REG_TYPE_VFD;
2312 else if (strncmp (p, " .qn ", 5) == 0)
2313 basetype = REG_TYPE_NQ;
2314 else
c921be7d 2315 return FALSE;
5f4273c7 2316
dcbf9037 2317 p += 5;
5f4273c7 2318
dcbf9037 2319 if (*p == '\0')
c921be7d 2320 return FALSE;
5f4273c7 2321
dcbf9037
JB
2322 basereg = arm_reg_parse_multi (&p);
2323
2324 if (basereg && basereg->type != basetype)
2325 {
2326 as_bad (_("bad type for register"));
c921be7d 2327 return FALSE;
dcbf9037
JB
2328 }
2329
2330 if (basereg == NULL)
2331 {
2332 expressionS exp;
2333 /* Try parsing as an integer. */
2334 my_get_expression (&exp, &p, GE_NO_PREFIX);
2335 if (exp.X_op != O_constant)
477330fc
RM
2336 {
2337 as_bad (_("expression must be constant"));
2338 return FALSE;
2339 }
dcbf9037
JB
2340 basereg = &mybasereg;
2341 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2342 : exp.X_add_number;
dcbf9037
JB
2343 basereg->neon = 0;
2344 }
2345
2346 if (basereg->neon)
2347 typeinfo = *basereg->neon;
2348
2349 if (parse_neon_type (&ntype, &p) == SUCCESS)
2350 {
2351 /* We got a type. */
2352 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2353 {
2354 as_bad (_("can't redefine the type of a register alias"));
2355 return FALSE;
2356 }
5f4273c7 2357
dcbf9037
JB
2358 typeinfo.defined |= NTA_HASTYPE;
2359 if (ntype.elems != 1)
477330fc
RM
2360 {
2361 as_bad (_("you must specify a single type only"));
2362 return FALSE;
2363 }
dcbf9037
JB
2364 typeinfo.eltype = ntype.el[0];
2365 }
5f4273c7 2366
dcbf9037
JB
2367 if (skip_past_char (&p, '[') == SUCCESS)
2368 {
2369 expressionS exp;
2370 /* We got a scalar index. */
5f4273c7 2371
dcbf9037 2372 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2373 {
2374 as_bad (_("can't redefine the index of a scalar alias"));
2375 return FALSE;
2376 }
5f4273c7 2377
dcbf9037 2378 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2379
dcbf9037 2380 if (exp.X_op != O_constant)
477330fc
RM
2381 {
2382 as_bad (_("scalar index must be constant"));
2383 return FALSE;
2384 }
5f4273c7 2385
dcbf9037
JB
2386 typeinfo.defined |= NTA_HASINDEX;
2387 typeinfo.index = exp.X_add_number;
5f4273c7 2388
dcbf9037 2389 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2390 {
2391 as_bad (_("expecting ]"));
2392 return FALSE;
2393 }
dcbf9037
JB
2394 }
2395
15735687
NS
2396 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2397 the desired alias name, and p points to its end. If not, then
2398 the desired alias name is in the global original_case_string. */
2399#ifdef TC_CASE_SENSITIVE
dcbf9037 2400 namelen = nameend - newname;
15735687
NS
2401#else
2402 newname = original_case_string;
2403 namelen = strlen (newname);
2404#endif
2405
21d799b5 2406 namebuf = (char *) alloca (namelen + 1);
dcbf9037
JB
2407 strncpy (namebuf, newname, namelen);
2408 namebuf[namelen] = '\0';
5f4273c7 2409
dcbf9037 2410 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2411 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2412
dcbf9037
JB
2413 /* Insert name in all uppercase. */
2414 for (p = namebuf; *p; p++)
2415 *p = TOUPPER (*p);
5f4273c7 2416
dcbf9037
JB
2417 if (strncmp (namebuf, newname, namelen))
2418 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2419 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2420
dcbf9037
JB
2421 /* Insert name in all lowercase. */
2422 for (p = namebuf; *p; p++)
2423 *p = TOLOWER (*p);
5f4273c7 2424
dcbf9037
JB
2425 if (strncmp (namebuf, newname, namelen))
2426 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2427 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2428
c921be7d 2429 return TRUE;
dcbf9037
JB
2430}
2431
c19d1205
ZW
2432/* Should never be called, as .req goes between the alias and the
2433 register name, not at the beginning of the line. */
c921be7d 2434
b99bd4ef 2435static void
c19d1205 2436s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2437{
c19d1205
ZW
2438 as_bad (_("invalid syntax for .req directive"));
2439}
b99bd4ef 2440
dcbf9037
JB
2441static void
2442s_dn (int a ATTRIBUTE_UNUSED)
2443{
2444 as_bad (_("invalid syntax for .dn directive"));
2445}
2446
2447static void
2448s_qn (int a ATTRIBUTE_UNUSED)
2449{
2450 as_bad (_("invalid syntax for .qn directive"));
2451}
2452
c19d1205
ZW
2453/* The .unreq directive deletes an alias which was previously defined
2454 by .req. For example:
b99bd4ef 2455
c19d1205
ZW
2456 my_alias .req r11
2457 .unreq my_alias */
b99bd4ef
NC
2458
2459static void
c19d1205 2460s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2461{
c19d1205
ZW
2462 char * name;
2463 char saved_char;
b99bd4ef 2464
c19d1205
ZW
2465 name = input_line_pointer;
2466
2467 while (*input_line_pointer != 0
2468 && *input_line_pointer != ' '
2469 && *input_line_pointer != '\n')
2470 ++input_line_pointer;
2471
2472 saved_char = *input_line_pointer;
2473 *input_line_pointer = 0;
2474
2475 if (!*name)
2476 as_bad (_("invalid syntax for .unreq directive"));
2477 else
2478 {
21d799b5 2479 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2480 name);
c19d1205
ZW
2481
2482 if (!reg)
2483 as_bad (_("unknown register alias '%s'"), name);
2484 else if (reg->builtin)
a1727c1a 2485 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2486 name);
2487 else
2488 {
d929913e
NC
2489 char * p;
2490 char * nbuf;
2491
db0bc284 2492 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2493 free ((char *) reg->name);
477330fc
RM
2494 if (reg->neon)
2495 free (reg->neon);
c19d1205 2496 free (reg);
d929913e
NC
2497
2498 /* Also locate the all upper case and all lower case versions.
2499 Do not complain if we cannot find one or the other as it
2500 was probably deleted above. */
5f4273c7 2501
d929913e
NC
2502 nbuf = strdup (name);
2503 for (p = nbuf; *p; p++)
2504 *p = TOUPPER (*p);
21d799b5 2505 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2506 if (reg)
2507 {
db0bc284 2508 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2509 free ((char *) reg->name);
2510 if (reg->neon)
2511 free (reg->neon);
2512 free (reg);
2513 }
2514
2515 for (p = nbuf; *p; p++)
2516 *p = TOLOWER (*p);
21d799b5 2517 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2518 if (reg)
2519 {
db0bc284 2520 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2521 free ((char *) reg->name);
2522 if (reg->neon)
2523 free (reg->neon);
2524 free (reg);
2525 }
2526
2527 free (nbuf);
c19d1205
ZW
2528 }
2529 }
b99bd4ef 2530
c19d1205 2531 *input_line_pointer = saved_char;
b99bd4ef
NC
2532 demand_empty_rest_of_line ();
2533}
2534
c19d1205
ZW
2535/* Directives: Instruction set selection. */
2536
2537#ifdef OBJ_ELF
2538/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2539 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2540 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2541 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2542
cd000bff
DJ
2543/* Create a new mapping symbol for the transition to STATE. */
2544
2545static void
2546make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2547{
a737bd4d 2548 symbolS * symbolP;
c19d1205
ZW
2549 const char * symname;
2550 int type;
b99bd4ef 2551
c19d1205 2552 switch (state)
b99bd4ef 2553 {
c19d1205
ZW
2554 case MAP_DATA:
2555 symname = "$d";
2556 type = BSF_NO_FLAGS;
2557 break;
2558 case MAP_ARM:
2559 symname = "$a";
2560 type = BSF_NO_FLAGS;
2561 break;
2562 case MAP_THUMB:
2563 symname = "$t";
2564 type = BSF_NO_FLAGS;
2565 break;
c19d1205
ZW
2566 default:
2567 abort ();
2568 }
2569
cd000bff 2570 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2571 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2572
2573 switch (state)
2574 {
2575 case MAP_ARM:
2576 THUMB_SET_FUNC (symbolP, 0);
2577 ARM_SET_THUMB (symbolP, 0);
2578 ARM_SET_INTERWORK (symbolP, support_interwork);
2579 break;
2580
2581 case MAP_THUMB:
2582 THUMB_SET_FUNC (symbolP, 1);
2583 ARM_SET_THUMB (symbolP, 1);
2584 ARM_SET_INTERWORK (symbolP, support_interwork);
2585 break;
2586
2587 case MAP_DATA:
2588 default:
cd000bff
DJ
2589 break;
2590 }
2591
2592 /* Save the mapping symbols for future reference. Also check that
2593 we do not place two mapping symbols at the same offset within a
2594 frag. We'll handle overlap between frags in
2de7820f
JZ
2595 check_mapping_symbols.
2596
2597 If .fill or other data filling directive generates zero sized data,
2598 the mapping symbol for the following code will have the same value
2599 as the one generated for the data filling directive. In this case,
2600 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2601 if (value == 0)
2602 {
2de7820f
JZ
2603 if (frag->tc_frag_data.first_map != NULL)
2604 {
2605 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2606 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2607 }
cd000bff
DJ
2608 frag->tc_frag_data.first_map = symbolP;
2609 }
2610 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2611 {
2612 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2613 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2614 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2615 }
cd000bff
DJ
2616 frag->tc_frag_data.last_map = symbolP;
2617}
2618
2619/* We must sometimes convert a region marked as code to data during
2620 code alignment, if an odd number of bytes have to be padded. The
2621 code mapping symbol is pushed to an aligned address. */
2622
2623static void
2624insert_data_mapping_symbol (enum mstate state,
2625 valueT value, fragS *frag, offsetT bytes)
2626{
2627 /* If there was already a mapping symbol, remove it. */
2628 if (frag->tc_frag_data.last_map != NULL
2629 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2630 {
2631 symbolS *symp = frag->tc_frag_data.last_map;
2632
2633 if (value == 0)
2634 {
2635 know (frag->tc_frag_data.first_map == symp);
2636 frag->tc_frag_data.first_map = NULL;
2637 }
2638 frag->tc_frag_data.last_map = NULL;
2639 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2640 }
cd000bff
DJ
2641
2642 make_mapping_symbol (MAP_DATA, value, frag);
2643 make_mapping_symbol (state, value + bytes, frag);
2644}
2645
2646static void mapping_state_2 (enum mstate state, int max_chars);
2647
2648/* Set the mapping state to STATE. Only call this when about to
2649 emit some STATE bytes to the file. */
2650
4e9aaefb 2651#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2652void
2653mapping_state (enum mstate state)
2654{
940b5ce0
DJ
2655 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2656
cd000bff
DJ
2657 if (mapstate == state)
2658 /* The mapping symbol has already been emitted.
2659 There is nothing else to do. */
2660 return;
49c62a33
NC
2661
2662 if (state == MAP_ARM || state == MAP_THUMB)
2663 /* PR gas/12931
2664 All ARM instructions require 4-byte alignment.
2665 (Almost) all Thumb instructions require 2-byte alignment.
2666
2667 When emitting instructions into any section, mark the section
2668 appropriately.
2669
2670 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2671 but themselves require 2-byte alignment; this applies to some
2672 PC- relative forms. However, these cases will invovle implicit
2673 literal pool generation or an explicit .align >=2, both of
2674 which will cause the section to me marked with sufficient
2675 alignment. Thus, we don't handle those cases here. */
2676 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2677
2678 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2679 /* This case will be evaluated later. */
cd000bff 2680 return;
cd000bff
DJ
2681
2682 mapping_state_2 (state, 0);
cd000bff
DJ
2683}
2684
2685/* Same as mapping_state, but MAX_CHARS bytes have already been
2686 allocated. Put the mapping symbol that far back. */
2687
2688static void
2689mapping_state_2 (enum mstate state, int max_chars)
2690{
940b5ce0
DJ
2691 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2692
2693 if (!SEG_NORMAL (now_seg))
2694 return;
2695
cd000bff
DJ
2696 if (mapstate == state)
2697 /* The mapping symbol has already been emitted.
2698 There is nothing else to do. */
2699 return;
2700
4e9aaefb
SA
2701 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2702 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2703 {
2704 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2705 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2706
2707 if (add_symbol)
2708 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2709 }
2710
cd000bff
DJ
2711 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2712 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2713}
4e9aaefb 2714#undef TRANSITION
c19d1205 2715#else
d3106081
NS
2716#define mapping_state(x) ((void)0)
2717#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2718#endif
2719
2720/* Find the real, Thumb encoded start of a Thumb function. */
2721
4343666d 2722#ifdef OBJ_COFF
c19d1205
ZW
2723static symbolS *
2724find_real_start (symbolS * symbolP)
2725{
2726 char * real_start;
2727 const char * name = S_GET_NAME (symbolP);
2728 symbolS * new_target;
2729
2730 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2731#define STUB_NAME ".real_start_of"
2732
2733 if (name == NULL)
2734 abort ();
2735
37f6032b
ZW
2736 /* The compiler may generate BL instructions to local labels because
2737 it needs to perform a branch to a far away location. These labels
2738 do not have a corresponding ".real_start_of" label. We check
2739 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2740 the ".real_start_of" convention for nonlocal branches. */
2741 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2742 return symbolP;
2743
37f6032b 2744 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2745 new_target = symbol_find (real_start);
2746
2747 if (new_target == NULL)
2748 {
bd3ba5d1 2749 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2750 new_target = symbolP;
2751 }
2752
c19d1205
ZW
2753 return new_target;
2754}
4343666d 2755#endif
c19d1205
ZW
2756
2757static void
2758opcode_select (int width)
2759{
2760 switch (width)
2761 {
2762 case 16:
2763 if (! thumb_mode)
2764 {
e74cfd16 2765 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2766 as_bad (_("selected processor does not support THUMB opcodes"));
2767
2768 thumb_mode = 1;
2769 /* No need to force the alignment, since we will have been
2770 coming from ARM mode, which is word-aligned. */
2771 record_alignment (now_seg, 1);
2772 }
c19d1205
ZW
2773 break;
2774
2775 case 32:
2776 if (thumb_mode)
2777 {
e74cfd16 2778 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2779 as_bad (_("selected processor does not support ARM opcodes"));
2780
2781 thumb_mode = 0;
2782
2783 if (!need_pass_2)
2784 frag_align (2, 0, 0);
2785
2786 record_alignment (now_seg, 1);
2787 }
c19d1205
ZW
2788 break;
2789
2790 default:
2791 as_bad (_("invalid instruction size selected (%d)"), width);
2792 }
2793}
2794
2795static void
2796s_arm (int ignore ATTRIBUTE_UNUSED)
2797{
2798 opcode_select (32);
2799 demand_empty_rest_of_line ();
2800}
2801
2802static void
2803s_thumb (int ignore ATTRIBUTE_UNUSED)
2804{
2805 opcode_select (16);
2806 demand_empty_rest_of_line ();
2807}
2808
2809static void
2810s_code (int unused ATTRIBUTE_UNUSED)
2811{
2812 int temp;
2813
2814 temp = get_absolute_expression ();
2815 switch (temp)
2816 {
2817 case 16:
2818 case 32:
2819 opcode_select (temp);
2820 break;
2821
2822 default:
2823 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2824 }
2825}
2826
2827static void
2828s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2829{
2830 /* If we are not already in thumb mode go into it, EVEN if
2831 the target processor does not support thumb instructions.
2832 This is used by gcc/config/arm/lib1funcs.asm for example
2833 to compile interworking support functions even if the
2834 target processor should not support interworking. */
2835 if (! thumb_mode)
2836 {
2837 thumb_mode = 2;
2838 record_alignment (now_seg, 1);
2839 }
2840
2841 demand_empty_rest_of_line ();
2842}
2843
2844static void
2845s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2846{
2847 s_thumb (0);
2848
2849 /* The following label is the name/address of the start of a Thumb function.
2850 We need to know this for the interworking support. */
2851 label_is_thumb_function_name = TRUE;
2852}
2853
2854/* Perform a .set directive, but also mark the alias as
2855 being a thumb function. */
2856
2857static void
2858s_thumb_set (int equiv)
2859{
2860 /* XXX the following is a duplicate of the code for s_set() in read.c
2861 We cannot just call that code as we need to get at the symbol that
2862 is created. */
2863 char * name;
2864 char delim;
2865 char * end_name;
2866 symbolS * symbolP;
2867
2868 /* Especial apologies for the random logic:
2869 This just grew, and could be parsed much more simply!
2870 Dean - in haste. */
2871 name = input_line_pointer;
2872 delim = get_symbol_end ();
2873 end_name = input_line_pointer;
2874 *end_name = delim;
2875
2876 if (*input_line_pointer != ',')
2877 {
2878 *end_name = 0;
2879 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2880 *end_name = delim;
2881 ignore_rest_of_line ();
2882 return;
2883 }
2884
2885 input_line_pointer++;
2886 *end_name = 0;
2887
2888 if (name[0] == '.' && name[1] == '\0')
2889 {
2890 /* XXX - this should not happen to .thumb_set. */
2891 abort ();
2892 }
2893
2894 if ((symbolP = symbol_find (name)) == NULL
2895 && (symbolP = md_undefined_symbol (name)) == NULL)
2896 {
2897#ifndef NO_LISTING
2898 /* When doing symbol listings, play games with dummy fragments living
2899 outside the normal fragment chain to record the file and line info
c19d1205 2900 for this symbol. */
b99bd4ef
NC
2901 if (listing & LISTING_SYMBOLS)
2902 {
2903 extern struct list_info_struct * listing_tail;
21d799b5 2904 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2905
2906 memset (dummy_frag, 0, sizeof (fragS));
2907 dummy_frag->fr_type = rs_fill;
2908 dummy_frag->line = listing_tail;
2909 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2910 dummy_frag->fr_symbol = symbolP;
2911 }
2912 else
2913#endif
2914 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2915
2916#ifdef OBJ_COFF
2917 /* "set" symbols are local unless otherwise specified. */
2918 SF_SET_LOCAL (symbolP);
2919#endif /* OBJ_COFF */
2920 } /* Make a new symbol. */
2921
2922 symbol_table_insert (symbolP);
2923
2924 * end_name = delim;
2925
2926 if (equiv
2927 && S_IS_DEFINED (symbolP)
2928 && S_GET_SEGMENT (symbolP) != reg_section)
2929 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2930
2931 pseudo_set (symbolP);
2932
2933 demand_empty_rest_of_line ();
2934
c19d1205 2935 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2936
2937 THUMB_SET_FUNC (symbolP, 1);
2938 ARM_SET_THUMB (symbolP, 1);
2939#if defined OBJ_ELF || defined OBJ_COFF
2940 ARM_SET_INTERWORK (symbolP, support_interwork);
2941#endif
2942}
2943
c19d1205 2944/* Directives: Mode selection. */
b99bd4ef 2945
c19d1205
ZW
2946/* .syntax [unified|divided] - choose the new unified syntax
2947 (same for Arm and Thumb encoding, modulo slight differences in what
2948 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2949static void
c19d1205 2950s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2951{
c19d1205
ZW
2952 char *name, delim;
2953
2954 name = input_line_pointer;
2955 delim = get_symbol_end ();
2956
2957 if (!strcasecmp (name, "unified"))
2958 unified_syntax = TRUE;
2959 else if (!strcasecmp (name, "divided"))
2960 unified_syntax = FALSE;
2961 else
2962 {
2963 as_bad (_("unrecognized syntax mode \"%s\""), name);
2964 return;
2965 }
2966 *input_line_pointer = delim;
b99bd4ef
NC
2967 demand_empty_rest_of_line ();
2968}
2969
c19d1205
ZW
2970/* Directives: sectioning and alignment. */
2971
2972/* Same as s_align_ptwo but align 0 => align 2. */
2973
b99bd4ef 2974static void
c19d1205 2975s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2976{
a737bd4d 2977 int temp;
dce323d1 2978 bfd_boolean fill_p;
c19d1205
ZW
2979 long temp_fill;
2980 long max_alignment = 15;
b99bd4ef
NC
2981
2982 temp = get_absolute_expression ();
c19d1205
ZW
2983 if (temp > max_alignment)
2984 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2985 else if (temp < 0)
b99bd4ef 2986 {
c19d1205
ZW
2987 as_bad (_("alignment negative. 0 assumed."));
2988 temp = 0;
2989 }
b99bd4ef 2990
c19d1205
ZW
2991 if (*input_line_pointer == ',')
2992 {
2993 input_line_pointer++;
2994 temp_fill = get_absolute_expression ();
dce323d1 2995 fill_p = TRUE;
b99bd4ef 2996 }
c19d1205 2997 else
dce323d1
PB
2998 {
2999 fill_p = FALSE;
3000 temp_fill = 0;
3001 }
b99bd4ef 3002
c19d1205
ZW
3003 if (!temp)
3004 temp = 2;
b99bd4ef 3005
c19d1205
ZW
3006 /* Only make a frag if we HAVE to. */
3007 if (temp && !need_pass_2)
dce323d1
PB
3008 {
3009 if (!fill_p && subseg_text_p (now_seg))
3010 frag_align_code (temp, 0);
3011 else
3012 frag_align (temp, (int) temp_fill, 0);
3013 }
c19d1205
ZW
3014 demand_empty_rest_of_line ();
3015
3016 record_alignment (now_seg, temp);
b99bd4ef
NC
3017}
3018
c19d1205
ZW
3019static void
3020s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3021{
c19d1205
ZW
3022 /* We don't support putting frags in the BSS segment, we fake it by
3023 marking in_bss, then looking at s_skip for clues. */
3024 subseg_set (bss_section, 0);
3025 demand_empty_rest_of_line ();
cd000bff
DJ
3026
3027#ifdef md_elf_section_change_hook
3028 md_elf_section_change_hook ();
3029#endif
c19d1205 3030}
b99bd4ef 3031
c19d1205
ZW
3032static void
3033s_even (int ignore ATTRIBUTE_UNUSED)
3034{
3035 /* Never make frag if expect extra pass. */
3036 if (!need_pass_2)
3037 frag_align (1, 0, 0);
b99bd4ef 3038
c19d1205 3039 record_alignment (now_seg, 1);
b99bd4ef 3040
c19d1205 3041 demand_empty_rest_of_line ();
b99bd4ef
NC
3042}
3043
2e6976a8
DG
3044/* Directives: CodeComposer Studio. */
3045
3046/* .ref (for CodeComposer Studio syntax only). */
3047static void
3048s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3049{
3050 if (codecomposer_syntax)
3051 ignore_rest_of_line ();
3052 else
3053 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3054}
3055
3056/* If name is not NULL, then it is used for marking the beginning of a
3057 function, wherease if it is NULL then it means the function end. */
3058static void
3059asmfunc_debug (const char * name)
3060{
3061 static const char * last_name = NULL;
3062
3063 if (name != NULL)
3064 {
3065 gas_assert (last_name == NULL);
3066 last_name = name;
3067
3068 if (debug_type == DEBUG_STABS)
3069 stabs_generate_asm_func (name, name);
3070 }
3071 else
3072 {
3073 gas_assert (last_name != NULL);
3074
3075 if (debug_type == DEBUG_STABS)
3076 stabs_generate_asm_endfunc (last_name, last_name);
3077
3078 last_name = NULL;
3079 }
3080}
3081
3082static void
3083s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3084{
3085 if (codecomposer_syntax)
3086 {
3087 switch (asmfunc_state)
3088 {
3089 case OUTSIDE_ASMFUNC:
3090 asmfunc_state = WAITING_ASMFUNC_NAME;
3091 break;
3092
3093 case WAITING_ASMFUNC_NAME:
3094 as_bad (_(".asmfunc repeated."));
3095 break;
3096
3097 case WAITING_ENDASMFUNC:
3098 as_bad (_(".asmfunc without function."));
3099 break;
3100 }
3101 demand_empty_rest_of_line ();
3102 }
3103 else
3104 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3105}
3106
3107static void
3108s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3109{
3110 if (codecomposer_syntax)
3111 {
3112 switch (asmfunc_state)
3113 {
3114 case OUTSIDE_ASMFUNC:
3115 as_bad (_(".endasmfunc without a .asmfunc."));
3116 break;
3117
3118 case WAITING_ASMFUNC_NAME:
3119 as_bad (_(".endasmfunc without function."));
3120 break;
3121
3122 case WAITING_ENDASMFUNC:
3123 asmfunc_state = OUTSIDE_ASMFUNC;
3124 asmfunc_debug (NULL);
3125 break;
3126 }
3127 demand_empty_rest_of_line ();
3128 }
3129 else
3130 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3131}
3132
3133static void
3134s_ccs_def (int name)
3135{
3136 if (codecomposer_syntax)
3137 s_globl (name);
3138 else
3139 as_bad (_(".def pseudo-op only available with -mccs flag."));
3140}
3141
c19d1205 3142/* Directives: Literal pools. */
a737bd4d 3143
c19d1205
ZW
3144static literal_pool *
3145find_literal_pool (void)
a737bd4d 3146{
c19d1205 3147 literal_pool * pool;
a737bd4d 3148
c19d1205 3149 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3150 {
c19d1205
ZW
3151 if (pool->section == now_seg
3152 && pool->sub_section == now_subseg)
3153 break;
a737bd4d
NC
3154 }
3155
c19d1205 3156 return pool;
a737bd4d
NC
3157}
3158
c19d1205
ZW
3159static literal_pool *
3160find_or_make_literal_pool (void)
a737bd4d 3161{
c19d1205
ZW
3162 /* Next literal pool ID number. */
3163 static unsigned int latest_pool_num = 1;
3164 literal_pool * pool;
a737bd4d 3165
c19d1205 3166 pool = find_literal_pool ();
a737bd4d 3167
c19d1205 3168 if (pool == NULL)
a737bd4d 3169 {
c19d1205 3170 /* Create a new pool. */
21d799b5 3171 pool = (literal_pool *) xmalloc (sizeof (* pool));
c19d1205
ZW
3172 if (! pool)
3173 return NULL;
a737bd4d 3174
c19d1205
ZW
3175 pool->next_free_entry = 0;
3176 pool->section = now_seg;
3177 pool->sub_section = now_subseg;
3178 pool->next = list_of_pools;
3179 pool->symbol = NULL;
8335d6aa 3180 pool->alignment = 2;
c19d1205
ZW
3181
3182 /* Add it to the list. */
3183 list_of_pools = pool;
a737bd4d 3184 }
a737bd4d 3185
c19d1205
ZW
3186 /* New pools, and emptied pools, will have a NULL symbol. */
3187 if (pool->symbol == NULL)
a737bd4d 3188 {
c19d1205
ZW
3189 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3190 (valueT) 0, &zero_address_frag);
3191 pool->id = latest_pool_num ++;
a737bd4d
NC
3192 }
3193
c19d1205
ZW
3194 /* Done. */
3195 return pool;
a737bd4d
NC
3196}
3197
c19d1205 3198/* Add the literal in the global 'inst'
5f4273c7 3199 structure to the relevant literal pool. */
b99bd4ef
NC
3200
3201static int
8335d6aa 3202add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3203{
8335d6aa
JW
3204#define PADDING_SLOT 0x1
3205#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3206 literal_pool * pool;
8335d6aa
JW
3207 unsigned int entry, pool_size = 0;
3208 bfd_boolean padding_slot_p = FALSE;
e56c722b 3209 unsigned imm1 = 0;
8335d6aa
JW
3210 unsigned imm2 = 0;
3211
3212 if (nbytes == 8)
3213 {
3214 imm1 = inst.operands[1].imm;
3215 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3216 : inst.reloc.exp.X_unsigned ? 0
2569ceb0 3217 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3218 if (target_big_endian)
3219 {
3220 imm1 = imm2;
3221 imm2 = inst.operands[1].imm;
3222 }
3223 }
b99bd4ef 3224
c19d1205
ZW
3225 pool = find_or_make_literal_pool ();
3226
3227 /* Check if this literal value is already in the pool. */
3228 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3229 {
8335d6aa
JW
3230 if (nbytes == 4)
3231 {
3232 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3233 && (inst.reloc.exp.X_op == O_constant)
3234 && (pool->literals[entry].X_add_number
3235 == inst.reloc.exp.X_add_number)
3236 && (pool->literals[entry].X_md == nbytes)
3237 && (pool->literals[entry].X_unsigned
3238 == inst.reloc.exp.X_unsigned))
3239 break;
3240
3241 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3242 && (inst.reloc.exp.X_op == O_symbol)
3243 && (pool->literals[entry].X_add_number
3244 == inst.reloc.exp.X_add_number)
3245 && (pool->literals[entry].X_add_symbol
3246 == inst.reloc.exp.X_add_symbol)
3247 && (pool->literals[entry].X_op_symbol
3248 == inst.reloc.exp.X_op_symbol)
3249 && (pool->literals[entry].X_md == nbytes))
3250 break;
3251 }
3252 else if ((nbytes == 8)
3253 && !(pool_size & 0x7)
3254 && ((entry + 1) != pool->next_free_entry)
3255 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3256 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa
JW
3257 && (pool->literals[entry].X_unsigned
3258 == inst.reloc.exp.X_unsigned)
3259 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3260 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa
JW
3261 && (pool->literals[entry + 1].X_unsigned
3262 == inst.reloc.exp.X_unsigned))
c19d1205
ZW
3263 break;
3264
8335d6aa
JW
3265 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3266 if (padding_slot_p && (nbytes == 4))
c19d1205 3267 break;
8335d6aa
JW
3268
3269 pool_size += 4;
b99bd4ef
NC
3270 }
3271
c19d1205
ZW
3272 /* Do we need to create a new entry? */
3273 if (entry == pool->next_free_entry)
3274 {
3275 if (entry >= MAX_LITERAL_POOL_SIZE)
3276 {
3277 inst.error = _("literal pool overflow");
3278 return FAIL;
3279 }
3280
8335d6aa
JW
3281 if (nbytes == 8)
3282 {
3283 /* For 8-byte entries, we align to an 8-byte boundary,
3284 and split it into two 4-byte entries, because on 32-bit
3285 host, 8-byte constants are treated as big num, thus
3286 saved in "generic_bignum" which will be overwritten
3287 by later assignments.
3288
3289 We also need to make sure there is enough space for
3290 the split.
3291
3292 We also check to make sure the literal operand is a
3293 constant number. */
19f2f6a9
JW
3294 if (!(inst.reloc.exp.X_op == O_constant
3295 || inst.reloc.exp.X_op == O_big))
8335d6aa
JW
3296 {
3297 inst.error = _("invalid type for literal pool");
3298 return FAIL;
3299 }
3300 else if (pool_size & 0x7)
3301 {
3302 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3303 {
3304 inst.error = _("literal pool overflow");
3305 return FAIL;
3306 }
3307
3308 pool->literals[entry] = inst.reloc.exp;
3309 pool->literals[entry].X_add_number = 0;
3310 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3311 pool->next_free_entry += 1;
3312 pool_size += 4;
3313 }
3314 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3315 {
3316 inst.error = _("literal pool overflow");
3317 return FAIL;
3318 }
3319
3320 pool->literals[entry] = inst.reloc.exp;
3321 pool->literals[entry].X_op = O_constant;
3322 pool->literals[entry].X_add_number = imm1;
3323 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3324 pool->literals[entry++].X_md = 4;
3325 pool->literals[entry] = inst.reloc.exp;
3326 pool->literals[entry].X_op = O_constant;
3327 pool->literals[entry].X_add_number = imm2;
3328 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3329 pool->literals[entry].X_md = 4;
3330 pool->alignment = 3;
3331 pool->next_free_entry += 1;
3332 }
3333 else
3334 {
3335 pool->literals[entry] = inst.reloc.exp;
3336 pool->literals[entry].X_md = 4;
3337 }
3338
a8040cf2
NC
3339#ifdef OBJ_ELF
3340 /* PR ld/12974: Record the location of the first source line to reference
3341 this entry in the literal pool. If it turns out during linking that the
3342 symbol does not exist we will be able to give an accurate line number for
3343 the (first use of the) missing reference. */
3344 if (debug_type == DEBUG_DWARF2)
3345 dwarf2_where (pool->locs + entry);
3346#endif
c19d1205
ZW
3347 pool->next_free_entry += 1;
3348 }
8335d6aa
JW
3349 else if (padding_slot_p)
3350 {
3351 pool->literals[entry] = inst.reloc.exp;
3352 pool->literals[entry].X_md = nbytes;
3353 }
b99bd4ef 3354
c19d1205 3355 inst.reloc.exp.X_op = O_symbol;
8335d6aa 3356 inst.reloc.exp.X_add_number = pool_size;
c19d1205 3357 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3358
c19d1205 3359 return SUCCESS;
b99bd4ef
NC
3360}
3361
2e6976a8
DG
3362bfd_boolean
3363tc_start_label_without_colon (char unused1 ATTRIBUTE_UNUSED, const char * rest)
3364{
3365 bfd_boolean ret = TRUE;
3366
3367 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3368 {
3369 const char *label = rest;
3370
3371 while (!is_end_of_line[(int) label[-1]])
3372 --label;
3373
3374 if (*label == '.')
3375 {
3376 as_bad (_("Invalid label '%s'"), label);
3377 ret = FALSE;
3378 }
3379
3380 asmfunc_debug (label);
3381
3382 asmfunc_state = WAITING_ENDASMFUNC;
3383 }
3384
3385 return ret;
3386}
3387
c19d1205
ZW
3388/* Can't use symbol_new here, so have to create a symbol and then at
3389 a later date assign it a value. Thats what these functions do. */
e16bb312 3390
c19d1205
ZW
3391static void
3392symbol_locate (symbolS * symbolP,
3393 const char * name, /* It is copied, the caller can modify. */
3394 segT segment, /* Segment identifier (SEG_<something>). */
3395 valueT valu, /* Symbol value. */
3396 fragS * frag) /* Associated fragment. */
3397{
e57e6ddc 3398 size_t name_length;
c19d1205 3399 char * preserved_copy_of_name;
e16bb312 3400
c19d1205
ZW
3401 name_length = strlen (name) + 1; /* +1 for \0. */
3402 obstack_grow (&notes, name, name_length);
21d799b5 3403 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3404
c19d1205
ZW
3405#ifdef tc_canonicalize_symbol_name
3406 preserved_copy_of_name =
3407 tc_canonicalize_symbol_name (preserved_copy_of_name);
3408#endif
b99bd4ef 3409
c19d1205 3410 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3411
c19d1205
ZW
3412 S_SET_SEGMENT (symbolP, segment);
3413 S_SET_VALUE (symbolP, valu);
3414 symbol_clear_list_pointers (symbolP);
b99bd4ef 3415
c19d1205 3416 symbol_set_frag (symbolP, frag);
b99bd4ef 3417
c19d1205
ZW
3418 /* Link to end of symbol chain. */
3419 {
3420 extern int symbol_table_frozen;
b99bd4ef 3421
c19d1205
ZW
3422 if (symbol_table_frozen)
3423 abort ();
3424 }
b99bd4ef 3425
c19d1205 3426 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3427
c19d1205 3428 obj_symbol_new_hook (symbolP);
b99bd4ef 3429
c19d1205
ZW
3430#ifdef tc_symbol_new_hook
3431 tc_symbol_new_hook (symbolP);
3432#endif
3433
3434#ifdef DEBUG_SYMS
3435 verify_symbol_chain (symbol_rootP, symbol_lastP);
3436#endif /* DEBUG_SYMS */
b99bd4ef
NC
3437}
3438
c19d1205
ZW
3439static void
3440s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3441{
c19d1205
ZW
3442 unsigned int entry;
3443 literal_pool * pool;
3444 char sym_name[20];
b99bd4ef 3445
c19d1205
ZW
3446 pool = find_literal_pool ();
3447 if (pool == NULL
3448 || pool->symbol == NULL
3449 || pool->next_free_entry == 0)
3450 return;
b99bd4ef 3451
c19d1205
ZW
3452 /* Align pool as you have word accesses.
3453 Only make a frag if we have to. */
3454 if (!need_pass_2)
8335d6aa 3455 frag_align (pool->alignment, 0, 0);
b99bd4ef 3456
c19d1205 3457 record_alignment (now_seg, 2);
b99bd4ef 3458
aaca88ef 3459#ifdef OBJ_ELF
47fc6e36
WN
3460 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3461 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3462#endif
c19d1205 3463 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3464
c19d1205
ZW
3465 symbol_locate (pool->symbol, sym_name, now_seg,
3466 (valueT) frag_now_fix (), frag_now);
3467 symbol_table_insert (pool->symbol);
b99bd4ef 3468
c19d1205 3469 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3470
c19d1205
ZW
3471#if defined OBJ_COFF || defined OBJ_ELF
3472 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3473#endif
6c43fab6 3474
c19d1205 3475 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3476 {
3477#ifdef OBJ_ELF
3478 if (debug_type == DEBUG_DWARF2)
3479 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3480#endif
3481 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3482 emit_expr (&(pool->literals[entry]),
3483 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3484 }
b99bd4ef 3485
c19d1205
ZW
3486 /* Mark the pool as empty. */
3487 pool->next_free_entry = 0;
3488 pool->symbol = NULL;
b99bd4ef
NC
3489}
3490
c19d1205
ZW
3491#ifdef OBJ_ELF
3492/* Forward declarations for functions below, in the MD interface
3493 section. */
3494static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3495static valueT create_unwind_entry (int);
3496static void start_unwind_section (const segT, int);
3497static void add_unwind_opcode (valueT, int);
3498static void flush_pending_unwind (void);
b99bd4ef 3499
c19d1205 3500/* Directives: Data. */
b99bd4ef 3501
c19d1205
ZW
3502static void
3503s_arm_elf_cons (int nbytes)
3504{
3505 expressionS exp;
b99bd4ef 3506
c19d1205
ZW
3507#ifdef md_flush_pending_output
3508 md_flush_pending_output ();
3509#endif
b99bd4ef 3510
c19d1205 3511 if (is_it_end_of_statement ())
b99bd4ef 3512 {
c19d1205
ZW
3513 demand_empty_rest_of_line ();
3514 return;
b99bd4ef
NC
3515 }
3516
c19d1205
ZW
3517#ifdef md_cons_align
3518 md_cons_align (nbytes);
3519#endif
b99bd4ef 3520
c19d1205
ZW
3521 mapping_state (MAP_DATA);
3522 do
b99bd4ef 3523 {
c19d1205
ZW
3524 int reloc;
3525 char *base = input_line_pointer;
b99bd4ef 3526
c19d1205 3527 expression (& exp);
b99bd4ef 3528
c19d1205
ZW
3529 if (exp.X_op != O_symbol)
3530 emit_expr (&exp, (unsigned int) nbytes);
3531 else
3532 {
3533 char *before_reloc = input_line_pointer;
3534 reloc = parse_reloc (&input_line_pointer);
3535 if (reloc == -1)
3536 {
3537 as_bad (_("unrecognized relocation suffix"));
3538 ignore_rest_of_line ();
3539 return;
3540 }
3541 else if (reloc == BFD_RELOC_UNUSED)
3542 emit_expr (&exp, (unsigned int) nbytes);
3543 else
3544 {
21d799b5 3545 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3546 bfd_reloc_type_lookup (stdoutput,
3547 (bfd_reloc_code_real_type) reloc);
c19d1205 3548 int size = bfd_get_reloc_size (howto);
b99bd4ef 3549
2fc8bdac
ZW
3550 if (reloc == BFD_RELOC_ARM_PLT32)
3551 {
3552 as_bad (_("(plt) is only valid on branch targets"));
3553 reloc = BFD_RELOC_UNUSED;
3554 size = 0;
3555 }
3556
c19d1205 3557 if (size > nbytes)
2fc8bdac 3558 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3559 howto->name, nbytes);
3560 else
3561 {
3562 /* We've parsed an expression stopping at O_symbol.
3563 But there may be more expression left now that we
3564 have parsed the relocation marker. Parse it again.
3565 XXX Surely there is a cleaner way to do this. */
3566 char *p = input_line_pointer;
3567 int offset;
21d799b5 3568 char *save_buf = (char *) alloca (input_line_pointer - base);
c19d1205
ZW
3569 memcpy (save_buf, base, input_line_pointer - base);
3570 memmove (base + (input_line_pointer - before_reloc),
3571 base, before_reloc - base);
3572
3573 input_line_pointer = base + (input_line_pointer-before_reloc);
3574 expression (&exp);
3575 memcpy (base, save_buf, p - base);
3576
3577 offset = nbytes - size;
4b1a927e
AM
3578 p = frag_more (nbytes);
3579 memset (p, 0, nbytes);
c19d1205 3580 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3581 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
c19d1205
ZW
3582 }
3583 }
3584 }
b99bd4ef 3585 }
c19d1205 3586 while (*input_line_pointer++ == ',');
b99bd4ef 3587
c19d1205
ZW
3588 /* Put terminator back into stream. */
3589 input_line_pointer --;
3590 demand_empty_rest_of_line ();
b99bd4ef
NC
3591}
3592
c921be7d
NC
3593/* Emit an expression containing a 32-bit thumb instruction.
3594 Implementation based on put_thumb32_insn. */
3595
3596static void
3597emit_thumb32_expr (expressionS * exp)
3598{
3599 expressionS exp_high = *exp;
3600
3601 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3602 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3603 exp->X_add_number &= 0xffff;
3604 emit_expr (exp, (unsigned int) THUMB_SIZE);
3605}
3606
3607/* Guess the instruction size based on the opcode. */
3608
3609static int
3610thumb_insn_size (int opcode)
3611{
3612 if ((unsigned int) opcode < 0xe800u)
3613 return 2;
3614 else if ((unsigned int) opcode >= 0xe8000000u)
3615 return 4;
3616 else
3617 return 0;
3618}
3619
3620static bfd_boolean
3621emit_insn (expressionS *exp, int nbytes)
3622{
3623 int size = 0;
3624
3625 if (exp->X_op == O_constant)
3626 {
3627 size = nbytes;
3628
3629 if (size == 0)
3630 size = thumb_insn_size (exp->X_add_number);
3631
3632 if (size != 0)
3633 {
3634 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3635 {
3636 as_bad (_(".inst.n operand too big. "\
3637 "Use .inst.w instead"));
3638 size = 0;
3639 }
3640 else
3641 {
3642 if (now_it.state == AUTOMATIC_IT_BLOCK)
3643 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3644 else
3645 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3646
3647 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3648 emit_thumb32_expr (exp);
3649 else
3650 emit_expr (exp, (unsigned int) size);
3651
3652 it_fsm_post_encode ();
3653 }
3654 }
3655 else
3656 as_bad (_("cannot determine Thumb instruction size. " \
3657 "Use .inst.n/.inst.w instead"));
3658 }
3659 else
3660 as_bad (_("constant expression required"));
3661
3662 return (size != 0);
3663}
3664
3665/* Like s_arm_elf_cons but do not use md_cons_align and
3666 set the mapping state to MAP_ARM/MAP_THUMB. */
3667
3668static void
3669s_arm_elf_inst (int nbytes)
3670{
3671 if (is_it_end_of_statement ())
3672 {
3673 demand_empty_rest_of_line ();
3674 return;
3675 }
3676
3677 /* Calling mapping_state () here will not change ARM/THUMB,
3678 but will ensure not to be in DATA state. */
3679
3680 if (thumb_mode)
3681 mapping_state (MAP_THUMB);
3682 else
3683 {
3684 if (nbytes != 0)
3685 {
3686 as_bad (_("width suffixes are invalid in ARM mode"));
3687 ignore_rest_of_line ();
3688 return;
3689 }
3690
3691 nbytes = 4;
3692
3693 mapping_state (MAP_ARM);
3694 }
3695
3696 do
3697 {
3698 expressionS exp;
3699
3700 expression (& exp);
3701
3702 if (! emit_insn (& exp, nbytes))
3703 {
3704 ignore_rest_of_line ();
3705 return;
3706 }
3707 }
3708 while (*input_line_pointer++ == ',');
3709
3710 /* Put terminator back into stream. */
3711 input_line_pointer --;
3712 demand_empty_rest_of_line ();
3713}
b99bd4ef 3714
c19d1205 3715/* Parse a .rel31 directive. */
b99bd4ef 3716
c19d1205
ZW
3717static void
3718s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3719{
3720 expressionS exp;
3721 char *p;
3722 valueT highbit;
b99bd4ef 3723
c19d1205
ZW
3724 highbit = 0;
3725 if (*input_line_pointer == '1')
3726 highbit = 0x80000000;
3727 else if (*input_line_pointer != '0')
3728 as_bad (_("expected 0 or 1"));
b99bd4ef 3729
c19d1205
ZW
3730 input_line_pointer++;
3731 if (*input_line_pointer != ',')
3732 as_bad (_("missing comma"));
3733 input_line_pointer++;
b99bd4ef 3734
c19d1205
ZW
3735#ifdef md_flush_pending_output
3736 md_flush_pending_output ();
3737#endif
b99bd4ef 3738
c19d1205
ZW
3739#ifdef md_cons_align
3740 md_cons_align (4);
3741#endif
b99bd4ef 3742
c19d1205 3743 mapping_state (MAP_DATA);
b99bd4ef 3744
c19d1205 3745 expression (&exp);
b99bd4ef 3746
c19d1205
ZW
3747 p = frag_more (4);
3748 md_number_to_chars (p, highbit, 4);
3749 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3750 BFD_RELOC_ARM_PREL31);
b99bd4ef 3751
c19d1205 3752 demand_empty_rest_of_line ();
b99bd4ef
NC
3753}
3754
c19d1205 3755/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3756
c19d1205 3757/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3758
c19d1205
ZW
3759static void
3760s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3761{
3762 demand_empty_rest_of_line ();
921e5f0a
PB
3763 if (unwind.proc_start)
3764 {
c921be7d 3765 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3766 return;
3767 }
3768
c19d1205
ZW
3769 /* Mark the start of the function. */
3770 unwind.proc_start = expr_build_dot ();
b99bd4ef 3771
c19d1205
ZW
3772 /* Reset the rest of the unwind info. */
3773 unwind.opcode_count = 0;
3774 unwind.table_entry = NULL;
3775 unwind.personality_routine = NULL;
3776 unwind.personality_index = -1;
3777 unwind.frame_size = 0;
3778 unwind.fp_offset = 0;
fdfde340 3779 unwind.fp_reg = REG_SP;
c19d1205
ZW
3780 unwind.fp_used = 0;
3781 unwind.sp_restored = 0;
3782}
b99bd4ef 3783
b99bd4ef 3784
c19d1205
ZW
3785/* Parse a handlerdata directive. Creates the exception handling table entry
3786 for the function. */
b99bd4ef 3787
c19d1205
ZW
3788static void
3789s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3790{
3791 demand_empty_rest_of_line ();
921e5f0a 3792 if (!unwind.proc_start)
c921be7d 3793 as_bad (MISSING_FNSTART);
921e5f0a 3794
c19d1205 3795 if (unwind.table_entry)
6decc662 3796 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3797
c19d1205
ZW
3798 create_unwind_entry (1);
3799}
a737bd4d 3800
c19d1205 3801/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3802
c19d1205
ZW
3803static void
3804s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3805{
3806 long where;
3807 char *ptr;
3808 valueT val;
940b5ce0 3809 unsigned int marked_pr_dependency;
f02232aa 3810
c19d1205 3811 demand_empty_rest_of_line ();
f02232aa 3812
921e5f0a
PB
3813 if (!unwind.proc_start)
3814 {
c921be7d 3815 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3816 return;
3817 }
3818
c19d1205
ZW
3819 /* Add eh table entry. */
3820 if (unwind.table_entry == NULL)
3821 val = create_unwind_entry (0);
3822 else
3823 val = 0;
f02232aa 3824
c19d1205
ZW
3825 /* Add index table entry. This is two words. */
3826 start_unwind_section (unwind.saved_seg, 1);
3827 frag_align (2, 0, 0);
3828 record_alignment (now_seg, 2);
b99bd4ef 3829
c19d1205 3830 ptr = frag_more (8);
5011093d 3831 memset (ptr, 0, 8);
c19d1205 3832 where = frag_now_fix () - 8;
f02232aa 3833
c19d1205
ZW
3834 /* Self relative offset of the function start. */
3835 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3836 BFD_RELOC_ARM_PREL31);
f02232aa 3837
c19d1205
ZW
3838 /* Indicate dependency on EHABI-defined personality routines to the
3839 linker, if it hasn't been done already. */
940b5ce0
DJ
3840 marked_pr_dependency
3841 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3842 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3843 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3844 {
5f4273c7
NC
3845 static const char *const name[] =
3846 {
3847 "__aeabi_unwind_cpp_pr0",
3848 "__aeabi_unwind_cpp_pr1",
3849 "__aeabi_unwind_cpp_pr2"
3850 };
c19d1205
ZW
3851 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3852 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3853 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3854 |= 1 << unwind.personality_index;
c19d1205 3855 }
f02232aa 3856
c19d1205
ZW
3857 if (val)
3858 /* Inline exception table entry. */
3859 md_number_to_chars (ptr + 4, val, 4);
3860 else
3861 /* Self relative offset of the table entry. */
3862 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3863 BFD_RELOC_ARM_PREL31);
f02232aa 3864
c19d1205
ZW
3865 /* Restore the original section. */
3866 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3867
3868 unwind.proc_start = NULL;
c19d1205 3869}
f02232aa 3870
f02232aa 3871
c19d1205 3872/* Parse an unwind_cantunwind directive. */
b99bd4ef 3873
c19d1205
ZW
3874static void
3875s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3876{
3877 demand_empty_rest_of_line ();
921e5f0a 3878 if (!unwind.proc_start)
c921be7d 3879 as_bad (MISSING_FNSTART);
921e5f0a 3880
c19d1205
ZW
3881 if (unwind.personality_routine || unwind.personality_index != -1)
3882 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3883
c19d1205
ZW
3884 unwind.personality_index = -2;
3885}
b99bd4ef 3886
b99bd4ef 3887
c19d1205 3888/* Parse a personalityindex directive. */
b99bd4ef 3889
c19d1205
ZW
3890static void
3891s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3892{
3893 expressionS exp;
b99bd4ef 3894
921e5f0a 3895 if (!unwind.proc_start)
c921be7d 3896 as_bad (MISSING_FNSTART);
921e5f0a 3897
c19d1205
ZW
3898 if (unwind.personality_routine || unwind.personality_index != -1)
3899 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3900
c19d1205 3901 expression (&exp);
b99bd4ef 3902
c19d1205
ZW
3903 if (exp.X_op != O_constant
3904 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3905 {
c19d1205
ZW
3906 as_bad (_("bad personality routine number"));
3907 ignore_rest_of_line ();
3908 return;
b99bd4ef
NC
3909 }
3910
c19d1205 3911 unwind.personality_index = exp.X_add_number;
b99bd4ef 3912
c19d1205
ZW
3913 demand_empty_rest_of_line ();
3914}
e16bb312 3915
e16bb312 3916
c19d1205 3917/* Parse a personality directive. */
e16bb312 3918
c19d1205
ZW
3919static void
3920s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3921{
3922 char *name, *p, c;
a737bd4d 3923
921e5f0a 3924 if (!unwind.proc_start)
c921be7d 3925 as_bad (MISSING_FNSTART);
921e5f0a 3926
c19d1205
ZW
3927 if (unwind.personality_routine || unwind.personality_index != -1)
3928 as_bad (_("duplicate .personality directive"));
a737bd4d 3929
c19d1205
ZW
3930 name = input_line_pointer;
3931 c = get_symbol_end ();
3932 p = input_line_pointer;
3933 unwind.personality_routine = symbol_find_or_make (name);
3934 *p = c;
3935 demand_empty_rest_of_line ();
3936}
e16bb312 3937
e16bb312 3938
c19d1205 3939/* Parse a directive saving core registers. */
e16bb312 3940
c19d1205
ZW
3941static void
3942s_arm_unwind_save_core (void)
e16bb312 3943{
c19d1205
ZW
3944 valueT op;
3945 long range;
3946 int n;
e16bb312 3947
c19d1205
ZW
3948 range = parse_reg_list (&input_line_pointer);
3949 if (range == FAIL)
e16bb312 3950 {
c19d1205
ZW
3951 as_bad (_("expected register list"));
3952 ignore_rest_of_line ();
3953 return;
3954 }
e16bb312 3955
c19d1205 3956 demand_empty_rest_of_line ();
e16bb312 3957
c19d1205
ZW
3958 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3959 into .unwind_save {..., sp...}. We aren't bothered about the value of
3960 ip because it is clobbered by calls. */
3961 if (unwind.sp_restored && unwind.fp_reg == 12
3962 && (range & 0x3000) == 0x1000)
3963 {
3964 unwind.opcode_count--;
3965 unwind.sp_restored = 0;
3966 range = (range | 0x2000) & ~0x1000;
3967 unwind.pending_offset = 0;
3968 }
e16bb312 3969
01ae4198
DJ
3970 /* Pop r4-r15. */
3971 if (range & 0xfff0)
c19d1205 3972 {
01ae4198
DJ
3973 /* See if we can use the short opcodes. These pop a block of up to 8
3974 registers starting with r4, plus maybe r14. */
3975 for (n = 0; n < 8; n++)
3976 {
3977 /* Break at the first non-saved register. */
3978 if ((range & (1 << (n + 4))) == 0)
3979 break;
3980 }
3981 /* See if there are any other bits set. */
3982 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3983 {
3984 /* Use the long form. */
3985 op = 0x8000 | ((range >> 4) & 0xfff);
3986 add_unwind_opcode (op, 2);
3987 }
0dd132b6 3988 else
01ae4198
DJ
3989 {
3990 /* Use the short form. */
3991 if (range & 0x4000)
3992 op = 0xa8; /* Pop r14. */
3993 else
3994 op = 0xa0; /* Do not pop r14. */
3995 op |= (n - 1);
3996 add_unwind_opcode (op, 1);
3997 }
c19d1205 3998 }
0dd132b6 3999
c19d1205
ZW
4000 /* Pop r0-r3. */
4001 if (range & 0xf)
4002 {
4003 op = 0xb100 | (range & 0xf);
4004 add_unwind_opcode (op, 2);
0dd132b6
NC
4005 }
4006
c19d1205
ZW
4007 /* Record the number of bytes pushed. */
4008 for (n = 0; n < 16; n++)
4009 {
4010 if (range & (1 << n))
4011 unwind.frame_size += 4;
4012 }
0dd132b6
NC
4013}
4014
c19d1205
ZW
4015
4016/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4017
4018static void
c19d1205 4019s_arm_unwind_save_fpa (int reg)
b99bd4ef 4020{
c19d1205
ZW
4021 expressionS exp;
4022 int num_regs;
4023 valueT op;
b99bd4ef 4024
c19d1205
ZW
4025 /* Get Number of registers to transfer. */
4026 if (skip_past_comma (&input_line_pointer) != FAIL)
4027 expression (&exp);
4028 else
4029 exp.X_op = O_illegal;
b99bd4ef 4030
c19d1205 4031 if (exp.X_op != O_constant)
b99bd4ef 4032 {
c19d1205
ZW
4033 as_bad (_("expected , <constant>"));
4034 ignore_rest_of_line ();
b99bd4ef
NC
4035 return;
4036 }
4037
c19d1205
ZW
4038 num_regs = exp.X_add_number;
4039
4040 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4041 {
c19d1205
ZW
4042 as_bad (_("number of registers must be in the range [1:4]"));
4043 ignore_rest_of_line ();
b99bd4ef
NC
4044 return;
4045 }
4046
c19d1205 4047 demand_empty_rest_of_line ();
b99bd4ef 4048
c19d1205
ZW
4049 if (reg == 4)
4050 {
4051 /* Short form. */
4052 op = 0xb4 | (num_regs - 1);
4053 add_unwind_opcode (op, 1);
4054 }
b99bd4ef
NC
4055 else
4056 {
c19d1205
ZW
4057 /* Long form. */
4058 op = 0xc800 | (reg << 4) | (num_regs - 1);
4059 add_unwind_opcode (op, 2);
b99bd4ef 4060 }
c19d1205 4061 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4062}
4063
c19d1205 4064
fa073d69
MS
4065/* Parse a directive saving VFP registers for ARMv6 and above. */
4066
4067static void
4068s_arm_unwind_save_vfp_armv6 (void)
4069{
4070 int count;
4071 unsigned int start;
4072 valueT op;
4073 int num_vfpv3_regs = 0;
4074 int num_regs_below_16;
4075
4076 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4077 if (count == FAIL)
4078 {
4079 as_bad (_("expected register list"));
4080 ignore_rest_of_line ();
4081 return;
4082 }
4083
4084 demand_empty_rest_of_line ();
4085
4086 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4087 than FSTMX/FLDMX-style ones). */
4088
4089 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4090 if (start >= 16)
4091 num_vfpv3_regs = count;
4092 else if (start + count > 16)
4093 num_vfpv3_regs = start + count - 16;
4094
4095 if (num_vfpv3_regs > 0)
4096 {
4097 int start_offset = start > 16 ? start - 16 : 0;
4098 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4099 add_unwind_opcode (op, 2);
4100 }
4101
4102 /* Generate opcode for registers numbered in the range 0 .. 15. */
4103 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4104 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4105 if (num_regs_below_16 > 0)
4106 {
4107 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4108 add_unwind_opcode (op, 2);
4109 }
4110
4111 unwind.frame_size += count * 8;
4112}
4113
4114
4115/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4116
4117static void
c19d1205 4118s_arm_unwind_save_vfp (void)
b99bd4ef 4119{
c19d1205 4120 int count;
ca3f61f7 4121 unsigned int reg;
c19d1205 4122 valueT op;
b99bd4ef 4123
5287ad62 4124 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4125 if (count == FAIL)
b99bd4ef 4126 {
c19d1205
ZW
4127 as_bad (_("expected register list"));
4128 ignore_rest_of_line ();
b99bd4ef
NC
4129 return;
4130 }
4131
c19d1205 4132 demand_empty_rest_of_line ();
b99bd4ef 4133
c19d1205 4134 if (reg == 8)
b99bd4ef 4135 {
c19d1205
ZW
4136 /* Short form. */
4137 op = 0xb8 | (count - 1);
4138 add_unwind_opcode (op, 1);
b99bd4ef 4139 }
c19d1205 4140 else
b99bd4ef 4141 {
c19d1205
ZW
4142 /* Long form. */
4143 op = 0xb300 | (reg << 4) | (count - 1);
4144 add_unwind_opcode (op, 2);
b99bd4ef 4145 }
c19d1205
ZW
4146 unwind.frame_size += count * 8 + 4;
4147}
b99bd4ef 4148
b99bd4ef 4149
c19d1205
ZW
4150/* Parse a directive saving iWMMXt data registers. */
4151
4152static void
4153s_arm_unwind_save_mmxwr (void)
4154{
4155 int reg;
4156 int hi_reg;
4157 int i;
4158 unsigned mask = 0;
4159 valueT op;
b99bd4ef 4160
c19d1205
ZW
4161 if (*input_line_pointer == '{')
4162 input_line_pointer++;
b99bd4ef 4163
c19d1205 4164 do
b99bd4ef 4165 {
dcbf9037 4166 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4167
c19d1205 4168 if (reg == FAIL)
b99bd4ef 4169 {
9b7132d3 4170 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4171 goto error;
b99bd4ef
NC
4172 }
4173
c19d1205
ZW
4174 if (mask >> reg)
4175 as_tsktsk (_("register list not in ascending order"));
4176 mask |= 1 << reg;
b99bd4ef 4177
c19d1205
ZW
4178 if (*input_line_pointer == '-')
4179 {
4180 input_line_pointer++;
dcbf9037 4181 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4182 if (hi_reg == FAIL)
4183 {
9b7132d3 4184 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4185 goto error;
4186 }
4187 else if (reg >= hi_reg)
4188 {
4189 as_bad (_("bad register range"));
4190 goto error;
4191 }
4192 for (; reg < hi_reg; reg++)
4193 mask |= 1 << reg;
4194 }
4195 }
4196 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4197
d996d970 4198 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4199
c19d1205 4200 demand_empty_rest_of_line ();
b99bd4ef 4201
708587a4 4202 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4203 the list. */
4204 flush_pending_unwind ();
b99bd4ef 4205
c19d1205 4206 for (i = 0; i < 16; i++)
b99bd4ef 4207 {
c19d1205
ZW
4208 if (mask & (1 << i))
4209 unwind.frame_size += 8;
b99bd4ef
NC
4210 }
4211
c19d1205
ZW
4212 /* Attempt to combine with a previous opcode. We do this because gcc
4213 likes to output separate unwind directives for a single block of
4214 registers. */
4215 if (unwind.opcode_count > 0)
b99bd4ef 4216 {
c19d1205
ZW
4217 i = unwind.opcodes[unwind.opcode_count - 1];
4218 if ((i & 0xf8) == 0xc0)
4219 {
4220 i &= 7;
4221 /* Only merge if the blocks are contiguous. */
4222 if (i < 6)
4223 {
4224 if ((mask & 0xfe00) == (1 << 9))
4225 {
4226 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4227 unwind.opcode_count--;
4228 }
4229 }
4230 else if (i == 6 && unwind.opcode_count >= 2)
4231 {
4232 i = unwind.opcodes[unwind.opcode_count - 2];
4233 reg = i >> 4;
4234 i &= 0xf;
b99bd4ef 4235
c19d1205
ZW
4236 op = 0xffff << (reg - 1);
4237 if (reg > 0
87a1fd79 4238 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4239 {
4240 op = (1 << (reg + i + 1)) - 1;
4241 op &= ~((1 << reg) - 1);
4242 mask |= op;
4243 unwind.opcode_count -= 2;
4244 }
4245 }
4246 }
b99bd4ef
NC
4247 }
4248
c19d1205
ZW
4249 hi_reg = 15;
4250 /* We want to generate opcodes in the order the registers have been
4251 saved, ie. descending order. */
4252 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4253 {
c19d1205
ZW
4254 /* Save registers in blocks. */
4255 if (reg < 0
4256 || !(mask & (1 << reg)))
4257 {
4258 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4259 preceding block. */
c19d1205
ZW
4260 if (reg != hi_reg)
4261 {
4262 if (reg == 9)
4263 {
4264 /* Short form. */
4265 op = 0xc0 | (hi_reg - 10);
4266 add_unwind_opcode (op, 1);
4267 }
4268 else
4269 {
4270 /* Long form. */
4271 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4272 add_unwind_opcode (op, 2);
4273 }
4274 }
4275 hi_reg = reg - 1;
4276 }
b99bd4ef
NC
4277 }
4278
c19d1205
ZW
4279 return;
4280error:
4281 ignore_rest_of_line ();
b99bd4ef
NC
4282}
4283
4284static void
c19d1205 4285s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4286{
c19d1205
ZW
4287 int reg;
4288 int hi_reg;
4289 unsigned mask = 0;
4290 valueT op;
b99bd4ef 4291
c19d1205
ZW
4292 if (*input_line_pointer == '{')
4293 input_line_pointer++;
b99bd4ef 4294
477330fc
RM
4295 skip_whitespace (input_line_pointer);
4296
c19d1205 4297 do
b99bd4ef 4298 {
dcbf9037 4299 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4300
c19d1205
ZW
4301 if (reg == FAIL)
4302 {
9b7132d3 4303 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4304 goto error;
4305 }
b99bd4ef 4306
c19d1205
ZW
4307 reg -= 8;
4308 if (mask >> reg)
4309 as_tsktsk (_("register list not in ascending order"));
4310 mask |= 1 << reg;
b99bd4ef 4311
c19d1205
ZW
4312 if (*input_line_pointer == '-')
4313 {
4314 input_line_pointer++;
dcbf9037 4315 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4316 if (hi_reg == FAIL)
4317 {
9b7132d3 4318 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4319 goto error;
4320 }
4321 else if (reg >= hi_reg)
4322 {
4323 as_bad (_("bad register range"));
4324 goto error;
4325 }
4326 for (; reg < hi_reg; reg++)
4327 mask |= 1 << reg;
4328 }
b99bd4ef 4329 }
c19d1205 4330 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4331
d996d970 4332 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4333
c19d1205
ZW
4334 demand_empty_rest_of_line ();
4335
708587a4 4336 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4337 the list. */
4338 flush_pending_unwind ();
b99bd4ef 4339
c19d1205 4340 for (reg = 0; reg < 16; reg++)
b99bd4ef 4341 {
c19d1205
ZW
4342 if (mask & (1 << reg))
4343 unwind.frame_size += 4;
b99bd4ef 4344 }
c19d1205
ZW
4345 op = 0xc700 | mask;
4346 add_unwind_opcode (op, 2);
4347 return;
4348error:
4349 ignore_rest_of_line ();
b99bd4ef
NC
4350}
4351
c19d1205 4352
fa073d69
MS
4353/* Parse an unwind_save directive.
4354 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4355
b99bd4ef 4356static void
fa073d69 4357s_arm_unwind_save (int arch_v6)
b99bd4ef 4358{
c19d1205
ZW
4359 char *peek;
4360 struct reg_entry *reg;
4361 bfd_boolean had_brace = FALSE;
b99bd4ef 4362
921e5f0a 4363 if (!unwind.proc_start)
c921be7d 4364 as_bad (MISSING_FNSTART);
921e5f0a 4365
c19d1205
ZW
4366 /* Figure out what sort of save we have. */
4367 peek = input_line_pointer;
b99bd4ef 4368
c19d1205 4369 if (*peek == '{')
b99bd4ef 4370 {
c19d1205
ZW
4371 had_brace = TRUE;
4372 peek++;
b99bd4ef
NC
4373 }
4374
c19d1205 4375 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4376
c19d1205 4377 if (!reg)
b99bd4ef 4378 {
c19d1205
ZW
4379 as_bad (_("register expected"));
4380 ignore_rest_of_line ();
b99bd4ef
NC
4381 return;
4382 }
4383
c19d1205 4384 switch (reg->type)
b99bd4ef 4385 {
c19d1205
ZW
4386 case REG_TYPE_FN:
4387 if (had_brace)
4388 {
4389 as_bad (_("FPA .unwind_save does not take a register list"));
4390 ignore_rest_of_line ();
4391 return;
4392 }
93ac2687 4393 input_line_pointer = peek;
c19d1205 4394 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4395 return;
c19d1205 4396
1f5afe1c
NC
4397 case REG_TYPE_RN:
4398 s_arm_unwind_save_core ();
4399 return;
4400
fa073d69
MS
4401 case REG_TYPE_VFD:
4402 if (arch_v6)
477330fc 4403 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4404 else
477330fc 4405 s_arm_unwind_save_vfp ();
fa073d69 4406 return;
1f5afe1c
NC
4407
4408 case REG_TYPE_MMXWR:
4409 s_arm_unwind_save_mmxwr ();
4410 return;
4411
4412 case REG_TYPE_MMXWCG:
4413 s_arm_unwind_save_mmxwcg ();
4414 return;
c19d1205
ZW
4415
4416 default:
4417 as_bad (_(".unwind_save does not support this kind of register"));
4418 ignore_rest_of_line ();
b99bd4ef 4419 }
c19d1205 4420}
b99bd4ef 4421
b99bd4ef 4422
c19d1205
ZW
4423/* Parse an unwind_movsp directive. */
4424
4425static void
4426s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4427{
4428 int reg;
4429 valueT op;
4fa3602b 4430 int offset;
c19d1205 4431
921e5f0a 4432 if (!unwind.proc_start)
c921be7d 4433 as_bad (MISSING_FNSTART);
921e5f0a 4434
dcbf9037 4435 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4436 if (reg == FAIL)
b99bd4ef 4437 {
9b7132d3 4438 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4439 ignore_rest_of_line ();
b99bd4ef
NC
4440 return;
4441 }
4fa3602b
PB
4442
4443 /* Optional constant. */
4444 if (skip_past_comma (&input_line_pointer) != FAIL)
4445 {
4446 if (immediate_for_directive (&offset) == FAIL)
4447 return;
4448 }
4449 else
4450 offset = 0;
4451
c19d1205 4452 demand_empty_rest_of_line ();
b99bd4ef 4453
c19d1205 4454 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4455 {
c19d1205 4456 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4457 return;
4458 }
4459
c19d1205
ZW
4460 if (unwind.fp_reg != REG_SP)
4461 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4462
c19d1205
ZW
4463 /* Generate opcode to restore the value. */
4464 op = 0x90 | reg;
4465 add_unwind_opcode (op, 1);
4466
4467 /* Record the information for later. */
4468 unwind.fp_reg = reg;
4fa3602b 4469 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4470 unwind.sp_restored = 1;
b05fe5cf
ZW
4471}
4472
c19d1205
ZW
4473/* Parse an unwind_pad directive. */
4474
b05fe5cf 4475static void
c19d1205 4476s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4477{
c19d1205 4478 int offset;
b05fe5cf 4479
921e5f0a 4480 if (!unwind.proc_start)
c921be7d 4481 as_bad (MISSING_FNSTART);
921e5f0a 4482
c19d1205
ZW
4483 if (immediate_for_directive (&offset) == FAIL)
4484 return;
b99bd4ef 4485
c19d1205
ZW
4486 if (offset & 3)
4487 {
4488 as_bad (_("stack increment must be multiple of 4"));
4489 ignore_rest_of_line ();
4490 return;
4491 }
b99bd4ef 4492
c19d1205
ZW
4493 /* Don't generate any opcodes, just record the details for later. */
4494 unwind.frame_size += offset;
4495 unwind.pending_offset += offset;
4496
4497 demand_empty_rest_of_line ();
4498}
4499
4500/* Parse an unwind_setfp directive. */
4501
4502static void
4503s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4504{
c19d1205
ZW
4505 int sp_reg;
4506 int fp_reg;
4507 int offset;
4508
921e5f0a 4509 if (!unwind.proc_start)
c921be7d 4510 as_bad (MISSING_FNSTART);
921e5f0a 4511
dcbf9037 4512 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4513 if (skip_past_comma (&input_line_pointer) == FAIL)
4514 sp_reg = FAIL;
4515 else
dcbf9037 4516 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4517
c19d1205
ZW
4518 if (fp_reg == FAIL || sp_reg == FAIL)
4519 {
4520 as_bad (_("expected <reg>, <reg>"));
4521 ignore_rest_of_line ();
4522 return;
4523 }
b99bd4ef 4524
c19d1205
ZW
4525 /* Optional constant. */
4526 if (skip_past_comma (&input_line_pointer) != FAIL)
4527 {
4528 if (immediate_for_directive (&offset) == FAIL)
4529 return;
4530 }
4531 else
4532 offset = 0;
a737bd4d 4533
c19d1205 4534 demand_empty_rest_of_line ();
a737bd4d 4535
fdfde340 4536 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4537 {
c19d1205
ZW
4538 as_bad (_("register must be either sp or set by a previous"
4539 "unwind_movsp directive"));
4540 return;
a737bd4d
NC
4541 }
4542
c19d1205
ZW
4543 /* Don't generate any opcodes, just record the information for later. */
4544 unwind.fp_reg = fp_reg;
4545 unwind.fp_used = 1;
fdfde340 4546 if (sp_reg == REG_SP)
c19d1205
ZW
4547 unwind.fp_offset = unwind.frame_size - offset;
4548 else
4549 unwind.fp_offset -= offset;
a737bd4d
NC
4550}
4551
c19d1205
ZW
4552/* Parse an unwind_raw directive. */
4553
4554static void
4555s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4556{
c19d1205 4557 expressionS exp;
708587a4 4558 /* This is an arbitrary limit. */
c19d1205
ZW
4559 unsigned char op[16];
4560 int count;
a737bd4d 4561
921e5f0a 4562 if (!unwind.proc_start)
c921be7d 4563 as_bad (MISSING_FNSTART);
921e5f0a 4564
c19d1205
ZW
4565 expression (&exp);
4566 if (exp.X_op == O_constant
4567 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4568 {
c19d1205
ZW
4569 unwind.frame_size += exp.X_add_number;
4570 expression (&exp);
4571 }
4572 else
4573 exp.X_op = O_illegal;
a737bd4d 4574
c19d1205
ZW
4575 if (exp.X_op != O_constant)
4576 {
4577 as_bad (_("expected <offset>, <opcode>"));
4578 ignore_rest_of_line ();
4579 return;
4580 }
a737bd4d 4581
c19d1205 4582 count = 0;
a737bd4d 4583
c19d1205
ZW
4584 /* Parse the opcode. */
4585 for (;;)
4586 {
4587 if (count >= 16)
4588 {
4589 as_bad (_("unwind opcode too long"));
4590 ignore_rest_of_line ();
a737bd4d 4591 }
c19d1205 4592 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4593 {
c19d1205
ZW
4594 as_bad (_("invalid unwind opcode"));
4595 ignore_rest_of_line ();
4596 return;
a737bd4d 4597 }
c19d1205 4598 op[count++] = exp.X_add_number;
a737bd4d 4599
c19d1205
ZW
4600 /* Parse the next byte. */
4601 if (skip_past_comma (&input_line_pointer) == FAIL)
4602 break;
a737bd4d 4603
c19d1205
ZW
4604 expression (&exp);
4605 }
b99bd4ef 4606
c19d1205
ZW
4607 /* Add the opcode bytes in reverse order. */
4608 while (count--)
4609 add_unwind_opcode (op[count], 1);
b99bd4ef 4610
c19d1205 4611 demand_empty_rest_of_line ();
b99bd4ef 4612}
ee065d83
PB
4613
4614
4615/* Parse a .eabi_attribute directive. */
4616
4617static void
4618s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4619{
0420f52b 4620 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4621
4622 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4623 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4624}
4625
0855e32b
NS
4626/* Emit a tls fix for the symbol. */
4627
4628static void
4629s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4630{
4631 char *p;
4632 expressionS exp;
4633#ifdef md_flush_pending_output
4634 md_flush_pending_output ();
4635#endif
4636
4637#ifdef md_cons_align
4638 md_cons_align (4);
4639#endif
4640
4641 /* Since we're just labelling the code, there's no need to define a
4642 mapping symbol. */
4643 expression (&exp);
4644 p = obstack_next_free (&frchain_now->frch_obstack);
4645 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4646 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4647 : BFD_RELOC_ARM_TLS_DESCSEQ);
4648}
cdf9ccec 4649#endif /* OBJ_ELF */
0855e32b 4650
ee065d83 4651static void s_arm_arch (int);
7a1d4c38 4652static void s_arm_object_arch (int);
ee065d83
PB
4653static void s_arm_cpu (int);
4654static void s_arm_fpu (int);
69133863 4655static void s_arm_arch_extension (int);
b99bd4ef 4656
f0927246
NC
4657#ifdef TE_PE
4658
4659static void
5f4273c7 4660pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4661{
4662 expressionS exp;
4663
4664 do
4665 {
4666 expression (&exp);
4667 if (exp.X_op == O_symbol)
4668 exp.X_op = O_secrel;
4669
4670 emit_expr (&exp, 4);
4671 }
4672 while (*input_line_pointer++ == ',');
4673
4674 input_line_pointer--;
4675 demand_empty_rest_of_line ();
4676}
4677#endif /* TE_PE */
4678
c19d1205
ZW
4679/* This table describes all the machine specific pseudo-ops the assembler
4680 has to support. The fields are:
4681 pseudo-op name without dot
4682 function to call to execute this pseudo-op
4683 Integer arg to pass to the function. */
b99bd4ef 4684
c19d1205 4685const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4686{
c19d1205
ZW
4687 /* Never called because '.req' does not start a line. */
4688 { "req", s_req, 0 },
dcbf9037
JB
4689 /* Following two are likewise never called. */
4690 { "dn", s_dn, 0 },
4691 { "qn", s_qn, 0 },
c19d1205
ZW
4692 { "unreq", s_unreq, 0 },
4693 { "bss", s_bss, 0 },
4694 { "align", s_align, 0 },
4695 { "arm", s_arm, 0 },
4696 { "thumb", s_thumb, 0 },
4697 { "code", s_code, 0 },
4698 { "force_thumb", s_force_thumb, 0 },
4699 { "thumb_func", s_thumb_func, 0 },
4700 { "thumb_set", s_thumb_set, 0 },
4701 { "even", s_even, 0 },
4702 { "ltorg", s_ltorg, 0 },
4703 { "pool", s_ltorg, 0 },
4704 { "syntax", s_syntax, 0 },
8463be01
PB
4705 { "cpu", s_arm_cpu, 0 },
4706 { "arch", s_arm_arch, 0 },
7a1d4c38 4707 { "object_arch", s_arm_object_arch, 0 },
8463be01 4708 { "fpu", s_arm_fpu, 0 },
69133863 4709 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4710#ifdef OBJ_ELF
c921be7d
NC
4711 { "word", s_arm_elf_cons, 4 },
4712 { "long", s_arm_elf_cons, 4 },
4713 { "inst.n", s_arm_elf_inst, 2 },
4714 { "inst.w", s_arm_elf_inst, 4 },
4715 { "inst", s_arm_elf_inst, 0 },
4716 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4717 { "fnstart", s_arm_unwind_fnstart, 0 },
4718 { "fnend", s_arm_unwind_fnend, 0 },
4719 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4720 { "personality", s_arm_unwind_personality, 0 },
4721 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4722 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4723 { "save", s_arm_unwind_save, 0 },
fa073d69 4724 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4725 { "movsp", s_arm_unwind_movsp, 0 },
4726 { "pad", s_arm_unwind_pad, 0 },
4727 { "setfp", s_arm_unwind_setfp, 0 },
4728 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4729 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4730 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4731#else
4732 { "word", cons, 4},
f0927246
NC
4733
4734 /* These are used for dwarf. */
4735 {"2byte", cons, 2},
4736 {"4byte", cons, 4},
4737 {"8byte", cons, 8},
4738 /* These are used for dwarf2. */
4739 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4740 { "loc", dwarf2_directive_loc, 0 },
4741 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4742#endif
4743 { "extend", float_cons, 'x' },
4744 { "ldouble", float_cons, 'x' },
4745 { "packed", float_cons, 'p' },
f0927246
NC
4746#ifdef TE_PE
4747 {"secrel32", pe_directive_secrel, 0},
4748#endif
2e6976a8
DG
4749
4750 /* These are for compatibility with CodeComposer Studio. */
4751 {"ref", s_ccs_ref, 0},
4752 {"def", s_ccs_def, 0},
4753 {"asmfunc", s_ccs_asmfunc, 0},
4754 {"endasmfunc", s_ccs_endasmfunc, 0},
4755
c19d1205
ZW
4756 { 0, 0, 0 }
4757};
4758\f
4759/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4760
c19d1205
ZW
4761/* Generic immediate-value read function for use in insn parsing.
4762 STR points to the beginning of the immediate (the leading #);
4763 VAL receives the value; if the value is outside [MIN, MAX]
4764 issue an error. PREFIX_OPT is true if the immediate prefix is
4765 optional. */
b99bd4ef 4766
c19d1205
ZW
4767static int
4768parse_immediate (char **str, int *val, int min, int max,
4769 bfd_boolean prefix_opt)
4770{
4771 expressionS exp;
4772 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4773 if (exp.X_op != O_constant)
b99bd4ef 4774 {
c19d1205
ZW
4775 inst.error = _("constant expression required");
4776 return FAIL;
4777 }
b99bd4ef 4778
c19d1205
ZW
4779 if (exp.X_add_number < min || exp.X_add_number > max)
4780 {
4781 inst.error = _("immediate value out of range");
4782 return FAIL;
4783 }
b99bd4ef 4784
c19d1205
ZW
4785 *val = exp.X_add_number;
4786 return SUCCESS;
4787}
b99bd4ef 4788
5287ad62 4789/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4790 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4791 instructions. Puts the result directly in inst.operands[i]. */
4792
4793static int
8335d6aa
JW
4794parse_big_immediate (char **str, int i, expressionS *in_exp,
4795 bfd_boolean allow_symbol_p)
5287ad62
JB
4796{
4797 expressionS exp;
8335d6aa 4798 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4799 char *ptr = *str;
4800
8335d6aa 4801 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 4802
8335d6aa 4803 if (exp_p->X_op == O_constant)
036dc3f7 4804 {
8335d6aa 4805 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
4806 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4807 O_constant. We have to be careful not to break compilation for
4808 32-bit X_add_number, though. */
8335d6aa 4809 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4810 {
8335d6aa
JW
4811 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4812 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4813 & 0xffffffff);
036dc3f7
PB
4814 inst.operands[i].regisimm = 1;
4815 }
4816 }
8335d6aa
JW
4817 else if (exp_p->X_op == O_big
4818 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
4819 {
4820 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4821
5287ad62 4822 /* Bignums have their least significant bits in
477330fc
RM
4823 generic_bignum[0]. Make sure we put 32 bits in imm and
4824 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4825 gas_assert (parts != 0);
95b75c01
NC
4826
4827 /* Make sure that the number is not too big.
4828 PR 11972: Bignums can now be sign-extended to the
4829 size of a .octa so check that the out of range bits
4830 are all zero or all one. */
8335d6aa 4831 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
4832 {
4833 LITTLENUM_TYPE m = -1;
4834
4835 if (generic_bignum[parts * 2] != 0
4836 && generic_bignum[parts * 2] != m)
4837 return FAIL;
4838
8335d6aa 4839 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
4840 if (generic_bignum[j] != generic_bignum[j-1])
4841 return FAIL;
4842 }
4843
5287ad62
JB
4844 inst.operands[i].imm = 0;
4845 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4846 inst.operands[i].imm |= generic_bignum[idx]
4847 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4848 inst.operands[i].reg = 0;
4849 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4850 inst.operands[i].reg |= generic_bignum[idx]
4851 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4852 inst.operands[i].regisimm = 1;
4853 }
8335d6aa 4854 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 4855 return FAIL;
5f4273c7 4856
5287ad62
JB
4857 *str = ptr;
4858
4859 return SUCCESS;
4860}
4861
c19d1205
ZW
4862/* Returns the pseudo-register number of an FPA immediate constant,
4863 or FAIL if there isn't a valid constant here. */
b99bd4ef 4864
c19d1205
ZW
4865static int
4866parse_fpa_immediate (char ** str)
4867{
4868 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4869 char * save_in;
4870 expressionS exp;
4871 int i;
4872 int j;
b99bd4ef 4873
c19d1205
ZW
4874 /* First try and match exact strings, this is to guarantee
4875 that some formats will work even for cross assembly. */
b99bd4ef 4876
c19d1205
ZW
4877 for (i = 0; fp_const[i]; i++)
4878 {
4879 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4880 {
c19d1205 4881 char *start = *str;
b99bd4ef 4882
c19d1205
ZW
4883 *str += strlen (fp_const[i]);
4884 if (is_end_of_line[(unsigned char) **str])
4885 return i + 8;
4886 *str = start;
4887 }
4888 }
b99bd4ef 4889
c19d1205
ZW
4890 /* Just because we didn't get a match doesn't mean that the constant
4891 isn't valid, just that it is in a format that we don't
4892 automatically recognize. Try parsing it with the standard
4893 expression routines. */
b99bd4ef 4894
c19d1205 4895 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4896
c19d1205
ZW
4897 /* Look for a raw floating point number. */
4898 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4899 && is_end_of_line[(unsigned char) *save_in])
4900 {
4901 for (i = 0; i < NUM_FLOAT_VALS; i++)
4902 {
4903 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4904 {
c19d1205
ZW
4905 if (words[j] != fp_values[i][j])
4906 break;
b99bd4ef
NC
4907 }
4908
c19d1205 4909 if (j == MAX_LITTLENUMS)
b99bd4ef 4910 {
c19d1205
ZW
4911 *str = save_in;
4912 return i + 8;
b99bd4ef
NC
4913 }
4914 }
4915 }
b99bd4ef 4916
c19d1205
ZW
4917 /* Try and parse a more complex expression, this will probably fail
4918 unless the code uses a floating point prefix (eg "0f"). */
4919 save_in = input_line_pointer;
4920 input_line_pointer = *str;
4921 if (expression (&exp) == absolute_section
4922 && exp.X_op == O_big
4923 && exp.X_add_number < 0)
4924 {
4925 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4926 Ditto for 15. */
ba592044
AM
4927#define X_PRECISION 5
4928#define E_PRECISION 15L
4929 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
4930 {
4931 for (i = 0; i < NUM_FLOAT_VALS; i++)
4932 {
4933 for (j = 0; j < MAX_LITTLENUMS; j++)
4934 {
4935 if (words[j] != fp_values[i][j])
4936 break;
4937 }
b99bd4ef 4938
c19d1205
ZW
4939 if (j == MAX_LITTLENUMS)
4940 {
4941 *str = input_line_pointer;
4942 input_line_pointer = save_in;
4943 return i + 8;
4944 }
4945 }
4946 }
b99bd4ef
NC
4947 }
4948
c19d1205
ZW
4949 *str = input_line_pointer;
4950 input_line_pointer = save_in;
4951 inst.error = _("invalid FPA immediate expression");
4952 return FAIL;
b99bd4ef
NC
4953}
4954
136da414
JB
4955/* Returns 1 if a number has "quarter-precision" float format
4956 0baBbbbbbc defgh000 00000000 00000000. */
4957
4958static int
4959is_quarter_float (unsigned imm)
4960{
4961 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4962 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4963}
4964
aacf0b33
KT
4965
4966/* Detect the presence of a floating point or integer zero constant,
4967 i.e. #0.0 or #0. */
4968
4969static bfd_boolean
4970parse_ifimm_zero (char **in)
4971{
4972 int error_code;
4973
4974 if (!is_immediate_prefix (**in))
4975 return FALSE;
4976
4977 ++*in;
0900a05b
JW
4978
4979 /* Accept #0x0 as a synonym for #0. */
4980 if (strncmp (*in, "0x", 2) == 0)
4981 {
4982 int val;
4983 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
4984 return FALSE;
4985 return TRUE;
4986 }
4987
aacf0b33
KT
4988 error_code = atof_generic (in, ".", EXP_CHARS,
4989 &generic_floating_point_number);
4990
4991 if (!error_code
4992 && generic_floating_point_number.sign == '+'
4993 && (generic_floating_point_number.low
4994 > generic_floating_point_number.leader))
4995 return TRUE;
4996
4997 return FALSE;
4998}
4999
136da414
JB
5000/* Parse an 8-bit "quarter-precision" floating point number of the form:
5001 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
5002 The zero and minus-zero cases need special handling, since they can't be
5003 encoded in the "quarter-precision" float format, but can nonetheless be
5004 loaded as integer constants. */
136da414
JB
5005
5006static unsigned
5007parse_qfloat_immediate (char **ccp, int *immed)
5008{
5009 char *str = *ccp;
c96612cc 5010 char *fpnum;
136da414 5011 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5012 int found_fpchar = 0;
5f4273c7 5013
136da414 5014 skip_past_char (&str, '#');
5f4273c7 5015
c96612cc
JB
5016 /* We must not accidentally parse an integer as a floating-point number. Make
5017 sure that the value we parse is not an integer by checking for special
5018 characters '.' or 'e'.
5019 FIXME: This is a horrible hack, but doing better is tricky because type
5020 information isn't in a very usable state at parse time. */
5021 fpnum = str;
5022 skip_whitespace (fpnum);
5023
5024 if (strncmp (fpnum, "0x", 2) == 0)
5025 return FAIL;
5026 else
5027 {
5028 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5029 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5030 {
5031 found_fpchar = 1;
5032 break;
5033 }
c96612cc
JB
5034
5035 if (!found_fpchar)
477330fc 5036 return FAIL;
c96612cc 5037 }
5f4273c7 5038
136da414
JB
5039 if ((str = atof_ieee (str, 's', words)) != NULL)
5040 {
5041 unsigned fpword = 0;
5042 int i;
5f4273c7 5043
136da414
JB
5044 /* Our FP word must be 32 bits (single-precision FP). */
5045 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5046 {
5047 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5048 fpword |= words[i];
5049 }
5f4273c7 5050
c96612cc 5051 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5052 *immed = fpword;
136da414 5053 else
477330fc 5054 return FAIL;
136da414
JB
5055
5056 *ccp = str;
5f4273c7 5057
136da414
JB
5058 return SUCCESS;
5059 }
5f4273c7 5060
136da414
JB
5061 return FAIL;
5062}
5063
c19d1205
ZW
5064/* Shift operands. */
5065enum shift_kind
b99bd4ef 5066{
c19d1205
ZW
5067 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5068};
b99bd4ef 5069
c19d1205
ZW
5070struct asm_shift_name
5071{
5072 const char *name;
5073 enum shift_kind kind;
5074};
b99bd4ef 5075
c19d1205
ZW
5076/* Third argument to parse_shift. */
5077enum parse_shift_mode
5078{
5079 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5080 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5081 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5082 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5083 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5084};
b99bd4ef 5085
c19d1205
ZW
5086/* Parse a <shift> specifier on an ARM data processing instruction.
5087 This has three forms:
b99bd4ef 5088
c19d1205
ZW
5089 (LSL|LSR|ASL|ASR|ROR) Rs
5090 (LSL|LSR|ASL|ASR|ROR) #imm
5091 RRX
b99bd4ef 5092
c19d1205
ZW
5093 Note that ASL is assimilated to LSL in the instruction encoding, and
5094 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5095
c19d1205
ZW
5096static int
5097parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5098{
c19d1205
ZW
5099 const struct asm_shift_name *shift_name;
5100 enum shift_kind shift;
5101 char *s = *str;
5102 char *p = s;
5103 int reg;
b99bd4ef 5104
c19d1205
ZW
5105 for (p = *str; ISALPHA (*p); p++)
5106 ;
b99bd4ef 5107
c19d1205 5108 if (p == *str)
b99bd4ef 5109 {
c19d1205
ZW
5110 inst.error = _("shift expression expected");
5111 return FAIL;
b99bd4ef
NC
5112 }
5113
21d799b5 5114 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5115 p - *str);
c19d1205
ZW
5116
5117 if (shift_name == NULL)
b99bd4ef 5118 {
c19d1205
ZW
5119 inst.error = _("shift expression expected");
5120 return FAIL;
b99bd4ef
NC
5121 }
5122
c19d1205 5123 shift = shift_name->kind;
b99bd4ef 5124
c19d1205
ZW
5125 switch (mode)
5126 {
5127 case NO_SHIFT_RESTRICT:
5128 case SHIFT_IMMEDIATE: break;
b99bd4ef 5129
c19d1205
ZW
5130 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5131 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5132 {
5133 inst.error = _("'LSL' or 'ASR' required");
5134 return FAIL;
5135 }
5136 break;
b99bd4ef 5137
c19d1205
ZW
5138 case SHIFT_LSL_IMMEDIATE:
5139 if (shift != SHIFT_LSL)
5140 {
5141 inst.error = _("'LSL' required");
5142 return FAIL;
5143 }
5144 break;
b99bd4ef 5145
c19d1205
ZW
5146 case SHIFT_ASR_IMMEDIATE:
5147 if (shift != SHIFT_ASR)
5148 {
5149 inst.error = _("'ASR' required");
5150 return FAIL;
5151 }
5152 break;
b99bd4ef 5153
c19d1205
ZW
5154 default: abort ();
5155 }
b99bd4ef 5156
c19d1205
ZW
5157 if (shift != SHIFT_RRX)
5158 {
5159 /* Whitespace can appear here if the next thing is a bare digit. */
5160 skip_whitespace (p);
b99bd4ef 5161
c19d1205 5162 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5163 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5164 {
5165 inst.operands[i].imm = reg;
5166 inst.operands[i].immisreg = 1;
5167 }
5168 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5169 return FAIL;
5170 }
5171 inst.operands[i].shift_kind = shift;
5172 inst.operands[i].shifted = 1;
5173 *str = p;
5174 return SUCCESS;
b99bd4ef
NC
5175}
5176
c19d1205 5177/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5178
c19d1205
ZW
5179 #<immediate>
5180 #<immediate>, <rotate>
5181 <Rm>
5182 <Rm>, <shift>
b99bd4ef 5183
c19d1205
ZW
5184 where <shift> is defined by parse_shift above, and <rotate> is a
5185 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5186 is deferred to md_apply_fix. */
b99bd4ef 5187
c19d1205
ZW
5188static int
5189parse_shifter_operand (char **str, int i)
5190{
5191 int value;
91d6fa6a 5192 expressionS exp;
b99bd4ef 5193
dcbf9037 5194 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5195 {
5196 inst.operands[i].reg = value;
5197 inst.operands[i].isreg = 1;
b99bd4ef 5198
c19d1205
ZW
5199 /* parse_shift will override this if appropriate */
5200 inst.reloc.exp.X_op = O_constant;
5201 inst.reloc.exp.X_add_number = 0;
b99bd4ef 5202
c19d1205
ZW
5203 if (skip_past_comma (str) == FAIL)
5204 return SUCCESS;
b99bd4ef 5205
c19d1205
ZW
5206 /* Shift operation on register. */
5207 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5208 }
5209
c19d1205
ZW
5210 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5211 return FAIL;
b99bd4ef 5212
c19d1205 5213 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5214 {
c19d1205 5215 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5216 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5217 return FAIL;
b99bd4ef 5218
91d6fa6a 5219 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
5220 {
5221 inst.error = _("constant expression expected");
5222 return FAIL;
5223 }
b99bd4ef 5224
91d6fa6a 5225 value = exp.X_add_number;
c19d1205
ZW
5226 if (value < 0 || value > 30 || value % 2 != 0)
5227 {
5228 inst.error = _("invalid rotation");
5229 return FAIL;
5230 }
5231 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5232 {
5233 inst.error = _("invalid constant");
5234 return FAIL;
5235 }
09d92015 5236
a415b1cd
JB
5237 /* Encode as specified. */
5238 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5239 return SUCCESS;
09d92015
MM
5240 }
5241
c19d1205
ZW
5242 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5243 inst.reloc.pc_rel = 0;
5244 return SUCCESS;
09d92015
MM
5245}
5246
4962c51a
MS
5247/* Group relocation information. Each entry in the table contains the
5248 textual name of the relocation as may appear in assembler source
5249 and must end with a colon.
5250 Along with this textual name are the relocation codes to be used if
5251 the corresponding instruction is an ALU instruction (ADD or SUB only),
5252 an LDR, an LDRS, or an LDC. */
5253
5254struct group_reloc_table_entry
5255{
5256 const char *name;
5257 int alu_code;
5258 int ldr_code;
5259 int ldrs_code;
5260 int ldc_code;
5261};
5262
5263typedef enum
5264{
5265 /* Varieties of non-ALU group relocation. */
5266
5267 GROUP_LDR,
5268 GROUP_LDRS,
5269 GROUP_LDC
5270} group_reloc_type;
5271
5272static struct group_reloc_table_entry group_reloc_table[] =
5273 { /* Program counter relative: */
5274 { "pc_g0_nc",
5275 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5276 0, /* LDR */
5277 0, /* LDRS */
5278 0 }, /* LDC */
5279 { "pc_g0",
5280 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5281 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5282 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5283 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5284 { "pc_g1_nc",
5285 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5286 0, /* LDR */
5287 0, /* LDRS */
5288 0 }, /* LDC */
5289 { "pc_g1",
5290 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5291 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5292 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5293 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5294 { "pc_g2",
5295 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5296 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5297 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5298 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5299 /* Section base relative */
5300 { "sb_g0_nc",
5301 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5302 0, /* LDR */
5303 0, /* LDRS */
5304 0 }, /* LDC */
5305 { "sb_g0",
5306 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5307 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5308 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5309 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5310 { "sb_g1_nc",
5311 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5312 0, /* LDR */
5313 0, /* LDRS */
5314 0 }, /* LDC */
5315 { "sb_g1",
5316 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5317 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5318 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5319 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5320 { "sb_g2",
5321 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5322 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5323 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
5324 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
5325
5326/* Given the address of a pointer pointing to the textual name of a group
5327 relocation as may appear in assembler source, attempt to find its details
5328 in group_reloc_table. The pointer will be updated to the character after
5329 the trailing colon. On failure, FAIL will be returned; SUCCESS
5330 otherwise. On success, *entry will be updated to point at the relevant
5331 group_reloc_table entry. */
5332
5333static int
5334find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5335{
5336 unsigned int i;
5337 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5338 {
5339 int length = strlen (group_reloc_table[i].name);
5340
5f4273c7
NC
5341 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5342 && (*str)[length] == ':')
477330fc
RM
5343 {
5344 *out = &group_reloc_table[i];
5345 *str += (length + 1);
5346 return SUCCESS;
5347 }
4962c51a
MS
5348 }
5349
5350 return FAIL;
5351}
5352
5353/* Parse a <shifter_operand> for an ARM data processing instruction
5354 (as for parse_shifter_operand) where group relocations are allowed:
5355
5356 #<immediate>
5357 #<immediate>, <rotate>
5358 #:<group_reloc>:<expression>
5359 <Rm>
5360 <Rm>, <shift>
5361
5362 where <group_reloc> is one of the strings defined in group_reloc_table.
5363 The hashes are optional.
5364
5365 Everything else is as for parse_shifter_operand. */
5366
5367static parse_operand_result
5368parse_shifter_operand_group_reloc (char **str, int i)
5369{
5370 /* Determine if we have the sequence of characters #: or just :
5371 coming next. If we do, then we check for a group relocation.
5372 If we don't, punt the whole lot to parse_shifter_operand. */
5373
5374 if (((*str)[0] == '#' && (*str)[1] == ':')
5375 || (*str)[0] == ':')
5376 {
5377 struct group_reloc_table_entry *entry;
5378
5379 if ((*str)[0] == '#')
477330fc 5380 (*str) += 2;
4962c51a 5381 else
477330fc 5382 (*str)++;
4962c51a
MS
5383
5384 /* Try to parse a group relocation. Anything else is an error. */
5385 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5386 {
5387 inst.error = _("unknown group relocation");
5388 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5389 }
4962c51a
MS
5390
5391 /* We now have the group relocation table entry corresponding to
477330fc 5392 the name in the assembler source. Next, we parse the expression. */
4962c51a 5393 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
477330fc 5394 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5395
5396 /* Record the relocation type (always the ALU variant here). */
21d799b5 5397 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5398 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5399
5400 return PARSE_OPERAND_SUCCESS;
5401 }
5402 else
5403 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5404 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5405
5406 /* Never reached. */
5407}
5408
8e560766
MGD
5409/* Parse a Neon alignment expression. Information is written to
5410 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5411
8e560766
MGD
5412 align .imm = align << 8, .immisalign=1, .preind=0 */
5413static parse_operand_result
5414parse_neon_alignment (char **str, int i)
5415{
5416 char *p = *str;
5417 expressionS exp;
5418
5419 my_get_expression (&exp, &p, GE_NO_PREFIX);
5420
5421 if (exp.X_op != O_constant)
5422 {
5423 inst.error = _("alignment must be constant");
5424 return PARSE_OPERAND_FAIL;
5425 }
5426
5427 inst.operands[i].imm = exp.X_add_number << 8;
5428 inst.operands[i].immisalign = 1;
5429 /* Alignments are not pre-indexes. */
5430 inst.operands[i].preind = 0;
5431
5432 *str = p;
5433 return PARSE_OPERAND_SUCCESS;
5434}
5435
c19d1205
ZW
5436/* Parse all forms of an ARM address expression. Information is written
5437 to inst.operands[i] and/or inst.reloc.
09d92015 5438
c19d1205 5439 Preindexed addressing (.preind=1):
09d92015 5440
c19d1205
ZW
5441 [Rn, #offset] .reg=Rn .reloc.exp=offset
5442 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5443 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5444 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5445
c19d1205 5446 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5447
c19d1205 5448 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5449
c19d1205
ZW
5450 [Rn], #offset .reg=Rn .reloc.exp=offset
5451 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5452 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5453 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5454
c19d1205 5455 Unindexed addressing (.preind=0, .postind=0):
09d92015 5456
c19d1205 5457 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5458
c19d1205 5459 Other:
09d92015 5460
c19d1205
ZW
5461 [Rn]{!} shorthand for [Rn,#0]{!}
5462 =immediate .isreg=0 .reloc.exp=immediate
5463 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5464
c19d1205
ZW
5465 It is the caller's responsibility to check for addressing modes not
5466 supported by the instruction, and to set inst.reloc.type. */
5467
4962c51a
MS
5468static parse_operand_result
5469parse_address_main (char **str, int i, int group_relocations,
477330fc 5470 group_reloc_type group_type)
09d92015 5471{
c19d1205
ZW
5472 char *p = *str;
5473 int reg;
09d92015 5474
c19d1205 5475 if (skip_past_char (&p, '[') == FAIL)
09d92015 5476 {
c19d1205
ZW
5477 if (skip_past_char (&p, '=') == FAIL)
5478 {
974da60d 5479 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5480 inst.reloc.pc_rel = 1;
5481 inst.operands[i].reg = REG_PC;
5482 inst.operands[i].isreg = 1;
5483 inst.operands[i].preind = 1;
09d92015 5484
8335d6aa
JW
5485 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5486 return PARSE_OPERAND_FAIL;
5487 }
5488 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5489 /*allow_symbol_p=*/TRUE))
4962c51a 5490 return PARSE_OPERAND_FAIL;
09d92015 5491
c19d1205 5492 *str = p;
4962c51a 5493 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5494 }
5495
8ab8155f
NC
5496 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5497 skip_whitespace (p);
5498
dcbf9037 5499 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5500 {
c19d1205 5501 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5502 return PARSE_OPERAND_FAIL;
09d92015 5503 }
c19d1205
ZW
5504 inst.operands[i].reg = reg;
5505 inst.operands[i].isreg = 1;
09d92015 5506
c19d1205 5507 if (skip_past_comma (&p) == SUCCESS)
09d92015 5508 {
c19d1205 5509 inst.operands[i].preind = 1;
09d92015 5510
c19d1205
ZW
5511 if (*p == '+') p++;
5512 else if (*p == '-') p++, inst.operands[i].negative = 1;
5513
dcbf9037 5514 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5515 {
c19d1205
ZW
5516 inst.operands[i].imm = reg;
5517 inst.operands[i].immisreg = 1;
5518
5519 if (skip_past_comma (&p) == SUCCESS)
5520 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5521 return PARSE_OPERAND_FAIL;
c19d1205 5522 }
5287ad62 5523 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5524 {
5525 /* FIXME: '@' should be used here, but it's filtered out by generic
5526 code before we get to see it here. This may be subject to
5527 change. */
5528 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5529
8e560766
MGD
5530 if (result != PARSE_OPERAND_SUCCESS)
5531 return result;
5532 }
c19d1205
ZW
5533 else
5534 {
5535 if (inst.operands[i].negative)
5536 {
5537 inst.operands[i].negative = 0;
5538 p--;
5539 }
4962c51a 5540
5f4273c7
NC
5541 if (group_relocations
5542 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5543 {
5544 struct group_reloc_table_entry *entry;
5545
477330fc
RM
5546 /* Skip over the #: or : sequence. */
5547 if (*p == '#')
5548 p += 2;
5549 else
5550 p++;
4962c51a
MS
5551
5552 /* Try to parse a group relocation. Anything else is an
477330fc 5553 error. */
4962c51a
MS
5554 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5555 {
5556 inst.error = _("unknown group relocation");
5557 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5558 }
5559
5560 /* We now have the group relocation table entry corresponding to
5561 the name in the assembler source. Next, we parse the
477330fc 5562 expression. */
4962c51a
MS
5563 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5564 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5565
5566 /* Record the relocation type. */
477330fc
RM
5567 switch (group_type)
5568 {
5569 case GROUP_LDR:
5570 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5571 break;
4962c51a 5572
477330fc
RM
5573 case GROUP_LDRS:
5574 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5575 break;
4962c51a 5576
477330fc
RM
5577 case GROUP_LDC:
5578 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5579 break;
4962c51a 5580
477330fc
RM
5581 default:
5582 gas_assert (0);
5583 }
4962c51a 5584
477330fc 5585 if (inst.reloc.type == 0)
4962c51a
MS
5586 {
5587 inst.error = _("this group relocation is not allowed on this instruction");
5588 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5589 }
477330fc
RM
5590 }
5591 else
26d97720
NS
5592 {
5593 char *q = p;
5594 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5595 return PARSE_OPERAND_FAIL;
5596 /* If the offset is 0, find out if it's a +0 or -0. */
5597 if (inst.reloc.exp.X_op == O_constant
5598 && inst.reloc.exp.X_add_number == 0)
5599 {
5600 skip_whitespace (q);
5601 if (*q == '#')
5602 {
5603 q++;
5604 skip_whitespace (q);
5605 }
5606 if (*q == '-')
5607 inst.operands[i].negative = 1;
5608 }
5609 }
09d92015
MM
5610 }
5611 }
8e560766
MGD
5612 else if (skip_past_char (&p, ':') == SUCCESS)
5613 {
5614 /* FIXME: '@' should be used here, but it's filtered out by generic code
5615 before we get to see it here. This may be subject to change. */
5616 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5617
8e560766
MGD
5618 if (result != PARSE_OPERAND_SUCCESS)
5619 return result;
5620 }
09d92015 5621
c19d1205 5622 if (skip_past_char (&p, ']') == FAIL)
09d92015 5623 {
c19d1205 5624 inst.error = _("']' expected");
4962c51a 5625 return PARSE_OPERAND_FAIL;
09d92015
MM
5626 }
5627
c19d1205
ZW
5628 if (skip_past_char (&p, '!') == SUCCESS)
5629 inst.operands[i].writeback = 1;
09d92015 5630
c19d1205 5631 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5632 {
c19d1205
ZW
5633 if (skip_past_char (&p, '{') == SUCCESS)
5634 {
5635 /* [Rn], {expr} - unindexed, with option */
5636 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5637 0, 255, TRUE) == FAIL)
4962c51a 5638 return PARSE_OPERAND_FAIL;
09d92015 5639
c19d1205
ZW
5640 if (skip_past_char (&p, '}') == FAIL)
5641 {
5642 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5643 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5644 }
5645 if (inst.operands[i].preind)
5646 {
5647 inst.error = _("cannot combine index with option");
4962c51a 5648 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5649 }
5650 *str = p;
4962c51a 5651 return PARSE_OPERAND_SUCCESS;
09d92015 5652 }
c19d1205
ZW
5653 else
5654 {
5655 inst.operands[i].postind = 1;
5656 inst.operands[i].writeback = 1;
09d92015 5657
c19d1205
ZW
5658 if (inst.operands[i].preind)
5659 {
5660 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5661 return PARSE_OPERAND_FAIL;
c19d1205 5662 }
09d92015 5663
c19d1205
ZW
5664 if (*p == '+') p++;
5665 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5666
dcbf9037 5667 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5668 {
477330fc
RM
5669 /* We might be using the immediate for alignment already. If we
5670 are, OR the register number into the low-order bits. */
5671 if (inst.operands[i].immisalign)
5672 inst.operands[i].imm |= reg;
5673 else
5674 inst.operands[i].imm = reg;
c19d1205 5675 inst.operands[i].immisreg = 1;
a737bd4d 5676
c19d1205
ZW
5677 if (skip_past_comma (&p) == SUCCESS)
5678 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5679 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5680 }
5681 else
5682 {
26d97720 5683 char *q = p;
c19d1205
ZW
5684 if (inst.operands[i].negative)
5685 {
5686 inst.operands[i].negative = 0;
5687 p--;
5688 }
5689 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5690 return PARSE_OPERAND_FAIL;
26d97720
NS
5691 /* If the offset is 0, find out if it's a +0 or -0. */
5692 if (inst.reloc.exp.X_op == O_constant
5693 && inst.reloc.exp.X_add_number == 0)
5694 {
5695 skip_whitespace (q);
5696 if (*q == '#')
5697 {
5698 q++;
5699 skip_whitespace (q);
5700 }
5701 if (*q == '-')
5702 inst.operands[i].negative = 1;
5703 }
c19d1205
ZW
5704 }
5705 }
a737bd4d
NC
5706 }
5707
c19d1205
ZW
5708 /* If at this point neither .preind nor .postind is set, we have a
5709 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5710 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5711 {
5712 inst.operands[i].preind = 1;
5713 inst.reloc.exp.X_op = O_constant;
5714 inst.reloc.exp.X_add_number = 0;
5715 }
5716 *str = p;
4962c51a
MS
5717 return PARSE_OPERAND_SUCCESS;
5718}
5719
5720static int
5721parse_address (char **str, int i)
5722{
21d799b5 5723 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5724 ? SUCCESS : FAIL;
4962c51a
MS
5725}
5726
5727static parse_operand_result
5728parse_address_group_reloc (char **str, int i, group_reloc_type type)
5729{
5730 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5731}
5732
b6895b4f
PB
5733/* Parse an operand for a MOVW or MOVT instruction. */
5734static int
5735parse_half (char **str)
5736{
5737 char * p;
5f4273c7 5738
b6895b4f
PB
5739 p = *str;
5740 skip_past_char (&p, '#');
5f4273c7 5741 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5742 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5743 else if (strncasecmp (p, ":upper16:", 9) == 0)
5744 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5745
5746 if (inst.reloc.type != BFD_RELOC_UNUSED)
5747 {
5748 p += 9;
5f4273c7 5749 skip_whitespace (p);
b6895b4f
PB
5750 }
5751
5752 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5753 return FAIL;
5754
5755 if (inst.reloc.type == BFD_RELOC_UNUSED)
5756 {
5757 if (inst.reloc.exp.X_op != O_constant)
5758 {
5759 inst.error = _("constant expression expected");
5760 return FAIL;
5761 }
5762 if (inst.reloc.exp.X_add_number < 0
5763 || inst.reloc.exp.X_add_number > 0xffff)
5764 {
5765 inst.error = _("immediate value out of range");
5766 return FAIL;
5767 }
5768 }
5769 *str = p;
5770 return SUCCESS;
5771}
5772
c19d1205 5773/* Miscellaneous. */
a737bd4d 5774
c19d1205
ZW
5775/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5776 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5777static int
d2cd1205 5778parse_psr (char **str, bfd_boolean lhs)
09d92015 5779{
c19d1205
ZW
5780 char *p;
5781 unsigned long psr_field;
62b3e311
PB
5782 const struct asm_psr *psr;
5783 char *start;
d2cd1205 5784 bfd_boolean is_apsr = FALSE;
ac7f631b 5785 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5786
a4482bb6
NC
5787 /* PR gas/12698: If the user has specified -march=all then m_profile will
5788 be TRUE, but we want to ignore it in this case as we are building for any
5789 CPU type, including non-m variants. */
823d2571 5790 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
5791 m_profile = FALSE;
5792
c19d1205
ZW
5793 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5794 feature for ease of use and backwards compatibility. */
5795 p = *str;
62b3e311 5796 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5797 {
5798 if (m_profile)
5799 goto unsupported_psr;
fa94de6b 5800
d2cd1205
JB
5801 psr_field = SPSR_BIT;
5802 }
5803 else if (strncasecmp (p, "CPSR", 4) == 0)
5804 {
5805 if (m_profile)
5806 goto unsupported_psr;
5807
5808 psr_field = 0;
5809 }
5810 else if (strncasecmp (p, "APSR", 4) == 0)
5811 {
5812 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5813 and ARMv7-R architecture CPUs. */
5814 is_apsr = TRUE;
5815 psr_field = 0;
5816 }
5817 else if (m_profile)
62b3e311
PB
5818 {
5819 start = p;
5820 do
5821 p++;
5822 while (ISALNUM (*p) || *p == '_');
5823
d2cd1205
JB
5824 if (strncasecmp (start, "iapsr", 5) == 0
5825 || strncasecmp (start, "eapsr", 5) == 0
5826 || strncasecmp (start, "xpsr", 4) == 0
5827 || strncasecmp (start, "psr", 3) == 0)
5828 p = start + strcspn (start, "rR") + 1;
5829
21d799b5 5830 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5831 p - start);
d2cd1205 5832
62b3e311
PB
5833 if (!psr)
5834 return FAIL;
09d92015 5835
d2cd1205
JB
5836 /* If APSR is being written, a bitfield may be specified. Note that
5837 APSR itself is handled above. */
5838 if (psr->field <= 3)
5839 {
5840 psr_field = psr->field;
5841 is_apsr = TRUE;
5842 goto check_suffix;
5843 }
5844
62b3e311 5845 *str = p;
d2cd1205
JB
5846 /* M-profile MSR instructions have the mask field set to "10", except
5847 *PSR variants which modify APSR, which may use a different mask (and
5848 have been handled already). Do that by setting the PSR_f field
5849 here. */
5850 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5851 }
d2cd1205
JB
5852 else
5853 goto unsupported_psr;
09d92015 5854
62b3e311 5855 p += 4;
d2cd1205 5856check_suffix:
c19d1205
ZW
5857 if (*p == '_')
5858 {
5859 /* A suffix follows. */
c19d1205
ZW
5860 p++;
5861 start = p;
a737bd4d 5862
c19d1205
ZW
5863 do
5864 p++;
5865 while (ISALNUM (*p) || *p == '_');
a737bd4d 5866
d2cd1205
JB
5867 if (is_apsr)
5868 {
5869 /* APSR uses a notation for bits, rather than fields. */
5870 unsigned int nzcvq_bits = 0;
5871 unsigned int g_bit = 0;
5872 char *bit;
fa94de6b 5873
d2cd1205
JB
5874 for (bit = start; bit != p; bit++)
5875 {
5876 switch (TOLOWER (*bit))
477330fc 5877 {
d2cd1205
JB
5878 case 'n':
5879 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5880 break;
5881
5882 case 'z':
5883 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5884 break;
5885
5886 case 'c':
5887 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5888 break;
5889
5890 case 'v':
5891 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5892 break;
fa94de6b 5893
d2cd1205
JB
5894 case 'q':
5895 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5896 break;
fa94de6b 5897
d2cd1205
JB
5898 case 'g':
5899 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5900 break;
fa94de6b 5901
d2cd1205
JB
5902 default:
5903 inst.error = _("unexpected bit specified after APSR");
5904 return FAIL;
5905 }
5906 }
fa94de6b 5907
d2cd1205
JB
5908 if (nzcvq_bits == 0x1f)
5909 psr_field |= PSR_f;
fa94de6b 5910
d2cd1205
JB
5911 if (g_bit == 0x1)
5912 {
5913 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5914 {
d2cd1205
JB
5915 inst.error = _("selected processor does not "
5916 "support DSP extension");
5917 return FAIL;
5918 }
5919
5920 psr_field |= PSR_s;
5921 }
fa94de6b 5922
d2cd1205
JB
5923 if ((nzcvq_bits & 0x20) != 0
5924 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5925 || (g_bit & 0x2) != 0)
5926 {
5927 inst.error = _("bad bitmask specified after APSR");
5928 return FAIL;
5929 }
5930 }
5931 else
477330fc 5932 {
d2cd1205 5933 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 5934 p - start);
d2cd1205 5935 if (!psr)
477330fc 5936 goto error;
a737bd4d 5937
d2cd1205
JB
5938 psr_field |= psr->field;
5939 }
a737bd4d 5940 }
c19d1205 5941 else
a737bd4d 5942 {
c19d1205
ZW
5943 if (ISALNUM (*p))
5944 goto error; /* Garbage after "[CS]PSR". */
5945
d2cd1205 5946 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 5947 is deprecated, but allow it anyway. */
d2cd1205
JB
5948 if (is_apsr && lhs)
5949 {
5950 psr_field |= PSR_f;
5951 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5952 "deprecated"));
5953 }
5954 else if (!m_profile)
5955 /* These bits are never right for M-profile devices: don't set them
5956 (only code paths which read/write APSR reach here). */
5957 psr_field |= (PSR_c | PSR_f);
a737bd4d 5958 }
c19d1205
ZW
5959 *str = p;
5960 return psr_field;
a737bd4d 5961
d2cd1205
JB
5962 unsupported_psr:
5963 inst.error = _("selected processor does not support requested special "
5964 "purpose register");
5965 return FAIL;
5966
c19d1205
ZW
5967 error:
5968 inst.error = _("flag for {c}psr instruction expected");
5969 return FAIL;
a737bd4d
NC
5970}
5971
c19d1205
ZW
5972/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5973 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5974
c19d1205
ZW
5975static int
5976parse_cps_flags (char **str)
a737bd4d 5977{
c19d1205
ZW
5978 int val = 0;
5979 int saw_a_flag = 0;
5980 char *s = *str;
a737bd4d 5981
c19d1205
ZW
5982 for (;;)
5983 switch (*s++)
5984 {
5985 case '\0': case ',':
5986 goto done;
a737bd4d 5987
c19d1205
ZW
5988 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5989 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5990 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5991
c19d1205
ZW
5992 default:
5993 inst.error = _("unrecognized CPS flag");
5994 return FAIL;
5995 }
a737bd4d 5996
c19d1205
ZW
5997 done:
5998 if (saw_a_flag == 0)
a737bd4d 5999 {
c19d1205
ZW
6000 inst.error = _("missing CPS flags");
6001 return FAIL;
a737bd4d 6002 }
a737bd4d 6003
c19d1205
ZW
6004 *str = s - 1;
6005 return val;
a737bd4d
NC
6006}
6007
c19d1205
ZW
6008/* Parse an endian specifier ("BE" or "LE", case insensitive);
6009 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6010
6011static int
c19d1205 6012parse_endian_specifier (char **str)
a737bd4d 6013{
c19d1205
ZW
6014 int little_endian;
6015 char *s = *str;
a737bd4d 6016
c19d1205
ZW
6017 if (strncasecmp (s, "BE", 2))
6018 little_endian = 0;
6019 else if (strncasecmp (s, "LE", 2))
6020 little_endian = 1;
6021 else
a737bd4d 6022 {
c19d1205 6023 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6024 return FAIL;
6025 }
6026
c19d1205 6027 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6028 {
c19d1205 6029 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6030 return FAIL;
6031 }
6032
c19d1205
ZW
6033 *str = s + 2;
6034 return little_endian;
6035}
a737bd4d 6036
c19d1205
ZW
6037/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6038 value suitable for poking into the rotate field of an sxt or sxta
6039 instruction, or FAIL on error. */
6040
6041static int
6042parse_ror (char **str)
6043{
6044 int rot;
6045 char *s = *str;
6046
6047 if (strncasecmp (s, "ROR", 3) == 0)
6048 s += 3;
6049 else
a737bd4d 6050 {
c19d1205 6051 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6052 return FAIL;
6053 }
c19d1205
ZW
6054
6055 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6056 return FAIL;
6057
6058 switch (rot)
a737bd4d 6059 {
c19d1205
ZW
6060 case 0: *str = s; return 0x0;
6061 case 8: *str = s; return 0x1;
6062 case 16: *str = s; return 0x2;
6063 case 24: *str = s; return 0x3;
6064
6065 default:
6066 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6067 return FAIL;
6068 }
c19d1205 6069}
a737bd4d 6070
c19d1205
ZW
6071/* Parse a conditional code (from conds[] below). The value returned is in the
6072 range 0 .. 14, or FAIL. */
6073static int
6074parse_cond (char **str)
6075{
c462b453 6076 char *q;
c19d1205 6077 const struct asm_cond *c;
c462b453
PB
6078 int n;
6079 /* Condition codes are always 2 characters, so matching up to
6080 3 characters is sufficient. */
6081 char cond[3];
a737bd4d 6082
c462b453
PB
6083 q = *str;
6084 n = 0;
6085 while (ISALPHA (*q) && n < 3)
6086 {
e07e6e58 6087 cond[n] = TOLOWER (*q);
c462b453
PB
6088 q++;
6089 n++;
6090 }
a737bd4d 6091
21d799b5 6092 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6093 if (!c)
a737bd4d 6094 {
c19d1205 6095 inst.error = _("condition required");
a737bd4d
NC
6096 return FAIL;
6097 }
6098
c19d1205
ZW
6099 *str = q;
6100 return c->value;
6101}
6102
e797f7e0
MGD
6103/* If the given feature available in the selected CPU, mark it as used.
6104 Returns TRUE iff feature is available. */
6105static bfd_boolean
6106mark_feature_used (const arm_feature_set *feature)
6107{
6108 /* Ensure the option is valid on the current architecture. */
6109 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6110 return FALSE;
6111
6112 /* Add the appropriate architecture feature for the barrier option used.
6113 */
6114 if (thumb_mode)
6115 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6116 else
6117 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6118
6119 return TRUE;
6120}
6121
62b3e311
PB
6122/* Parse an option for a barrier instruction. Returns the encoding for the
6123 option, or FAIL. */
6124static int
6125parse_barrier (char **str)
6126{
6127 char *p, *q;
6128 const struct asm_barrier_opt *o;
6129
6130 p = q = *str;
6131 while (ISALPHA (*q))
6132 q++;
6133
21d799b5 6134 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6135 q - p);
62b3e311
PB
6136 if (!o)
6137 return FAIL;
6138
e797f7e0
MGD
6139 if (!mark_feature_used (&o->arch))
6140 return FAIL;
6141
62b3e311
PB
6142 *str = q;
6143 return o->value;
6144}
6145
92e90b6e
PB
6146/* Parse the operands of a table branch instruction. Similar to a memory
6147 operand. */
6148static int
6149parse_tb (char **str)
6150{
6151 char * p = *str;
6152 int reg;
6153
6154 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6155 {
6156 inst.error = _("'[' expected");
6157 return FAIL;
6158 }
92e90b6e 6159
dcbf9037 6160 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6161 {
6162 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6163 return FAIL;
6164 }
6165 inst.operands[0].reg = reg;
6166
6167 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6168 {
6169 inst.error = _("',' expected");
6170 return FAIL;
6171 }
5f4273c7 6172
dcbf9037 6173 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6174 {
6175 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6176 return FAIL;
6177 }
6178 inst.operands[0].imm = reg;
6179
6180 if (skip_past_comma (&p) == SUCCESS)
6181 {
6182 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6183 return FAIL;
6184 if (inst.reloc.exp.X_add_number != 1)
6185 {
6186 inst.error = _("invalid shift");
6187 return FAIL;
6188 }
6189 inst.operands[0].shifted = 1;
6190 }
6191
6192 if (skip_past_char (&p, ']') == FAIL)
6193 {
6194 inst.error = _("']' expected");
6195 return FAIL;
6196 }
6197 *str = p;
6198 return SUCCESS;
6199}
6200
5287ad62
JB
6201/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6202 information on the types the operands can take and how they are encoded.
037e8744
JB
6203 Up to four operands may be read; this function handles setting the
6204 ".present" field for each read operand itself.
5287ad62
JB
6205 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6206 else returns FAIL. */
6207
6208static int
6209parse_neon_mov (char **str, int *which_operand)
6210{
6211 int i = *which_operand, val;
6212 enum arm_reg_type rtype;
6213 char *ptr = *str;
dcbf9037 6214 struct neon_type_el optype;
5f4273c7 6215
dcbf9037 6216 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6217 {
6218 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6219 inst.operands[i].reg = val;
6220 inst.operands[i].isscalar = 1;
dcbf9037 6221 inst.operands[i].vectype = optype;
5287ad62
JB
6222 inst.operands[i++].present = 1;
6223
6224 if (skip_past_comma (&ptr) == FAIL)
477330fc 6225 goto wanted_comma;
5f4273c7 6226
dcbf9037 6227 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6228 goto wanted_arm;
5f4273c7 6229
5287ad62
JB
6230 inst.operands[i].reg = val;
6231 inst.operands[i].isreg = 1;
6232 inst.operands[i].present = 1;
6233 }
037e8744 6234 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6235 != FAIL)
5287ad62
JB
6236 {
6237 /* Cases 0, 1, 2, 3, 5 (D only). */
6238 if (skip_past_comma (&ptr) == FAIL)
477330fc 6239 goto wanted_comma;
5f4273c7 6240
5287ad62
JB
6241 inst.operands[i].reg = val;
6242 inst.operands[i].isreg = 1;
6243 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6244 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6245 inst.operands[i].isvec = 1;
dcbf9037 6246 inst.operands[i].vectype = optype;
5287ad62
JB
6247 inst.operands[i++].present = 1;
6248
dcbf9037 6249 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6250 {
6251 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6252 Case 13: VMOV <Sd>, <Rm> */
6253 inst.operands[i].reg = val;
6254 inst.operands[i].isreg = 1;
6255 inst.operands[i].present = 1;
6256
6257 if (rtype == REG_TYPE_NQ)
6258 {
6259 first_error (_("can't use Neon quad register here"));
6260 return FAIL;
6261 }
6262 else if (rtype != REG_TYPE_VFS)
6263 {
6264 i++;
6265 if (skip_past_comma (&ptr) == FAIL)
6266 goto wanted_comma;
6267 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6268 goto wanted_arm;
6269 inst.operands[i].reg = val;
6270 inst.operands[i].isreg = 1;
6271 inst.operands[i].present = 1;
6272 }
6273 }
037e8744 6274 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6275 &optype)) != FAIL)
6276 {
6277 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6278 Case 1: VMOV<c><q> <Dd>, <Dm>
6279 Case 8: VMOV.F32 <Sd>, <Sm>
6280 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6281
6282 inst.operands[i].reg = val;
6283 inst.operands[i].isreg = 1;
6284 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6285 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6286 inst.operands[i].isvec = 1;
6287 inst.operands[i].vectype = optype;
6288 inst.operands[i].present = 1;
6289
6290 if (skip_past_comma (&ptr) == SUCCESS)
6291 {
6292 /* Case 15. */
6293 i++;
6294
6295 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6296 goto wanted_arm;
6297
6298 inst.operands[i].reg = val;
6299 inst.operands[i].isreg = 1;
6300 inst.operands[i++].present = 1;
6301
6302 if (skip_past_comma (&ptr) == FAIL)
6303 goto wanted_comma;
6304
6305 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6306 goto wanted_arm;
6307
6308 inst.operands[i].reg = val;
6309 inst.operands[i].isreg = 1;
6310 inst.operands[i].present = 1;
6311 }
6312 }
4641781c 6313 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6314 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6315 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6316 Case 10: VMOV.F32 <Sd>, #<imm>
6317 Case 11: VMOV.F64 <Dd>, #<imm> */
6318 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6319 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6320 == SUCCESS)
477330fc
RM
6321 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6322 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6323 ;
5287ad62 6324 else
477330fc
RM
6325 {
6326 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6327 return FAIL;
6328 }
5287ad62 6329 }
dcbf9037 6330 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6331 {
6332 /* Cases 6, 7. */
6333 inst.operands[i].reg = val;
6334 inst.operands[i].isreg = 1;
6335 inst.operands[i++].present = 1;
5f4273c7 6336
5287ad62 6337 if (skip_past_comma (&ptr) == FAIL)
477330fc 6338 goto wanted_comma;
5f4273c7 6339
dcbf9037 6340 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6341 {
6342 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6343 inst.operands[i].reg = val;
6344 inst.operands[i].isscalar = 1;
6345 inst.operands[i].present = 1;
6346 inst.operands[i].vectype = optype;
6347 }
dcbf9037 6348 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6349 {
6350 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6351 inst.operands[i].reg = val;
6352 inst.operands[i].isreg = 1;
6353 inst.operands[i++].present = 1;
6354
6355 if (skip_past_comma (&ptr) == FAIL)
6356 goto wanted_comma;
6357
6358 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6359 == FAIL)
6360 {
6361 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6362 return FAIL;
6363 }
6364
6365 inst.operands[i].reg = val;
6366 inst.operands[i].isreg = 1;
6367 inst.operands[i].isvec = 1;
6368 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6369 inst.operands[i].vectype = optype;
6370 inst.operands[i].present = 1;
6371
6372 if (rtype == REG_TYPE_VFS)
6373 {
6374 /* Case 14. */
6375 i++;
6376 if (skip_past_comma (&ptr) == FAIL)
6377 goto wanted_comma;
6378 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6379 &optype)) == FAIL)
6380 {
6381 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6382 return FAIL;
6383 }
6384 inst.operands[i].reg = val;
6385 inst.operands[i].isreg = 1;
6386 inst.operands[i].isvec = 1;
6387 inst.operands[i].issingle = 1;
6388 inst.operands[i].vectype = optype;
6389 inst.operands[i].present = 1;
6390 }
6391 }
037e8744 6392 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6393 != FAIL)
6394 {
6395 /* Case 13. */
6396 inst.operands[i].reg = val;
6397 inst.operands[i].isreg = 1;
6398 inst.operands[i].isvec = 1;
6399 inst.operands[i].issingle = 1;
6400 inst.operands[i].vectype = optype;
6401 inst.operands[i].present = 1;
6402 }
5287ad62
JB
6403 }
6404 else
6405 {
dcbf9037 6406 first_error (_("parse error"));
5287ad62
JB
6407 return FAIL;
6408 }
6409
6410 /* Successfully parsed the operands. Update args. */
6411 *which_operand = i;
6412 *str = ptr;
6413 return SUCCESS;
6414
5f4273c7 6415 wanted_comma:
dcbf9037 6416 first_error (_("expected comma"));
5287ad62 6417 return FAIL;
5f4273c7
NC
6418
6419 wanted_arm:
dcbf9037 6420 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6421 return FAIL;
5287ad62
JB
6422}
6423
5be8be5d
DG
6424/* Use this macro when the operand constraints are different
6425 for ARM and THUMB (e.g. ldrd). */
6426#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6427 ((arm_operand) | ((thumb_operand) << 16))
6428
c19d1205
ZW
6429/* Matcher codes for parse_operands. */
6430enum operand_parse_code
6431{
6432 OP_stop, /* end of line */
6433
6434 OP_RR, /* ARM register */
6435 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6436 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6437 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6438 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6439 optional trailing ! */
c19d1205
ZW
6440 OP_RRw, /* ARM register, not r15, optional trailing ! */
6441 OP_RCP, /* Coprocessor number */
6442 OP_RCN, /* Coprocessor register */
6443 OP_RF, /* FPA register */
6444 OP_RVS, /* VFP single precision register */
5287ad62
JB
6445 OP_RVD, /* VFP double precision register (0..15) */
6446 OP_RND, /* Neon double precision register (0..31) */
6447 OP_RNQ, /* Neon quad precision register */
037e8744 6448 OP_RVSD, /* VFP single or double precision register */
5287ad62 6449 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6450 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6451 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6452 OP_RVC, /* VFP control register */
6453 OP_RMF, /* Maverick F register */
6454 OP_RMD, /* Maverick D register */
6455 OP_RMFX, /* Maverick FX register */
6456 OP_RMDX, /* Maverick DX register */
6457 OP_RMAX, /* Maverick AX register */
6458 OP_RMDS, /* Maverick DSPSC register */
6459 OP_RIWR, /* iWMMXt wR register */
6460 OP_RIWC, /* iWMMXt wC register */
6461 OP_RIWG, /* iWMMXt wCG register */
6462 OP_RXA, /* XScale accumulator register */
6463
6464 OP_REGLST, /* ARM register list */
6465 OP_VRSLST, /* VFP single-precision register list */
6466 OP_VRDLST, /* VFP double-precision register list */
037e8744 6467 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6468 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6469 OP_NSTRLST, /* Neon element/structure list */
6470
5287ad62 6471 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6472 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6473 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6474 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6475 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6476 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6477 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6478 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6479 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6480 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6481 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6482
6483 OP_I0, /* immediate zero */
c19d1205
ZW
6484 OP_I7, /* immediate value 0 .. 7 */
6485 OP_I15, /* 0 .. 15 */
6486 OP_I16, /* 1 .. 16 */
5287ad62 6487 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6488 OP_I31, /* 0 .. 31 */
6489 OP_I31w, /* 0 .. 31, optional trailing ! */
6490 OP_I32, /* 1 .. 32 */
5287ad62
JB
6491 OP_I32z, /* 0 .. 32 */
6492 OP_I63, /* 0 .. 63 */
c19d1205 6493 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6494 OP_I64, /* 1 .. 64 */
6495 OP_I64z, /* 0 .. 64 */
c19d1205 6496 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6497
6498 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6499 OP_I7b, /* 0 .. 7 */
6500 OP_I15b, /* 0 .. 15 */
6501 OP_I31b, /* 0 .. 31 */
6502
6503 OP_SH, /* shifter operand */
4962c51a 6504 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6505 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6506 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6507 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6508 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6509 OP_EXP, /* arbitrary expression */
6510 OP_EXPi, /* same, with optional immediate prefix */
6511 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6512 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
6513
6514 OP_CPSF, /* CPS flags */
6515 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6516 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6517 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6518 OP_COND, /* conditional code */
92e90b6e 6519 OP_TB, /* Table branch. */
c19d1205 6520
037e8744
JB
6521 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6522
c19d1205
ZW
6523 OP_RRnpc_I0, /* ARM register or literal 0 */
6524 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6525 OP_RR_EXi, /* ARM register or expression with imm prefix */
6526 OP_RF_IF, /* FPA register or immediate */
6527 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6528 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6529
6530 /* Optional operands. */
6531 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6532 OP_oI31b, /* 0 .. 31 */
5287ad62 6533 OP_oI32b, /* 1 .. 32 */
5f1af56b 6534 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6535 OP_oIffffb, /* 0 .. 65535 */
6536 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6537
6538 OP_oRR, /* ARM register */
6539 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6540 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6541 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6542 OP_oRND, /* Optional Neon double precision register */
6543 OP_oRNQ, /* Optional Neon quad precision register */
6544 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6545 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6546 OP_oSHll, /* LSL immediate */
6547 OP_oSHar, /* ASR immediate */
6548 OP_oSHllar, /* LSL or ASR immediate */
6549 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6550 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6551
5be8be5d
DG
6552 /* Some pre-defined mixed (ARM/THUMB) operands. */
6553 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6554 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6555 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6556
c19d1205
ZW
6557 OP_FIRST_OPTIONAL = OP_oI7b
6558};
a737bd4d 6559
c19d1205
ZW
6560/* Generic instruction operand parser. This does no encoding and no
6561 semantic validation; it merely squirrels values away in the inst
6562 structure. Returns SUCCESS or FAIL depending on whether the
6563 specified grammar matched. */
6564static int
5be8be5d 6565parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6566{
5be8be5d 6567 unsigned const int *upat = pattern;
c19d1205
ZW
6568 char *backtrack_pos = 0;
6569 const char *backtrack_error = 0;
99aad254 6570 int i, val = 0, backtrack_index = 0;
5287ad62 6571 enum arm_reg_type rtype;
4962c51a 6572 parse_operand_result result;
5be8be5d 6573 unsigned int op_parse_code;
c19d1205 6574
e07e6e58
NC
6575#define po_char_or_fail(chr) \
6576 do \
6577 { \
6578 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6579 goto bad_args; \
e07e6e58
NC
6580 } \
6581 while (0)
c19d1205 6582
e07e6e58
NC
6583#define po_reg_or_fail(regtype) \
6584 do \
dcbf9037 6585 { \
e07e6e58 6586 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6587 & inst.operands[i].vectype); \
e07e6e58 6588 if (val == FAIL) \
477330fc
RM
6589 { \
6590 first_error (_(reg_expected_msgs[regtype])); \
6591 goto failure; \
6592 } \
e07e6e58
NC
6593 inst.operands[i].reg = val; \
6594 inst.operands[i].isreg = 1; \
6595 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6596 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6597 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6598 || rtype == REG_TYPE_VFD \
6599 || rtype == REG_TYPE_NQ); \
dcbf9037 6600 } \
e07e6e58
NC
6601 while (0)
6602
6603#define po_reg_or_goto(regtype, label) \
6604 do \
6605 { \
6606 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6607 & inst.operands[i].vectype); \
6608 if (val == FAIL) \
6609 goto label; \
dcbf9037 6610 \
e07e6e58
NC
6611 inst.operands[i].reg = val; \
6612 inst.operands[i].isreg = 1; \
6613 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6614 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6615 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6616 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6617 || rtype == REG_TYPE_NQ); \
6618 } \
6619 while (0)
6620
6621#define po_imm_or_fail(min, max, popt) \
6622 do \
6623 { \
6624 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6625 goto failure; \
6626 inst.operands[i].imm = val; \
6627 } \
6628 while (0)
6629
6630#define po_scalar_or_goto(elsz, label) \
6631 do \
6632 { \
6633 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6634 if (val == FAIL) \
6635 goto label; \
6636 inst.operands[i].reg = val; \
6637 inst.operands[i].isscalar = 1; \
6638 } \
6639 while (0)
6640
6641#define po_misc_or_fail(expr) \
6642 do \
6643 { \
6644 if (expr) \
6645 goto failure; \
6646 } \
6647 while (0)
6648
6649#define po_misc_or_fail_no_backtrack(expr) \
6650 do \
6651 { \
6652 result = expr; \
6653 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6654 backtrack_pos = 0; \
6655 if (result != PARSE_OPERAND_SUCCESS) \
6656 goto failure; \
6657 } \
6658 while (0)
4962c51a 6659
52e7f43d
RE
6660#define po_barrier_or_imm(str) \
6661 do \
6662 { \
6663 val = parse_barrier (&str); \
ccb84d65
JB
6664 if (val == FAIL && ! ISALPHA (*str)) \
6665 goto immediate; \
6666 if (val == FAIL \
6667 /* ISB can only take SY as an option. */ \
6668 || ((inst.instruction & 0xf0) == 0x60 \
6669 && val != 0xf)) \
52e7f43d 6670 { \
ccb84d65
JB
6671 inst.error = _("invalid barrier type"); \
6672 backtrack_pos = 0; \
6673 goto failure; \
52e7f43d
RE
6674 } \
6675 } \
6676 while (0)
6677
c19d1205
ZW
6678 skip_whitespace (str);
6679
6680 for (i = 0; upat[i] != OP_stop; i++)
6681 {
5be8be5d
DG
6682 op_parse_code = upat[i];
6683 if (op_parse_code >= 1<<16)
6684 op_parse_code = thumb ? (op_parse_code >> 16)
6685 : (op_parse_code & ((1<<16)-1));
6686
6687 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6688 {
6689 /* Remember where we are in case we need to backtrack. */
9c2799c2 6690 gas_assert (!backtrack_pos);
c19d1205
ZW
6691 backtrack_pos = str;
6692 backtrack_error = inst.error;
6693 backtrack_index = i;
6694 }
6695
b6702015 6696 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6697 po_char_or_fail (',');
6698
5be8be5d 6699 switch (op_parse_code)
c19d1205
ZW
6700 {
6701 /* Registers */
6702 case OP_oRRnpc:
5be8be5d 6703 case OP_oRRnpcsp:
c19d1205 6704 case OP_RRnpc:
5be8be5d 6705 case OP_RRnpcsp:
c19d1205
ZW
6706 case OP_oRR:
6707 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6708 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6709 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6710 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6711 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6712 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6713 case OP_oRND:
5287ad62 6714 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6715 case OP_RVC:
6716 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6717 break;
6718 /* Also accept generic coprocessor regs for unknown registers. */
6719 coproc_reg:
6720 po_reg_or_fail (REG_TYPE_CN);
6721 break;
c19d1205
ZW
6722 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6723 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6724 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6725 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6726 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6727 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6728 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6729 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6730 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6731 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6732 case OP_oRNQ:
5287ad62 6733 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
477330fc 6734 case OP_oRNDQ:
5287ad62 6735 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6736 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6737 case OP_oRNSDQ:
6738 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6739
6740 /* Neon scalar. Using an element size of 8 means that some invalid
6741 scalars are accepted here, so deal with those in later code. */
6742 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6743
6744 case OP_RNDQ_I0:
6745 {
6746 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6747 break;
6748 try_imm0:
6749 po_imm_or_fail (0, 0, TRUE);
6750 }
6751 break;
6752
6753 case OP_RVSD_I0:
6754 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6755 break;
6756
aacf0b33
KT
6757 case OP_RSVD_FI0:
6758 {
6759 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6760 break;
6761 try_ifimm0:
6762 if (parse_ifimm_zero (&str))
6763 inst.operands[i].imm = 0;
6764 else
6765 {
6766 inst.error
6767 = _("only floating point zero is allowed as immediate value");
6768 goto failure;
6769 }
6770 }
6771 break;
6772
477330fc
RM
6773 case OP_RR_RNSC:
6774 {
6775 po_scalar_or_goto (8, try_rr);
6776 break;
6777 try_rr:
6778 po_reg_or_fail (REG_TYPE_RN);
6779 }
6780 break;
6781
6782 case OP_RNSDQ_RNSC:
6783 {
6784 po_scalar_or_goto (8, try_nsdq);
6785 break;
6786 try_nsdq:
6787 po_reg_or_fail (REG_TYPE_NSDQ);
6788 }
6789 break;
6790
6791 case OP_RNDQ_RNSC:
6792 {
6793 po_scalar_or_goto (8, try_ndq);
6794 break;
6795 try_ndq:
6796 po_reg_or_fail (REG_TYPE_NDQ);
6797 }
6798 break;
6799
6800 case OP_RND_RNSC:
6801 {
6802 po_scalar_or_goto (8, try_vfd);
6803 break;
6804 try_vfd:
6805 po_reg_or_fail (REG_TYPE_VFD);
6806 }
6807 break;
6808
6809 case OP_VMOV:
6810 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6811 not careful then bad things might happen. */
6812 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6813 break;
6814
6815 case OP_RNDQ_Ibig:
6816 {
6817 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6818 break;
6819 try_immbig:
6820 /* There's a possibility of getting a 64-bit immediate here, so
6821 we need special handling. */
8335d6aa
JW
6822 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6823 == FAIL)
477330fc
RM
6824 {
6825 inst.error = _("immediate value is out of range");
6826 goto failure;
6827 }
6828 }
6829 break;
6830
6831 case OP_RNDQ_I63b:
6832 {
6833 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6834 break;
6835 try_shimm:
6836 po_imm_or_fail (0, 63, TRUE);
6837 }
6838 break;
c19d1205
ZW
6839
6840 case OP_RRnpcb:
6841 po_char_or_fail ('[');
6842 po_reg_or_fail (REG_TYPE_RN);
6843 po_char_or_fail (']');
6844 break;
a737bd4d 6845
55881a11 6846 case OP_RRnpctw:
c19d1205 6847 case OP_RRw:
b6702015 6848 case OP_oRRw:
c19d1205
ZW
6849 po_reg_or_fail (REG_TYPE_RN);
6850 if (skip_past_char (&str, '!') == SUCCESS)
6851 inst.operands[i].writeback = 1;
6852 break;
6853
6854 /* Immediates */
6855 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6856 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6857 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6858 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6859 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6860 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6861 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6862 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6863 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6864 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6865 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6866 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6867
6868 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6869 case OP_oI7b:
6870 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6871 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6872 case OP_oI31b:
6873 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6874 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6875 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6876 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6877
6878 /* Immediate variants */
6879 case OP_oI255c:
6880 po_char_or_fail ('{');
6881 po_imm_or_fail (0, 255, TRUE);
6882 po_char_or_fail ('}');
6883 break;
6884
6885 case OP_I31w:
6886 /* The expression parser chokes on a trailing !, so we have
6887 to find it first and zap it. */
6888 {
6889 char *s = str;
6890 while (*s && *s != ',')
6891 s++;
6892 if (s[-1] == '!')
6893 {
6894 s[-1] = '\0';
6895 inst.operands[i].writeback = 1;
6896 }
6897 po_imm_or_fail (0, 31, TRUE);
6898 if (str == s - 1)
6899 str = s;
6900 }
6901 break;
6902
6903 /* Expressions */
6904 case OP_EXPi: EXPi:
6905 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6906 GE_OPT_PREFIX));
6907 break;
6908
6909 case OP_EXP:
6910 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6911 GE_NO_PREFIX));
6912 break;
6913
6914 case OP_EXPr: EXPr:
6915 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6916 GE_NO_PREFIX));
6917 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6918 {
c19d1205
ZW
6919 val = parse_reloc (&str);
6920 if (val == -1)
6921 {
6922 inst.error = _("unrecognized relocation suffix");
6923 goto failure;
6924 }
6925 else if (val != BFD_RELOC_UNUSED)
6926 {
6927 inst.operands[i].imm = val;
6928 inst.operands[i].hasreloc = 1;
6929 }
a737bd4d 6930 }
c19d1205 6931 break;
a737bd4d 6932
b6895b4f
PB
6933 /* Operand for MOVW or MOVT. */
6934 case OP_HALF:
6935 po_misc_or_fail (parse_half (&str));
6936 break;
6937
e07e6e58 6938 /* Register or expression. */
c19d1205
ZW
6939 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6940 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6941
e07e6e58 6942 /* Register or immediate. */
c19d1205
ZW
6943 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6944 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6945
c19d1205
ZW
6946 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6947 IF:
6948 if (!is_immediate_prefix (*str))
6949 goto bad_args;
6950 str++;
6951 val = parse_fpa_immediate (&str);
6952 if (val == FAIL)
6953 goto failure;
6954 /* FPA immediates are encoded as registers 8-15.
6955 parse_fpa_immediate has already applied the offset. */
6956 inst.operands[i].reg = val;
6957 inst.operands[i].isreg = 1;
6958 break;
09d92015 6959
2d447fca
JM
6960 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6961 I32z: po_imm_or_fail (0, 32, FALSE); break;
6962
e07e6e58 6963 /* Two kinds of register. */
c19d1205
ZW
6964 case OP_RIWR_RIWC:
6965 {
6966 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6967 if (!rege
6968 || (rege->type != REG_TYPE_MMXWR
6969 && rege->type != REG_TYPE_MMXWC
6970 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6971 {
6972 inst.error = _("iWMMXt data or control register expected");
6973 goto failure;
6974 }
6975 inst.operands[i].reg = rege->number;
6976 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6977 }
6978 break;
09d92015 6979
41adaa5c
JM
6980 case OP_RIWC_RIWG:
6981 {
6982 struct reg_entry *rege = arm_reg_parse_multi (&str);
6983 if (!rege
6984 || (rege->type != REG_TYPE_MMXWC
6985 && rege->type != REG_TYPE_MMXWCG))
6986 {
6987 inst.error = _("iWMMXt control register expected");
6988 goto failure;
6989 }
6990 inst.operands[i].reg = rege->number;
6991 inst.operands[i].isreg = 1;
6992 }
6993 break;
6994
c19d1205
ZW
6995 /* Misc */
6996 case OP_CPSF: val = parse_cps_flags (&str); break;
6997 case OP_ENDI: val = parse_endian_specifier (&str); break;
6998 case OP_oROR: val = parse_ror (&str); break;
c19d1205 6999 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7000 case OP_oBARRIER_I15:
7001 po_barrier_or_imm (str); break;
7002 immediate:
7003 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7004 goto failure;
52e7f43d 7005 break;
c19d1205 7006
fa94de6b 7007 case OP_wPSR:
d2cd1205 7008 case OP_rPSR:
90ec0d68
MGD
7009 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7010 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7011 {
7012 inst.error = _("Banked registers are not available with this "
7013 "architecture.");
7014 goto failure;
7015 }
7016 break;
d2cd1205
JB
7017 try_psr:
7018 val = parse_psr (&str, op_parse_code == OP_wPSR);
7019 break;
037e8744 7020
477330fc
RM
7021 case OP_APSR_RR:
7022 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7023 break;
7024 try_apsr:
7025 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7026 instruction). */
7027 if (strncasecmp (str, "APSR_", 5) == 0)
7028 {
7029 unsigned found = 0;
7030 str += 5;
7031 while (found < 15)
7032 switch (*str++)
7033 {
7034 case 'c': found = (found & 1) ? 16 : found | 1; break;
7035 case 'n': found = (found & 2) ? 16 : found | 2; break;
7036 case 'z': found = (found & 4) ? 16 : found | 4; break;
7037 case 'v': found = (found & 8) ? 16 : found | 8; break;
7038 default: found = 16;
7039 }
7040 if (found != 15)
7041 goto failure;
7042 inst.operands[i].isvec = 1;
f7c21dc7
NC
7043 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7044 inst.operands[i].reg = REG_PC;
477330fc
RM
7045 }
7046 else
7047 goto failure;
7048 break;
037e8744 7049
92e90b6e
PB
7050 case OP_TB:
7051 po_misc_or_fail (parse_tb (&str));
7052 break;
7053
e07e6e58 7054 /* Register lists. */
c19d1205
ZW
7055 case OP_REGLST:
7056 val = parse_reg_list (&str);
7057 if (*str == '^')
7058 {
5e0d7f77 7059 inst.operands[i].writeback = 1;
c19d1205
ZW
7060 str++;
7061 }
7062 break;
09d92015 7063
c19d1205 7064 case OP_VRSLST:
5287ad62 7065 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7066 break;
09d92015 7067
c19d1205 7068 case OP_VRDLST:
5287ad62 7069 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7070 break;
a737bd4d 7071
477330fc
RM
7072 case OP_VRSDLST:
7073 /* Allow Q registers too. */
7074 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7075 REGLIST_NEON_D);
7076 if (val == FAIL)
7077 {
7078 inst.error = NULL;
7079 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7080 REGLIST_VFP_S);
7081 inst.operands[i].issingle = 1;
7082 }
7083 break;
7084
7085 case OP_NRDLST:
7086 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7087 REGLIST_NEON_D);
7088 break;
5287ad62
JB
7089
7090 case OP_NSTRLST:
477330fc
RM
7091 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7092 &inst.operands[i].vectype);
7093 break;
5287ad62 7094
c19d1205
ZW
7095 /* Addressing modes */
7096 case OP_ADDR:
7097 po_misc_or_fail (parse_address (&str, i));
7098 break;
09d92015 7099
4962c51a
MS
7100 case OP_ADDRGLDR:
7101 po_misc_or_fail_no_backtrack (
477330fc 7102 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7103 break;
7104
7105 case OP_ADDRGLDRS:
7106 po_misc_or_fail_no_backtrack (
477330fc 7107 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7108 break;
7109
7110 case OP_ADDRGLDC:
7111 po_misc_or_fail_no_backtrack (
477330fc 7112 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7113 break;
7114
c19d1205
ZW
7115 case OP_SH:
7116 po_misc_or_fail (parse_shifter_operand (&str, i));
7117 break;
09d92015 7118
4962c51a
MS
7119 case OP_SHG:
7120 po_misc_or_fail_no_backtrack (
477330fc 7121 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7122 break;
7123
c19d1205
ZW
7124 case OP_oSHll:
7125 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7126 break;
09d92015 7127
c19d1205
ZW
7128 case OP_oSHar:
7129 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7130 break;
09d92015 7131
c19d1205
ZW
7132 case OP_oSHllar:
7133 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7134 break;
09d92015 7135
c19d1205 7136 default:
5be8be5d 7137 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7138 }
09d92015 7139
c19d1205
ZW
7140 /* Various value-based sanity checks and shared operations. We
7141 do not signal immediate failures for the register constraints;
7142 this allows a syntax error to take precedence. */
5be8be5d 7143 switch (op_parse_code)
c19d1205
ZW
7144 {
7145 case OP_oRRnpc:
7146 case OP_RRnpc:
7147 case OP_RRnpcb:
7148 case OP_RRw:
b6702015 7149 case OP_oRRw:
c19d1205
ZW
7150 case OP_RRnpc_I0:
7151 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7152 inst.error = BAD_PC;
7153 break;
09d92015 7154
5be8be5d
DG
7155 case OP_oRRnpcsp:
7156 case OP_RRnpcsp:
7157 if (inst.operands[i].isreg)
7158 {
7159 if (inst.operands[i].reg == REG_PC)
7160 inst.error = BAD_PC;
7161 else if (inst.operands[i].reg == REG_SP)
7162 inst.error = BAD_SP;
7163 }
7164 break;
7165
55881a11 7166 case OP_RRnpctw:
fa94de6b
RM
7167 if (inst.operands[i].isreg
7168 && inst.operands[i].reg == REG_PC
55881a11
MGD
7169 && (inst.operands[i].writeback || thumb))
7170 inst.error = BAD_PC;
7171 break;
7172
c19d1205
ZW
7173 case OP_CPSF:
7174 case OP_ENDI:
7175 case OP_oROR:
d2cd1205
JB
7176 case OP_wPSR:
7177 case OP_rPSR:
c19d1205 7178 case OP_COND:
52e7f43d 7179 case OP_oBARRIER_I15:
c19d1205
ZW
7180 case OP_REGLST:
7181 case OP_VRSLST:
7182 case OP_VRDLST:
477330fc
RM
7183 case OP_VRSDLST:
7184 case OP_NRDLST:
7185 case OP_NSTRLST:
c19d1205
ZW
7186 if (val == FAIL)
7187 goto failure;
7188 inst.operands[i].imm = val;
7189 break;
a737bd4d 7190
c19d1205
ZW
7191 default:
7192 break;
7193 }
09d92015 7194
c19d1205
ZW
7195 /* If we get here, this operand was successfully parsed. */
7196 inst.operands[i].present = 1;
7197 continue;
09d92015 7198
c19d1205 7199 bad_args:
09d92015 7200 inst.error = BAD_ARGS;
c19d1205
ZW
7201
7202 failure:
7203 if (!backtrack_pos)
d252fdde
PB
7204 {
7205 /* The parse routine should already have set inst.error, but set a
5f4273c7 7206 default here just in case. */
d252fdde
PB
7207 if (!inst.error)
7208 inst.error = _("syntax error");
7209 return FAIL;
7210 }
c19d1205
ZW
7211
7212 /* Do not backtrack over a trailing optional argument that
7213 absorbed some text. We will only fail again, with the
7214 'garbage following instruction' error message, which is
7215 probably less helpful than the current one. */
7216 if (backtrack_index == i && backtrack_pos != str
7217 && upat[i+1] == OP_stop)
d252fdde
PB
7218 {
7219 if (!inst.error)
7220 inst.error = _("syntax error");
7221 return FAIL;
7222 }
c19d1205
ZW
7223
7224 /* Try again, skipping the optional argument at backtrack_pos. */
7225 str = backtrack_pos;
7226 inst.error = backtrack_error;
7227 inst.operands[backtrack_index].present = 0;
7228 i = backtrack_index;
7229 backtrack_pos = 0;
09d92015 7230 }
09d92015 7231
c19d1205
ZW
7232 /* Check that we have parsed all the arguments. */
7233 if (*str != '\0' && !inst.error)
7234 inst.error = _("garbage following instruction");
09d92015 7235
c19d1205 7236 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7237}
7238
c19d1205
ZW
7239#undef po_char_or_fail
7240#undef po_reg_or_fail
7241#undef po_reg_or_goto
7242#undef po_imm_or_fail
5287ad62 7243#undef po_scalar_or_fail
52e7f43d 7244#undef po_barrier_or_imm
e07e6e58 7245
c19d1205 7246/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7247#define constraint(expr, err) \
7248 do \
c19d1205 7249 { \
e07e6e58
NC
7250 if (expr) \
7251 { \
7252 inst.error = err; \
7253 return; \
7254 } \
c19d1205 7255 } \
e07e6e58 7256 while (0)
c19d1205 7257
fdfde340
JM
7258/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7259 instructions are unpredictable if these registers are used. This
7260 is the BadReg predicate in ARM's Thumb-2 documentation. */
7261#define reject_bad_reg(reg) \
7262 do \
7263 if (reg == REG_SP || reg == REG_PC) \
7264 { \
7265 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
7266 return; \
7267 } \
7268 while (0)
7269
94206790
MM
7270/* If REG is R13 (the stack pointer), warn that its use is
7271 deprecated. */
7272#define warn_deprecated_sp(reg) \
7273 do \
7274 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7275 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7276 while (0)
7277
c19d1205
ZW
7278/* Functions for operand encoding. ARM, then Thumb. */
7279
d840c081 7280#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205
ZW
7281
7282/* If VAL can be encoded in the immediate field of an ARM instruction,
7283 return the encoded form. Otherwise, return FAIL. */
7284
7285static unsigned int
7286encode_arm_immediate (unsigned int val)
09d92015 7287{
c19d1205
ZW
7288 unsigned int a, i;
7289
7290 for (i = 0; i < 32; i += 2)
7291 if ((a = rotate_left (val, i)) <= 0xff)
7292 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7293
7294 return FAIL;
09d92015
MM
7295}
7296
c19d1205
ZW
7297/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7298 return the encoded form. Otherwise, return FAIL. */
7299static unsigned int
7300encode_thumb32_immediate (unsigned int val)
09d92015 7301{
c19d1205 7302 unsigned int a, i;
09d92015 7303
9c3c69f2 7304 if (val <= 0xff)
c19d1205 7305 return val;
a737bd4d 7306
9c3c69f2 7307 for (i = 1; i <= 24; i++)
09d92015 7308 {
9c3c69f2
PB
7309 a = val >> i;
7310 if ((val & ~(0xff << i)) == 0)
7311 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7312 }
a737bd4d 7313
c19d1205
ZW
7314 a = val & 0xff;
7315 if (val == ((a << 16) | a))
7316 return 0x100 | a;
7317 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7318 return 0x300 | a;
09d92015 7319
c19d1205
ZW
7320 a = val & 0xff00;
7321 if (val == ((a << 16) | a))
7322 return 0x200 | (a >> 8);
a737bd4d 7323
c19d1205 7324 return FAIL;
09d92015 7325}
5287ad62 7326/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7327
7328static void
5287ad62
JB
7329encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7330{
7331 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7332 && reg > 15)
7333 {
b1cc4aeb 7334 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7335 {
7336 if (thumb_mode)
7337 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7338 fpu_vfp_ext_d32);
7339 else
7340 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7341 fpu_vfp_ext_d32);
7342 }
5287ad62 7343 else
477330fc
RM
7344 {
7345 first_error (_("D register out of range for selected VFP version"));
7346 return;
7347 }
5287ad62
JB
7348 }
7349
c19d1205 7350 switch (pos)
09d92015 7351 {
c19d1205
ZW
7352 case VFP_REG_Sd:
7353 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7354 break;
7355
7356 case VFP_REG_Sn:
7357 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7358 break;
7359
7360 case VFP_REG_Sm:
7361 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7362 break;
7363
5287ad62
JB
7364 case VFP_REG_Dd:
7365 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7366 break;
5f4273c7 7367
5287ad62
JB
7368 case VFP_REG_Dn:
7369 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7370 break;
5f4273c7 7371
5287ad62
JB
7372 case VFP_REG_Dm:
7373 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7374 break;
7375
c19d1205
ZW
7376 default:
7377 abort ();
09d92015 7378 }
09d92015
MM
7379}
7380
c19d1205 7381/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7382 if any, is handled by md_apply_fix. */
09d92015 7383static void
c19d1205 7384encode_arm_shift (int i)
09d92015 7385{
c19d1205
ZW
7386 if (inst.operands[i].shift_kind == SHIFT_RRX)
7387 inst.instruction |= SHIFT_ROR << 5;
7388 else
09d92015 7389 {
c19d1205
ZW
7390 inst.instruction |= inst.operands[i].shift_kind << 5;
7391 if (inst.operands[i].immisreg)
7392 {
7393 inst.instruction |= SHIFT_BY_REG;
7394 inst.instruction |= inst.operands[i].imm << 8;
7395 }
7396 else
7397 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7398 }
c19d1205 7399}
09d92015 7400
c19d1205
ZW
7401static void
7402encode_arm_shifter_operand (int i)
7403{
7404 if (inst.operands[i].isreg)
09d92015 7405 {
c19d1205
ZW
7406 inst.instruction |= inst.operands[i].reg;
7407 encode_arm_shift (i);
09d92015 7408 }
c19d1205 7409 else
a415b1cd
JB
7410 {
7411 inst.instruction |= INST_IMMEDIATE;
7412 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7413 inst.instruction |= inst.operands[i].imm;
7414 }
09d92015
MM
7415}
7416
c19d1205 7417/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7418static void
c19d1205 7419encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7420{
2b2f5df9
NC
7421 /* PR 14260:
7422 Generate an error if the operand is not a register. */
7423 constraint (!inst.operands[i].isreg,
7424 _("Instruction does not support =N addresses"));
7425
c19d1205 7426 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7427
c19d1205 7428 if (inst.operands[i].preind)
09d92015 7429 {
c19d1205
ZW
7430 if (is_t)
7431 {
7432 inst.error = _("instruction does not accept preindexed addressing");
7433 return;
7434 }
7435 inst.instruction |= PRE_INDEX;
7436 if (inst.operands[i].writeback)
7437 inst.instruction |= WRITE_BACK;
09d92015 7438
c19d1205
ZW
7439 }
7440 else if (inst.operands[i].postind)
7441 {
9c2799c2 7442 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7443 if (is_t)
7444 inst.instruction |= WRITE_BACK;
7445 }
7446 else /* unindexed - only for coprocessor */
09d92015 7447 {
c19d1205 7448 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7449 return;
7450 }
7451
c19d1205
ZW
7452 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7453 && (((inst.instruction & 0x000f0000) >> 16)
7454 == ((inst.instruction & 0x0000f000) >> 12)))
7455 as_warn ((inst.instruction & LOAD_BIT)
7456 ? _("destination register same as write-back base")
7457 : _("source register same as write-back base"));
09d92015
MM
7458}
7459
c19d1205
ZW
7460/* inst.operands[i] was set up by parse_address. Encode it into an
7461 ARM-format mode 2 load or store instruction. If is_t is true,
7462 reject forms that cannot be used with a T instruction (i.e. not
7463 post-indexed). */
a737bd4d 7464static void
c19d1205 7465encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7466{
5be8be5d
DG
7467 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7468
c19d1205 7469 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7470
c19d1205 7471 if (inst.operands[i].immisreg)
09d92015 7472 {
5be8be5d
DG
7473 constraint ((inst.operands[i].imm == REG_PC
7474 || (is_pc && inst.operands[i].writeback)),
7475 BAD_PC_ADDRESSING);
c19d1205
ZW
7476 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7477 inst.instruction |= inst.operands[i].imm;
7478 if (!inst.operands[i].negative)
7479 inst.instruction |= INDEX_UP;
7480 if (inst.operands[i].shifted)
7481 {
7482 if (inst.operands[i].shift_kind == SHIFT_RRX)
7483 inst.instruction |= SHIFT_ROR << 5;
7484 else
7485 {
7486 inst.instruction |= inst.operands[i].shift_kind << 5;
7487 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7488 }
7489 }
09d92015 7490 }
c19d1205 7491 else /* immediate offset in inst.reloc */
09d92015 7492 {
5be8be5d
DG
7493 if (is_pc && !inst.reloc.pc_rel)
7494 {
7495 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7496
7497 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7498 cannot use PC in addressing.
7499 PC cannot be used in writeback addressing, either. */
7500 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7501 BAD_PC_ADDRESSING);
23a10334 7502
dc5ec521 7503 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7504 if (warn_on_deprecated
7505 && !is_load
7506 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7507 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7508 }
7509
c19d1205 7510 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7511 {
7512 /* Prefer + for zero encoded value. */
7513 if (!inst.operands[i].negative)
7514 inst.instruction |= INDEX_UP;
7515 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7516 }
09d92015 7517 }
09d92015
MM
7518}
7519
c19d1205
ZW
7520/* inst.operands[i] was set up by parse_address. Encode it into an
7521 ARM-format mode 3 load or store instruction. Reject forms that
7522 cannot be used with such instructions. If is_t is true, reject
7523 forms that cannot be used with a T instruction (i.e. not
7524 post-indexed). */
7525static void
7526encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7527{
c19d1205 7528 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7529 {
c19d1205
ZW
7530 inst.error = _("instruction does not accept scaled register index");
7531 return;
09d92015 7532 }
a737bd4d 7533
c19d1205 7534 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7535
c19d1205
ZW
7536 if (inst.operands[i].immisreg)
7537 {
5be8be5d 7538 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7539 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7540 BAD_PC_ADDRESSING);
eb9f3f00
JB
7541 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7542 BAD_PC_WRITEBACK);
c19d1205
ZW
7543 inst.instruction |= inst.operands[i].imm;
7544 if (!inst.operands[i].negative)
7545 inst.instruction |= INDEX_UP;
7546 }
7547 else /* immediate offset in inst.reloc */
7548 {
5be8be5d
DG
7549 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7550 && inst.operands[i].writeback),
7551 BAD_PC_WRITEBACK);
c19d1205
ZW
7552 inst.instruction |= HWOFFSET_IMM;
7553 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7554 {
7555 /* Prefer + for zero encoded value. */
7556 if (!inst.operands[i].negative)
7557 inst.instruction |= INDEX_UP;
7558
7559 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7560 }
c19d1205 7561 }
a737bd4d
NC
7562}
7563
8335d6aa
JW
7564/* Write immediate bits [7:0] to the following locations:
7565
7566 |28/24|23 19|18 16|15 4|3 0|
7567 | 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|
7568
7569 This function is used by VMOV/VMVN/VORR/VBIC. */
7570
7571static void
7572neon_write_immbits (unsigned immbits)
7573{
7574 inst.instruction |= immbits & 0xf;
7575 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7576 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7577}
7578
7579/* Invert low-order SIZE bits of XHI:XLO. */
7580
7581static void
7582neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7583{
7584 unsigned immlo = xlo ? *xlo : 0;
7585 unsigned immhi = xhi ? *xhi : 0;
7586
7587 switch (size)
7588 {
7589 case 8:
7590 immlo = (~immlo) & 0xff;
7591 break;
7592
7593 case 16:
7594 immlo = (~immlo) & 0xffff;
7595 break;
7596
7597 case 64:
7598 immhi = (~immhi) & 0xffffffff;
7599 /* fall through. */
7600
7601 case 32:
7602 immlo = (~immlo) & 0xffffffff;
7603 break;
7604
7605 default:
7606 abort ();
7607 }
7608
7609 if (xlo)
7610 *xlo = immlo;
7611
7612 if (xhi)
7613 *xhi = immhi;
7614}
7615
7616/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7617 A, B, C, D. */
09d92015 7618
c19d1205 7619static int
8335d6aa 7620neon_bits_same_in_bytes (unsigned imm)
09d92015 7621{
8335d6aa
JW
7622 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7623 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7624 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7625 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7626}
a737bd4d 7627
8335d6aa 7628/* For immediate of above form, return 0bABCD. */
09d92015 7629
8335d6aa
JW
7630static unsigned
7631neon_squash_bits (unsigned imm)
7632{
7633 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7634 | ((imm & 0x01000000) >> 21);
7635}
7636
7637/* Compress quarter-float representation to 0b...000 abcdefgh. */
7638
7639static unsigned
7640neon_qfloat_bits (unsigned imm)
7641{
7642 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7643}
7644
7645/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7646 the instruction. *OP is passed as the initial value of the op field, and
7647 may be set to a different value depending on the constant (i.e.
7648 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7649 MVN). If the immediate looks like a repeated pattern then also
7650 try smaller element sizes. */
7651
7652static int
7653neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7654 unsigned *immbits, int *op, int size,
7655 enum neon_el_type type)
7656{
7657 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7658 float. */
7659 if (type == NT_float && !float_p)
7660 return FAIL;
7661
7662 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7663 {
8335d6aa
JW
7664 if (size != 32 || *op == 1)
7665 return FAIL;
7666 *immbits = neon_qfloat_bits (immlo);
7667 return 0xf;
7668 }
7669
7670 if (size == 64)
7671 {
7672 if (neon_bits_same_in_bytes (immhi)
7673 && neon_bits_same_in_bytes (immlo))
c19d1205 7674 {
8335d6aa
JW
7675 if (*op == 1)
7676 return FAIL;
7677 *immbits = (neon_squash_bits (immhi) << 4)
7678 | neon_squash_bits (immlo);
7679 *op = 1;
7680 return 0xe;
c19d1205 7681 }
a737bd4d 7682
8335d6aa
JW
7683 if (immhi != immlo)
7684 return FAIL;
7685 }
a737bd4d 7686
8335d6aa 7687 if (size >= 32)
09d92015 7688 {
8335d6aa 7689 if (immlo == (immlo & 0x000000ff))
c19d1205 7690 {
8335d6aa
JW
7691 *immbits = immlo;
7692 return 0x0;
c19d1205 7693 }
8335d6aa 7694 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7695 {
8335d6aa
JW
7696 *immbits = immlo >> 8;
7697 return 0x2;
c19d1205 7698 }
8335d6aa
JW
7699 else if (immlo == (immlo & 0x00ff0000))
7700 {
7701 *immbits = immlo >> 16;
7702 return 0x4;
7703 }
7704 else if (immlo == (immlo & 0xff000000))
7705 {
7706 *immbits = immlo >> 24;
7707 return 0x6;
7708 }
7709 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7710 {
7711 *immbits = (immlo >> 8) & 0xff;
7712 return 0xc;
7713 }
7714 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7715 {
7716 *immbits = (immlo >> 16) & 0xff;
7717 return 0xd;
7718 }
7719
7720 if ((immlo & 0xffff) != (immlo >> 16))
7721 return FAIL;
7722 immlo &= 0xffff;
09d92015 7723 }
a737bd4d 7724
8335d6aa 7725 if (size >= 16)
4962c51a 7726 {
8335d6aa
JW
7727 if (immlo == (immlo & 0x000000ff))
7728 {
7729 *immbits = immlo;
7730 return 0x8;
7731 }
7732 else if (immlo == (immlo & 0x0000ff00))
7733 {
7734 *immbits = immlo >> 8;
7735 return 0xa;
7736 }
7737
7738 if ((immlo & 0xff) != (immlo >> 8))
7739 return FAIL;
7740 immlo &= 0xff;
4962c51a
MS
7741 }
7742
8335d6aa
JW
7743 if (immlo == (immlo & 0x000000ff))
7744 {
7745 /* Don't allow MVN with 8-bit immediate. */
7746 if (*op == 1)
7747 return FAIL;
7748 *immbits = immlo;
7749 return 0xe;
7750 }
26d97720 7751
8335d6aa 7752 return FAIL;
c19d1205 7753}
a737bd4d 7754
ba592044
AM
7755/* Returns TRUE if double precision value V may be cast
7756 to single precision without loss of accuracy. */
7757
7758static bfd_boolean
7759is_double_a_single (long int v)
7760{
7761 int exp = (int) (v >> 52) & 0x7FF;
7762 long int mantissa = (v & 0xFFFFFFFFFFFFFl);
7763
7764 return (exp == 0 || exp == 0x7FF
7765 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7766 && (mantissa & 0x1FFFFFFFl) == 0;
7767}
7768
7769/* Returns a double precision value casted to single precision
7770 (ignoring the least significant bits in exponent and mantissa). */
7771
7772static int
7773double_to_single (long int v)
7774{
7775 int sign = (int) ((v >> 63) & 1l);
7776 int exp = (int) (v >> 52) & 0x7FF;
7777 long int mantissa = (v & 0xFFFFFFFFFFFFFl);
7778
7779 if (exp == 0x7FF)
7780 exp = 0xFF;
7781 else
7782 {
7783 exp = exp - 1023 + 127;
7784 if (exp >= 0xFF)
7785 {
7786 /* Infinity. */
7787 exp = 0x7F;
7788 mantissa = 0;
7789 }
7790 else if (exp < 0)
7791 {
7792 /* No denormalized numbers. */
7793 exp = 0;
7794 mantissa = 0;
7795 }
7796 }
7797 mantissa >>= 29;
7798 return (sign << 31) | (exp << 23) | mantissa;
7799}
7800
8335d6aa
JW
7801enum lit_type
7802{
7803 CONST_THUMB,
7804 CONST_ARM,
7805 CONST_VEC
7806};
7807
ba592044
AM
7808static void do_vfp_nsyn_opcode (const char *);
7809
c19d1205
ZW
7810/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7811 Determine whether it can be performed with a move instruction; if
7812 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7813 return TRUE; if it can't, convert inst.instruction to a literal-pool
7814 load and return FALSE. If this is not a valid thing to do in the
7815 current context, set inst.error and return TRUE.
a737bd4d 7816
c19d1205
ZW
7817 inst.operands[i] describes the destination register. */
7818
c921be7d 7819static bfd_boolean
8335d6aa 7820move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7821{
53365c0d 7822 unsigned long tbit;
8335d6aa
JW
7823 bfd_boolean thumb_p = (t == CONST_THUMB);
7824 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7825
7826 if (thumb_p)
7827 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7828 else
7829 tbit = LOAD_BIT;
7830
7831 if ((inst.instruction & tbit) == 0)
09d92015 7832 {
c19d1205 7833 inst.error = _("invalid pseudo operation");
c921be7d 7834 return TRUE;
09d92015 7835 }
ba592044 7836
8335d6aa
JW
7837 if (inst.reloc.exp.X_op != O_constant
7838 && inst.reloc.exp.X_op != O_symbol
7839 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7840 {
7841 inst.error = _("constant expression expected");
c921be7d 7842 return TRUE;
09d92015 7843 }
ba592044
AM
7844
7845 if (inst.reloc.exp.X_op == O_constant
7846 || inst.reloc.exp.X_op == O_big)
8335d6aa 7847 {
ba592044
AM
7848 offsetT v;
7849
7850 if (inst.reloc.exp.X_op == O_big)
8335d6aa 7851 {
ba592044
AM
7852 LITTLENUM_TYPE w[X_PRECISION];
7853 LITTLENUM_TYPE * l;
7854
7855 if (inst.reloc.exp.X_add_number == -1)
8335d6aa 7856 {
ba592044
AM
7857 gen_to_words (w, X_PRECISION, E_PRECISION);
7858 l = w;
7859 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 7860 }
ba592044
AM
7861 else
7862 l = generic_bignum;
7863
7864 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
7865 | (l[0] & LITTLENUM_MASK);
8335d6aa 7866 }
ba592044
AM
7867 else
7868 v = inst.reloc.exp.X_add_number;
7869
7870 if (!inst.operands[i].issingle)
8335d6aa 7871 {
ba592044 7872 if (thumb_p && inst.reloc.exp.X_op == O_constant)
8335d6aa 7873 {
ba592044
AM
7874 if (!unified_syntax && (v & ~0xFF) == 0)
7875 {
7876 /* This can be done with a mov(1) instruction. */
7877 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7878 inst.instruction |= v;
7879 return TRUE;
7880 }
8335d6aa 7881 }
ba592044
AM
7882 else if (arm_p && inst.reloc.exp.X_op == O_constant)
7883 {
7884 int value = encode_arm_immediate (v);
7885 if (value != FAIL)
7886 {
7887 /* This can be done with a mov instruction. */
7888 inst.instruction &= LITERAL_MASK;
7889 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7890 inst.instruction |= value & 0xfff;
7891 return TRUE;
7892 }
8335d6aa 7893
ba592044
AM
7894 value = encode_arm_immediate (~ v);
7895 if (value != FAIL)
7896 {
7897 /* This can be done with a mvn instruction. */
7898 inst.instruction &= LITERAL_MASK;
7899 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7900 inst.instruction |= value & 0xfff;
7901 return TRUE;
7902 }
7903 }
7904 else if (t == CONST_VEC)
8335d6aa 7905 {
ba592044
AM
7906 int op = 0;
7907 unsigned immbits = 0;
7908 unsigned immlo = inst.operands[1].imm;
7909 unsigned immhi = inst.operands[1].regisimm
7910 ? inst.operands[1].reg
7911 : inst.reloc.exp.X_unsigned
7912 ? 0
7913 : ((bfd_int64_t)((int) immlo)) >> 32;
7914 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
7915 &op, 64, NT_invtype);
7916
7917 if (cmode == FAIL)
7918 {
7919 neon_invert_size (&immlo, &immhi, 64);
7920 op = !op;
7921 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
7922 &op, 64, NT_invtype);
7923 }
7924
7925 if (cmode != FAIL)
7926 {
7927 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
7928 | (1 << 23)
7929 | (cmode << 8)
7930 | (op << 5)
7931 | (1 << 4);
7932
7933 /* Fill other bits in vmov encoding for both thumb and arm. */
7934 if (thumb_mode)
7935 inst.instruction |= (0x7 << 29) | (0xF << 24);
7936 else
7937 inst.instruction |= (0xF << 28) | (0x1 << 25);
7938 neon_write_immbits (immbits);
7939 return TRUE;
7940 }
8335d6aa
JW
7941 }
7942 }
8335d6aa 7943
ba592044
AM
7944 if (t == CONST_VEC)
7945 {
7946 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
7947 if (inst.operands[i].issingle
7948 && is_quarter_float (inst.operands[1].imm)
7949 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 7950 {
ba592044
AM
7951 inst.operands[1].imm =
7952 neon_qfloat_bits (v);
7953 do_vfp_nsyn_opcode ("fconsts");
7954 return TRUE;
8335d6aa 7955 }
ba592044
AM
7956 else if (!inst.operands[1].issingle
7957 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 7958 {
ba592044
AM
7959 if (is_double_a_single (v)
7960 && is_quarter_float (double_to_single (v)))
7961 {
7962 inst.operands[1].imm =
7963 neon_qfloat_bits (double_to_single (v));
7964 do_vfp_nsyn_opcode ("fconstd");
7965 return TRUE;
7966 }
8335d6aa
JW
7967 }
7968 }
7969 }
7970
7971 if (add_to_lit_pool ((!inst.operands[i].isvec
7972 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
7973 return TRUE;
7974
7975 inst.operands[1].reg = REG_PC;
7976 inst.operands[1].isreg = 1;
7977 inst.operands[1].preind = 1;
7978 inst.reloc.pc_rel = 1;
7979 inst.reloc.type = (thumb_p
7980 ? BFD_RELOC_ARM_THUMB_OFFSET
7981 : (mode_3
7982 ? BFD_RELOC_ARM_HWLITERAL
7983 : BFD_RELOC_ARM_LITERAL));
7984 return FALSE;
7985}
7986
7987/* inst.operands[i] was set up by parse_address. Encode it into an
7988 ARM-format instruction. Reject all forms which cannot be encoded
7989 into a coprocessor load/store instruction. If wb_ok is false,
7990 reject use of writeback; if unind_ok is false, reject use of
7991 unindexed addressing. If reloc_override is not 0, use it instead
7992 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
7993 (in which case it is preserved). */
7994
7995static int
7996encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
7997{
7998 if (!inst.operands[i].isreg)
7999 {
99b2a2dd
NC
8000 /* PR 18256 */
8001 if (! inst.operands[0].isvec)
8002 {
8003 inst.error = _("invalid co-processor operand");
8004 return FAIL;
8005 }
8335d6aa
JW
8006 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8007 return SUCCESS;
8008 }
8009
8010 inst.instruction |= inst.operands[i].reg << 16;
8011
8012 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8013
8014 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8015 {
8016 gas_assert (!inst.operands[i].writeback);
8017 if (!unind_ok)
8018 {
8019 inst.error = _("instruction does not support unindexed addressing");
8020 return FAIL;
8021 }
8022 inst.instruction |= inst.operands[i].imm;
8023 inst.instruction |= INDEX_UP;
8024 return SUCCESS;
8025 }
8026
8027 if (inst.operands[i].preind)
8028 inst.instruction |= PRE_INDEX;
8029
8030 if (inst.operands[i].writeback)
09d92015 8031 {
8335d6aa 8032 if (inst.operands[i].reg == REG_PC)
c19d1205 8033 {
8335d6aa
JW
8034 inst.error = _("pc may not be used with write-back");
8035 return FAIL;
c19d1205 8036 }
8335d6aa 8037 if (!wb_ok)
c19d1205 8038 {
8335d6aa
JW
8039 inst.error = _("instruction does not support writeback");
8040 return FAIL;
c19d1205 8041 }
8335d6aa 8042 inst.instruction |= WRITE_BACK;
09d92015
MM
8043 }
8044
8335d6aa
JW
8045 if (reloc_override)
8046 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8047 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8048 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8049 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8050 {
8335d6aa
JW
8051 if (thumb_mode)
8052 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8053 else
8054 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8055 }
8335d6aa
JW
8056
8057 /* Prefer + for zero encoded value. */
8058 if (!inst.operands[i].negative)
8059 inst.instruction |= INDEX_UP;
8060
8061 return SUCCESS;
09d92015
MM
8062}
8063
5f4273c7 8064/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8065 First some generics; their names are taken from the conventional
8066 bit positions for register arguments in ARM format instructions. */
09d92015 8067
a737bd4d 8068static void
c19d1205 8069do_noargs (void)
09d92015 8070{
c19d1205 8071}
a737bd4d 8072
c19d1205
ZW
8073static void
8074do_rd (void)
8075{
8076 inst.instruction |= inst.operands[0].reg << 12;
8077}
a737bd4d 8078
c19d1205
ZW
8079static void
8080do_rd_rm (void)
8081{
8082 inst.instruction |= inst.operands[0].reg << 12;
8083 inst.instruction |= inst.operands[1].reg;
8084}
09d92015 8085
9eb6c0f1
MGD
8086static void
8087do_rm_rn (void)
8088{
8089 inst.instruction |= inst.operands[0].reg;
8090 inst.instruction |= inst.operands[1].reg << 16;
8091}
8092
c19d1205
ZW
8093static void
8094do_rd_rn (void)
8095{
8096 inst.instruction |= inst.operands[0].reg << 12;
8097 inst.instruction |= inst.operands[1].reg << 16;
8098}
a737bd4d 8099
c19d1205
ZW
8100static void
8101do_rn_rd (void)
8102{
8103 inst.instruction |= inst.operands[0].reg << 16;
8104 inst.instruction |= inst.operands[1].reg << 12;
8105}
09d92015 8106
59d09be6
MGD
8107static bfd_boolean
8108check_obsolete (const arm_feature_set *feature, const char *msg)
8109{
8110 if (ARM_CPU_IS_ANY (cpu_variant))
8111 {
5c3696f8 8112 as_tsktsk ("%s", msg);
59d09be6
MGD
8113 return TRUE;
8114 }
8115 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8116 {
8117 as_bad ("%s", msg);
8118 return TRUE;
8119 }
8120
8121 return FALSE;
8122}
8123
c19d1205
ZW
8124static void
8125do_rd_rm_rn (void)
8126{
9a64e435 8127 unsigned Rn = inst.operands[2].reg;
708587a4 8128 /* Enforce restrictions on SWP instruction. */
9a64e435 8129 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8130 {
8131 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8132 _("Rn must not overlap other operands"));
8133
59d09be6
MGD
8134 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8135 */
8136 if (!check_obsolete (&arm_ext_v8,
8137 _("swp{b} use is obsoleted for ARMv8 and later"))
8138 && warn_on_deprecated
8139 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8140 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8141 }
59d09be6 8142
c19d1205
ZW
8143 inst.instruction |= inst.operands[0].reg << 12;
8144 inst.instruction |= inst.operands[1].reg;
9a64e435 8145 inst.instruction |= Rn << 16;
c19d1205 8146}
09d92015 8147
c19d1205
ZW
8148static void
8149do_rd_rn_rm (void)
8150{
8151 inst.instruction |= inst.operands[0].reg << 12;
8152 inst.instruction |= inst.operands[1].reg << 16;
8153 inst.instruction |= inst.operands[2].reg;
8154}
a737bd4d 8155
c19d1205
ZW
8156static void
8157do_rm_rd_rn (void)
8158{
5be8be5d
DG
8159 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8160 constraint (((inst.reloc.exp.X_op != O_constant
8161 && inst.reloc.exp.X_op != O_illegal)
8162 || inst.reloc.exp.X_add_number != 0),
8163 BAD_ADDR_MODE);
c19d1205
ZW
8164 inst.instruction |= inst.operands[0].reg;
8165 inst.instruction |= inst.operands[1].reg << 12;
8166 inst.instruction |= inst.operands[2].reg << 16;
8167}
09d92015 8168
c19d1205
ZW
8169static void
8170do_imm0 (void)
8171{
8172 inst.instruction |= inst.operands[0].imm;
8173}
09d92015 8174
c19d1205
ZW
8175static void
8176do_rd_cpaddr (void)
8177{
8178 inst.instruction |= inst.operands[0].reg << 12;
8179 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8180}
a737bd4d 8181
c19d1205
ZW
8182/* ARM instructions, in alphabetical order by function name (except
8183 that wrapper functions appear immediately after the function they
8184 wrap). */
09d92015 8185
c19d1205
ZW
8186/* This is a pseudo-op of the form "adr rd, label" to be converted
8187 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8188
8189static void
c19d1205 8190do_adr (void)
09d92015 8191{
c19d1205 8192 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8193
c19d1205
ZW
8194 /* Frag hacking will turn this into a sub instruction if the offset turns
8195 out to be negative. */
8196 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8197 inst.reloc.pc_rel = 1;
2fc8bdac 8198 inst.reloc.exp.X_add_number -= 8;
c19d1205 8199}
b99bd4ef 8200
c19d1205
ZW
8201/* This is a pseudo-op of the form "adrl rd, label" to be converted
8202 into a relative address of the form:
8203 add rd, pc, #low(label-.-8)"
8204 add rd, rd, #high(label-.-8)" */
b99bd4ef 8205
c19d1205
ZW
8206static void
8207do_adrl (void)
8208{
8209 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8210
c19d1205
ZW
8211 /* Frag hacking will turn this into a sub instruction if the offset turns
8212 out to be negative. */
8213 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8214 inst.reloc.pc_rel = 1;
8215 inst.size = INSN_SIZE * 2;
2fc8bdac 8216 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
8217}
8218
b99bd4ef 8219static void
c19d1205 8220do_arit (void)
b99bd4ef 8221{
c19d1205
ZW
8222 if (!inst.operands[1].present)
8223 inst.operands[1].reg = inst.operands[0].reg;
8224 inst.instruction |= inst.operands[0].reg << 12;
8225 inst.instruction |= inst.operands[1].reg << 16;
8226 encode_arm_shifter_operand (2);
8227}
b99bd4ef 8228
62b3e311
PB
8229static void
8230do_barrier (void)
8231{
8232 if (inst.operands[0].present)
ccb84d65 8233 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8234 else
8235 inst.instruction |= 0xf;
8236}
8237
c19d1205
ZW
8238static void
8239do_bfc (void)
8240{
8241 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8242 constraint (msb > 32, _("bit-field extends past end of register"));
8243 /* The instruction encoding stores the LSB and MSB,
8244 not the LSB and width. */
8245 inst.instruction |= inst.operands[0].reg << 12;
8246 inst.instruction |= inst.operands[1].imm << 7;
8247 inst.instruction |= (msb - 1) << 16;
8248}
b99bd4ef 8249
c19d1205
ZW
8250static void
8251do_bfi (void)
8252{
8253 unsigned int msb;
b99bd4ef 8254
c19d1205
ZW
8255 /* #0 in second position is alternative syntax for bfc, which is
8256 the same instruction but with REG_PC in the Rm field. */
8257 if (!inst.operands[1].isreg)
8258 inst.operands[1].reg = REG_PC;
b99bd4ef 8259
c19d1205
ZW
8260 msb = inst.operands[2].imm + inst.operands[3].imm;
8261 constraint (msb > 32, _("bit-field extends past end of register"));
8262 /* The instruction encoding stores the LSB and MSB,
8263 not the LSB and width. */
8264 inst.instruction |= inst.operands[0].reg << 12;
8265 inst.instruction |= inst.operands[1].reg;
8266 inst.instruction |= inst.operands[2].imm << 7;
8267 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8268}
8269
b99bd4ef 8270static void
c19d1205 8271do_bfx (void)
b99bd4ef 8272{
c19d1205
ZW
8273 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8274 _("bit-field extends past end of register"));
8275 inst.instruction |= inst.operands[0].reg << 12;
8276 inst.instruction |= inst.operands[1].reg;
8277 inst.instruction |= inst.operands[2].imm << 7;
8278 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8279}
09d92015 8280
c19d1205
ZW
8281/* ARM V5 breakpoint instruction (argument parse)
8282 BKPT <16 bit unsigned immediate>
8283 Instruction is not conditional.
8284 The bit pattern given in insns[] has the COND_ALWAYS condition,
8285 and it is an error if the caller tried to override that. */
b99bd4ef 8286
c19d1205
ZW
8287static void
8288do_bkpt (void)
8289{
8290 /* Top 12 of 16 bits to bits 19:8. */
8291 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8292
c19d1205
ZW
8293 /* Bottom 4 of 16 bits to bits 3:0. */
8294 inst.instruction |= inst.operands[0].imm & 0xf;
8295}
09d92015 8296
c19d1205
ZW
8297static void
8298encode_branch (int default_reloc)
8299{
8300 if (inst.operands[0].hasreloc)
8301 {
0855e32b
NS
8302 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8303 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8304 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8305 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8306 ? BFD_RELOC_ARM_PLT32
8307 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8308 }
b99bd4ef 8309 else
9ae92b05 8310 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8311 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8312}
8313
b99bd4ef 8314static void
c19d1205 8315do_branch (void)
b99bd4ef 8316{
39b41c9c
PB
8317#ifdef OBJ_ELF
8318 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8319 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8320 else
8321#endif
8322 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8323}
8324
8325static void
8326do_bl (void)
8327{
8328#ifdef OBJ_ELF
8329 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8330 {
8331 if (inst.cond == COND_ALWAYS)
8332 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8333 else
8334 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8335 }
8336 else
8337#endif
8338 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8339}
b99bd4ef 8340
c19d1205
ZW
8341/* ARM V5 branch-link-exchange instruction (argument parse)
8342 BLX <target_addr> ie BLX(1)
8343 BLX{<condition>} <Rm> ie BLX(2)
8344 Unfortunately, there are two different opcodes for this mnemonic.
8345 So, the insns[].value is not used, and the code here zaps values
8346 into inst.instruction.
8347 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8348
c19d1205
ZW
8349static void
8350do_blx (void)
8351{
8352 if (inst.operands[0].isreg)
b99bd4ef 8353 {
c19d1205
ZW
8354 /* Arg is a register; the opcode provided by insns[] is correct.
8355 It is not illegal to do "blx pc", just useless. */
8356 if (inst.operands[0].reg == REG_PC)
8357 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8358
c19d1205
ZW
8359 inst.instruction |= inst.operands[0].reg;
8360 }
8361 else
b99bd4ef 8362 {
c19d1205 8363 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8364 conditionally, and the opcode must be adjusted.
8365 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8366 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8367 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8368 inst.instruction = 0xfa000000;
267bf995 8369 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8370 }
c19d1205
ZW
8371}
8372
8373static void
8374do_bx (void)
8375{
845b51d6
PB
8376 bfd_boolean want_reloc;
8377
c19d1205
ZW
8378 if (inst.operands[0].reg == REG_PC)
8379 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8380
c19d1205 8381 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8382 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8383 it is for ARMv4t or earlier. */
8384 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8385 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
8386 want_reloc = TRUE;
8387
5ad34203 8388#ifdef OBJ_ELF
845b51d6 8389 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8390#endif
584206db 8391 want_reloc = FALSE;
845b51d6
PB
8392
8393 if (want_reloc)
8394 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8395}
8396
c19d1205
ZW
8397
8398/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8399
8400static void
c19d1205 8401do_bxj (void)
a737bd4d 8402{
c19d1205
ZW
8403 if (inst.operands[0].reg == REG_PC)
8404 as_tsktsk (_("use of r15 in bxj is not really useful"));
8405
8406 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8407}
8408
c19d1205
ZW
8409/* Co-processor data operation:
8410 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8411 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8412static void
8413do_cdp (void)
8414{
8415 inst.instruction |= inst.operands[0].reg << 8;
8416 inst.instruction |= inst.operands[1].imm << 20;
8417 inst.instruction |= inst.operands[2].reg << 12;
8418 inst.instruction |= inst.operands[3].reg << 16;
8419 inst.instruction |= inst.operands[4].reg;
8420 inst.instruction |= inst.operands[5].imm << 5;
8421}
a737bd4d
NC
8422
8423static void
c19d1205 8424do_cmp (void)
a737bd4d 8425{
c19d1205
ZW
8426 inst.instruction |= inst.operands[0].reg << 16;
8427 encode_arm_shifter_operand (1);
a737bd4d
NC
8428}
8429
c19d1205
ZW
8430/* Transfer between coprocessor and ARM registers.
8431 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8432 MRC2
8433 MCR{cond}
8434 MCR2
8435
8436 No special properties. */
09d92015 8437
dcbd0d71
MGD
8438struct deprecated_coproc_regs_s
8439{
8440 unsigned cp;
8441 int opc1;
8442 unsigned crn;
8443 unsigned crm;
8444 int opc2;
8445 arm_feature_set deprecated;
8446 arm_feature_set obsoleted;
8447 const char *dep_msg;
8448 const char *obs_msg;
8449};
8450
8451#define DEPR_ACCESS_V8 \
8452 N_("This coprocessor register access is deprecated in ARMv8")
8453
8454/* Table of all deprecated coprocessor registers. */
8455static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8456{
8457 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8458 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8459 DEPR_ACCESS_V8, NULL},
8460 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8461 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8462 DEPR_ACCESS_V8, NULL},
8463 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8464 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8465 DEPR_ACCESS_V8, NULL},
8466 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8467 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8468 DEPR_ACCESS_V8, NULL},
8469 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8470 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8471 DEPR_ACCESS_V8, NULL},
8472};
8473
8474#undef DEPR_ACCESS_V8
8475
8476static const size_t deprecated_coproc_reg_count =
8477 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8478
09d92015 8479static void
c19d1205 8480do_co_reg (void)
09d92015 8481{
fdfde340 8482 unsigned Rd;
dcbd0d71 8483 size_t i;
fdfde340
JM
8484
8485 Rd = inst.operands[2].reg;
8486 if (thumb_mode)
8487 {
8488 if (inst.instruction == 0xee000010
8489 || inst.instruction == 0xfe000010)
8490 /* MCR, MCR2 */
8491 reject_bad_reg (Rd);
8492 else
8493 /* MRC, MRC2 */
8494 constraint (Rd == REG_SP, BAD_SP);
8495 }
8496 else
8497 {
8498 /* MCR */
8499 if (inst.instruction == 0xe000010)
8500 constraint (Rd == REG_PC, BAD_PC);
8501 }
8502
dcbd0d71
MGD
8503 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8504 {
8505 const struct deprecated_coproc_regs_s *r =
8506 deprecated_coproc_regs + i;
8507
8508 if (inst.operands[0].reg == r->cp
8509 && inst.operands[1].imm == r->opc1
8510 && inst.operands[3].reg == r->crn
8511 && inst.operands[4].reg == r->crm
8512 && inst.operands[5].imm == r->opc2)
8513 {
b10bf8c5 8514 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8515 && warn_on_deprecated
dcbd0d71 8516 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8517 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8518 }
8519 }
fdfde340 8520
c19d1205
ZW
8521 inst.instruction |= inst.operands[0].reg << 8;
8522 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8523 inst.instruction |= Rd << 12;
c19d1205
ZW
8524 inst.instruction |= inst.operands[3].reg << 16;
8525 inst.instruction |= inst.operands[4].reg;
8526 inst.instruction |= inst.operands[5].imm << 5;
8527}
09d92015 8528
c19d1205
ZW
8529/* Transfer between coprocessor register and pair of ARM registers.
8530 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8531 MCRR2
8532 MRRC{cond}
8533 MRRC2
b99bd4ef 8534
c19d1205 8535 Two XScale instructions are special cases of these:
09d92015 8536
c19d1205
ZW
8537 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8538 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8539
5f4273c7 8540 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8541
c19d1205
ZW
8542static void
8543do_co_reg2c (void)
8544{
fdfde340
JM
8545 unsigned Rd, Rn;
8546
8547 Rd = inst.operands[2].reg;
8548 Rn = inst.operands[3].reg;
8549
8550 if (thumb_mode)
8551 {
8552 reject_bad_reg (Rd);
8553 reject_bad_reg (Rn);
8554 }
8555 else
8556 {
8557 constraint (Rd == REG_PC, BAD_PC);
8558 constraint (Rn == REG_PC, BAD_PC);
8559 }
8560
c19d1205
ZW
8561 inst.instruction |= inst.operands[0].reg << 8;
8562 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8563 inst.instruction |= Rd << 12;
8564 inst.instruction |= Rn << 16;
c19d1205 8565 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8566}
8567
c19d1205
ZW
8568static void
8569do_cpsi (void)
8570{
8571 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8572 if (inst.operands[1].present)
8573 {
8574 inst.instruction |= CPSI_MMOD;
8575 inst.instruction |= inst.operands[1].imm;
8576 }
c19d1205 8577}
b99bd4ef 8578
62b3e311
PB
8579static void
8580do_dbg (void)
8581{
8582 inst.instruction |= inst.operands[0].imm;
8583}
8584
eea54501
MGD
8585static void
8586do_div (void)
8587{
8588 unsigned Rd, Rn, Rm;
8589
8590 Rd = inst.operands[0].reg;
8591 Rn = (inst.operands[1].present
8592 ? inst.operands[1].reg : Rd);
8593 Rm = inst.operands[2].reg;
8594
8595 constraint ((Rd == REG_PC), BAD_PC);
8596 constraint ((Rn == REG_PC), BAD_PC);
8597 constraint ((Rm == REG_PC), BAD_PC);
8598
8599 inst.instruction |= Rd << 16;
8600 inst.instruction |= Rn << 0;
8601 inst.instruction |= Rm << 8;
8602}
8603
b99bd4ef 8604static void
c19d1205 8605do_it (void)
b99bd4ef 8606{
c19d1205 8607 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8608 process it to do the validation as if in
8609 thumb mode, just in case the code gets
8610 assembled for thumb using the unified syntax. */
8611
c19d1205 8612 inst.size = 0;
e07e6e58
NC
8613 if (unified_syntax)
8614 {
8615 set_it_insn_type (IT_INSN);
8616 now_it.mask = (inst.instruction & 0xf) | 0x10;
8617 now_it.cc = inst.operands[0].imm;
8618 }
09d92015 8619}
b99bd4ef 8620
6530b175
NC
8621/* If there is only one register in the register list,
8622 then return its register number. Otherwise return -1. */
8623static int
8624only_one_reg_in_list (int range)
8625{
8626 int i = ffs (range) - 1;
8627 return (i > 15 || range != (1 << i)) ? -1 : i;
8628}
8629
09d92015 8630static void
6530b175 8631encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8632{
c19d1205
ZW
8633 int base_reg = inst.operands[0].reg;
8634 int range = inst.operands[1].imm;
6530b175 8635 int one_reg;
ea6ef066 8636
c19d1205
ZW
8637 inst.instruction |= base_reg << 16;
8638 inst.instruction |= range;
ea6ef066 8639
c19d1205
ZW
8640 if (inst.operands[1].writeback)
8641 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8642
c19d1205 8643 if (inst.operands[0].writeback)
ea6ef066 8644 {
c19d1205
ZW
8645 inst.instruction |= WRITE_BACK;
8646 /* Check for unpredictable uses of writeback. */
8647 if (inst.instruction & LOAD_BIT)
09d92015 8648 {
c19d1205
ZW
8649 /* Not allowed in LDM type 2. */
8650 if ((inst.instruction & LDM_TYPE_2_OR_3)
8651 && ((range & (1 << REG_PC)) == 0))
8652 as_warn (_("writeback of base register is UNPREDICTABLE"));
8653 /* Only allowed if base reg not in list for other types. */
8654 else if (range & (1 << base_reg))
8655 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8656 }
8657 else /* STM. */
8658 {
8659 /* Not allowed for type 2. */
8660 if (inst.instruction & LDM_TYPE_2_OR_3)
8661 as_warn (_("writeback of base register is UNPREDICTABLE"));
8662 /* Only allowed if base reg not in list, or first in list. */
8663 else if ((range & (1 << base_reg))
8664 && (range & ((1 << base_reg) - 1)))
8665 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8666 }
ea6ef066 8667 }
6530b175
NC
8668
8669 /* If PUSH/POP has only one register, then use the A2 encoding. */
8670 one_reg = only_one_reg_in_list (range);
8671 if (from_push_pop_mnem && one_reg >= 0)
8672 {
8673 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8674
8675 inst.instruction &= A_COND_MASK;
8676 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8677 inst.instruction |= one_reg << 12;
8678 }
8679}
8680
8681static void
8682do_ldmstm (void)
8683{
8684 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8685}
8686
c19d1205
ZW
8687/* ARMv5TE load-consecutive (argument parse)
8688 Mode is like LDRH.
8689
8690 LDRccD R, mode
8691 STRccD R, mode. */
8692
a737bd4d 8693static void
c19d1205 8694do_ldrd (void)
a737bd4d 8695{
c19d1205 8696 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8697 _("first transfer register must be even"));
c19d1205
ZW
8698 constraint (inst.operands[1].present
8699 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8700 _("can only transfer two consecutive registers"));
c19d1205
ZW
8701 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8702 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8703
c19d1205
ZW
8704 if (!inst.operands[1].present)
8705 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8706
c56791bb
RE
8707 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8708 register and the first register written; we have to diagnose
8709 overlap between the base and the second register written here. */
ea6ef066 8710
c56791bb
RE
8711 if (inst.operands[2].reg == inst.operands[1].reg
8712 && (inst.operands[2].writeback || inst.operands[2].postind))
8713 as_warn (_("base register written back, and overlaps "
8714 "second transfer register"));
b05fe5cf 8715
c56791bb
RE
8716 if (!(inst.instruction & V4_STR_BIT))
8717 {
c19d1205 8718 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8719 destination (even if not write-back). */
8720 if (inst.operands[2].immisreg
8721 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8722 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8723 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8724 }
c19d1205
ZW
8725 inst.instruction |= inst.operands[0].reg << 12;
8726 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8727}
8728
8729static void
c19d1205 8730do_ldrex (void)
b05fe5cf 8731{
c19d1205
ZW
8732 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8733 || inst.operands[1].postind || inst.operands[1].writeback
8734 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8735 || inst.operands[1].negative
8736 /* This can arise if the programmer has written
8737 strex rN, rM, foo
8738 or if they have mistakenly used a register name as the last
8739 operand, eg:
8740 strex rN, rM, rX
8741 It is very difficult to distinguish between these two cases
8742 because "rX" might actually be a label. ie the register
8743 name has been occluded by a symbol of the same name. So we
8744 just generate a general 'bad addressing mode' type error
8745 message and leave it up to the programmer to discover the
8746 true cause and fix their mistake. */
8747 || (inst.operands[1].reg == REG_PC),
8748 BAD_ADDR_MODE);
b05fe5cf 8749
c19d1205
ZW
8750 constraint (inst.reloc.exp.X_op != O_constant
8751 || inst.reloc.exp.X_add_number != 0,
8752 _("offset must be zero in ARM encoding"));
b05fe5cf 8753
5be8be5d
DG
8754 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8755
c19d1205
ZW
8756 inst.instruction |= inst.operands[0].reg << 12;
8757 inst.instruction |= inst.operands[1].reg << 16;
8758 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
8759}
8760
8761static void
c19d1205 8762do_ldrexd (void)
b05fe5cf 8763{
c19d1205
ZW
8764 constraint (inst.operands[0].reg % 2 != 0,
8765 _("even register required"));
8766 constraint (inst.operands[1].present
8767 && inst.operands[1].reg != inst.operands[0].reg + 1,
8768 _("can only load two consecutive registers"));
8769 /* If op 1 were present and equal to PC, this function wouldn't
8770 have been called in the first place. */
8771 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 8772
c19d1205
ZW
8773 inst.instruction |= inst.operands[0].reg << 12;
8774 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
8775}
8776
1be5fd2e
NC
8777/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8778 which is not a multiple of four is UNPREDICTABLE. */
8779static void
8780check_ldr_r15_aligned (void)
8781{
8782 constraint (!(inst.operands[1].immisreg)
8783 && (inst.operands[0].reg == REG_PC
8784 && inst.operands[1].reg == REG_PC
8785 && (inst.reloc.exp.X_add_number & 0x3)),
8786 _("ldr to register 15 must be 4-byte alligned"));
8787}
8788
b05fe5cf 8789static void
c19d1205 8790do_ldst (void)
b05fe5cf 8791{
c19d1205
ZW
8792 inst.instruction |= inst.operands[0].reg << 12;
8793 if (!inst.operands[1].isreg)
8335d6aa 8794 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 8795 return;
c19d1205 8796 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 8797 check_ldr_r15_aligned ();
b05fe5cf
ZW
8798}
8799
8800static void
c19d1205 8801do_ldstt (void)
b05fe5cf 8802{
c19d1205
ZW
8803 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8804 reject [Rn,...]. */
8805 if (inst.operands[1].preind)
b05fe5cf 8806 {
bd3ba5d1
NC
8807 constraint (inst.reloc.exp.X_op != O_constant
8808 || inst.reloc.exp.X_add_number != 0,
c19d1205 8809 _("this instruction requires a post-indexed address"));
b05fe5cf 8810
c19d1205
ZW
8811 inst.operands[1].preind = 0;
8812 inst.operands[1].postind = 1;
8813 inst.operands[1].writeback = 1;
b05fe5cf 8814 }
c19d1205
ZW
8815 inst.instruction |= inst.operands[0].reg << 12;
8816 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
8817}
b05fe5cf 8818
c19d1205 8819/* Halfword and signed-byte load/store operations. */
b05fe5cf 8820
c19d1205
ZW
8821static void
8822do_ldstv4 (void)
8823{
ff4a8d2b 8824 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
8825 inst.instruction |= inst.operands[0].reg << 12;
8826 if (!inst.operands[1].isreg)
8335d6aa 8827 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 8828 return;
c19d1205 8829 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
8830}
8831
8832static void
c19d1205 8833do_ldsttv4 (void)
b05fe5cf 8834{
c19d1205
ZW
8835 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8836 reject [Rn,...]. */
8837 if (inst.operands[1].preind)
b05fe5cf 8838 {
bd3ba5d1
NC
8839 constraint (inst.reloc.exp.X_op != O_constant
8840 || inst.reloc.exp.X_add_number != 0,
c19d1205 8841 _("this instruction requires a post-indexed address"));
b05fe5cf 8842
c19d1205
ZW
8843 inst.operands[1].preind = 0;
8844 inst.operands[1].postind = 1;
8845 inst.operands[1].writeback = 1;
b05fe5cf 8846 }
c19d1205
ZW
8847 inst.instruction |= inst.operands[0].reg << 12;
8848 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
8849}
b05fe5cf 8850
c19d1205
ZW
8851/* Co-processor register load/store.
8852 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
8853static void
8854do_lstc (void)
8855{
8856 inst.instruction |= inst.operands[0].reg << 8;
8857 inst.instruction |= inst.operands[1].reg << 12;
8858 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
8859}
8860
b05fe5cf 8861static void
c19d1205 8862do_mlas (void)
b05fe5cf 8863{
8fb9d7b9 8864 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 8865 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 8866 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 8867 && !(inst.instruction & 0x00400000))
8fb9d7b9 8868 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 8869
c19d1205
ZW
8870 inst.instruction |= inst.operands[0].reg << 16;
8871 inst.instruction |= inst.operands[1].reg;
8872 inst.instruction |= inst.operands[2].reg << 8;
8873 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 8874}
b05fe5cf 8875
c19d1205
ZW
8876static void
8877do_mov (void)
8878{
8879 inst.instruction |= inst.operands[0].reg << 12;
8880 encode_arm_shifter_operand (1);
8881}
b05fe5cf 8882
c19d1205
ZW
8883/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
8884static void
8885do_mov16 (void)
8886{
b6895b4f
PB
8887 bfd_vma imm;
8888 bfd_boolean top;
8889
8890 top = (inst.instruction & 0x00400000) != 0;
8891 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
8892 _(":lower16: not allowed this instruction"));
8893 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
8894 _(":upper16: not allowed instruction"));
c19d1205 8895 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
8896 if (inst.reloc.type == BFD_RELOC_UNUSED)
8897 {
8898 imm = inst.reloc.exp.X_add_number;
8899 /* The value is in two pieces: 0:11, 16:19. */
8900 inst.instruction |= (imm & 0x00000fff);
8901 inst.instruction |= (imm & 0x0000f000) << 4;
8902 }
b05fe5cf 8903}
b99bd4ef 8904
037e8744
JB
8905static int
8906do_vfp_nsyn_mrs (void)
8907{
8908 if (inst.operands[0].isvec)
8909 {
8910 if (inst.operands[1].reg != 1)
477330fc 8911 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
8912 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
8913 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
8914 do_vfp_nsyn_opcode ("fmstat");
8915 }
8916 else if (inst.operands[1].isvec)
8917 do_vfp_nsyn_opcode ("fmrx");
8918 else
8919 return FAIL;
5f4273c7 8920
037e8744
JB
8921 return SUCCESS;
8922}
8923
8924static int
8925do_vfp_nsyn_msr (void)
8926{
8927 if (inst.operands[0].isvec)
8928 do_vfp_nsyn_opcode ("fmxr");
8929 else
8930 return FAIL;
8931
8932 return SUCCESS;
8933}
8934
f7c21dc7
NC
8935static void
8936do_vmrs (void)
8937{
8938 unsigned Rt = inst.operands[0].reg;
fa94de6b 8939
16d02dc9 8940 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
8941 {
8942 inst.error = BAD_SP;
8943 return;
8944 }
8945
8946 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 8947 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
8948 {
8949 inst.error = BAD_PC;
8950 return;
8951 }
8952
16d02dc9
JB
8953 /* If we get through parsing the register name, we just insert the number
8954 generated into the instruction without further validation. */
8955 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
8956 inst.instruction |= (Rt << 12);
8957}
8958
8959static void
8960do_vmsr (void)
8961{
8962 unsigned Rt = inst.operands[1].reg;
fa94de6b 8963
f7c21dc7
NC
8964 if (thumb_mode)
8965 reject_bad_reg (Rt);
8966 else if (Rt == REG_PC)
8967 {
8968 inst.error = BAD_PC;
8969 return;
8970 }
8971
16d02dc9
JB
8972 /* If we get through parsing the register name, we just insert the number
8973 generated into the instruction without further validation. */
8974 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
8975 inst.instruction |= (Rt << 12);
8976}
8977
b99bd4ef 8978static void
c19d1205 8979do_mrs (void)
b99bd4ef 8980{
90ec0d68
MGD
8981 unsigned br;
8982
037e8744
JB
8983 if (do_vfp_nsyn_mrs () == SUCCESS)
8984 return;
8985
ff4a8d2b 8986 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 8987 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
8988
8989 if (inst.operands[1].isreg)
8990 {
8991 br = inst.operands[1].reg;
8992 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
8993 as_bad (_("bad register for mrs"));
8994 }
8995 else
8996 {
8997 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
8998 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
8999 != (PSR_c|PSR_f),
d2cd1205 9000 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9001 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9002 }
9003
9004 inst.instruction |= br;
c19d1205 9005}
b99bd4ef 9006
c19d1205
ZW
9007/* Two possible forms:
9008 "{C|S}PSR_<field>, Rm",
9009 "{C|S}PSR_f, #expression". */
b99bd4ef 9010
c19d1205
ZW
9011static void
9012do_msr (void)
9013{
037e8744
JB
9014 if (do_vfp_nsyn_msr () == SUCCESS)
9015 return;
9016
c19d1205
ZW
9017 inst.instruction |= inst.operands[0].imm;
9018 if (inst.operands[1].isreg)
9019 inst.instruction |= inst.operands[1].reg;
9020 else
b99bd4ef 9021 {
c19d1205
ZW
9022 inst.instruction |= INST_IMMEDIATE;
9023 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9024 inst.reloc.pc_rel = 0;
b99bd4ef 9025 }
b99bd4ef
NC
9026}
9027
c19d1205
ZW
9028static void
9029do_mul (void)
a737bd4d 9030{
ff4a8d2b
NC
9031 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9032
c19d1205
ZW
9033 if (!inst.operands[2].present)
9034 inst.operands[2].reg = inst.operands[0].reg;
9035 inst.instruction |= inst.operands[0].reg << 16;
9036 inst.instruction |= inst.operands[1].reg;
9037 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9038
8fb9d7b9
MS
9039 if (inst.operands[0].reg == inst.operands[1].reg
9040 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9041 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9042}
9043
c19d1205
ZW
9044/* Long Multiply Parser
9045 UMULL RdLo, RdHi, Rm, Rs
9046 SMULL RdLo, RdHi, Rm, Rs
9047 UMLAL RdLo, RdHi, Rm, Rs
9048 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9049
9050static void
c19d1205 9051do_mull (void)
b99bd4ef 9052{
c19d1205
ZW
9053 inst.instruction |= inst.operands[0].reg << 12;
9054 inst.instruction |= inst.operands[1].reg << 16;
9055 inst.instruction |= inst.operands[2].reg;
9056 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9057
682b27ad
PB
9058 /* rdhi and rdlo must be different. */
9059 if (inst.operands[0].reg == inst.operands[1].reg)
9060 as_tsktsk (_("rdhi and rdlo must be different"));
9061
9062 /* rdhi, rdlo and rm must all be different before armv6. */
9063 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9064 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9065 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9066 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9067}
b99bd4ef 9068
c19d1205
ZW
9069static void
9070do_nop (void)
9071{
e7495e45
NS
9072 if (inst.operands[0].present
9073 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9074 {
9075 /* Architectural NOP hints are CPSR sets with no bits selected. */
9076 inst.instruction &= 0xf0000000;
e7495e45
NS
9077 inst.instruction |= 0x0320f000;
9078 if (inst.operands[0].present)
9079 inst.instruction |= inst.operands[0].imm;
c19d1205 9080 }
b99bd4ef
NC
9081}
9082
c19d1205
ZW
9083/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9084 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9085 Condition defaults to COND_ALWAYS.
9086 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9087
9088static void
c19d1205 9089do_pkhbt (void)
b99bd4ef 9090{
c19d1205
ZW
9091 inst.instruction |= inst.operands[0].reg << 12;
9092 inst.instruction |= inst.operands[1].reg << 16;
9093 inst.instruction |= inst.operands[2].reg;
9094 if (inst.operands[3].present)
9095 encode_arm_shift (3);
9096}
b99bd4ef 9097
c19d1205 9098/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9099
c19d1205
ZW
9100static void
9101do_pkhtb (void)
9102{
9103 if (!inst.operands[3].present)
b99bd4ef 9104 {
c19d1205
ZW
9105 /* If the shift specifier is omitted, turn the instruction
9106 into pkhbt rd, rm, rn. */
9107 inst.instruction &= 0xfff00010;
9108 inst.instruction |= inst.operands[0].reg << 12;
9109 inst.instruction |= inst.operands[1].reg;
9110 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9111 }
9112 else
9113 {
c19d1205
ZW
9114 inst.instruction |= inst.operands[0].reg << 12;
9115 inst.instruction |= inst.operands[1].reg << 16;
9116 inst.instruction |= inst.operands[2].reg;
9117 encode_arm_shift (3);
b99bd4ef
NC
9118 }
9119}
9120
c19d1205 9121/* ARMv5TE: Preload-Cache
60e5ef9f 9122 MP Extensions: Preload for write
c19d1205 9123
60e5ef9f 9124 PLD(W) <addr_mode>
c19d1205
ZW
9125
9126 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9127
9128static void
c19d1205 9129do_pld (void)
b99bd4ef 9130{
c19d1205
ZW
9131 constraint (!inst.operands[0].isreg,
9132 _("'[' expected after PLD mnemonic"));
9133 constraint (inst.operands[0].postind,
9134 _("post-indexed expression used in preload instruction"));
9135 constraint (inst.operands[0].writeback,
9136 _("writeback used in preload instruction"));
9137 constraint (!inst.operands[0].preind,
9138 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9139 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9140}
b99bd4ef 9141
62b3e311
PB
9142/* ARMv7: PLI <addr_mode> */
9143static void
9144do_pli (void)
9145{
9146 constraint (!inst.operands[0].isreg,
9147 _("'[' expected after PLI mnemonic"));
9148 constraint (inst.operands[0].postind,
9149 _("post-indexed expression used in preload instruction"));
9150 constraint (inst.operands[0].writeback,
9151 _("writeback used in preload instruction"));
9152 constraint (!inst.operands[0].preind,
9153 _("unindexed addressing used in preload instruction"));
9154 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9155 inst.instruction &= ~PRE_INDEX;
9156}
9157
c19d1205
ZW
9158static void
9159do_push_pop (void)
9160{
5e0d7f77
MP
9161 constraint (inst.operands[0].writeback,
9162 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9163 inst.operands[1] = inst.operands[0];
9164 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9165 inst.operands[0].isreg = 1;
9166 inst.operands[0].writeback = 1;
9167 inst.operands[0].reg = REG_SP;
6530b175 9168 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9169}
b99bd4ef 9170
c19d1205
ZW
9171/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9172 word at the specified address and the following word
9173 respectively.
9174 Unconditionally executed.
9175 Error if Rn is R15. */
b99bd4ef 9176
c19d1205
ZW
9177static void
9178do_rfe (void)
9179{
9180 inst.instruction |= inst.operands[0].reg << 16;
9181 if (inst.operands[0].writeback)
9182 inst.instruction |= WRITE_BACK;
9183}
b99bd4ef 9184
c19d1205 9185/* ARM V6 ssat (argument parse). */
b99bd4ef 9186
c19d1205
ZW
9187static void
9188do_ssat (void)
9189{
9190 inst.instruction |= inst.operands[0].reg << 12;
9191 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9192 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9193
c19d1205
ZW
9194 if (inst.operands[3].present)
9195 encode_arm_shift (3);
b99bd4ef
NC
9196}
9197
c19d1205 9198/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9199
9200static void
c19d1205 9201do_usat (void)
b99bd4ef 9202{
c19d1205
ZW
9203 inst.instruction |= inst.operands[0].reg << 12;
9204 inst.instruction |= inst.operands[1].imm << 16;
9205 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9206
c19d1205
ZW
9207 if (inst.operands[3].present)
9208 encode_arm_shift (3);
b99bd4ef
NC
9209}
9210
c19d1205 9211/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9212
9213static void
c19d1205 9214do_ssat16 (void)
09d92015 9215{
c19d1205
ZW
9216 inst.instruction |= inst.operands[0].reg << 12;
9217 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9218 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9219}
9220
c19d1205
ZW
9221static void
9222do_usat16 (void)
a737bd4d 9223{
c19d1205
ZW
9224 inst.instruction |= inst.operands[0].reg << 12;
9225 inst.instruction |= inst.operands[1].imm << 16;
9226 inst.instruction |= inst.operands[2].reg;
9227}
a737bd4d 9228
c19d1205
ZW
9229/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9230 preserving the other bits.
a737bd4d 9231
c19d1205
ZW
9232 setend <endian_specifier>, where <endian_specifier> is either
9233 BE or LE. */
a737bd4d 9234
c19d1205
ZW
9235static void
9236do_setend (void)
9237{
12e37cbc
MGD
9238 if (warn_on_deprecated
9239 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9240 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9241
c19d1205
ZW
9242 if (inst.operands[0].imm)
9243 inst.instruction |= 0x200;
a737bd4d
NC
9244}
9245
9246static void
c19d1205 9247do_shift (void)
a737bd4d 9248{
c19d1205
ZW
9249 unsigned int Rm = (inst.operands[1].present
9250 ? inst.operands[1].reg
9251 : inst.operands[0].reg);
a737bd4d 9252
c19d1205
ZW
9253 inst.instruction |= inst.operands[0].reg << 12;
9254 inst.instruction |= Rm;
9255 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9256 {
c19d1205
ZW
9257 inst.instruction |= inst.operands[2].reg << 8;
9258 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9259 /* PR 12854: Error on extraneous shifts. */
9260 constraint (inst.operands[2].shifted,
9261 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9262 }
9263 else
c19d1205 9264 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9265}
9266
09d92015 9267static void
3eb17e6b 9268do_smc (void)
09d92015 9269{
3eb17e6b 9270 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9271 inst.reloc.pc_rel = 0;
09d92015
MM
9272}
9273
90ec0d68
MGD
9274static void
9275do_hvc (void)
9276{
9277 inst.reloc.type = BFD_RELOC_ARM_HVC;
9278 inst.reloc.pc_rel = 0;
9279}
9280
09d92015 9281static void
c19d1205 9282do_swi (void)
09d92015 9283{
c19d1205
ZW
9284 inst.reloc.type = BFD_RELOC_ARM_SWI;
9285 inst.reloc.pc_rel = 0;
09d92015
MM
9286}
9287
ddfded2f
MW
9288static void
9289do_setpan (void)
9290{
9291 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9292 _("selected processor does not support SETPAN instruction"));
9293
9294 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9295}
9296
9297static void
9298do_t_setpan (void)
9299{
9300 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9301 _("selected processor does not support SETPAN instruction"));
9302
9303 inst.instruction |= (inst.operands[0].imm << 3);
9304}
9305
c19d1205
ZW
9306/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9307 SMLAxy{cond} Rd,Rm,Rs,Rn
9308 SMLAWy{cond} Rd,Rm,Rs,Rn
9309 Error if any register is R15. */
e16bb312 9310
c19d1205
ZW
9311static void
9312do_smla (void)
e16bb312 9313{
c19d1205
ZW
9314 inst.instruction |= inst.operands[0].reg << 16;
9315 inst.instruction |= inst.operands[1].reg;
9316 inst.instruction |= inst.operands[2].reg << 8;
9317 inst.instruction |= inst.operands[3].reg << 12;
9318}
a737bd4d 9319
c19d1205
ZW
9320/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9321 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9322 Error if any register is R15.
9323 Warning if Rdlo == Rdhi. */
a737bd4d 9324
c19d1205
ZW
9325static void
9326do_smlal (void)
9327{
9328 inst.instruction |= inst.operands[0].reg << 12;
9329 inst.instruction |= inst.operands[1].reg << 16;
9330 inst.instruction |= inst.operands[2].reg;
9331 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9332
c19d1205
ZW
9333 if (inst.operands[0].reg == inst.operands[1].reg)
9334 as_tsktsk (_("rdhi and rdlo must be different"));
9335}
a737bd4d 9336
c19d1205
ZW
9337/* ARM V5E (El Segundo) signed-multiply (argument parse)
9338 SMULxy{cond} Rd,Rm,Rs
9339 Error if any register is R15. */
a737bd4d 9340
c19d1205
ZW
9341static void
9342do_smul (void)
9343{
9344 inst.instruction |= inst.operands[0].reg << 16;
9345 inst.instruction |= inst.operands[1].reg;
9346 inst.instruction |= inst.operands[2].reg << 8;
9347}
a737bd4d 9348
b6702015
PB
9349/* ARM V6 srs (argument parse). The variable fields in the encoding are
9350 the same for both ARM and Thumb-2. */
a737bd4d 9351
c19d1205
ZW
9352static void
9353do_srs (void)
9354{
b6702015
PB
9355 int reg;
9356
9357 if (inst.operands[0].present)
9358 {
9359 reg = inst.operands[0].reg;
fdfde340 9360 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9361 }
9362 else
fdfde340 9363 reg = REG_SP;
b6702015
PB
9364
9365 inst.instruction |= reg << 16;
9366 inst.instruction |= inst.operands[1].imm;
9367 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9368 inst.instruction |= WRITE_BACK;
9369}
a737bd4d 9370
c19d1205 9371/* ARM V6 strex (argument parse). */
a737bd4d 9372
c19d1205
ZW
9373static void
9374do_strex (void)
9375{
9376 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9377 || inst.operands[2].postind || inst.operands[2].writeback
9378 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9379 || inst.operands[2].negative
9380 /* See comment in do_ldrex(). */
9381 || (inst.operands[2].reg == REG_PC),
9382 BAD_ADDR_MODE);
a737bd4d 9383
c19d1205
ZW
9384 constraint (inst.operands[0].reg == inst.operands[1].reg
9385 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9386
c19d1205
ZW
9387 constraint (inst.reloc.exp.X_op != O_constant
9388 || inst.reloc.exp.X_add_number != 0,
9389 _("offset must be zero in ARM encoding"));
a737bd4d 9390
c19d1205
ZW
9391 inst.instruction |= inst.operands[0].reg << 12;
9392 inst.instruction |= inst.operands[1].reg;
9393 inst.instruction |= inst.operands[2].reg << 16;
9394 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9395}
9396
877807f8
NC
9397static void
9398do_t_strexbh (void)
9399{
9400 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9401 || inst.operands[2].postind || inst.operands[2].writeback
9402 || inst.operands[2].immisreg || inst.operands[2].shifted
9403 || inst.operands[2].negative,
9404 BAD_ADDR_MODE);
9405
9406 constraint (inst.operands[0].reg == inst.operands[1].reg
9407 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9408
9409 do_rm_rd_rn ();
9410}
9411
e16bb312 9412static void
c19d1205 9413do_strexd (void)
e16bb312 9414{
c19d1205
ZW
9415 constraint (inst.operands[1].reg % 2 != 0,
9416 _("even register required"));
9417 constraint (inst.operands[2].present
9418 && inst.operands[2].reg != inst.operands[1].reg + 1,
9419 _("can only store two consecutive registers"));
9420 /* If op 2 were present and equal to PC, this function wouldn't
9421 have been called in the first place. */
9422 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9423
c19d1205
ZW
9424 constraint (inst.operands[0].reg == inst.operands[1].reg
9425 || inst.operands[0].reg == inst.operands[1].reg + 1
9426 || inst.operands[0].reg == inst.operands[3].reg,
9427 BAD_OVERLAP);
e16bb312 9428
c19d1205
ZW
9429 inst.instruction |= inst.operands[0].reg << 12;
9430 inst.instruction |= inst.operands[1].reg;
9431 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9432}
9433
9eb6c0f1
MGD
9434/* ARM V8 STRL. */
9435static void
4b8c8c02 9436do_stlex (void)
9eb6c0f1
MGD
9437{
9438 constraint (inst.operands[0].reg == inst.operands[1].reg
9439 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9440
9441 do_rd_rm_rn ();
9442}
9443
9444static void
4b8c8c02 9445do_t_stlex (void)
9eb6c0f1
MGD
9446{
9447 constraint (inst.operands[0].reg == inst.operands[1].reg
9448 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9449
9450 do_rm_rd_rn ();
9451}
9452
c19d1205
ZW
9453/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9454 extends it to 32-bits, and adds the result to a value in another
9455 register. You can specify a rotation by 0, 8, 16, or 24 bits
9456 before extracting the 16-bit value.
9457 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9458 Condition defaults to COND_ALWAYS.
9459 Error if any register uses R15. */
9460
e16bb312 9461static void
c19d1205 9462do_sxtah (void)
e16bb312 9463{
c19d1205
ZW
9464 inst.instruction |= inst.operands[0].reg << 12;
9465 inst.instruction |= inst.operands[1].reg << 16;
9466 inst.instruction |= inst.operands[2].reg;
9467 inst.instruction |= inst.operands[3].imm << 10;
9468}
e16bb312 9469
c19d1205 9470/* ARM V6 SXTH.
e16bb312 9471
c19d1205
ZW
9472 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9473 Condition defaults to COND_ALWAYS.
9474 Error if any register uses R15. */
e16bb312
NC
9475
9476static void
c19d1205 9477do_sxth (void)
e16bb312 9478{
c19d1205
ZW
9479 inst.instruction |= inst.operands[0].reg << 12;
9480 inst.instruction |= inst.operands[1].reg;
9481 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9482}
c19d1205
ZW
9483\f
9484/* VFP instructions. In a logical order: SP variant first, monad
9485 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9486
9487static void
c19d1205 9488do_vfp_sp_monadic (void)
e16bb312 9489{
5287ad62
JB
9490 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9491 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9492}
9493
9494static void
c19d1205 9495do_vfp_sp_dyadic (void)
e16bb312 9496{
5287ad62
JB
9497 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9498 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9499 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9500}
9501
9502static void
c19d1205 9503do_vfp_sp_compare_z (void)
e16bb312 9504{
5287ad62 9505 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9506}
9507
9508static void
c19d1205 9509do_vfp_dp_sp_cvt (void)
e16bb312 9510{
5287ad62
JB
9511 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9512 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9513}
9514
9515static void
c19d1205 9516do_vfp_sp_dp_cvt (void)
e16bb312 9517{
5287ad62
JB
9518 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9519 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9520}
9521
9522static void
c19d1205 9523do_vfp_reg_from_sp (void)
e16bb312 9524{
c19d1205 9525 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9526 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9527}
9528
9529static void
c19d1205 9530do_vfp_reg2_from_sp2 (void)
e16bb312 9531{
c19d1205
ZW
9532 constraint (inst.operands[2].imm != 2,
9533 _("only two consecutive VFP SP registers allowed here"));
9534 inst.instruction |= inst.operands[0].reg << 12;
9535 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9536 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9537}
9538
9539static void
c19d1205 9540do_vfp_sp_from_reg (void)
e16bb312 9541{
5287ad62 9542 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9543 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9544}
9545
9546static void
c19d1205 9547do_vfp_sp2_from_reg2 (void)
e16bb312 9548{
c19d1205
ZW
9549 constraint (inst.operands[0].imm != 2,
9550 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9551 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9552 inst.instruction |= inst.operands[1].reg << 12;
9553 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9554}
9555
9556static void
c19d1205 9557do_vfp_sp_ldst (void)
e16bb312 9558{
5287ad62 9559 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9560 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9561}
9562
9563static void
c19d1205 9564do_vfp_dp_ldst (void)
e16bb312 9565{
5287ad62 9566 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9567 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9568}
9569
c19d1205 9570
e16bb312 9571static void
c19d1205 9572vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9573{
c19d1205
ZW
9574 if (inst.operands[0].writeback)
9575 inst.instruction |= WRITE_BACK;
9576 else
9577 constraint (ldstm_type != VFP_LDSTMIA,
9578 _("this addressing mode requires base-register writeback"));
9579 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9580 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9581 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9582}
9583
9584static void
c19d1205 9585vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9586{
c19d1205 9587 int count;
e16bb312 9588
c19d1205
ZW
9589 if (inst.operands[0].writeback)
9590 inst.instruction |= WRITE_BACK;
9591 else
9592 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9593 _("this addressing mode requires base-register writeback"));
e16bb312 9594
c19d1205 9595 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9596 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9597
c19d1205
ZW
9598 count = inst.operands[1].imm << 1;
9599 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9600 count += 1;
e16bb312 9601
c19d1205 9602 inst.instruction |= count;
e16bb312
NC
9603}
9604
9605static void
c19d1205 9606do_vfp_sp_ldstmia (void)
e16bb312 9607{
c19d1205 9608 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9609}
9610
9611static void
c19d1205 9612do_vfp_sp_ldstmdb (void)
e16bb312 9613{
c19d1205 9614 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9615}
9616
9617static void
c19d1205 9618do_vfp_dp_ldstmia (void)
e16bb312 9619{
c19d1205 9620 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9621}
9622
9623static void
c19d1205 9624do_vfp_dp_ldstmdb (void)
e16bb312 9625{
c19d1205 9626 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9627}
9628
9629static void
c19d1205 9630do_vfp_xp_ldstmia (void)
e16bb312 9631{
c19d1205
ZW
9632 vfp_dp_ldstm (VFP_LDSTMIAX);
9633}
e16bb312 9634
c19d1205
ZW
9635static void
9636do_vfp_xp_ldstmdb (void)
9637{
9638 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9639}
5287ad62
JB
9640
9641static void
9642do_vfp_dp_rd_rm (void)
9643{
9644 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9645 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9646}
9647
9648static void
9649do_vfp_dp_rn_rd (void)
9650{
9651 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9652 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9653}
9654
9655static void
9656do_vfp_dp_rd_rn (void)
9657{
9658 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9659 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9660}
9661
9662static void
9663do_vfp_dp_rd_rn_rm (void)
9664{
9665 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9666 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9667 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9668}
9669
9670static void
9671do_vfp_dp_rd (void)
9672{
9673 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9674}
9675
9676static void
9677do_vfp_dp_rm_rd_rn (void)
9678{
9679 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9680 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9681 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9682}
9683
9684/* VFPv3 instructions. */
9685static void
9686do_vfp_sp_const (void)
9687{
9688 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9689 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9690 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9691}
9692
9693static void
9694do_vfp_dp_const (void)
9695{
9696 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9697 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9698 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9699}
9700
9701static void
9702vfp_conv (int srcsize)
9703{
5f1af56b
MGD
9704 int immbits = srcsize - inst.operands[1].imm;
9705
fa94de6b
RM
9706 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9707 {
5f1af56b 9708 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9709 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9710 inst.error = _("immediate value out of range, expected range [0, 16]");
9711 return;
9712 }
fa94de6b 9713 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9714 {
9715 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9716 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9717 inst.error = _("immediate value out of range, expected range [1, 32]");
9718 return;
9719 }
9720
5287ad62
JB
9721 inst.instruction |= (immbits & 1) << 5;
9722 inst.instruction |= (immbits >> 1);
9723}
9724
9725static void
9726do_vfp_sp_conv_16 (void)
9727{
9728 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9729 vfp_conv (16);
9730}
9731
9732static void
9733do_vfp_dp_conv_16 (void)
9734{
9735 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9736 vfp_conv (16);
9737}
9738
9739static void
9740do_vfp_sp_conv_32 (void)
9741{
9742 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9743 vfp_conv (32);
9744}
9745
9746static void
9747do_vfp_dp_conv_32 (void)
9748{
9749 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9750 vfp_conv (32);
9751}
c19d1205
ZW
9752\f
9753/* FPA instructions. Also in a logical order. */
e16bb312 9754
c19d1205
ZW
9755static void
9756do_fpa_cmp (void)
9757{
9758 inst.instruction |= inst.operands[0].reg << 16;
9759 inst.instruction |= inst.operands[1].reg;
9760}
b99bd4ef
NC
9761
9762static void
c19d1205 9763do_fpa_ldmstm (void)
b99bd4ef 9764{
c19d1205
ZW
9765 inst.instruction |= inst.operands[0].reg << 12;
9766 switch (inst.operands[1].imm)
9767 {
9768 case 1: inst.instruction |= CP_T_X; break;
9769 case 2: inst.instruction |= CP_T_Y; break;
9770 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9771 case 4: break;
9772 default: abort ();
9773 }
b99bd4ef 9774
c19d1205
ZW
9775 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9776 {
9777 /* The instruction specified "ea" or "fd", so we can only accept
9778 [Rn]{!}. The instruction does not really support stacking or
9779 unstacking, so we have to emulate these by setting appropriate
9780 bits and offsets. */
9781 constraint (inst.reloc.exp.X_op != O_constant
9782 || inst.reloc.exp.X_add_number != 0,
9783 _("this instruction does not support indexing"));
b99bd4ef 9784
c19d1205
ZW
9785 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9786 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 9787
c19d1205
ZW
9788 if (!(inst.instruction & INDEX_UP))
9789 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 9790
c19d1205
ZW
9791 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
9792 {
9793 inst.operands[2].preind = 0;
9794 inst.operands[2].postind = 1;
9795 }
9796 }
b99bd4ef 9797
c19d1205 9798 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 9799}
c19d1205
ZW
9800\f
9801/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 9802
c19d1205
ZW
9803static void
9804do_iwmmxt_tandorc (void)
9805{
9806 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
9807}
b99bd4ef 9808
c19d1205
ZW
9809static void
9810do_iwmmxt_textrc (void)
9811{
9812 inst.instruction |= inst.operands[0].reg << 12;
9813 inst.instruction |= inst.operands[1].imm;
9814}
b99bd4ef
NC
9815
9816static void
c19d1205 9817do_iwmmxt_textrm (void)
b99bd4ef 9818{
c19d1205
ZW
9819 inst.instruction |= inst.operands[0].reg << 12;
9820 inst.instruction |= inst.operands[1].reg << 16;
9821 inst.instruction |= inst.operands[2].imm;
9822}
b99bd4ef 9823
c19d1205
ZW
9824static void
9825do_iwmmxt_tinsr (void)
9826{
9827 inst.instruction |= inst.operands[0].reg << 16;
9828 inst.instruction |= inst.operands[1].reg << 12;
9829 inst.instruction |= inst.operands[2].imm;
9830}
b99bd4ef 9831
c19d1205
ZW
9832static void
9833do_iwmmxt_tmia (void)
9834{
9835 inst.instruction |= inst.operands[0].reg << 5;
9836 inst.instruction |= inst.operands[1].reg;
9837 inst.instruction |= inst.operands[2].reg << 12;
9838}
b99bd4ef 9839
c19d1205
ZW
9840static void
9841do_iwmmxt_waligni (void)
9842{
9843 inst.instruction |= inst.operands[0].reg << 12;
9844 inst.instruction |= inst.operands[1].reg << 16;
9845 inst.instruction |= inst.operands[2].reg;
9846 inst.instruction |= inst.operands[3].imm << 20;
9847}
b99bd4ef 9848
2d447fca
JM
9849static void
9850do_iwmmxt_wmerge (void)
9851{
9852 inst.instruction |= inst.operands[0].reg << 12;
9853 inst.instruction |= inst.operands[1].reg << 16;
9854 inst.instruction |= inst.operands[2].reg;
9855 inst.instruction |= inst.operands[3].imm << 21;
9856}
9857
c19d1205
ZW
9858static void
9859do_iwmmxt_wmov (void)
9860{
9861 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
9862 inst.instruction |= inst.operands[0].reg << 12;
9863 inst.instruction |= inst.operands[1].reg << 16;
9864 inst.instruction |= inst.operands[1].reg;
9865}
b99bd4ef 9866
c19d1205
ZW
9867static void
9868do_iwmmxt_wldstbh (void)
9869{
8f06b2d8 9870 int reloc;
c19d1205 9871 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
9872 if (thumb_mode)
9873 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
9874 else
9875 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
9876 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
9877}
9878
c19d1205
ZW
9879static void
9880do_iwmmxt_wldstw (void)
9881{
9882 /* RIWR_RIWC clears .isreg for a control register. */
9883 if (!inst.operands[0].isreg)
9884 {
9885 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9886 inst.instruction |= 0xf0000000;
9887 }
b99bd4ef 9888
c19d1205
ZW
9889 inst.instruction |= inst.operands[0].reg << 12;
9890 encode_arm_cp_address (1, TRUE, TRUE, 0);
9891}
b99bd4ef
NC
9892
9893static void
c19d1205 9894do_iwmmxt_wldstd (void)
b99bd4ef 9895{
c19d1205 9896 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
9897 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
9898 && inst.operands[1].immisreg)
9899 {
9900 inst.instruction &= ~0x1a000ff;
9901 inst.instruction |= (0xf << 28);
9902 if (inst.operands[1].preind)
9903 inst.instruction |= PRE_INDEX;
9904 if (!inst.operands[1].negative)
9905 inst.instruction |= INDEX_UP;
9906 if (inst.operands[1].writeback)
9907 inst.instruction |= WRITE_BACK;
9908 inst.instruction |= inst.operands[1].reg << 16;
9909 inst.instruction |= inst.reloc.exp.X_add_number << 4;
9910 inst.instruction |= inst.operands[1].imm;
9911 }
9912 else
9913 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 9914}
b99bd4ef 9915
c19d1205
ZW
9916static void
9917do_iwmmxt_wshufh (void)
9918{
9919 inst.instruction |= inst.operands[0].reg << 12;
9920 inst.instruction |= inst.operands[1].reg << 16;
9921 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
9922 inst.instruction |= (inst.operands[2].imm & 0x0f);
9923}
b99bd4ef 9924
c19d1205
ZW
9925static void
9926do_iwmmxt_wzero (void)
9927{
9928 /* WZERO reg is an alias for WANDN reg, reg, reg. */
9929 inst.instruction |= inst.operands[0].reg;
9930 inst.instruction |= inst.operands[0].reg << 12;
9931 inst.instruction |= inst.operands[0].reg << 16;
9932}
2d447fca
JM
9933
9934static void
9935do_iwmmxt_wrwrwr_or_imm5 (void)
9936{
9937 if (inst.operands[2].isreg)
9938 do_rd_rn_rm ();
9939 else {
9940 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
9941 _("immediate operand requires iWMMXt2"));
9942 do_rd_rn ();
9943 if (inst.operands[2].imm == 0)
9944 {
9945 switch ((inst.instruction >> 20) & 0xf)
9946 {
9947 case 4:
9948 case 5:
9949 case 6:
5f4273c7 9950 case 7:
2d447fca
JM
9951 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
9952 inst.operands[2].imm = 16;
9953 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
9954 break;
9955 case 8:
9956 case 9:
9957 case 10:
9958 case 11:
9959 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
9960 inst.operands[2].imm = 32;
9961 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
9962 break;
9963 case 12:
9964 case 13:
9965 case 14:
9966 case 15:
9967 {
9968 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
9969 unsigned long wrn;
9970 wrn = (inst.instruction >> 16) & 0xf;
9971 inst.instruction &= 0xff0fff0f;
9972 inst.instruction |= wrn;
9973 /* Bail out here; the instruction is now assembled. */
9974 return;
9975 }
9976 }
9977 }
9978 /* Map 32 -> 0, etc. */
9979 inst.operands[2].imm &= 0x1f;
9980 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
9981 }
9982}
c19d1205
ZW
9983\f
9984/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
9985 operations first, then control, shift, and load/store. */
b99bd4ef 9986
c19d1205 9987/* Insns like "foo X,Y,Z". */
b99bd4ef 9988
c19d1205
ZW
9989static void
9990do_mav_triple (void)
9991{
9992 inst.instruction |= inst.operands[0].reg << 16;
9993 inst.instruction |= inst.operands[1].reg;
9994 inst.instruction |= inst.operands[2].reg << 12;
9995}
b99bd4ef 9996
c19d1205
ZW
9997/* Insns like "foo W,X,Y,Z".
9998 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 9999
c19d1205
ZW
10000static void
10001do_mav_quad (void)
10002{
10003 inst.instruction |= inst.operands[0].reg << 5;
10004 inst.instruction |= inst.operands[1].reg << 12;
10005 inst.instruction |= inst.operands[2].reg << 16;
10006 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10007}
10008
c19d1205
ZW
10009/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10010static void
10011do_mav_dspsc (void)
a737bd4d 10012{
c19d1205
ZW
10013 inst.instruction |= inst.operands[1].reg << 12;
10014}
a737bd4d 10015
c19d1205
ZW
10016/* Maverick shift immediate instructions.
10017 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10018 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10019
c19d1205
ZW
10020static void
10021do_mav_shift (void)
10022{
10023 int imm = inst.operands[2].imm;
a737bd4d 10024
c19d1205
ZW
10025 inst.instruction |= inst.operands[0].reg << 12;
10026 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10027
c19d1205
ZW
10028 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10029 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10030 Bit 4 should be 0. */
10031 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10032
c19d1205
ZW
10033 inst.instruction |= imm;
10034}
10035\f
10036/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10037
c19d1205
ZW
10038/* Xscale multiply-accumulate (argument parse)
10039 MIAcc acc0,Rm,Rs
10040 MIAPHcc acc0,Rm,Rs
10041 MIAxycc acc0,Rm,Rs. */
a737bd4d 10042
c19d1205
ZW
10043static void
10044do_xsc_mia (void)
10045{
10046 inst.instruction |= inst.operands[1].reg;
10047 inst.instruction |= inst.operands[2].reg << 12;
10048}
a737bd4d 10049
c19d1205 10050/* Xscale move-accumulator-register (argument parse)
a737bd4d 10051
c19d1205 10052 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10053
c19d1205
ZW
10054static void
10055do_xsc_mar (void)
10056{
10057 inst.instruction |= inst.operands[1].reg << 12;
10058 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10059}
10060
c19d1205 10061/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10062
c19d1205 10063 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10064
10065static void
c19d1205 10066do_xsc_mra (void)
b99bd4ef 10067{
c19d1205
ZW
10068 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10069 inst.instruction |= inst.operands[0].reg << 12;
10070 inst.instruction |= inst.operands[1].reg << 16;
10071}
10072\f
10073/* Encoding functions relevant only to Thumb. */
b99bd4ef 10074
c19d1205
ZW
10075/* inst.operands[i] is a shifted-register operand; encode
10076 it into inst.instruction in the format used by Thumb32. */
10077
10078static void
10079encode_thumb32_shifted_operand (int i)
10080{
10081 unsigned int value = inst.reloc.exp.X_add_number;
10082 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10083
9c3c69f2
PB
10084 constraint (inst.operands[i].immisreg,
10085 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10086 inst.instruction |= inst.operands[i].reg;
10087 if (shift == SHIFT_RRX)
10088 inst.instruction |= SHIFT_ROR << 4;
10089 else
b99bd4ef 10090 {
c19d1205
ZW
10091 constraint (inst.reloc.exp.X_op != O_constant,
10092 _("expression too complex"));
10093
10094 constraint (value > 32
10095 || (value == 32 && (shift == SHIFT_LSL
10096 || shift == SHIFT_ROR)),
10097 _("shift expression is too large"));
10098
10099 if (value == 0)
10100 shift = SHIFT_LSL;
10101 else if (value == 32)
10102 value = 0;
10103
10104 inst.instruction |= shift << 4;
10105 inst.instruction |= (value & 0x1c) << 10;
10106 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10107 }
c19d1205 10108}
b99bd4ef 10109
b99bd4ef 10110
c19d1205
ZW
10111/* inst.operands[i] was set up by parse_address. Encode it into a
10112 Thumb32 format load or store instruction. Reject forms that cannot
10113 be used with such instructions. If is_t is true, reject forms that
10114 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10115 that cannot be used with a D instruction. If it is a store insn,
10116 reject PC in Rn. */
b99bd4ef 10117
c19d1205
ZW
10118static void
10119encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10120{
5be8be5d 10121 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10122
10123 constraint (!inst.operands[i].isreg,
53365c0d 10124 _("Instruction does not support =N addresses"));
b99bd4ef 10125
c19d1205
ZW
10126 inst.instruction |= inst.operands[i].reg << 16;
10127 if (inst.operands[i].immisreg)
b99bd4ef 10128 {
5be8be5d 10129 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10130 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10131 constraint (inst.operands[i].negative,
10132 _("Thumb does not support negative register indexing"));
10133 constraint (inst.operands[i].postind,
10134 _("Thumb does not support register post-indexing"));
10135 constraint (inst.operands[i].writeback,
10136 _("Thumb does not support register indexing with writeback"));
10137 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10138 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10139
f40d1643 10140 inst.instruction |= inst.operands[i].imm;
c19d1205 10141 if (inst.operands[i].shifted)
b99bd4ef 10142 {
c19d1205
ZW
10143 constraint (inst.reloc.exp.X_op != O_constant,
10144 _("expression too complex"));
9c3c69f2
PB
10145 constraint (inst.reloc.exp.X_add_number < 0
10146 || inst.reloc.exp.X_add_number > 3,
c19d1205 10147 _("shift out of range"));
9c3c69f2 10148 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10149 }
10150 inst.reloc.type = BFD_RELOC_UNUSED;
10151 }
10152 else if (inst.operands[i].preind)
10153 {
5be8be5d 10154 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10155 constraint (is_t && inst.operands[i].writeback,
c19d1205 10156 _("cannot use writeback with this instruction"));
4755303e
WN
10157 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10158 BAD_PC_ADDRESSING);
c19d1205
ZW
10159
10160 if (is_d)
10161 {
10162 inst.instruction |= 0x01000000;
10163 if (inst.operands[i].writeback)
10164 inst.instruction |= 0x00200000;
b99bd4ef 10165 }
c19d1205 10166 else
b99bd4ef 10167 {
c19d1205
ZW
10168 inst.instruction |= 0x00000c00;
10169 if (inst.operands[i].writeback)
10170 inst.instruction |= 0x00000100;
b99bd4ef 10171 }
c19d1205 10172 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10173 }
c19d1205 10174 else if (inst.operands[i].postind)
b99bd4ef 10175 {
9c2799c2 10176 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10177 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10178 constraint (is_t, _("cannot use post-indexing with this instruction"));
10179
10180 if (is_d)
10181 inst.instruction |= 0x00200000;
10182 else
10183 inst.instruction |= 0x00000900;
10184 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10185 }
10186 else /* unindexed - only for coprocessor */
10187 inst.error = _("instruction does not accept unindexed addressing");
10188}
10189
10190/* Table of Thumb instructions which exist in both 16- and 32-bit
10191 encodings (the latter only in post-V6T2 cores). The index is the
10192 value used in the insns table below. When there is more than one
10193 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10194 holds variant (1).
10195 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10196#define T16_32_TAB \
21d799b5
NC
10197 X(_adc, 4140, eb400000), \
10198 X(_adcs, 4140, eb500000), \
10199 X(_add, 1c00, eb000000), \
10200 X(_adds, 1c00, eb100000), \
10201 X(_addi, 0000, f1000000), \
10202 X(_addis, 0000, f1100000), \
10203 X(_add_pc,000f, f20f0000), \
10204 X(_add_sp,000d, f10d0000), \
10205 X(_adr, 000f, f20f0000), \
10206 X(_and, 4000, ea000000), \
10207 X(_ands, 4000, ea100000), \
10208 X(_asr, 1000, fa40f000), \
10209 X(_asrs, 1000, fa50f000), \
10210 X(_b, e000, f000b000), \
10211 X(_bcond, d000, f0008000), \
10212 X(_bic, 4380, ea200000), \
10213 X(_bics, 4380, ea300000), \
10214 X(_cmn, 42c0, eb100f00), \
10215 X(_cmp, 2800, ebb00f00), \
10216 X(_cpsie, b660, f3af8400), \
10217 X(_cpsid, b670, f3af8600), \
10218 X(_cpy, 4600, ea4f0000), \
10219 X(_dec_sp,80dd, f1ad0d00), \
10220 X(_eor, 4040, ea800000), \
10221 X(_eors, 4040, ea900000), \
10222 X(_inc_sp,00dd, f10d0d00), \
10223 X(_ldmia, c800, e8900000), \
10224 X(_ldr, 6800, f8500000), \
10225 X(_ldrb, 7800, f8100000), \
10226 X(_ldrh, 8800, f8300000), \
10227 X(_ldrsb, 5600, f9100000), \
10228 X(_ldrsh, 5e00, f9300000), \
10229 X(_ldr_pc,4800, f85f0000), \
10230 X(_ldr_pc2,4800, f85f0000), \
10231 X(_ldr_sp,9800, f85d0000), \
10232 X(_lsl, 0000, fa00f000), \
10233 X(_lsls, 0000, fa10f000), \
10234 X(_lsr, 0800, fa20f000), \
10235 X(_lsrs, 0800, fa30f000), \
10236 X(_mov, 2000, ea4f0000), \
10237 X(_movs, 2000, ea5f0000), \
10238 X(_mul, 4340, fb00f000), \
10239 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10240 X(_mvn, 43c0, ea6f0000), \
10241 X(_mvns, 43c0, ea7f0000), \
10242 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10243 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10244 X(_orr, 4300, ea400000), \
10245 X(_orrs, 4300, ea500000), \
10246 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10247 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10248 X(_rev, ba00, fa90f080), \
10249 X(_rev16, ba40, fa90f090), \
10250 X(_revsh, bac0, fa90f0b0), \
10251 X(_ror, 41c0, fa60f000), \
10252 X(_rors, 41c0, fa70f000), \
10253 X(_sbc, 4180, eb600000), \
10254 X(_sbcs, 4180, eb700000), \
10255 X(_stmia, c000, e8800000), \
10256 X(_str, 6000, f8400000), \
10257 X(_strb, 7000, f8000000), \
10258 X(_strh, 8000, f8200000), \
10259 X(_str_sp,9000, f84d0000), \
10260 X(_sub, 1e00, eba00000), \
10261 X(_subs, 1e00, ebb00000), \
10262 X(_subi, 8000, f1a00000), \
10263 X(_subis, 8000, f1b00000), \
10264 X(_sxtb, b240, fa4ff080), \
10265 X(_sxth, b200, fa0ff080), \
10266 X(_tst, 4200, ea100f00), \
10267 X(_uxtb, b2c0, fa5ff080), \
10268 X(_uxth, b280, fa1ff080), \
10269 X(_nop, bf00, f3af8000), \
10270 X(_yield, bf10, f3af8001), \
10271 X(_wfe, bf20, f3af8002), \
10272 X(_wfi, bf30, f3af8003), \
53c4b28b 10273 X(_sev, bf40, f3af8004), \
74db7efb
NC
10274 X(_sevl, bf50, f3af8005), \
10275 X(_udf, de00, f7f0a000)
c19d1205
ZW
10276
10277/* To catch errors in encoding functions, the codes are all offset by
10278 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10279 as 16-bit instructions. */
21d799b5 10280#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10281enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10282#undef X
10283
10284#define X(a,b,c) 0x##b
10285static const unsigned short thumb_op16[] = { T16_32_TAB };
10286#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10287#undef X
10288
10289#define X(a,b,c) 0x##c
10290static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10291#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10292#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10293#undef X
10294#undef T16_32_TAB
10295
10296/* Thumb instruction encoders, in alphabetical order. */
10297
92e90b6e 10298/* ADDW or SUBW. */
c921be7d 10299
92e90b6e
PB
10300static void
10301do_t_add_sub_w (void)
10302{
10303 int Rd, Rn;
10304
10305 Rd = inst.operands[0].reg;
10306 Rn = inst.operands[1].reg;
10307
539d4391
NC
10308 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10309 is the SP-{plus,minus}-immediate form of the instruction. */
10310 if (Rn == REG_SP)
10311 constraint (Rd == REG_PC, BAD_PC);
10312 else
10313 reject_bad_reg (Rd);
fdfde340 10314
92e90b6e
PB
10315 inst.instruction |= (Rn << 16) | (Rd << 8);
10316 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10317}
10318
c19d1205
ZW
10319/* Parse an add or subtract instruction. We get here with inst.instruction
10320 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
10321
10322static void
10323do_t_add_sub (void)
10324{
10325 int Rd, Rs, Rn;
10326
10327 Rd = inst.operands[0].reg;
10328 Rs = (inst.operands[1].present
10329 ? inst.operands[1].reg /* Rd, Rs, foo */
10330 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10331
e07e6e58
NC
10332 if (Rd == REG_PC)
10333 set_it_insn_type_last ();
10334
c19d1205
ZW
10335 if (unified_syntax)
10336 {
0110f2b8
PB
10337 bfd_boolean flags;
10338 bfd_boolean narrow;
10339 int opcode;
10340
10341 flags = (inst.instruction == T_MNEM_adds
10342 || inst.instruction == T_MNEM_subs);
10343 if (flags)
e07e6e58 10344 narrow = !in_it_block ();
0110f2b8 10345 else
e07e6e58 10346 narrow = in_it_block ();
c19d1205 10347 if (!inst.operands[2].isreg)
b99bd4ef 10348 {
16805f35
PB
10349 int add;
10350
fdfde340
JM
10351 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10352
16805f35
PB
10353 add = (inst.instruction == T_MNEM_add
10354 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10355 opcode = 0;
10356 if (inst.size_req != 4)
10357 {
0110f2b8 10358 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10359 appropriate. */
0110f2b8
PB
10360 if (Rd == REG_SP && Rs == REG_SP && !flags)
10361 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10362 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10363 opcode = T_MNEM_add_sp;
10364 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10365 opcode = T_MNEM_add_pc;
10366 else if (Rd <= 7 && Rs <= 7 && narrow)
10367 {
10368 if (flags)
10369 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10370 else
10371 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10372 }
10373 if (opcode)
10374 {
10375 inst.instruction = THUMB_OP16(opcode);
10376 inst.instruction |= (Rd << 4) | Rs;
10377 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10378 if (inst.size_req != 2)
10379 inst.relax = opcode;
10380 }
10381 else
10382 constraint (inst.size_req == 2, BAD_HIREG);
10383 }
10384 if (inst.size_req == 4
10385 || (inst.size_req != 2 && !opcode))
10386 {
efd81785
PB
10387 if (Rd == REG_PC)
10388 {
fdfde340 10389 constraint (add, BAD_PC);
efd81785
PB
10390 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10391 _("only SUBS PC, LR, #const allowed"));
10392 constraint (inst.reloc.exp.X_op != O_constant,
10393 _("expression too complex"));
10394 constraint (inst.reloc.exp.X_add_number < 0
10395 || inst.reloc.exp.X_add_number > 0xff,
10396 _("immediate value out of range"));
10397 inst.instruction = T2_SUBS_PC_LR
10398 | inst.reloc.exp.X_add_number;
10399 inst.reloc.type = BFD_RELOC_UNUSED;
10400 return;
10401 }
10402 else if (Rs == REG_PC)
16805f35
PB
10403 {
10404 /* Always use addw/subw. */
10405 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10406 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10407 }
10408 else
10409 {
10410 inst.instruction = THUMB_OP32 (inst.instruction);
10411 inst.instruction = (inst.instruction & 0xe1ffffff)
10412 | 0x10000000;
10413 if (flags)
10414 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10415 else
10416 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10417 }
dc4503c6
PB
10418 inst.instruction |= Rd << 8;
10419 inst.instruction |= Rs << 16;
0110f2b8 10420 }
b99bd4ef 10421 }
c19d1205
ZW
10422 else
10423 {
5f4cb198
NC
10424 unsigned int value = inst.reloc.exp.X_add_number;
10425 unsigned int shift = inst.operands[2].shift_kind;
10426
c19d1205
ZW
10427 Rn = inst.operands[2].reg;
10428 /* See if we can do this with a 16-bit instruction. */
10429 if (!inst.operands[2].shifted && inst.size_req != 4)
10430 {
e27ec89e
PB
10431 if (Rd > 7 || Rs > 7 || Rn > 7)
10432 narrow = FALSE;
10433
10434 if (narrow)
c19d1205 10435 {
e27ec89e
PB
10436 inst.instruction = ((inst.instruction == T_MNEM_adds
10437 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10438 ? T_OPCODE_ADD_R3
10439 : T_OPCODE_SUB_R3);
10440 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10441 return;
10442 }
b99bd4ef 10443
7e806470 10444 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10445 {
7e806470
PB
10446 /* Thumb-1 cores (except v6-M) require at least one high
10447 register in a narrow non flag setting add. */
10448 if (Rd > 7 || Rn > 7
10449 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10450 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10451 {
7e806470
PB
10452 if (Rd == Rn)
10453 {
10454 Rn = Rs;
10455 Rs = Rd;
10456 }
c19d1205
ZW
10457 inst.instruction = T_OPCODE_ADD_HI;
10458 inst.instruction |= (Rd & 8) << 4;
10459 inst.instruction |= (Rd & 7);
10460 inst.instruction |= Rn << 3;
10461 return;
10462 }
c19d1205
ZW
10463 }
10464 }
c921be7d 10465
fdfde340
JM
10466 constraint (Rd == REG_PC, BAD_PC);
10467 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10468 constraint (Rs == REG_PC, BAD_PC);
10469 reject_bad_reg (Rn);
10470
c19d1205
ZW
10471 /* If we get here, it can't be done in 16 bits. */
10472 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10473 _("shift must be constant"));
10474 inst.instruction = THUMB_OP32 (inst.instruction);
10475 inst.instruction |= Rd << 8;
10476 inst.instruction |= Rs << 16;
5f4cb198
NC
10477 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10478 _("shift value over 3 not allowed in thumb mode"));
10479 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10480 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10481 encode_thumb32_shifted_operand (2);
10482 }
10483 }
10484 else
10485 {
10486 constraint (inst.instruction == T_MNEM_adds
10487 || inst.instruction == T_MNEM_subs,
10488 BAD_THUMB32);
b99bd4ef 10489
c19d1205 10490 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10491 {
c19d1205
ZW
10492 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10493 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10494 BAD_HIREG);
10495
10496 inst.instruction = (inst.instruction == T_MNEM_add
10497 ? 0x0000 : 0x8000);
10498 inst.instruction |= (Rd << 4) | Rs;
10499 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10500 return;
10501 }
10502
c19d1205
ZW
10503 Rn = inst.operands[2].reg;
10504 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10505
c19d1205
ZW
10506 /* We now have Rd, Rs, and Rn set to registers. */
10507 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10508 {
c19d1205
ZW
10509 /* Can't do this for SUB. */
10510 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10511 inst.instruction = T_OPCODE_ADD_HI;
10512 inst.instruction |= (Rd & 8) << 4;
10513 inst.instruction |= (Rd & 7);
10514 if (Rs == Rd)
10515 inst.instruction |= Rn << 3;
10516 else if (Rn == Rd)
10517 inst.instruction |= Rs << 3;
10518 else
10519 constraint (1, _("dest must overlap one source register"));
10520 }
10521 else
10522 {
10523 inst.instruction = (inst.instruction == T_MNEM_add
10524 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10525 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10526 }
b99bd4ef 10527 }
b99bd4ef
NC
10528}
10529
c19d1205
ZW
10530static void
10531do_t_adr (void)
10532{
fdfde340
JM
10533 unsigned Rd;
10534
10535 Rd = inst.operands[0].reg;
10536 reject_bad_reg (Rd);
10537
10538 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10539 {
10540 /* Defer to section relaxation. */
10541 inst.relax = inst.instruction;
10542 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10543 inst.instruction |= Rd << 4;
0110f2b8
PB
10544 }
10545 else if (unified_syntax && inst.size_req != 2)
e9f89963 10546 {
0110f2b8 10547 /* Generate a 32-bit opcode. */
e9f89963 10548 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10549 inst.instruction |= Rd << 8;
e9f89963
PB
10550 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10551 inst.reloc.pc_rel = 1;
10552 }
10553 else
10554 {
0110f2b8 10555 /* Generate a 16-bit opcode. */
e9f89963
PB
10556 inst.instruction = THUMB_OP16 (inst.instruction);
10557 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10558 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10559 inst.reloc.pc_rel = 1;
b99bd4ef 10560
fdfde340 10561 inst.instruction |= Rd << 4;
e9f89963 10562 }
c19d1205 10563}
b99bd4ef 10564
c19d1205
ZW
10565/* Arithmetic instructions for which there is just one 16-bit
10566 instruction encoding, and it allows only two low registers.
10567 For maximal compatibility with ARM syntax, we allow three register
10568 operands even when Thumb-32 instructions are not available, as long
10569 as the first two are identical. For instance, both "sbc r0,r1" and
10570 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10571static void
c19d1205 10572do_t_arit3 (void)
b99bd4ef 10573{
c19d1205 10574 int Rd, Rs, Rn;
b99bd4ef 10575
c19d1205
ZW
10576 Rd = inst.operands[0].reg;
10577 Rs = (inst.operands[1].present
10578 ? inst.operands[1].reg /* Rd, Rs, foo */
10579 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10580 Rn = inst.operands[2].reg;
b99bd4ef 10581
fdfde340
JM
10582 reject_bad_reg (Rd);
10583 reject_bad_reg (Rs);
10584 if (inst.operands[2].isreg)
10585 reject_bad_reg (Rn);
10586
c19d1205 10587 if (unified_syntax)
b99bd4ef 10588 {
c19d1205
ZW
10589 if (!inst.operands[2].isreg)
10590 {
10591 /* For an immediate, we always generate a 32-bit opcode;
10592 section relaxation will shrink it later if possible. */
10593 inst.instruction = THUMB_OP32 (inst.instruction);
10594 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10595 inst.instruction |= Rd << 8;
10596 inst.instruction |= Rs << 16;
10597 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10598 }
10599 else
10600 {
e27ec89e
PB
10601 bfd_boolean narrow;
10602
c19d1205 10603 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10604 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10605 narrow = !in_it_block ();
e27ec89e 10606 else
e07e6e58 10607 narrow = in_it_block ();
e27ec89e
PB
10608
10609 if (Rd > 7 || Rn > 7 || Rs > 7)
10610 narrow = FALSE;
10611 if (inst.operands[2].shifted)
10612 narrow = FALSE;
10613 if (inst.size_req == 4)
10614 narrow = FALSE;
10615
10616 if (narrow
c19d1205
ZW
10617 && Rd == Rs)
10618 {
10619 inst.instruction = THUMB_OP16 (inst.instruction);
10620 inst.instruction |= Rd;
10621 inst.instruction |= Rn << 3;
10622 return;
10623 }
b99bd4ef 10624
c19d1205
ZW
10625 /* If we get here, it can't be done in 16 bits. */
10626 constraint (inst.operands[2].shifted
10627 && inst.operands[2].immisreg,
10628 _("shift must be constant"));
10629 inst.instruction = THUMB_OP32 (inst.instruction);
10630 inst.instruction |= Rd << 8;
10631 inst.instruction |= Rs << 16;
10632 encode_thumb32_shifted_operand (2);
10633 }
a737bd4d 10634 }
c19d1205 10635 else
b99bd4ef 10636 {
c19d1205
ZW
10637 /* On its face this is a lie - the instruction does set the
10638 flags. However, the only supported mnemonic in this mode
10639 says it doesn't. */
10640 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10641
c19d1205
ZW
10642 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10643 _("unshifted register required"));
10644 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10645 constraint (Rd != Rs,
10646 _("dest and source1 must be the same register"));
a737bd4d 10647
c19d1205
ZW
10648 inst.instruction = THUMB_OP16 (inst.instruction);
10649 inst.instruction |= Rd;
10650 inst.instruction |= Rn << 3;
b99bd4ef 10651 }
a737bd4d 10652}
b99bd4ef 10653
c19d1205
ZW
10654/* Similarly, but for instructions where the arithmetic operation is
10655 commutative, so we can allow either of them to be different from
10656 the destination operand in a 16-bit instruction. For instance, all
10657 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10658 accepted. */
10659static void
10660do_t_arit3c (void)
a737bd4d 10661{
c19d1205 10662 int Rd, Rs, Rn;
b99bd4ef 10663
c19d1205
ZW
10664 Rd = inst.operands[0].reg;
10665 Rs = (inst.operands[1].present
10666 ? inst.operands[1].reg /* Rd, Rs, foo */
10667 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10668 Rn = inst.operands[2].reg;
c921be7d 10669
fdfde340
JM
10670 reject_bad_reg (Rd);
10671 reject_bad_reg (Rs);
10672 if (inst.operands[2].isreg)
10673 reject_bad_reg (Rn);
a737bd4d 10674
c19d1205 10675 if (unified_syntax)
a737bd4d 10676 {
c19d1205 10677 if (!inst.operands[2].isreg)
b99bd4ef 10678 {
c19d1205
ZW
10679 /* For an immediate, we always generate a 32-bit opcode;
10680 section relaxation will shrink it later if possible. */
10681 inst.instruction = THUMB_OP32 (inst.instruction);
10682 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10683 inst.instruction |= Rd << 8;
10684 inst.instruction |= Rs << 16;
10685 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10686 }
c19d1205 10687 else
a737bd4d 10688 {
e27ec89e
PB
10689 bfd_boolean narrow;
10690
c19d1205 10691 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10692 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10693 narrow = !in_it_block ();
e27ec89e 10694 else
e07e6e58 10695 narrow = in_it_block ();
e27ec89e
PB
10696
10697 if (Rd > 7 || Rn > 7 || Rs > 7)
10698 narrow = FALSE;
10699 if (inst.operands[2].shifted)
10700 narrow = FALSE;
10701 if (inst.size_req == 4)
10702 narrow = FALSE;
10703
10704 if (narrow)
a737bd4d 10705 {
c19d1205 10706 if (Rd == Rs)
a737bd4d 10707 {
c19d1205
ZW
10708 inst.instruction = THUMB_OP16 (inst.instruction);
10709 inst.instruction |= Rd;
10710 inst.instruction |= Rn << 3;
10711 return;
a737bd4d 10712 }
c19d1205 10713 if (Rd == Rn)
a737bd4d 10714 {
c19d1205
ZW
10715 inst.instruction = THUMB_OP16 (inst.instruction);
10716 inst.instruction |= Rd;
10717 inst.instruction |= Rs << 3;
10718 return;
a737bd4d
NC
10719 }
10720 }
c19d1205
ZW
10721
10722 /* If we get here, it can't be done in 16 bits. */
10723 constraint (inst.operands[2].shifted
10724 && inst.operands[2].immisreg,
10725 _("shift must be constant"));
10726 inst.instruction = THUMB_OP32 (inst.instruction);
10727 inst.instruction |= Rd << 8;
10728 inst.instruction |= Rs << 16;
10729 encode_thumb32_shifted_operand (2);
a737bd4d 10730 }
b99bd4ef 10731 }
c19d1205
ZW
10732 else
10733 {
10734 /* On its face this is a lie - the instruction does set the
10735 flags. However, the only supported mnemonic in this mode
10736 says it doesn't. */
10737 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10738
c19d1205
ZW
10739 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10740 _("unshifted register required"));
10741 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10742
10743 inst.instruction = THUMB_OP16 (inst.instruction);
10744 inst.instruction |= Rd;
10745
10746 if (Rd == Rs)
10747 inst.instruction |= Rn << 3;
10748 else if (Rd == Rn)
10749 inst.instruction |= Rs << 3;
10750 else
10751 constraint (1, _("dest must overlap one source register"));
10752 }
a737bd4d
NC
10753}
10754
c19d1205
ZW
10755static void
10756do_t_bfc (void)
a737bd4d 10757{
fdfde340 10758 unsigned Rd;
c19d1205
ZW
10759 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10760 constraint (msb > 32, _("bit-field extends past end of register"));
10761 /* The instruction encoding stores the LSB and MSB,
10762 not the LSB and width. */
fdfde340
JM
10763 Rd = inst.operands[0].reg;
10764 reject_bad_reg (Rd);
10765 inst.instruction |= Rd << 8;
c19d1205
ZW
10766 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10767 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10768 inst.instruction |= msb - 1;
b99bd4ef
NC
10769}
10770
c19d1205
ZW
10771static void
10772do_t_bfi (void)
b99bd4ef 10773{
fdfde340 10774 int Rd, Rn;
c19d1205 10775 unsigned int msb;
b99bd4ef 10776
fdfde340
JM
10777 Rd = inst.operands[0].reg;
10778 reject_bad_reg (Rd);
10779
c19d1205
ZW
10780 /* #0 in second position is alternative syntax for bfc, which is
10781 the same instruction but with REG_PC in the Rm field. */
10782 if (!inst.operands[1].isreg)
fdfde340
JM
10783 Rn = REG_PC;
10784 else
10785 {
10786 Rn = inst.operands[1].reg;
10787 reject_bad_reg (Rn);
10788 }
b99bd4ef 10789
c19d1205
ZW
10790 msb = inst.operands[2].imm + inst.operands[3].imm;
10791 constraint (msb > 32, _("bit-field extends past end of register"));
10792 /* The instruction encoding stores the LSB and MSB,
10793 not the LSB and width. */
fdfde340
JM
10794 inst.instruction |= Rd << 8;
10795 inst.instruction |= Rn << 16;
c19d1205
ZW
10796 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10797 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10798 inst.instruction |= msb - 1;
b99bd4ef
NC
10799}
10800
c19d1205
ZW
10801static void
10802do_t_bfx (void)
b99bd4ef 10803{
fdfde340
JM
10804 unsigned Rd, Rn;
10805
10806 Rd = inst.operands[0].reg;
10807 Rn = inst.operands[1].reg;
10808
10809 reject_bad_reg (Rd);
10810 reject_bad_reg (Rn);
10811
c19d1205
ZW
10812 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
10813 _("bit-field extends past end of register"));
fdfde340
JM
10814 inst.instruction |= Rd << 8;
10815 inst.instruction |= Rn << 16;
c19d1205
ZW
10816 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10817 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10818 inst.instruction |= inst.operands[3].imm - 1;
10819}
b99bd4ef 10820
c19d1205
ZW
10821/* ARM V5 Thumb BLX (argument parse)
10822 BLX <target_addr> which is BLX(1)
10823 BLX <Rm> which is BLX(2)
10824 Unfortunately, there are two different opcodes for this mnemonic.
10825 So, the insns[].value is not used, and the code here zaps values
10826 into inst.instruction.
b99bd4ef 10827
c19d1205
ZW
10828 ??? How to take advantage of the additional two bits of displacement
10829 available in Thumb32 mode? Need new relocation? */
b99bd4ef 10830
c19d1205
ZW
10831static void
10832do_t_blx (void)
10833{
e07e6e58
NC
10834 set_it_insn_type_last ();
10835
c19d1205 10836 if (inst.operands[0].isreg)
fdfde340
JM
10837 {
10838 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10839 /* We have a register, so this is BLX(2). */
10840 inst.instruction |= inst.operands[0].reg << 3;
10841 }
b99bd4ef
NC
10842 else
10843 {
c19d1205 10844 /* No register. This must be BLX(1). */
2fc8bdac 10845 inst.instruction = 0xf000e800;
0855e32b 10846 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
10847 }
10848}
10849
c19d1205
ZW
10850static void
10851do_t_branch (void)
b99bd4ef 10852{
0110f2b8 10853 int opcode;
dfa9f0d5 10854 int cond;
9ae92b05 10855 int reloc;
dfa9f0d5 10856
e07e6e58
NC
10857 cond = inst.cond;
10858 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
10859
10860 if (in_it_block ())
dfa9f0d5
PB
10861 {
10862 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 10863 branches. */
dfa9f0d5 10864 cond = COND_ALWAYS;
dfa9f0d5
PB
10865 }
10866 else
10867 cond = inst.cond;
10868
10869 if (cond != COND_ALWAYS)
0110f2b8
PB
10870 opcode = T_MNEM_bcond;
10871 else
10872 opcode = inst.instruction;
10873
12d6b0b7
RS
10874 if (unified_syntax
10875 && (inst.size_req == 4
10960bfb
PB
10876 || (inst.size_req != 2
10877 && (inst.operands[0].hasreloc
10878 || inst.reloc.exp.X_op == O_constant))))
c19d1205 10879 {
0110f2b8 10880 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 10881 if (cond == COND_ALWAYS)
9ae92b05 10882 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
10883 else
10884 {
9c2799c2 10885 gas_assert (cond != 0xF);
dfa9f0d5 10886 inst.instruction |= cond << 22;
9ae92b05 10887 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
10888 }
10889 }
b99bd4ef
NC
10890 else
10891 {
0110f2b8 10892 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 10893 if (cond == COND_ALWAYS)
9ae92b05 10894 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 10895 else
b99bd4ef 10896 {
dfa9f0d5 10897 inst.instruction |= cond << 8;
9ae92b05 10898 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 10899 }
0110f2b8
PB
10900 /* Allow section relaxation. */
10901 if (unified_syntax && inst.size_req != 2)
10902 inst.relax = opcode;
b99bd4ef 10903 }
9ae92b05 10904 inst.reloc.type = reloc;
c19d1205 10905 inst.reloc.pc_rel = 1;
b99bd4ef
NC
10906}
10907
8884b720 10908/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 10909 between the two is the maximum immediate allowed - which is passed in
8884b720 10910 RANGE. */
b99bd4ef 10911static void
8884b720 10912do_t_bkpt_hlt1 (int range)
b99bd4ef 10913{
dfa9f0d5
PB
10914 constraint (inst.cond != COND_ALWAYS,
10915 _("instruction is always unconditional"));
c19d1205 10916 if (inst.operands[0].present)
b99bd4ef 10917 {
8884b720 10918 constraint (inst.operands[0].imm > range,
c19d1205
ZW
10919 _("immediate value out of range"));
10920 inst.instruction |= inst.operands[0].imm;
b99bd4ef 10921 }
8884b720
MGD
10922
10923 set_it_insn_type (NEUTRAL_IT_INSN);
10924}
10925
10926static void
10927do_t_hlt (void)
10928{
10929 do_t_bkpt_hlt1 (63);
10930}
10931
10932static void
10933do_t_bkpt (void)
10934{
10935 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
10936}
10937
10938static void
c19d1205 10939do_t_branch23 (void)
b99bd4ef 10940{
e07e6e58 10941 set_it_insn_type_last ();
0855e32b 10942 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 10943
0855e32b
NS
10944 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
10945 this file. We used to simply ignore the PLT reloc type here --
10946 the branch encoding is now needed to deal with TLSCALL relocs.
10947 So if we see a PLT reloc now, put it back to how it used to be to
10948 keep the preexisting behaviour. */
10949 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
10950 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 10951
4343666d 10952#if defined(OBJ_COFF)
c19d1205
ZW
10953 /* If the destination of the branch is a defined symbol which does not have
10954 the THUMB_FUNC attribute, then we must be calling a function which has
10955 the (interfacearm) attribute. We look for the Thumb entry point to that
10956 function and change the branch to refer to that function instead. */
10957 if ( inst.reloc.exp.X_op == O_symbol
10958 && inst.reloc.exp.X_add_symbol != NULL
10959 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10960 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10961 inst.reloc.exp.X_add_symbol =
10962 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 10963#endif
90e4755a
RE
10964}
10965
10966static void
c19d1205 10967do_t_bx (void)
90e4755a 10968{
e07e6e58 10969 set_it_insn_type_last ();
c19d1205
ZW
10970 inst.instruction |= inst.operands[0].reg << 3;
10971 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
10972 should cause the alignment to be checked once it is known. This is
10973 because BX PC only works if the instruction is word aligned. */
10974}
90e4755a 10975
c19d1205
ZW
10976static void
10977do_t_bxj (void)
10978{
fdfde340 10979 int Rm;
90e4755a 10980
e07e6e58 10981 set_it_insn_type_last ();
fdfde340
JM
10982 Rm = inst.operands[0].reg;
10983 reject_bad_reg (Rm);
10984 inst.instruction |= Rm << 16;
90e4755a
RE
10985}
10986
10987static void
c19d1205 10988do_t_clz (void)
90e4755a 10989{
fdfde340
JM
10990 unsigned Rd;
10991 unsigned Rm;
10992
10993 Rd = inst.operands[0].reg;
10994 Rm = inst.operands[1].reg;
10995
10996 reject_bad_reg (Rd);
10997 reject_bad_reg (Rm);
10998
10999 inst.instruction |= Rd << 8;
11000 inst.instruction |= Rm << 16;
11001 inst.instruction |= Rm;
c19d1205 11002}
90e4755a 11003
dfa9f0d5
PB
11004static void
11005do_t_cps (void)
11006{
e07e6e58 11007 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11008 inst.instruction |= inst.operands[0].imm;
11009}
11010
c19d1205
ZW
11011static void
11012do_t_cpsi (void)
11013{
e07e6e58 11014 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11015 if (unified_syntax
62b3e311
PB
11016 && (inst.operands[1].present || inst.size_req == 4)
11017 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11018 {
c19d1205
ZW
11019 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11020 inst.instruction = 0xf3af8000;
11021 inst.instruction |= imod << 9;
11022 inst.instruction |= inst.operands[0].imm << 5;
11023 if (inst.operands[1].present)
11024 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11025 }
c19d1205 11026 else
90e4755a 11027 {
62b3e311
PB
11028 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11029 && (inst.operands[0].imm & 4),
11030 _("selected processor does not support 'A' form "
11031 "of this instruction"));
11032 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11033 _("Thumb does not support the 2-argument "
11034 "form of this instruction"));
11035 inst.instruction |= inst.operands[0].imm;
90e4755a 11036 }
90e4755a
RE
11037}
11038
c19d1205
ZW
11039/* THUMB CPY instruction (argument parse). */
11040
90e4755a 11041static void
c19d1205 11042do_t_cpy (void)
90e4755a 11043{
c19d1205 11044 if (inst.size_req == 4)
90e4755a 11045 {
c19d1205
ZW
11046 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11047 inst.instruction |= inst.operands[0].reg << 8;
11048 inst.instruction |= inst.operands[1].reg;
90e4755a 11049 }
c19d1205 11050 else
90e4755a 11051 {
c19d1205
ZW
11052 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11053 inst.instruction |= (inst.operands[0].reg & 0x7);
11054 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11055 }
90e4755a
RE
11056}
11057
90e4755a 11058static void
25fe350b 11059do_t_cbz (void)
90e4755a 11060{
e07e6e58 11061 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11062 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11063 inst.instruction |= inst.operands[0].reg;
11064 inst.reloc.pc_rel = 1;
11065 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11066}
90e4755a 11067
62b3e311
PB
11068static void
11069do_t_dbg (void)
11070{
11071 inst.instruction |= inst.operands[0].imm;
11072}
11073
11074static void
11075do_t_div (void)
11076{
fdfde340
JM
11077 unsigned Rd, Rn, Rm;
11078
11079 Rd = inst.operands[0].reg;
11080 Rn = (inst.operands[1].present
11081 ? inst.operands[1].reg : Rd);
11082 Rm = inst.operands[2].reg;
11083
11084 reject_bad_reg (Rd);
11085 reject_bad_reg (Rn);
11086 reject_bad_reg (Rm);
11087
11088 inst.instruction |= Rd << 8;
11089 inst.instruction |= Rn << 16;
11090 inst.instruction |= Rm;
62b3e311
PB
11091}
11092
c19d1205
ZW
11093static void
11094do_t_hint (void)
11095{
11096 if (unified_syntax && inst.size_req == 4)
11097 inst.instruction = THUMB_OP32 (inst.instruction);
11098 else
11099 inst.instruction = THUMB_OP16 (inst.instruction);
11100}
90e4755a 11101
c19d1205
ZW
11102static void
11103do_t_it (void)
11104{
11105 unsigned int cond = inst.operands[0].imm;
e27ec89e 11106
e07e6e58
NC
11107 set_it_insn_type (IT_INSN);
11108 now_it.mask = (inst.instruction & 0xf) | 0x10;
11109 now_it.cc = cond;
5a01bb1d 11110 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11111
11112 /* If the condition is a negative condition, invert the mask. */
c19d1205 11113 if ((cond & 0x1) == 0x0)
90e4755a 11114 {
c19d1205 11115 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11116
c19d1205 11117 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11118 {
11119 /* No conversion needed. */
11120 now_it.block_length = 1;
11121 }
c19d1205 11122 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11123 {
11124 mask ^= 0x8;
11125 now_it.block_length = 2;
11126 }
e27ec89e 11127 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11128 {
11129 mask ^= 0xC;
11130 now_it.block_length = 3;
11131 }
c19d1205 11132 else
5a01bb1d
MGD
11133 {
11134 mask ^= 0xE;
11135 now_it.block_length = 4;
11136 }
90e4755a 11137
e27ec89e
PB
11138 inst.instruction &= 0xfff0;
11139 inst.instruction |= mask;
c19d1205 11140 }
90e4755a 11141
c19d1205
ZW
11142 inst.instruction |= cond << 4;
11143}
90e4755a 11144
3c707909
PB
11145/* Helper function used for both push/pop and ldm/stm. */
11146static void
11147encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11148{
11149 bfd_boolean load;
11150
11151 load = (inst.instruction & (1 << 20)) != 0;
11152
11153 if (mask & (1 << 13))
11154 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11155
11156 if ((mask & (1 << base)) != 0
11157 && writeback)
11158 inst.error = _("having the base register in the register list when "
11159 "using write back is UNPREDICTABLE");
11160
3c707909
PB
11161 if (load)
11162 {
e07e6e58 11163 if (mask & (1 << 15))
477330fc
RM
11164 {
11165 if (mask & (1 << 14))
11166 inst.error = _("LR and PC should not both be in register list");
11167 else
11168 set_it_insn_type_last ();
11169 }
3c707909
PB
11170 }
11171 else
11172 {
11173 if (mask & (1 << 15))
11174 inst.error = _("PC not allowed in register list");
3c707909
PB
11175 }
11176
11177 if ((mask & (mask - 1)) == 0)
11178 {
11179 /* Single register transfers implemented as str/ldr. */
11180 if (writeback)
11181 {
11182 if (inst.instruction & (1 << 23))
11183 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11184 else
11185 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11186 }
11187 else
11188 {
11189 if (inst.instruction & (1 << 23))
11190 inst.instruction = 0x00800000; /* ia -> [base] */
11191 else
11192 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11193 }
11194
11195 inst.instruction |= 0xf8400000;
11196 if (load)
11197 inst.instruction |= 0x00100000;
11198
5f4273c7 11199 mask = ffs (mask) - 1;
3c707909
PB
11200 mask <<= 12;
11201 }
11202 else if (writeback)
11203 inst.instruction |= WRITE_BACK;
11204
11205 inst.instruction |= mask;
11206 inst.instruction |= base << 16;
11207}
11208
c19d1205
ZW
11209static void
11210do_t_ldmstm (void)
11211{
11212 /* This really doesn't seem worth it. */
11213 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11214 _("expression too complex"));
11215 constraint (inst.operands[1].writeback,
11216 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11217
c19d1205
ZW
11218 if (unified_syntax)
11219 {
3c707909
PB
11220 bfd_boolean narrow;
11221 unsigned mask;
11222
11223 narrow = FALSE;
c19d1205
ZW
11224 /* See if we can use a 16-bit instruction. */
11225 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11226 && inst.size_req != 4
3c707909 11227 && !(inst.operands[1].imm & ~0xff))
90e4755a 11228 {
3c707909 11229 mask = 1 << inst.operands[0].reg;
90e4755a 11230
eab4f823 11231 if (inst.operands[0].reg <= 7)
90e4755a 11232 {
3c707909 11233 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11234 ? inst.operands[0].writeback
11235 : (inst.operands[0].writeback
11236 == !(inst.operands[1].imm & mask)))
477330fc 11237 {
eab4f823
MGD
11238 if (inst.instruction == T_MNEM_stmia
11239 && (inst.operands[1].imm & mask)
11240 && (inst.operands[1].imm & (mask - 1)))
11241 as_warn (_("value stored for r%d is UNKNOWN"),
11242 inst.operands[0].reg);
3c707909 11243
eab4f823
MGD
11244 inst.instruction = THUMB_OP16 (inst.instruction);
11245 inst.instruction |= inst.operands[0].reg << 8;
11246 inst.instruction |= inst.operands[1].imm;
11247 narrow = TRUE;
11248 }
11249 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11250 {
11251 /* This means 1 register in reg list one of 3 situations:
11252 1. Instruction is stmia, but without writeback.
11253 2. lmdia without writeback, but with Rn not in
477330fc 11254 reglist.
eab4f823
MGD
11255 3. ldmia with writeback, but with Rn in reglist.
11256 Case 3 is UNPREDICTABLE behaviour, so we handle
11257 case 1 and 2 which can be converted into a 16-bit
11258 str or ldr. The SP cases are handled below. */
11259 unsigned long opcode;
11260 /* First, record an error for Case 3. */
11261 if (inst.operands[1].imm & mask
11262 && inst.operands[0].writeback)
fa94de6b 11263 inst.error =
eab4f823
MGD
11264 _("having the base register in the register list when "
11265 "using write back is UNPREDICTABLE");
fa94de6b
RM
11266
11267 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11268 : T_MNEM_ldr);
11269 inst.instruction = THUMB_OP16 (opcode);
11270 inst.instruction |= inst.operands[0].reg << 3;
11271 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11272 narrow = TRUE;
11273 }
90e4755a 11274 }
eab4f823 11275 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11276 {
eab4f823
MGD
11277 if (inst.operands[0].writeback)
11278 {
fa94de6b 11279 inst.instruction =
eab4f823 11280 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11281 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11282 inst.instruction |= inst.operands[1].imm;
477330fc 11283 narrow = TRUE;
eab4f823
MGD
11284 }
11285 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11286 {
fa94de6b 11287 inst.instruction =
eab4f823 11288 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11289 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11290 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11291 narrow = TRUE;
eab4f823 11292 }
90e4755a 11293 }
3c707909
PB
11294 }
11295
11296 if (!narrow)
11297 {
c19d1205
ZW
11298 if (inst.instruction < 0xffff)
11299 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11300
5f4273c7
NC
11301 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11302 inst.operands[0].writeback);
90e4755a
RE
11303 }
11304 }
c19d1205 11305 else
90e4755a 11306 {
c19d1205
ZW
11307 constraint (inst.operands[0].reg > 7
11308 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11309 constraint (inst.instruction != T_MNEM_ldmia
11310 && inst.instruction != T_MNEM_stmia,
11311 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11312 if (inst.instruction == T_MNEM_stmia)
f03698e6 11313 {
c19d1205
ZW
11314 if (!inst.operands[0].writeback)
11315 as_warn (_("this instruction will write back the base register"));
11316 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11317 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11318 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11319 inst.operands[0].reg);
f03698e6 11320 }
c19d1205 11321 else
90e4755a 11322 {
c19d1205
ZW
11323 if (!inst.operands[0].writeback
11324 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11325 as_warn (_("this instruction will write back the base register"));
11326 else if (inst.operands[0].writeback
11327 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11328 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11329 }
11330
c19d1205
ZW
11331 inst.instruction = THUMB_OP16 (inst.instruction);
11332 inst.instruction |= inst.operands[0].reg << 8;
11333 inst.instruction |= inst.operands[1].imm;
11334 }
11335}
e28cd48c 11336
c19d1205
ZW
11337static void
11338do_t_ldrex (void)
11339{
11340 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11341 || inst.operands[1].postind || inst.operands[1].writeback
11342 || inst.operands[1].immisreg || inst.operands[1].shifted
11343 || inst.operands[1].negative,
01cfc07f 11344 BAD_ADDR_MODE);
e28cd48c 11345
5be8be5d
DG
11346 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11347
c19d1205
ZW
11348 inst.instruction |= inst.operands[0].reg << 12;
11349 inst.instruction |= inst.operands[1].reg << 16;
11350 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11351}
e28cd48c 11352
c19d1205
ZW
11353static void
11354do_t_ldrexd (void)
11355{
11356 if (!inst.operands[1].present)
1cac9012 11357 {
c19d1205
ZW
11358 constraint (inst.operands[0].reg == REG_LR,
11359 _("r14 not allowed as first register "
11360 "when second register is omitted"));
11361 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11362 }
c19d1205
ZW
11363 constraint (inst.operands[0].reg == inst.operands[1].reg,
11364 BAD_OVERLAP);
b99bd4ef 11365
c19d1205
ZW
11366 inst.instruction |= inst.operands[0].reg << 12;
11367 inst.instruction |= inst.operands[1].reg << 8;
11368 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11369}
11370
11371static void
c19d1205 11372do_t_ldst (void)
b99bd4ef 11373{
0110f2b8
PB
11374 unsigned long opcode;
11375 int Rn;
11376
e07e6e58
NC
11377 if (inst.operands[0].isreg
11378 && !inst.operands[0].preind
11379 && inst.operands[0].reg == REG_PC)
11380 set_it_insn_type_last ();
11381
0110f2b8 11382 opcode = inst.instruction;
c19d1205 11383 if (unified_syntax)
b99bd4ef 11384 {
53365c0d
PB
11385 if (!inst.operands[1].isreg)
11386 {
11387 if (opcode <= 0xffff)
11388 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11389 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11390 return;
11391 }
0110f2b8
PB
11392 if (inst.operands[1].isreg
11393 && !inst.operands[1].writeback
c19d1205
ZW
11394 && !inst.operands[1].shifted && !inst.operands[1].postind
11395 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11396 && opcode <= 0xffff
11397 && inst.size_req != 4)
c19d1205 11398 {
0110f2b8
PB
11399 /* Insn may have a 16-bit form. */
11400 Rn = inst.operands[1].reg;
11401 if (inst.operands[1].immisreg)
11402 {
11403 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11404 /* [Rn, Rik] */
0110f2b8
PB
11405 if (Rn <= 7 && inst.operands[1].imm <= 7)
11406 goto op16;
5be8be5d
DG
11407 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11408 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11409 }
11410 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11411 && opcode != T_MNEM_ldrsb)
11412 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11413 || (Rn == REG_SP && opcode == T_MNEM_str))
11414 {
11415 /* [Rn, #const] */
11416 if (Rn > 7)
11417 {
11418 if (Rn == REG_PC)
11419 {
11420 if (inst.reloc.pc_rel)
11421 opcode = T_MNEM_ldr_pc2;
11422 else
11423 opcode = T_MNEM_ldr_pc;
11424 }
11425 else
11426 {
11427 if (opcode == T_MNEM_ldr)
11428 opcode = T_MNEM_ldr_sp;
11429 else
11430 opcode = T_MNEM_str_sp;
11431 }
11432 inst.instruction = inst.operands[0].reg << 8;
11433 }
11434 else
11435 {
11436 inst.instruction = inst.operands[0].reg;
11437 inst.instruction |= inst.operands[1].reg << 3;
11438 }
11439 inst.instruction |= THUMB_OP16 (opcode);
11440 if (inst.size_req == 2)
11441 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11442 else
11443 inst.relax = opcode;
11444 return;
11445 }
c19d1205 11446 }
0110f2b8 11447 /* Definitely a 32-bit variant. */
5be8be5d 11448
8d67f500
NC
11449 /* Warning for Erratum 752419. */
11450 if (opcode == T_MNEM_ldr
11451 && inst.operands[0].reg == REG_SP
11452 && inst.operands[1].writeback == 1
11453 && !inst.operands[1].immisreg)
11454 {
11455 if (no_cpu_selected ()
11456 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11457 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11458 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11459 as_warn (_("This instruction may be unpredictable "
11460 "if executed on M-profile cores "
11461 "with interrupts enabled."));
11462 }
11463
5be8be5d 11464 /* Do some validations regarding addressing modes. */
1be5fd2e 11465 if (inst.operands[1].immisreg)
5be8be5d
DG
11466 reject_bad_reg (inst.operands[1].imm);
11467
1be5fd2e
NC
11468 constraint (inst.operands[1].writeback == 1
11469 && inst.operands[0].reg == inst.operands[1].reg,
11470 BAD_OVERLAP);
11471
0110f2b8 11472 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11473 inst.instruction |= inst.operands[0].reg << 12;
11474 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11475 check_ldr_r15_aligned ();
b99bd4ef
NC
11476 return;
11477 }
11478
c19d1205
ZW
11479 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11480
11481 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11482 {
c19d1205
ZW
11483 /* Only [Rn,Rm] is acceptable. */
11484 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11485 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11486 || inst.operands[1].postind || inst.operands[1].shifted
11487 || inst.operands[1].negative,
11488 _("Thumb does not support this addressing mode"));
11489 inst.instruction = THUMB_OP16 (inst.instruction);
11490 goto op16;
b99bd4ef 11491 }
5f4273c7 11492
c19d1205
ZW
11493 inst.instruction = THUMB_OP16 (inst.instruction);
11494 if (!inst.operands[1].isreg)
8335d6aa 11495 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11496 return;
b99bd4ef 11497
c19d1205
ZW
11498 constraint (!inst.operands[1].preind
11499 || inst.operands[1].shifted
11500 || inst.operands[1].writeback,
11501 _("Thumb does not support this addressing mode"));
11502 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11503 {
c19d1205
ZW
11504 constraint (inst.instruction & 0x0600,
11505 _("byte or halfword not valid for base register"));
11506 constraint (inst.operands[1].reg == REG_PC
11507 && !(inst.instruction & THUMB_LOAD_BIT),
11508 _("r15 based store not allowed"));
11509 constraint (inst.operands[1].immisreg,
11510 _("invalid base register for register offset"));
b99bd4ef 11511
c19d1205
ZW
11512 if (inst.operands[1].reg == REG_PC)
11513 inst.instruction = T_OPCODE_LDR_PC;
11514 else if (inst.instruction & THUMB_LOAD_BIT)
11515 inst.instruction = T_OPCODE_LDR_SP;
11516 else
11517 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11518
c19d1205
ZW
11519 inst.instruction |= inst.operands[0].reg << 8;
11520 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11521 return;
11522 }
90e4755a 11523
c19d1205
ZW
11524 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11525 if (!inst.operands[1].immisreg)
11526 {
11527 /* Immediate offset. */
11528 inst.instruction |= inst.operands[0].reg;
11529 inst.instruction |= inst.operands[1].reg << 3;
11530 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11531 return;
11532 }
90e4755a 11533
c19d1205
ZW
11534 /* Register offset. */
11535 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11536 constraint (inst.operands[1].negative,
11537 _("Thumb does not support this addressing mode"));
90e4755a 11538
c19d1205
ZW
11539 op16:
11540 switch (inst.instruction)
11541 {
11542 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11543 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11544 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11545 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11546 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11547 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11548 case 0x5600 /* ldrsb */:
11549 case 0x5e00 /* ldrsh */: break;
11550 default: abort ();
11551 }
90e4755a 11552
c19d1205
ZW
11553 inst.instruction |= inst.operands[0].reg;
11554 inst.instruction |= inst.operands[1].reg << 3;
11555 inst.instruction |= inst.operands[1].imm << 6;
11556}
90e4755a 11557
c19d1205
ZW
11558static void
11559do_t_ldstd (void)
11560{
11561 if (!inst.operands[1].present)
b99bd4ef 11562 {
c19d1205
ZW
11563 inst.operands[1].reg = inst.operands[0].reg + 1;
11564 constraint (inst.operands[0].reg == REG_LR,
11565 _("r14 not allowed here"));
bd340a04 11566 constraint (inst.operands[0].reg == REG_R12,
477330fc 11567 _("r12 not allowed here"));
b99bd4ef 11568 }
bd340a04
MGD
11569
11570 if (inst.operands[2].writeback
11571 && (inst.operands[0].reg == inst.operands[2].reg
11572 || inst.operands[1].reg == inst.operands[2].reg))
11573 as_warn (_("base register written back, and overlaps "
477330fc 11574 "one of transfer registers"));
bd340a04 11575
c19d1205
ZW
11576 inst.instruction |= inst.operands[0].reg << 12;
11577 inst.instruction |= inst.operands[1].reg << 8;
11578 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11579}
11580
c19d1205
ZW
11581static void
11582do_t_ldstt (void)
11583{
11584 inst.instruction |= inst.operands[0].reg << 12;
11585 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11586}
a737bd4d 11587
b99bd4ef 11588static void
c19d1205 11589do_t_mla (void)
b99bd4ef 11590{
fdfde340 11591 unsigned Rd, Rn, Rm, Ra;
c921be7d 11592
fdfde340
JM
11593 Rd = inst.operands[0].reg;
11594 Rn = inst.operands[1].reg;
11595 Rm = inst.operands[2].reg;
11596 Ra = inst.operands[3].reg;
11597
11598 reject_bad_reg (Rd);
11599 reject_bad_reg (Rn);
11600 reject_bad_reg (Rm);
11601 reject_bad_reg (Ra);
11602
11603 inst.instruction |= Rd << 8;
11604 inst.instruction |= Rn << 16;
11605 inst.instruction |= Rm;
11606 inst.instruction |= Ra << 12;
c19d1205 11607}
b99bd4ef 11608
c19d1205
ZW
11609static void
11610do_t_mlal (void)
11611{
fdfde340
JM
11612 unsigned RdLo, RdHi, Rn, Rm;
11613
11614 RdLo = inst.operands[0].reg;
11615 RdHi = inst.operands[1].reg;
11616 Rn = inst.operands[2].reg;
11617 Rm = inst.operands[3].reg;
11618
11619 reject_bad_reg (RdLo);
11620 reject_bad_reg (RdHi);
11621 reject_bad_reg (Rn);
11622 reject_bad_reg (Rm);
11623
11624 inst.instruction |= RdLo << 12;
11625 inst.instruction |= RdHi << 8;
11626 inst.instruction |= Rn << 16;
11627 inst.instruction |= Rm;
c19d1205 11628}
b99bd4ef 11629
c19d1205
ZW
11630static void
11631do_t_mov_cmp (void)
11632{
fdfde340
JM
11633 unsigned Rn, Rm;
11634
11635 Rn = inst.operands[0].reg;
11636 Rm = inst.operands[1].reg;
11637
e07e6e58
NC
11638 if (Rn == REG_PC)
11639 set_it_insn_type_last ();
11640
c19d1205 11641 if (unified_syntax)
b99bd4ef 11642 {
c19d1205
ZW
11643 int r0off = (inst.instruction == T_MNEM_mov
11644 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11645 unsigned long opcode;
3d388997
PB
11646 bfd_boolean narrow;
11647 bfd_boolean low_regs;
11648
fdfde340 11649 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11650 opcode = inst.instruction;
e07e6e58 11651 if (in_it_block ())
0110f2b8 11652 narrow = opcode != T_MNEM_movs;
3d388997 11653 else
0110f2b8 11654 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11655 if (inst.size_req == 4
11656 || inst.operands[1].shifted)
11657 narrow = FALSE;
11658
efd81785
PB
11659 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11660 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11661 && !inst.operands[1].shifted
fdfde340
JM
11662 && Rn == REG_PC
11663 && Rm == REG_LR)
efd81785
PB
11664 {
11665 inst.instruction = T2_SUBS_PC_LR;
11666 return;
11667 }
11668
fdfde340
JM
11669 if (opcode == T_MNEM_cmp)
11670 {
11671 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11672 if (narrow)
11673 {
11674 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11675 but valid. */
11676 warn_deprecated_sp (Rm);
11677 /* R15 was documented as a valid choice for Rm in ARMv6,
11678 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11679 tools reject R15, so we do too. */
11680 constraint (Rm == REG_PC, BAD_PC);
11681 }
11682 else
11683 reject_bad_reg (Rm);
fdfde340
JM
11684 }
11685 else if (opcode == T_MNEM_mov
11686 || opcode == T_MNEM_movs)
11687 {
11688 if (inst.operands[1].isreg)
11689 {
11690 if (opcode == T_MNEM_movs)
11691 {
11692 reject_bad_reg (Rn);
11693 reject_bad_reg (Rm);
11694 }
76fa04a4
MGD
11695 else if (narrow)
11696 {
11697 /* This is mov.n. */
11698 if ((Rn == REG_SP || Rn == REG_PC)
11699 && (Rm == REG_SP || Rm == REG_PC))
11700 {
5c3696f8 11701 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
11702 "deprecated when r%u is the destination "
11703 "register."), Rm, Rn);
11704 }
11705 }
11706 else
11707 {
11708 /* This is mov.w. */
11709 constraint (Rn == REG_PC, BAD_PC);
11710 constraint (Rm == REG_PC, BAD_PC);
11711 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
11712 }
fdfde340
JM
11713 }
11714 else
11715 reject_bad_reg (Rn);
11716 }
11717
c19d1205
ZW
11718 if (!inst.operands[1].isreg)
11719 {
0110f2b8 11720 /* Immediate operand. */
e07e6e58 11721 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
11722 narrow = 0;
11723 if (low_regs && narrow)
11724 {
11725 inst.instruction = THUMB_OP16 (opcode);
fdfde340 11726 inst.instruction |= Rn << 8;
0110f2b8
PB
11727 if (inst.size_req == 2)
11728 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11729 else
11730 inst.relax = opcode;
11731 }
11732 else
11733 {
11734 inst.instruction = THUMB_OP32 (inst.instruction);
11735 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11736 inst.instruction |= Rn << r0off;
0110f2b8
PB
11737 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11738 }
c19d1205 11739 }
728ca7c9
PB
11740 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11741 && (inst.instruction == T_MNEM_mov
11742 || inst.instruction == T_MNEM_movs))
11743 {
11744 /* Register shifts are encoded as separate shift instructions. */
11745 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11746
e07e6e58 11747 if (in_it_block ())
728ca7c9
PB
11748 narrow = !flags;
11749 else
11750 narrow = flags;
11751
11752 if (inst.size_req == 4)
11753 narrow = FALSE;
11754
11755 if (!low_regs || inst.operands[1].imm > 7)
11756 narrow = FALSE;
11757
fdfde340 11758 if (Rn != Rm)
728ca7c9
PB
11759 narrow = FALSE;
11760
11761 switch (inst.operands[1].shift_kind)
11762 {
11763 case SHIFT_LSL:
11764 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
11765 break;
11766 case SHIFT_ASR:
11767 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
11768 break;
11769 case SHIFT_LSR:
11770 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
11771 break;
11772 case SHIFT_ROR:
11773 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
11774 break;
11775 default:
5f4273c7 11776 abort ();
728ca7c9
PB
11777 }
11778
11779 inst.instruction = opcode;
11780 if (narrow)
11781 {
fdfde340 11782 inst.instruction |= Rn;
728ca7c9
PB
11783 inst.instruction |= inst.operands[1].imm << 3;
11784 }
11785 else
11786 {
11787 if (flags)
11788 inst.instruction |= CONDS_BIT;
11789
fdfde340
JM
11790 inst.instruction |= Rn << 8;
11791 inst.instruction |= Rm << 16;
728ca7c9
PB
11792 inst.instruction |= inst.operands[1].imm;
11793 }
11794 }
3d388997 11795 else if (!narrow)
c19d1205 11796 {
728ca7c9
PB
11797 /* Some mov with immediate shift have narrow variants.
11798 Register shifts are handled above. */
11799 if (low_regs && inst.operands[1].shifted
11800 && (inst.instruction == T_MNEM_mov
11801 || inst.instruction == T_MNEM_movs))
11802 {
e07e6e58 11803 if (in_it_block ())
728ca7c9
PB
11804 narrow = (inst.instruction == T_MNEM_mov);
11805 else
11806 narrow = (inst.instruction == T_MNEM_movs);
11807 }
11808
11809 if (narrow)
11810 {
11811 switch (inst.operands[1].shift_kind)
11812 {
11813 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11814 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11815 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11816 default: narrow = FALSE; break;
11817 }
11818 }
11819
11820 if (narrow)
11821 {
fdfde340
JM
11822 inst.instruction |= Rn;
11823 inst.instruction |= Rm << 3;
728ca7c9
PB
11824 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11825 }
11826 else
11827 {
11828 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11829 inst.instruction |= Rn << r0off;
728ca7c9
PB
11830 encode_thumb32_shifted_operand (1);
11831 }
c19d1205
ZW
11832 }
11833 else
11834 switch (inst.instruction)
11835 {
11836 case T_MNEM_mov:
837b3435 11837 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
11838 results. Don't allow this. */
11839 if (low_regs)
11840 {
11841 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
11842 "MOV Rd, Rs with two low registers is not "
11843 "permitted on this architecture");
fa94de6b 11844 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
11845 arm_ext_v6);
11846 }
11847
c19d1205 11848 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
11849 inst.instruction |= (Rn & 0x8) << 4;
11850 inst.instruction |= (Rn & 0x7);
11851 inst.instruction |= Rm << 3;
c19d1205 11852 break;
b99bd4ef 11853
c19d1205
ZW
11854 case T_MNEM_movs:
11855 /* We know we have low registers at this point.
941a8a52
MGD
11856 Generate LSLS Rd, Rs, #0. */
11857 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
11858 inst.instruction |= Rn;
11859 inst.instruction |= Rm << 3;
c19d1205
ZW
11860 break;
11861
11862 case T_MNEM_cmp:
3d388997 11863 if (low_regs)
c19d1205
ZW
11864 {
11865 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
11866 inst.instruction |= Rn;
11867 inst.instruction |= Rm << 3;
c19d1205
ZW
11868 }
11869 else
11870 {
11871 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
11872 inst.instruction |= (Rn & 0x8) << 4;
11873 inst.instruction |= (Rn & 0x7);
11874 inst.instruction |= Rm << 3;
c19d1205
ZW
11875 }
11876 break;
11877 }
b99bd4ef
NC
11878 return;
11879 }
11880
c19d1205 11881 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
11882
11883 /* PR 10443: Do not silently ignore shifted operands. */
11884 constraint (inst.operands[1].shifted,
11885 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
11886
c19d1205 11887 if (inst.operands[1].isreg)
b99bd4ef 11888 {
fdfde340 11889 if (Rn < 8 && Rm < 8)
b99bd4ef 11890 {
c19d1205
ZW
11891 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
11892 since a MOV instruction produces unpredictable results. */
11893 if (inst.instruction == T_OPCODE_MOV_I8)
11894 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 11895 else
c19d1205 11896 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 11897
fdfde340
JM
11898 inst.instruction |= Rn;
11899 inst.instruction |= Rm << 3;
b99bd4ef
NC
11900 }
11901 else
11902 {
c19d1205
ZW
11903 if (inst.instruction == T_OPCODE_MOV_I8)
11904 inst.instruction = T_OPCODE_MOV_HR;
11905 else
11906 inst.instruction = T_OPCODE_CMP_HR;
11907 do_t_cpy ();
b99bd4ef
NC
11908 }
11909 }
c19d1205 11910 else
b99bd4ef 11911 {
fdfde340 11912 constraint (Rn > 7,
c19d1205 11913 _("only lo regs allowed with immediate"));
fdfde340 11914 inst.instruction |= Rn << 8;
c19d1205
ZW
11915 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11916 }
11917}
b99bd4ef 11918
c19d1205
ZW
11919static void
11920do_t_mov16 (void)
11921{
fdfde340 11922 unsigned Rd;
b6895b4f
PB
11923 bfd_vma imm;
11924 bfd_boolean top;
11925
11926 top = (inst.instruction & 0x00800000) != 0;
11927 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
11928 {
11929 constraint (top, _(":lower16: not allowed this instruction"));
11930 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
11931 }
11932 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
11933 {
11934 constraint (!top, _(":upper16: not allowed this instruction"));
11935 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
11936 }
11937
fdfde340
JM
11938 Rd = inst.operands[0].reg;
11939 reject_bad_reg (Rd);
11940
11941 inst.instruction |= Rd << 8;
b6895b4f
PB
11942 if (inst.reloc.type == BFD_RELOC_UNUSED)
11943 {
11944 imm = inst.reloc.exp.X_add_number;
11945 inst.instruction |= (imm & 0xf000) << 4;
11946 inst.instruction |= (imm & 0x0800) << 15;
11947 inst.instruction |= (imm & 0x0700) << 4;
11948 inst.instruction |= (imm & 0x00ff);
11949 }
c19d1205 11950}
b99bd4ef 11951
c19d1205
ZW
11952static void
11953do_t_mvn_tst (void)
11954{
fdfde340 11955 unsigned Rn, Rm;
c921be7d 11956
fdfde340
JM
11957 Rn = inst.operands[0].reg;
11958 Rm = inst.operands[1].reg;
11959
11960 if (inst.instruction == T_MNEM_cmp
11961 || inst.instruction == T_MNEM_cmn)
11962 constraint (Rn == REG_PC, BAD_PC);
11963 else
11964 reject_bad_reg (Rn);
11965 reject_bad_reg (Rm);
11966
c19d1205
ZW
11967 if (unified_syntax)
11968 {
11969 int r0off = (inst.instruction == T_MNEM_mvn
11970 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
11971 bfd_boolean narrow;
11972
11973 if (inst.size_req == 4
11974 || inst.instruction > 0xffff
11975 || inst.operands[1].shifted
fdfde340 11976 || Rn > 7 || Rm > 7)
3d388997 11977 narrow = FALSE;
fe8b4cc3
KT
11978 else if (inst.instruction == T_MNEM_cmn
11979 || inst.instruction == T_MNEM_tst)
3d388997
PB
11980 narrow = TRUE;
11981 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 11982 narrow = !in_it_block ();
3d388997 11983 else
e07e6e58 11984 narrow = in_it_block ();
3d388997 11985
c19d1205 11986 if (!inst.operands[1].isreg)
b99bd4ef 11987 {
c19d1205
ZW
11988 /* For an immediate, we always generate a 32-bit opcode;
11989 section relaxation will shrink it later if possible. */
11990 if (inst.instruction < 0xffff)
11991 inst.instruction = THUMB_OP32 (inst.instruction);
11992 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11993 inst.instruction |= Rn << r0off;
c19d1205 11994 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 11995 }
c19d1205 11996 else
b99bd4ef 11997 {
c19d1205 11998 /* See if we can do this with a 16-bit instruction. */
3d388997 11999 if (narrow)
b99bd4ef 12000 {
c19d1205 12001 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12002 inst.instruction |= Rn;
12003 inst.instruction |= Rm << 3;
b99bd4ef 12004 }
c19d1205 12005 else
b99bd4ef 12006 {
c19d1205
ZW
12007 constraint (inst.operands[1].shifted
12008 && inst.operands[1].immisreg,
12009 _("shift must be constant"));
12010 if (inst.instruction < 0xffff)
12011 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12012 inst.instruction |= Rn << r0off;
c19d1205 12013 encode_thumb32_shifted_operand (1);
b99bd4ef 12014 }
b99bd4ef
NC
12015 }
12016 }
12017 else
12018 {
c19d1205
ZW
12019 constraint (inst.instruction > 0xffff
12020 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12021 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12022 _("unshifted register required"));
fdfde340 12023 constraint (Rn > 7 || Rm > 7,
c19d1205 12024 BAD_HIREG);
b99bd4ef 12025
c19d1205 12026 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12027 inst.instruction |= Rn;
12028 inst.instruction |= Rm << 3;
b99bd4ef 12029 }
b99bd4ef
NC
12030}
12031
b05fe5cf 12032static void
c19d1205 12033do_t_mrs (void)
b05fe5cf 12034{
fdfde340 12035 unsigned Rd;
037e8744
JB
12036
12037 if (do_vfp_nsyn_mrs () == SUCCESS)
12038 return;
12039
90ec0d68
MGD
12040 Rd = inst.operands[0].reg;
12041 reject_bad_reg (Rd);
12042 inst.instruction |= Rd << 8;
12043
12044 if (inst.operands[1].isreg)
62b3e311 12045 {
90ec0d68
MGD
12046 unsigned br = inst.operands[1].reg;
12047 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12048 as_bad (_("bad register for mrs"));
12049
12050 inst.instruction |= br & (0xf << 16);
12051 inst.instruction |= (br & 0x300) >> 4;
12052 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12053 }
12054 else
12055 {
90ec0d68 12056 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12057
d2cd1205 12058 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12059 {
12060 /* PR gas/12698: The constraint is only applied for m_profile.
12061 If the user has specified -march=all, we want to ignore it as
12062 we are building for any CPU type, including non-m variants. */
823d2571
TG
12063 bfd_boolean m_profile =
12064 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12065 constraint ((flags != 0) && m_profile, _("selected processor does "
12066 "not support requested special purpose register"));
12067 }
90ec0d68 12068 else
d2cd1205
JB
12069 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12070 devices). */
12071 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12072 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12073
90ec0d68
MGD
12074 inst.instruction |= (flags & SPSR_BIT) >> 2;
12075 inst.instruction |= inst.operands[1].imm & 0xff;
12076 inst.instruction |= 0xf0000;
12077 }
c19d1205 12078}
b05fe5cf 12079
c19d1205
ZW
12080static void
12081do_t_msr (void)
12082{
62b3e311 12083 int flags;
fdfde340 12084 unsigned Rn;
62b3e311 12085
037e8744
JB
12086 if (do_vfp_nsyn_msr () == SUCCESS)
12087 return;
12088
c19d1205
ZW
12089 constraint (!inst.operands[1].isreg,
12090 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12091
12092 if (inst.operands[0].isreg)
12093 flags = (int)(inst.operands[0].reg);
12094 else
12095 flags = inst.operands[0].imm;
12096
d2cd1205 12097 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12098 {
d2cd1205
JB
12099 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12100
1a43faaf 12101 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12102 If the user has specified -march=all, we want to ignore it as
12103 we are building for any CPU type, including non-m variants. */
823d2571
TG
12104 bfd_boolean m_profile =
12105 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12106 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12107 && (bits & ~(PSR_s | PSR_f)) != 0)
12108 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12109 && bits != PSR_f)) && m_profile,
12110 _("selected processor does not support requested special "
12111 "purpose register"));
62b3e311
PB
12112 }
12113 else
d2cd1205
JB
12114 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12115 "requested special purpose register"));
c921be7d 12116
fdfde340
JM
12117 Rn = inst.operands[1].reg;
12118 reject_bad_reg (Rn);
12119
62b3e311 12120 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12121 inst.instruction |= (flags & 0xf0000) >> 8;
12122 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12123 inst.instruction |= (flags & 0xff);
fdfde340 12124 inst.instruction |= Rn << 16;
c19d1205 12125}
b05fe5cf 12126
c19d1205
ZW
12127static void
12128do_t_mul (void)
12129{
17828f45 12130 bfd_boolean narrow;
fdfde340 12131 unsigned Rd, Rn, Rm;
17828f45 12132
c19d1205
ZW
12133 if (!inst.operands[2].present)
12134 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12135
fdfde340
JM
12136 Rd = inst.operands[0].reg;
12137 Rn = inst.operands[1].reg;
12138 Rm = inst.operands[2].reg;
12139
17828f45 12140 if (unified_syntax)
b05fe5cf 12141 {
17828f45 12142 if (inst.size_req == 4
fdfde340
JM
12143 || (Rd != Rn
12144 && Rd != Rm)
12145 || Rn > 7
12146 || Rm > 7)
17828f45
JM
12147 narrow = FALSE;
12148 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12149 narrow = !in_it_block ();
17828f45 12150 else
e07e6e58 12151 narrow = in_it_block ();
b05fe5cf 12152 }
c19d1205 12153 else
b05fe5cf 12154 {
17828f45 12155 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12156 constraint (Rn > 7 || Rm > 7,
c19d1205 12157 BAD_HIREG);
17828f45
JM
12158 narrow = TRUE;
12159 }
b05fe5cf 12160
17828f45
JM
12161 if (narrow)
12162 {
12163 /* 16-bit MULS/Conditional MUL. */
c19d1205 12164 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12165 inst.instruction |= Rd;
b05fe5cf 12166
fdfde340
JM
12167 if (Rd == Rn)
12168 inst.instruction |= Rm << 3;
12169 else if (Rd == Rm)
12170 inst.instruction |= Rn << 3;
c19d1205
ZW
12171 else
12172 constraint (1, _("dest must overlap one source register"));
12173 }
17828f45
JM
12174 else
12175 {
e07e6e58
NC
12176 constraint (inst.instruction != T_MNEM_mul,
12177 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12178 /* 32-bit MUL. */
12179 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12180 inst.instruction |= Rd << 8;
12181 inst.instruction |= Rn << 16;
12182 inst.instruction |= Rm << 0;
12183
12184 reject_bad_reg (Rd);
12185 reject_bad_reg (Rn);
12186 reject_bad_reg (Rm);
17828f45 12187 }
c19d1205 12188}
b05fe5cf 12189
c19d1205
ZW
12190static void
12191do_t_mull (void)
12192{
fdfde340 12193 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12194
fdfde340
JM
12195 RdLo = inst.operands[0].reg;
12196 RdHi = inst.operands[1].reg;
12197 Rn = inst.operands[2].reg;
12198 Rm = inst.operands[3].reg;
12199
12200 reject_bad_reg (RdLo);
12201 reject_bad_reg (RdHi);
12202 reject_bad_reg (Rn);
12203 reject_bad_reg (Rm);
12204
12205 inst.instruction |= RdLo << 12;
12206 inst.instruction |= RdHi << 8;
12207 inst.instruction |= Rn << 16;
12208 inst.instruction |= Rm;
12209
12210 if (RdLo == RdHi)
c19d1205
ZW
12211 as_tsktsk (_("rdhi and rdlo must be different"));
12212}
b05fe5cf 12213
c19d1205
ZW
12214static void
12215do_t_nop (void)
12216{
e07e6e58
NC
12217 set_it_insn_type (NEUTRAL_IT_INSN);
12218
c19d1205
ZW
12219 if (unified_syntax)
12220 {
12221 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12222 {
c19d1205
ZW
12223 inst.instruction = THUMB_OP32 (inst.instruction);
12224 inst.instruction |= inst.operands[0].imm;
12225 }
12226 else
12227 {
bc2d1808
NC
12228 /* PR9722: Check for Thumb2 availability before
12229 generating a thumb2 nop instruction. */
afa62d5e 12230 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12231 {
12232 inst.instruction = THUMB_OP16 (inst.instruction);
12233 inst.instruction |= inst.operands[0].imm << 4;
12234 }
12235 else
12236 inst.instruction = 0x46c0;
c19d1205
ZW
12237 }
12238 }
12239 else
12240 {
12241 constraint (inst.operands[0].present,
12242 _("Thumb does not support NOP with hints"));
12243 inst.instruction = 0x46c0;
12244 }
12245}
b05fe5cf 12246
c19d1205
ZW
12247static void
12248do_t_neg (void)
12249{
12250 if (unified_syntax)
12251 {
3d388997
PB
12252 bfd_boolean narrow;
12253
12254 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12255 narrow = !in_it_block ();
3d388997 12256 else
e07e6e58 12257 narrow = in_it_block ();
3d388997
PB
12258 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12259 narrow = FALSE;
12260 if (inst.size_req == 4)
12261 narrow = FALSE;
12262
12263 if (!narrow)
c19d1205
ZW
12264 {
12265 inst.instruction = THUMB_OP32 (inst.instruction);
12266 inst.instruction |= inst.operands[0].reg << 8;
12267 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12268 }
12269 else
12270 {
c19d1205
ZW
12271 inst.instruction = THUMB_OP16 (inst.instruction);
12272 inst.instruction |= inst.operands[0].reg;
12273 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12274 }
12275 }
12276 else
12277 {
c19d1205
ZW
12278 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12279 BAD_HIREG);
12280 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12281
12282 inst.instruction = THUMB_OP16 (inst.instruction);
12283 inst.instruction |= inst.operands[0].reg;
12284 inst.instruction |= inst.operands[1].reg << 3;
12285 }
12286}
12287
1c444d06
JM
12288static void
12289do_t_orn (void)
12290{
12291 unsigned Rd, Rn;
12292
12293 Rd = inst.operands[0].reg;
12294 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12295
fdfde340
JM
12296 reject_bad_reg (Rd);
12297 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12298 reject_bad_reg (Rn);
12299
1c444d06
JM
12300 inst.instruction |= Rd << 8;
12301 inst.instruction |= Rn << 16;
12302
12303 if (!inst.operands[2].isreg)
12304 {
12305 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12306 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12307 }
12308 else
12309 {
12310 unsigned Rm;
12311
12312 Rm = inst.operands[2].reg;
fdfde340 12313 reject_bad_reg (Rm);
1c444d06
JM
12314
12315 constraint (inst.operands[2].shifted
12316 && inst.operands[2].immisreg,
12317 _("shift must be constant"));
12318 encode_thumb32_shifted_operand (2);
12319 }
12320}
12321
c19d1205
ZW
12322static void
12323do_t_pkhbt (void)
12324{
fdfde340
JM
12325 unsigned Rd, Rn, Rm;
12326
12327 Rd = inst.operands[0].reg;
12328 Rn = inst.operands[1].reg;
12329 Rm = inst.operands[2].reg;
12330
12331 reject_bad_reg (Rd);
12332 reject_bad_reg (Rn);
12333 reject_bad_reg (Rm);
12334
12335 inst.instruction |= Rd << 8;
12336 inst.instruction |= Rn << 16;
12337 inst.instruction |= Rm;
c19d1205
ZW
12338 if (inst.operands[3].present)
12339 {
12340 unsigned int val = inst.reloc.exp.X_add_number;
12341 constraint (inst.reloc.exp.X_op != O_constant,
12342 _("expression too complex"));
12343 inst.instruction |= (val & 0x1c) << 10;
12344 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12345 }
c19d1205 12346}
b05fe5cf 12347
c19d1205
ZW
12348static void
12349do_t_pkhtb (void)
12350{
12351 if (!inst.operands[3].present)
1ef52f49
NC
12352 {
12353 unsigned Rtmp;
12354
12355 inst.instruction &= ~0x00000020;
12356
12357 /* PR 10168. Swap the Rm and Rn registers. */
12358 Rtmp = inst.operands[1].reg;
12359 inst.operands[1].reg = inst.operands[2].reg;
12360 inst.operands[2].reg = Rtmp;
12361 }
c19d1205 12362 do_t_pkhbt ();
b05fe5cf
ZW
12363}
12364
c19d1205
ZW
12365static void
12366do_t_pld (void)
12367{
fdfde340
JM
12368 if (inst.operands[0].immisreg)
12369 reject_bad_reg (inst.operands[0].imm);
12370
c19d1205
ZW
12371 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12372}
b05fe5cf 12373
c19d1205
ZW
12374static void
12375do_t_push_pop (void)
b99bd4ef 12376{
e9f89963 12377 unsigned mask;
5f4273c7 12378
c19d1205
ZW
12379 constraint (inst.operands[0].writeback,
12380 _("push/pop do not support {reglist}^"));
12381 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12382 _("expression too complex"));
b99bd4ef 12383
e9f89963 12384 mask = inst.operands[0].imm;
d3bfe16e 12385 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12386 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e
JB
12387 else if (inst.size_req != 4
12388 && (mask & ~0xff) == (1 << (inst.instruction == T_MNEM_push
12389 ? REG_LR : REG_PC)))
b99bd4ef 12390 {
c19d1205
ZW
12391 inst.instruction = THUMB_OP16 (inst.instruction);
12392 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12393 inst.instruction |= mask & 0xff;
c19d1205
ZW
12394 }
12395 else if (unified_syntax)
12396 {
3c707909 12397 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12398 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12399 }
12400 else
12401 {
12402 inst.error = _("invalid register list to push/pop instruction");
12403 return;
12404 }
c19d1205 12405}
b99bd4ef 12406
c19d1205
ZW
12407static void
12408do_t_rbit (void)
12409{
fdfde340
JM
12410 unsigned Rd, Rm;
12411
12412 Rd = inst.operands[0].reg;
12413 Rm = inst.operands[1].reg;
12414
12415 reject_bad_reg (Rd);
12416 reject_bad_reg (Rm);
12417
12418 inst.instruction |= Rd << 8;
12419 inst.instruction |= Rm << 16;
12420 inst.instruction |= Rm;
c19d1205 12421}
b99bd4ef 12422
c19d1205
ZW
12423static void
12424do_t_rev (void)
12425{
fdfde340
JM
12426 unsigned Rd, Rm;
12427
12428 Rd = inst.operands[0].reg;
12429 Rm = inst.operands[1].reg;
12430
12431 reject_bad_reg (Rd);
12432 reject_bad_reg (Rm);
12433
12434 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12435 && inst.size_req != 4)
12436 {
12437 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12438 inst.instruction |= Rd;
12439 inst.instruction |= Rm << 3;
c19d1205
ZW
12440 }
12441 else if (unified_syntax)
12442 {
12443 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12444 inst.instruction |= Rd << 8;
12445 inst.instruction |= Rm << 16;
12446 inst.instruction |= Rm;
c19d1205
ZW
12447 }
12448 else
12449 inst.error = BAD_HIREG;
12450}
b99bd4ef 12451
1c444d06
JM
12452static void
12453do_t_rrx (void)
12454{
12455 unsigned Rd, Rm;
12456
12457 Rd = inst.operands[0].reg;
12458 Rm = inst.operands[1].reg;
12459
fdfde340
JM
12460 reject_bad_reg (Rd);
12461 reject_bad_reg (Rm);
c921be7d 12462
1c444d06
JM
12463 inst.instruction |= Rd << 8;
12464 inst.instruction |= Rm;
12465}
12466
c19d1205
ZW
12467static void
12468do_t_rsb (void)
12469{
fdfde340 12470 unsigned Rd, Rs;
b99bd4ef 12471
c19d1205
ZW
12472 Rd = inst.operands[0].reg;
12473 Rs = (inst.operands[1].present
12474 ? inst.operands[1].reg /* Rd, Rs, foo */
12475 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12476
fdfde340
JM
12477 reject_bad_reg (Rd);
12478 reject_bad_reg (Rs);
12479 if (inst.operands[2].isreg)
12480 reject_bad_reg (inst.operands[2].reg);
12481
c19d1205
ZW
12482 inst.instruction |= Rd << 8;
12483 inst.instruction |= Rs << 16;
12484 if (!inst.operands[2].isreg)
12485 {
026d3abb
PB
12486 bfd_boolean narrow;
12487
12488 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12489 narrow = !in_it_block ();
026d3abb 12490 else
e07e6e58 12491 narrow = in_it_block ();
026d3abb
PB
12492
12493 if (Rd > 7 || Rs > 7)
12494 narrow = FALSE;
12495
12496 if (inst.size_req == 4 || !unified_syntax)
12497 narrow = FALSE;
12498
12499 if (inst.reloc.exp.X_op != O_constant
12500 || inst.reloc.exp.X_add_number != 0)
12501 narrow = FALSE;
12502
12503 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12504 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12505 if (narrow)
12506 {
12507 inst.reloc.type = BFD_RELOC_UNUSED;
12508 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12509 inst.instruction |= Rs << 3;
12510 inst.instruction |= Rd;
12511 }
12512 else
12513 {
12514 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12515 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12516 }
c19d1205
ZW
12517 }
12518 else
12519 encode_thumb32_shifted_operand (2);
12520}
b99bd4ef 12521
c19d1205
ZW
12522static void
12523do_t_setend (void)
12524{
12e37cbc
MGD
12525 if (warn_on_deprecated
12526 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12527 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12528
e07e6e58 12529 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12530 if (inst.operands[0].imm)
12531 inst.instruction |= 0x8;
12532}
b99bd4ef 12533
c19d1205
ZW
12534static void
12535do_t_shift (void)
12536{
12537 if (!inst.operands[1].present)
12538 inst.operands[1].reg = inst.operands[0].reg;
12539
12540 if (unified_syntax)
12541 {
3d388997
PB
12542 bfd_boolean narrow;
12543 int shift_kind;
12544
12545 switch (inst.instruction)
12546 {
12547 case T_MNEM_asr:
12548 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12549 case T_MNEM_lsl:
12550 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12551 case T_MNEM_lsr:
12552 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12553 case T_MNEM_ror:
12554 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12555 default: abort ();
12556 }
12557
12558 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12559 narrow = !in_it_block ();
3d388997 12560 else
e07e6e58 12561 narrow = in_it_block ();
3d388997
PB
12562 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12563 narrow = FALSE;
12564 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12565 narrow = FALSE;
12566 if (inst.operands[2].isreg
12567 && (inst.operands[1].reg != inst.operands[0].reg
12568 || inst.operands[2].reg > 7))
12569 narrow = FALSE;
12570 if (inst.size_req == 4)
12571 narrow = FALSE;
12572
fdfde340
JM
12573 reject_bad_reg (inst.operands[0].reg);
12574 reject_bad_reg (inst.operands[1].reg);
c921be7d 12575
3d388997 12576 if (!narrow)
c19d1205
ZW
12577 {
12578 if (inst.operands[2].isreg)
b99bd4ef 12579 {
fdfde340 12580 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12581 inst.instruction = THUMB_OP32 (inst.instruction);
12582 inst.instruction |= inst.operands[0].reg << 8;
12583 inst.instruction |= inst.operands[1].reg << 16;
12584 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12585
12586 /* PR 12854: Error on extraneous shifts. */
12587 constraint (inst.operands[2].shifted,
12588 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12589 }
12590 else
12591 {
12592 inst.operands[1].shifted = 1;
3d388997 12593 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12594 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12595 ? T_MNEM_movs : T_MNEM_mov);
12596 inst.instruction |= inst.operands[0].reg << 8;
12597 encode_thumb32_shifted_operand (1);
12598 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12599 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12600 }
12601 }
12602 else
12603 {
c19d1205 12604 if (inst.operands[2].isreg)
b99bd4ef 12605 {
3d388997 12606 switch (shift_kind)
b99bd4ef 12607 {
3d388997
PB
12608 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12609 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12610 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12611 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12612 default: abort ();
b99bd4ef 12613 }
5f4273c7 12614
c19d1205
ZW
12615 inst.instruction |= inst.operands[0].reg;
12616 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12617
12618 /* PR 12854: Error on extraneous shifts. */
12619 constraint (inst.operands[2].shifted,
12620 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12621 }
12622 else
12623 {
3d388997 12624 switch (shift_kind)
b99bd4ef 12625 {
3d388997
PB
12626 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12627 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12628 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12629 default: abort ();
b99bd4ef 12630 }
c19d1205
ZW
12631 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12632 inst.instruction |= inst.operands[0].reg;
12633 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12634 }
12635 }
c19d1205
ZW
12636 }
12637 else
12638 {
12639 constraint (inst.operands[0].reg > 7
12640 || inst.operands[1].reg > 7, BAD_HIREG);
12641 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12642
c19d1205
ZW
12643 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12644 {
12645 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12646 constraint (inst.operands[0].reg != inst.operands[1].reg,
12647 _("source1 and dest must be same register"));
b99bd4ef 12648
c19d1205
ZW
12649 switch (inst.instruction)
12650 {
12651 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12652 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12653 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12654 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12655 default: abort ();
12656 }
5f4273c7 12657
c19d1205
ZW
12658 inst.instruction |= inst.operands[0].reg;
12659 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12660
12661 /* PR 12854: Error on extraneous shifts. */
12662 constraint (inst.operands[2].shifted,
12663 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12664 }
12665 else
b99bd4ef 12666 {
c19d1205
ZW
12667 switch (inst.instruction)
12668 {
12669 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12670 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12671 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12672 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12673 default: abort ();
12674 }
12675 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12676 inst.instruction |= inst.operands[0].reg;
12677 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12678 }
12679 }
b99bd4ef
NC
12680}
12681
12682static void
c19d1205 12683do_t_simd (void)
b99bd4ef 12684{
fdfde340
JM
12685 unsigned Rd, Rn, Rm;
12686
12687 Rd = inst.operands[0].reg;
12688 Rn = inst.operands[1].reg;
12689 Rm = inst.operands[2].reg;
12690
12691 reject_bad_reg (Rd);
12692 reject_bad_reg (Rn);
12693 reject_bad_reg (Rm);
12694
12695 inst.instruction |= Rd << 8;
12696 inst.instruction |= Rn << 16;
12697 inst.instruction |= Rm;
c19d1205 12698}
b99bd4ef 12699
03ee1b7f
NC
12700static void
12701do_t_simd2 (void)
12702{
12703 unsigned Rd, Rn, Rm;
12704
12705 Rd = inst.operands[0].reg;
12706 Rm = inst.operands[1].reg;
12707 Rn = inst.operands[2].reg;
12708
12709 reject_bad_reg (Rd);
12710 reject_bad_reg (Rn);
12711 reject_bad_reg (Rm);
12712
12713 inst.instruction |= Rd << 8;
12714 inst.instruction |= Rn << 16;
12715 inst.instruction |= Rm;
12716}
12717
c19d1205 12718static void
3eb17e6b 12719do_t_smc (void)
c19d1205
ZW
12720{
12721 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
12722 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12723 _("SMC is not permitted on this architecture"));
c19d1205
ZW
12724 constraint (inst.reloc.exp.X_op != O_constant,
12725 _("expression too complex"));
12726 inst.reloc.type = BFD_RELOC_UNUSED;
12727 inst.instruction |= (value & 0xf000) >> 12;
12728 inst.instruction |= (value & 0x0ff0);
12729 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
12730 /* PR gas/15623: SMC instructions must be last in an IT block. */
12731 set_it_insn_type_last ();
c19d1205 12732}
b99bd4ef 12733
90ec0d68
MGD
12734static void
12735do_t_hvc (void)
12736{
12737 unsigned int value = inst.reloc.exp.X_add_number;
12738
12739 inst.reloc.type = BFD_RELOC_UNUSED;
12740 inst.instruction |= (value & 0x0fff);
12741 inst.instruction |= (value & 0xf000) << 4;
12742}
12743
c19d1205 12744static void
3a21c15a 12745do_t_ssat_usat (int bias)
c19d1205 12746{
fdfde340
JM
12747 unsigned Rd, Rn;
12748
12749 Rd = inst.operands[0].reg;
12750 Rn = inst.operands[2].reg;
12751
12752 reject_bad_reg (Rd);
12753 reject_bad_reg (Rn);
12754
12755 inst.instruction |= Rd << 8;
3a21c15a 12756 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 12757 inst.instruction |= Rn << 16;
b99bd4ef 12758
c19d1205 12759 if (inst.operands[3].present)
b99bd4ef 12760 {
3a21c15a
NC
12761 offsetT shift_amount = inst.reloc.exp.X_add_number;
12762
12763 inst.reloc.type = BFD_RELOC_UNUSED;
12764
c19d1205
ZW
12765 constraint (inst.reloc.exp.X_op != O_constant,
12766 _("expression too complex"));
b99bd4ef 12767
3a21c15a 12768 if (shift_amount != 0)
6189168b 12769 {
3a21c15a
NC
12770 constraint (shift_amount > 31,
12771 _("shift expression is too large"));
12772
c19d1205 12773 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
12774 inst.instruction |= 0x00200000; /* sh bit. */
12775
12776 inst.instruction |= (shift_amount & 0x1c) << 10;
12777 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
12778 }
12779 }
b99bd4ef 12780}
c921be7d 12781
3a21c15a
NC
12782static void
12783do_t_ssat (void)
12784{
12785 do_t_ssat_usat (1);
12786}
b99bd4ef 12787
0dd132b6 12788static void
c19d1205 12789do_t_ssat16 (void)
0dd132b6 12790{
fdfde340
JM
12791 unsigned Rd, Rn;
12792
12793 Rd = inst.operands[0].reg;
12794 Rn = inst.operands[2].reg;
12795
12796 reject_bad_reg (Rd);
12797 reject_bad_reg (Rn);
12798
12799 inst.instruction |= Rd << 8;
c19d1205 12800 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 12801 inst.instruction |= Rn << 16;
c19d1205 12802}
0dd132b6 12803
c19d1205
ZW
12804static void
12805do_t_strex (void)
12806{
12807 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
12808 || inst.operands[2].postind || inst.operands[2].writeback
12809 || inst.operands[2].immisreg || inst.operands[2].shifted
12810 || inst.operands[2].negative,
01cfc07f 12811 BAD_ADDR_MODE);
0dd132b6 12812
5be8be5d
DG
12813 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
12814
c19d1205
ZW
12815 inst.instruction |= inst.operands[0].reg << 8;
12816 inst.instruction |= inst.operands[1].reg << 12;
12817 inst.instruction |= inst.operands[2].reg << 16;
12818 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
12819}
12820
b99bd4ef 12821static void
c19d1205 12822do_t_strexd (void)
b99bd4ef 12823{
c19d1205
ZW
12824 if (!inst.operands[2].present)
12825 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 12826
c19d1205
ZW
12827 constraint (inst.operands[0].reg == inst.operands[1].reg
12828 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 12829 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 12830 BAD_OVERLAP);
b99bd4ef 12831
c19d1205
ZW
12832 inst.instruction |= inst.operands[0].reg;
12833 inst.instruction |= inst.operands[1].reg << 12;
12834 inst.instruction |= inst.operands[2].reg << 8;
12835 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
12836}
12837
12838static void
c19d1205 12839do_t_sxtah (void)
b99bd4ef 12840{
fdfde340
JM
12841 unsigned Rd, Rn, Rm;
12842
12843 Rd = inst.operands[0].reg;
12844 Rn = inst.operands[1].reg;
12845 Rm = inst.operands[2].reg;
12846
12847 reject_bad_reg (Rd);
12848 reject_bad_reg (Rn);
12849 reject_bad_reg (Rm);
12850
12851 inst.instruction |= Rd << 8;
12852 inst.instruction |= Rn << 16;
12853 inst.instruction |= Rm;
c19d1205
ZW
12854 inst.instruction |= inst.operands[3].imm << 4;
12855}
b99bd4ef 12856
c19d1205
ZW
12857static void
12858do_t_sxth (void)
12859{
fdfde340
JM
12860 unsigned Rd, Rm;
12861
12862 Rd = inst.operands[0].reg;
12863 Rm = inst.operands[1].reg;
12864
12865 reject_bad_reg (Rd);
12866 reject_bad_reg (Rm);
c921be7d
NC
12867
12868 if (inst.instruction <= 0xffff
12869 && inst.size_req != 4
fdfde340 12870 && Rd <= 7 && Rm <= 7
c19d1205 12871 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 12872 {
c19d1205 12873 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12874 inst.instruction |= Rd;
12875 inst.instruction |= Rm << 3;
b99bd4ef 12876 }
c19d1205 12877 else if (unified_syntax)
b99bd4ef 12878 {
c19d1205
ZW
12879 if (inst.instruction <= 0xffff)
12880 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12881 inst.instruction |= Rd << 8;
12882 inst.instruction |= Rm;
c19d1205 12883 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 12884 }
c19d1205 12885 else
b99bd4ef 12886 {
c19d1205
ZW
12887 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
12888 _("Thumb encoding does not support rotation"));
12889 constraint (1, BAD_HIREG);
b99bd4ef 12890 }
c19d1205 12891}
b99bd4ef 12892
c19d1205
ZW
12893static void
12894do_t_swi (void)
12895{
b2a5fbdc
MGD
12896 /* We have to do the following check manually as ARM_EXT_OS only applies
12897 to ARM_EXT_V6M. */
12898 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
12899 {
ac7f631b
NC
12900 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
12901 /* This only applies to the v6m howver, not later architectures. */
12902 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
12903 as_bad (_("SVC is not permitted on this architecture"));
12904 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
12905 }
12906
c19d1205
ZW
12907 inst.reloc.type = BFD_RELOC_ARM_SWI;
12908}
b99bd4ef 12909
92e90b6e
PB
12910static void
12911do_t_tb (void)
12912{
fdfde340 12913 unsigned Rn, Rm;
92e90b6e
PB
12914 int half;
12915
12916 half = (inst.instruction & 0x10) != 0;
e07e6e58 12917 set_it_insn_type_last ();
dfa9f0d5
PB
12918 constraint (inst.operands[0].immisreg,
12919 _("instruction requires register index"));
fdfde340
JM
12920
12921 Rn = inst.operands[0].reg;
12922 Rm = inst.operands[0].imm;
c921be7d 12923
fdfde340
JM
12924 constraint (Rn == REG_SP, BAD_SP);
12925 reject_bad_reg (Rm);
12926
92e90b6e
PB
12927 constraint (!half && inst.operands[0].shifted,
12928 _("instruction does not allow shifted index"));
fdfde340 12929 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
12930}
12931
74db7efb
NC
12932static void
12933do_t_udf (void)
12934{
12935 if (!inst.operands[0].present)
12936 inst.operands[0].imm = 0;
12937
12938 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
12939 {
12940 constraint (inst.size_req == 2,
12941 _("immediate value out of range"));
12942 inst.instruction = THUMB_OP32 (inst.instruction);
12943 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
12944 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
12945 }
12946 else
12947 {
12948 inst.instruction = THUMB_OP16 (inst.instruction);
12949 inst.instruction |= inst.operands[0].imm;
12950 }
12951
12952 set_it_insn_type (NEUTRAL_IT_INSN);
12953}
12954
12955
c19d1205
ZW
12956static void
12957do_t_usat (void)
12958{
3a21c15a 12959 do_t_ssat_usat (0);
b99bd4ef
NC
12960}
12961
12962static void
c19d1205 12963do_t_usat16 (void)
b99bd4ef 12964{
fdfde340
JM
12965 unsigned Rd, Rn;
12966
12967 Rd = inst.operands[0].reg;
12968 Rn = inst.operands[2].reg;
12969
12970 reject_bad_reg (Rd);
12971 reject_bad_reg (Rn);
12972
12973 inst.instruction |= Rd << 8;
c19d1205 12974 inst.instruction |= inst.operands[1].imm;
fdfde340 12975 inst.instruction |= Rn << 16;
b99bd4ef 12976}
c19d1205 12977
5287ad62 12978/* Neon instruction encoder helpers. */
5f4273c7 12979
5287ad62 12980/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 12981
5287ad62
JB
12982/* An "invalid" code for the following tables. */
12983#define N_INV -1u
12984
12985struct neon_tab_entry
b99bd4ef 12986{
5287ad62
JB
12987 unsigned integer;
12988 unsigned float_or_poly;
12989 unsigned scalar_or_imm;
12990};
5f4273c7 12991
5287ad62
JB
12992/* Map overloaded Neon opcodes to their respective encodings. */
12993#define NEON_ENC_TAB \
12994 X(vabd, 0x0000700, 0x1200d00, N_INV), \
12995 X(vmax, 0x0000600, 0x0000f00, N_INV), \
12996 X(vmin, 0x0000610, 0x0200f00, N_INV), \
12997 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
12998 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
12999 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13000 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13001 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13002 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13003 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13004 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13005 /* Register variants of the following two instructions are encoded as
e07e6e58 13006 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13007 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13008 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13009 X(vfma, N_INV, 0x0000c10, N_INV), \
13010 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13011 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13012 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13013 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13014 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13015 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13016 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13017 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13018 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13019 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13020 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13021 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13022 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13023 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13024 X(vshl, 0x0000400, N_INV, 0x0800510), \
13025 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13026 X(vand, 0x0000110, N_INV, 0x0800030), \
13027 X(vbic, 0x0100110, N_INV, 0x0800030), \
13028 X(veor, 0x1000110, N_INV, N_INV), \
13029 X(vorn, 0x0300110, N_INV, 0x0800010), \
13030 X(vorr, 0x0200110, N_INV, 0x0800010), \
13031 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13032 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13033 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13034 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13035 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13036 X(vst1, 0x0000000, 0x0800000, N_INV), \
13037 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13038 X(vst2, 0x0000100, 0x0800100, N_INV), \
13039 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13040 X(vst3, 0x0000200, 0x0800200, N_INV), \
13041 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13042 X(vst4, 0x0000300, 0x0800300, N_INV), \
13043 X(vmovn, 0x1b20200, N_INV, N_INV), \
13044 X(vtrn, 0x1b20080, N_INV, N_INV), \
13045 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13046 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13047 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13048 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13049 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13050 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13051 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13052 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13053 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13054 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13055 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13056 X(vseleq, 0xe000a00, N_INV, N_INV), \
13057 X(vselvs, 0xe100a00, N_INV, N_INV), \
13058 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13059 X(vselgt, 0xe300a00, N_INV, N_INV), \
13060 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13061 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13062 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13063 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13064 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13065 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13066 X(sha3op, 0x2000c00, N_INV, N_INV), \
13067 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13068 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13069
13070enum neon_opc
13071{
13072#define X(OPC,I,F,S) N_MNEM_##OPC
13073NEON_ENC_TAB
13074#undef X
13075};
b99bd4ef 13076
5287ad62
JB
13077static const struct neon_tab_entry neon_enc_tab[] =
13078{
13079#define X(OPC,I,F,S) { (I), (F), (S) }
13080NEON_ENC_TAB
13081#undef X
13082};
b99bd4ef 13083
88714cb8
DG
13084/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13085#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13086#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13087#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13088#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13089#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13090#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13091#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13092#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13093#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13094#define NEON_ENC_SINGLE_(X) \
037e8744 13095 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13096#define NEON_ENC_DOUBLE_(X) \
037e8744 13097 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13098#define NEON_ENC_FPV8_(X) \
13099 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13100
88714cb8
DG
13101#define NEON_ENCODE(type, inst) \
13102 do \
13103 { \
13104 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13105 inst.is_neon = 1; \
13106 } \
13107 while (0)
13108
13109#define check_neon_suffixes \
13110 do \
13111 { \
13112 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13113 { \
13114 as_bad (_("invalid neon suffix for non neon instruction")); \
13115 return; \
13116 } \
13117 } \
13118 while (0)
13119
037e8744
JB
13120/* Define shapes for instruction operands. The following mnemonic characters
13121 are used in this table:
5287ad62 13122
037e8744 13123 F - VFP S<n> register
5287ad62
JB
13124 D - Neon D<n> register
13125 Q - Neon Q<n> register
13126 I - Immediate
13127 S - Scalar
13128 R - ARM register
13129 L - D<n> register list
5f4273c7 13130
037e8744
JB
13131 This table is used to generate various data:
13132 - enumerations of the form NS_DDR to be used as arguments to
13133 neon_select_shape.
13134 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13135 - a table used to drive neon_select_shape. */
b99bd4ef 13136
037e8744
JB
13137#define NEON_SHAPE_DEF \
13138 X(3, (D, D, D), DOUBLE), \
13139 X(3, (Q, Q, Q), QUAD), \
13140 X(3, (D, D, I), DOUBLE), \
13141 X(3, (Q, Q, I), QUAD), \
13142 X(3, (D, D, S), DOUBLE), \
13143 X(3, (Q, Q, S), QUAD), \
13144 X(2, (D, D), DOUBLE), \
13145 X(2, (Q, Q), QUAD), \
13146 X(2, (D, S), DOUBLE), \
13147 X(2, (Q, S), QUAD), \
13148 X(2, (D, R), DOUBLE), \
13149 X(2, (Q, R), QUAD), \
13150 X(2, (D, I), DOUBLE), \
13151 X(2, (Q, I), QUAD), \
13152 X(3, (D, L, D), DOUBLE), \
13153 X(2, (D, Q), MIXED), \
13154 X(2, (Q, D), MIXED), \
13155 X(3, (D, Q, I), MIXED), \
13156 X(3, (Q, D, I), MIXED), \
13157 X(3, (Q, D, D), MIXED), \
13158 X(3, (D, Q, Q), MIXED), \
13159 X(3, (Q, Q, D), MIXED), \
13160 X(3, (Q, D, S), MIXED), \
13161 X(3, (D, Q, S), MIXED), \
13162 X(4, (D, D, D, I), DOUBLE), \
13163 X(4, (Q, Q, Q, I), QUAD), \
13164 X(2, (F, F), SINGLE), \
13165 X(3, (F, F, F), SINGLE), \
13166 X(2, (F, I), SINGLE), \
13167 X(2, (F, D), MIXED), \
13168 X(2, (D, F), MIXED), \
13169 X(3, (F, F, I), MIXED), \
13170 X(4, (R, R, F, F), SINGLE), \
13171 X(4, (F, F, R, R), SINGLE), \
13172 X(3, (D, R, R), DOUBLE), \
13173 X(3, (R, R, D), DOUBLE), \
13174 X(2, (S, R), SINGLE), \
13175 X(2, (R, S), SINGLE), \
13176 X(2, (F, R), SINGLE), \
13177 X(2, (R, F), SINGLE)
13178
13179#define S2(A,B) NS_##A##B
13180#define S3(A,B,C) NS_##A##B##C
13181#define S4(A,B,C,D) NS_##A##B##C##D
13182
13183#define X(N, L, C) S##N L
13184
5287ad62
JB
13185enum neon_shape
13186{
037e8744
JB
13187 NEON_SHAPE_DEF,
13188 NS_NULL
5287ad62 13189};
b99bd4ef 13190
037e8744
JB
13191#undef X
13192#undef S2
13193#undef S3
13194#undef S4
13195
13196enum neon_shape_class
13197{
13198 SC_SINGLE,
13199 SC_DOUBLE,
13200 SC_QUAD,
13201 SC_MIXED
13202};
13203
13204#define X(N, L, C) SC_##C
13205
13206static enum neon_shape_class neon_shape_class[] =
13207{
13208 NEON_SHAPE_DEF
13209};
13210
13211#undef X
13212
13213enum neon_shape_el
13214{
13215 SE_F,
13216 SE_D,
13217 SE_Q,
13218 SE_I,
13219 SE_S,
13220 SE_R,
13221 SE_L
13222};
13223
13224/* Register widths of above. */
13225static unsigned neon_shape_el_size[] =
13226{
13227 32,
13228 64,
13229 128,
13230 0,
13231 32,
13232 32,
13233 0
13234};
13235
13236struct neon_shape_info
13237{
13238 unsigned els;
13239 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13240};
13241
13242#define S2(A,B) { SE_##A, SE_##B }
13243#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13244#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13245
13246#define X(N, L, C) { N, S##N L }
13247
13248static struct neon_shape_info neon_shape_tab[] =
13249{
13250 NEON_SHAPE_DEF
13251};
13252
13253#undef X
13254#undef S2
13255#undef S3
13256#undef S4
13257
5287ad62
JB
13258/* Bit masks used in type checking given instructions.
13259 'N_EQK' means the type must be the same as (or based on in some way) the key
13260 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13261 set, various other bits can be set as well in order to modify the meaning of
13262 the type constraint. */
13263
13264enum neon_type_mask
13265{
8e79c3df
CM
13266 N_S8 = 0x0000001,
13267 N_S16 = 0x0000002,
13268 N_S32 = 0x0000004,
13269 N_S64 = 0x0000008,
13270 N_U8 = 0x0000010,
13271 N_U16 = 0x0000020,
13272 N_U32 = 0x0000040,
13273 N_U64 = 0x0000080,
13274 N_I8 = 0x0000100,
13275 N_I16 = 0x0000200,
13276 N_I32 = 0x0000400,
13277 N_I64 = 0x0000800,
13278 N_8 = 0x0001000,
13279 N_16 = 0x0002000,
13280 N_32 = 0x0004000,
13281 N_64 = 0x0008000,
13282 N_P8 = 0x0010000,
13283 N_P16 = 0x0020000,
13284 N_F16 = 0x0040000,
13285 N_F32 = 0x0080000,
13286 N_F64 = 0x0100000,
4f51b4bd 13287 N_P64 = 0x0200000,
c921be7d
NC
13288 N_KEY = 0x1000000, /* Key element (main type specifier). */
13289 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13290 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13291 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13292 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13293 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13294 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13295 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13296 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13297 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13298 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13299 N_UTYP = 0,
4f51b4bd 13300 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13301};
13302
dcbf9037
JB
13303#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13304
5287ad62
JB
13305#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13306#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13307#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
13308#define N_SUF_32 (N_SU_32 | N_F32)
13309#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
13310#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
13311
13312/* Pass this as the first type argument to neon_check_type to ignore types
13313 altogether. */
13314#define N_IGNORE_TYPE (N_KEY | N_EQK)
13315
037e8744
JB
13316/* Select a "shape" for the current instruction (describing register types or
13317 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13318 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13319 function of operand parsing, so this function doesn't need to be called.
13320 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13321
13322static enum neon_shape
037e8744 13323neon_select_shape (enum neon_shape shape, ...)
5287ad62 13324{
037e8744
JB
13325 va_list ap;
13326 enum neon_shape first_shape = shape;
5287ad62
JB
13327
13328 /* Fix missing optional operands. FIXME: we don't know at this point how
13329 many arguments we should have, so this makes the assumption that we have
13330 > 1. This is true of all current Neon opcodes, I think, but may not be
13331 true in the future. */
13332 if (!inst.operands[1].present)
13333 inst.operands[1] = inst.operands[0];
13334
037e8744 13335 va_start (ap, shape);
5f4273c7 13336
21d799b5 13337 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13338 {
13339 unsigned j;
13340 int matches = 1;
13341
13342 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13343 {
13344 if (!inst.operands[j].present)
13345 {
13346 matches = 0;
13347 break;
13348 }
13349
13350 switch (neon_shape_tab[shape].el[j])
13351 {
13352 case SE_F:
13353 if (!(inst.operands[j].isreg
13354 && inst.operands[j].isvec
13355 && inst.operands[j].issingle
13356 && !inst.operands[j].isquad))
13357 matches = 0;
13358 break;
13359
13360 case SE_D:
13361 if (!(inst.operands[j].isreg
13362 && inst.operands[j].isvec
13363 && !inst.operands[j].isquad
13364 && !inst.operands[j].issingle))
13365 matches = 0;
13366 break;
13367
13368 case SE_R:
13369 if (!(inst.operands[j].isreg
13370 && !inst.operands[j].isvec))
13371 matches = 0;
13372 break;
13373
13374 case SE_Q:
13375 if (!(inst.operands[j].isreg
13376 && inst.operands[j].isvec
13377 && inst.operands[j].isquad
13378 && !inst.operands[j].issingle))
13379 matches = 0;
13380 break;
13381
13382 case SE_I:
13383 if (!(!inst.operands[j].isreg
13384 && !inst.operands[j].isscalar))
13385 matches = 0;
13386 break;
13387
13388 case SE_S:
13389 if (!(!inst.operands[j].isreg
13390 && inst.operands[j].isscalar))
13391 matches = 0;
13392 break;
13393
13394 case SE_L:
13395 break;
13396 }
3fde54a2
JZ
13397 if (!matches)
13398 break;
477330fc 13399 }
ad6cec43
MGD
13400 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13401 /* We've matched all the entries in the shape table, and we don't
13402 have any left over operands which have not been matched. */
477330fc 13403 break;
037e8744 13404 }
5f4273c7 13405
037e8744 13406 va_end (ap);
5287ad62 13407
037e8744
JB
13408 if (shape == NS_NULL && first_shape != NS_NULL)
13409 first_error (_("invalid instruction shape"));
5287ad62 13410
037e8744
JB
13411 return shape;
13412}
5287ad62 13413
037e8744
JB
13414/* True if SHAPE is predominantly a quadword operation (most of the time, this
13415 means the Q bit should be set). */
13416
13417static int
13418neon_quad (enum neon_shape shape)
13419{
13420 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13421}
037e8744 13422
5287ad62
JB
13423static void
13424neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13425 unsigned *g_size)
5287ad62
JB
13426{
13427 /* Allow modification to be made to types which are constrained to be
13428 based on the key element, based on bits set alongside N_EQK. */
13429 if ((typebits & N_EQK) != 0)
13430 {
13431 if ((typebits & N_HLF) != 0)
13432 *g_size /= 2;
13433 else if ((typebits & N_DBL) != 0)
13434 *g_size *= 2;
13435 if ((typebits & N_SGN) != 0)
13436 *g_type = NT_signed;
13437 else if ((typebits & N_UNS) != 0)
477330fc 13438 *g_type = NT_unsigned;
5287ad62 13439 else if ((typebits & N_INT) != 0)
477330fc 13440 *g_type = NT_integer;
5287ad62 13441 else if ((typebits & N_FLT) != 0)
477330fc 13442 *g_type = NT_float;
dcbf9037 13443 else if ((typebits & N_SIZ) != 0)
477330fc 13444 *g_type = NT_untyped;
5287ad62
JB
13445 }
13446}
5f4273c7 13447
5287ad62
JB
13448/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13449 operand type, i.e. the single type specified in a Neon instruction when it
13450 is the only one given. */
13451
13452static struct neon_type_el
13453neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13454{
13455 struct neon_type_el dest = *key;
5f4273c7 13456
9c2799c2 13457 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13458
5287ad62
JB
13459 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13460
13461 return dest;
13462}
13463
13464/* Convert Neon type and size into compact bitmask representation. */
13465
13466static enum neon_type_mask
13467type_chk_of_el_type (enum neon_el_type type, unsigned size)
13468{
13469 switch (type)
13470 {
13471 case NT_untyped:
13472 switch (size)
477330fc
RM
13473 {
13474 case 8: return N_8;
13475 case 16: return N_16;
13476 case 32: return N_32;
13477 case 64: return N_64;
13478 default: ;
13479 }
5287ad62
JB
13480 break;
13481
13482 case NT_integer:
13483 switch (size)
477330fc
RM
13484 {
13485 case 8: return N_I8;
13486 case 16: return N_I16;
13487 case 32: return N_I32;
13488 case 64: return N_I64;
13489 default: ;
13490 }
5287ad62
JB
13491 break;
13492
13493 case NT_float:
037e8744 13494 switch (size)
477330fc 13495 {
8e79c3df 13496 case 16: return N_F16;
477330fc
RM
13497 case 32: return N_F32;
13498 case 64: return N_F64;
13499 default: ;
13500 }
5287ad62
JB
13501 break;
13502
13503 case NT_poly:
13504 switch (size)
477330fc
RM
13505 {
13506 case 8: return N_P8;
13507 case 16: return N_P16;
4f51b4bd 13508 case 64: return N_P64;
477330fc
RM
13509 default: ;
13510 }
5287ad62
JB
13511 break;
13512
13513 case NT_signed:
13514 switch (size)
477330fc
RM
13515 {
13516 case 8: return N_S8;
13517 case 16: return N_S16;
13518 case 32: return N_S32;
13519 case 64: return N_S64;
13520 default: ;
13521 }
5287ad62
JB
13522 break;
13523
13524 case NT_unsigned:
13525 switch (size)
477330fc
RM
13526 {
13527 case 8: return N_U8;
13528 case 16: return N_U16;
13529 case 32: return N_U32;
13530 case 64: return N_U64;
13531 default: ;
13532 }
5287ad62
JB
13533 break;
13534
13535 default: ;
13536 }
5f4273c7 13537
5287ad62
JB
13538 return N_UTYP;
13539}
13540
13541/* Convert compact Neon bitmask type representation to a type and size. Only
13542 handles the case where a single bit is set in the mask. */
13543
dcbf9037 13544static int
5287ad62 13545el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13546 enum neon_type_mask mask)
5287ad62 13547{
dcbf9037
JB
13548 if ((mask & N_EQK) != 0)
13549 return FAIL;
13550
5287ad62
JB
13551 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13552 *size = 8;
c70a8987 13553 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13554 *size = 16;
dcbf9037 13555 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13556 *size = 32;
4f51b4bd 13557 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13558 *size = 64;
dcbf9037
JB
13559 else
13560 return FAIL;
13561
5287ad62
JB
13562 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13563 *type = NT_signed;
dcbf9037 13564 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13565 *type = NT_unsigned;
dcbf9037 13566 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13567 *type = NT_integer;
dcbf9037 13568 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13569 *type = NT_untyped;
4f51b4bd 13570 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13571 *type = NT_poly;
c70a8987 13572 else if ((mask & (N_F16 | N_F32 | N_F64)) != 0)
5287ad62 13573 *type = NT_float;
dcbf9037
JB
13574 else
13575 return FAIL;
5f4273c7 13576
dcbf9037 13577 return SUCCESS;
5287ad62
JB
13578}
13579
13580/* Modify a bitmask of allowed types. This is only needed for type
13581 relaxation. */
13582
13583static unsigned
13584modify_types_allowed (unsigned allowed, unsigned mods)
13585{
13586 unsigned size;
13587 enum neon_el_type type;
13588 unsigned destmask;
13589 int i;
5f4273c7 13590
5287ad62 13591 destmask = 0;
5f4273c7 13592
5287ad62
JB
13593 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13594 {
21d799b5 13595 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13596 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13597 {
13598 neon_modify_type_size (mods, &type, &size);
13599 destmask |= type_chk_of_el_type (type, size);
13600 }
5287ad62 13601 }
5f4273c7 13602
5287ad62
JB
13603 return destmask;
13604}
13605
13606/* Check type and return type classification.
13607 The manual states (paraphrase): If one datatype is given, it indicates the
13608 type given in:
13609 - the second operand, if there is one
13610 - the operand, if there is no second operand
13611 - the result, if there are no operands.
13612 This isn't quite good enough though, so we use a concept of a "key" datatype
13613 which is set on a per-instruction basis, which is the one which matters when
13614 only one data type is written.
13615 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13616 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13617
13618static struct neon_type_el
13619neon_check_type (unsigned els, enum neon_shape ns, ...)
13620{
13621 va_list ap;
13622 unsigned i, pass, key_el = 0;
13623 unsigned types[NEON_MAX_TYPE_ELS];
13624 enum neon_el_type k_type = NT_invtype;
13625 unsigned k_size = -1u;
13626 struct neon_type_el badtype = {NT_invtype, -1};
13627 unsigned key_allowed = 0;
13628
13629 /* Optional registers in Neon instructions are always (not) in operand 1.
13630 Fill in the missing operand here, if it was omitted. */
13631 if (els > 1 && !inst.operands[1].present)
13632 inst.operands[1] = inst.operands[0];
13633
13634 /* Suck up all the varargs. */
13635 va_start (ap, ns);
13636 for (i = 0; i < els; i++)
13637 {
13638 unsigned thisarg = va_arg (ap, unsigned);
13639 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
13640 {
13641 va_end (ap);
13642 return badtype;
13643 }
5287ad62
JB
13644 types[i] = thisarg;
13645 if ((thisarg & N_KEY) != 0)
477330fc 13646 key_el = i;
5287ad62
JB
13647 }
13648 va_end (ap);
13649
dcbf9037
JB
13650 if (inst.vectype.elems > 0)
13651 for (i = 0; i < els; i++)
13652 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
13653 {
13654 first_error (_("types specified in both the mnemonic and operands"));
13655 return badtype;
13656 }
dcbf9037 13657
5287ad62
JB
13658 /* Duplicate inst.vectype elements here as necessary.
13659 FIXME: No idea if this is exactly the same as the ARM assembler,
13660 particularly when an insn takes one register and one non-register
13661 operand. */
13662 if (inst.vectype.elems == 1 && els > 1)
13663 {
13664 unsigned j;
13665 inst.vectype.elems = els;
13666 inst.vectype.el[key_el] = inst.vectype.el[0];
13667 for (j = 0; j < els; j++)
477330fc
RM
13668 if (j != key_el)
13669 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13670 types[j]);
dcbf9037
JB
13671 }
13672 else if (inst.vectype.elems == 0 && els > 0)
13673 {
13674 unsigned j;
13675 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
13676 after each operand. We allow some flexibility here; as long as the
13677 "key" operand has a type, we can infer the others. */
dcbf9037 13678 for (j = 0; j < els; j++)
477330fc
RM
13679 if (inst.operands[j].vectype.type != NT_invtype)
13680 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
13681
13682 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
13683 {
13684 for (j = 0; j < els; j++)
13685 if (inst.operands[j].vectype.type == NT_invtype)
13686 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13687 types[j]);
13688 }
dcbf9037 13689 else
477330fc
RM
13690 {
13691 first_error (_("operand types can't be inferred"));
13692 return badtype;
13693 }
5287ad62
JB
13694 }
13695 else if (inst.vectype.elems != els)
13696 {
dcbf9037 13697 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
13698 return badtype;
13699 }
13700
13701 for (pass = 0; pass < 2; pass++)
13702 {
13703 for (i = 0; i < els; i++)
477330fc
RM
13704 {
13705 unsigned thisarg = types[i];
13706 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
13707 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
13708 enum neon_el_type g_type = inst.vectype.el[i].type;
13709 unsigned g_size = inst.vectype.el[i].size;
13710
13711 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 13712 integer types if sign-specific variants are unavailable. */
477330fc 13713 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
13714 && (types_allowed & N_SU_ALL) == 0)
13715 g_type = NT_integer;
13716
477330fc 13717 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
13718 them. Some instructions only care about signs for some element
13719 sizes, so handle that properly. */
477330fc 13720 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
13721 && ((g_size == 8 && (types_allowed & N_8) != 0)
13722 || (g_size == 16 && (types_allowed & N_16) != 0)
13723 || (g_size == 32 && (types_allowed & N_32) != 0)
13724 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
13725 g_type = NT_untyped;
13726
477330fc
RM
13727 if (pass == 0)
13728 {
13729 if ((thisarg & N_KEY) != 0)
13730 {
13731 k_type = g_type;
13732 k_size = g_size;
13733 key_allowed = thisarg & ~N_KEY;
13734 }
13735 }
13736 else
13737 {
13738 if ((thisarg & N_VFP) != 0)
13739 {
13740 enum neon_shape_el regshape;
13741 unsigned regwidth, match;
99b253c5
NC
13742
13743 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
13744 if (ns == NS_NULL)
13745 {
13746 first_error (_("invalid instruction shape"));
13747 return badtype;
13748 }
477330fc
RM
13749 regshape = neon_shape_tab[ns].el[i];
13750 regwidth = neon_shape_el_size[regshape];
13751
13752 /* In VFP mode, operands must match register widths. If we
13753 have a key operand, use its width, else use the width of
13754 the current operand. */
13755 if (k_size != -1u)
13756 match = k_size;
13757 else
13758 match = g_size;
13759
13760 if (regwidth != match)
13761 {
13762 first_error (_("operand size must match register width"));
13763 return badtype;
13764 }
13765 }
13766
13767 if ((thisarg & N_EQK) == 0)
13768 {
13769 unsigned given_type = type_chk_of_el_type (g_type, g_size);
13770
13771 if ((given_type & types_allowed) == 0)
13772 {
13773 first_error (_("bad type in Neon instruction"));
13774 return badtype;
13775 }
13776 }
13777 else
13778 {
13779 enum neon_el_type mod_k_type = k_type;
13780 unsigned mod_k_size = k_size;
13781 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
13782 if (g_type != mod_k_type || g_size != mod_k_size)
13783 {
13784 first_error (_("inconsistent types in Neon instruction"));
13785 return badtype;
13786 }
13787 }
13788 }
13789 }
5287ad62
JB
13790 }
13791
13792 return inst.vectype.el[key_el];
13793}
13794
037e8744 13795/* Neon-style VFP instruction forwarding. */
5287ad62 13796
037e8744
JB
13797/* Thumb VFP instructions have 0xE in the condition field. */
13798
13799static void
13800do_vfp_cond_or_thumb (void)
5287ad62 13801{
88714cb8
DG
13802 inst.is_neon = 1;
13803
5287ad62 13804 if (thumb_mode)
037e8744 13805 inst.instruction |= 0xe0000000;
5287ad62 13806 else
037e8744 13807 inst.instruction |= inst.cond << 28;
5287ad62
JB
13808}
13809
037e8744
JB
13810/* Look up and encode a simple mnemonic, for use as a helper function for the
13811 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
13812 etc. It is assumed that operand parsing has already been done, and that the
13813 operands are in the form expected by the given opcode (this isn't necessarily
13814 the same as the form in which they were parsed, hence some massaging must
13815 take place before this function is called).
13816 Checks current arch version against that in the looked-up opcode. */
5287ad62 13817
037e8744
JB
13818static void
13819do_vfp_nsyn_opcode (const char *opname)
5287ad62 13820{
037e8744 13821 const struct asm_opcode *opcode;
5f4273c7 13822
21d799b5 13823 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 13824
037e8744
JB
13825 if (!opcode)
13826 abort ();
5287ad62 13827
037e8744 13828 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
13829 thumb_mode ? *opcode->tvariant : *opcode->avariant),
13830 _(BAD_FPU));
5287ad62 13831
88714cb8
DG
13832 inst.is_neon = 1;
13833
037e8744
JB
13834 if (thumb_mode)
13835 {
13836 inst.instruction = opcode->tvalue;
13837 opcode->tencode ();
13838 }
13839 else
13840 {
13841 inst.instruction = (inst.cond << 28) | opcode->avalue;
13842 opcode->aencode ();
13843 }
13844}
5287ad62
JB
13845
13846static void
037e8744 13847do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 13848{
037e8744
JB
13849 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
13850
13851 if (rs == NS_FFF)
13852 {
13853 if (is_add)
477330fc 13854 do_vfp_nsyn_opcode ("fadds");
037e8744 13855 else
477330fc 13856 do_vfp_nsyn_opcode ("fsubs");
037e8744
JB
13857 }
13858 else
13859 {
13860 if (is_add)
477330fc 13861 do_vfp_nsyn_opcode ("faddd");
037e8744 13862 else
477330fc 13863 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
13864 }
13865}
13866
13867/* Check operand types to see if this is a VFP instruction, and if so call
13868 PFN (). */
13869
13870static int
13871try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
13872{
13873 enum neon_shape rs;
13874 struct neon_type_el et;
13875
13876 switch (args)
13877 {
13878 case 2:
13879 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13880 et = neon_check_type (2, rs,
477330fc 13881 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
037e8744 13882 break;
5f4273c7 13883
037e8744
JB
13884 case 3:
13885 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13886 et = neon_check_type (3, rs,
477330fc 13887 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
037e8744
JB
13888 break;
13889
13890 default:
13891 abort ();
13892 }
13893
13894 if (et.type != NT_invtype)
13895 {
13896 pfn (rs);
13897 return SUCCESS;
13898 }
037e8744 13899
99b253c5 13900 inst.error = NULL;
037e8744
JB
13901 return FAIL;
13902}
13903
13904static void
13905do_vfp_nsyn_mla_mls (enum neon_shape rs)
13906{
13907 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 13908
037e8744
JB
13909 if (rs == NS_FFF)
13910 {
13911 if (is_mla)
477330fc 13912 do_vfp_nsyn_opcode ("fmacs");
037e8744 13913 else
477330fc 13914 do_vfp_nsyn_opcode ("fnmacs");
037e8744
JB
13915 }
13916 else
13917 {
13918 if (is_mla)
477330fc 13919 do_vfp_nsyn_opcode ("fmacd");
037e8744 13920 else
477330fc 13921 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
13922 }
13923}
13924
62f3b8c8
PB
13925static void
13926do_vfp_nsyn_fma_fms (enum neon_shape rs)
13927{
13928 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
13929
13930 if (rs == NS_FFF)
13931 {
13932 if (is_fma)
477330fc 13933 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 13934 else
477330fc 13935 do_vfp_nsyn_opcode ("ffnmas");
62f3b8c8
PB
13936 }
13937 else
13938 {
13939 if (is_fma)
477330fc 13940 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 13941 else
477330fc 13942 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
13943 }
13944}
13945
037e8744
JB
13946static void
13947do_vfp_nsyn_mul (enum neon_shape rs)
13948{
13949 if (rs == NS_FFF)
13950 do_vfp_nsyn_opcode ("fmuls");
13951 else
13952 do_vfp_nsyn_opcode ("fmuld");
13953}
13954
13955static void
13956do_vfp_nsyn_abs_neg (enum neon_shape rs)
13957{
13958 int is_neg = (inst.instruction & 0x80) != 0;
13959 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
13960
13961 if (rs == NS_FF)
13962 {
13963 if (is_neg)
477330fc 13964 do_vfp_nsyn_opcode ("fnegs");
037e8744 13965 else
477330fc 13966 do_vfp_nsyn_opcode ("fabss");
037e8744
JB
13967 }
13968 else
13969 {
13970 if (is_neg)
477330fc 13971 do_vfp_nsyn_opcode ("fnegd");
037e8744 13972 else
477330fc 13973 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
13974 }
13975}
13976
13977/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
13978 insns belong to Neon, and are handled elsewhere. */
13979
13980static void
13981do_vfp_nsyn_ldm_stm (int is_dbmode)
13982{
13983 int is_ldm = (inst.instruction & (1 << 20)) != 0;
13984 if (is_ldm)
13985 {
13986 if (is_dbmode)
477330fc 13987 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 13988 else
477330fc 13989 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
13990 }
13991 else
13992 {
13993 if (is_dbmode)
477330fc 13994 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 13995 else
477330fc 13996 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
13997 }
13998}
13999
037e8744
JB
14000static void
14001do_vfp_nsyn_sqrt (void)
14002{
14003 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
14004 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 14005
037e8744
JB
14006 if (rs == NS_FF)
14007 do_vfp_nsyn_opcode ("fsqrts");
14008 else
14009 do_vfp_nsyn_opcode ("fsqrtd");
14010}
14011
14012static void
14013do_vfp_nsyn_div (void)
14014{
14015 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
14016 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14017 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 14018
037e8744
JB
14019 if (rs == NS_FFF)
14020 do_vfp_nsyn_opcode ("fdivs");
14021 else
14022 do_vfp_nsyn_opcode ("fdivd");
14023}
14024
14025static void
14026do_vfp_nsyn_nmul (void)
14027{
14028 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
14029 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14030 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 14031
037e8744
JB
14032 if (rs == NS_FFF)
14033 {
88714cb8 14034 NEON_ENCODE (SINGLE, inst);
037e8744
JB
14035 do_vfp_sp_dyadic ();
14036 }
14037 else
14038 {
88714cb8 14039 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14040 do_vfp_dp_rd_rn_rm ();
14041 }
14042 do_vfp_cond_or_thumb ();
14043}
14044
14045static void
14046do_vfp_nsyn_cmp (void)
14047{
14048 if (inst.operands[1].isreg)
14049 {
14050 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
14051 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 14052
037e8744 14053 if (rs == NS_FF)
477330fc
RM
14054 {
14055 NEON_ENCODE (SINGLE, inst);
14056 do_vfp_sp_monadic ();
14057 }
037e8744 14058 else
477330fc
RM
14059 {
14060 NEON_ENCODE (DOUBLE, inst);
14061 do_vfp_dp_rd_rm ();
14062 }
037e8744
JB
14063 }
14064 else
14065 {
14066 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
14067 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
14068
14069 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14070 {
14071 case N_MNEM_vcmp:
14072 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14073 break;
14074 case N_MNEM_vcmpe:
14075 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14076 break;
14077 default:
14078 abort ();
14079 }
5f4273c7 14080
037e8744 14081 if (rs == NS_FI)
477330fc
RM
14082 {
14083 NEON_ENCODE (SINGLE, inst);
14084 do_vfp_sp_compare_z ();
14085 }
037e8744 14086 else
477330fc
RM
14087 {
14088 NEON_ENCODE (DOUBLE, inst);
14089 do_vfp_dp_rd ();
14090 }
037e8744
JB
14091 }
14092 do_vfp_cond_or_thumb ();
14093}
14094
14095static void
14096nsyn_insert_sp (void)
14097{
14098 inst.operands[1] = inst.operands[0];
14099 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14100 inst.operands[0].reg = REG_SP;
037e8744
JB
14101 inst.operands[0].isreg = 1;
14102 inst.operands[0].writeback = 1;
14103 inst.operands[0].present = 1;
14104}
14105
14106static void
14107do_vfp_nsyn_push (void)
14108{
14109 nsyn_insert_sp ();
14110 if (inst.operands[1].issingle)
14111 do_vfp_nsyn_opcode ("fstmdbs");
14112 else
14113 do_vfp_nsyn_opcode ("fstmdbd");
14114}
14115
14116static void
14117do_vfp_nsyn_pop (void)
14118{
14119 nsyn_insert_sp ();
14120 if (inst.operands[1].issingle)
22b5b651 14121 do_vfp_nsyn_opcode ("fldmias");
037e8744 14122 else
22b5b651 14123 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14124}
14125
14126/* Fix up Neon data-processing instructions, ORing in the correct bits for
14127 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14128
88714cb8
DG
14129static void
14130neon_dp_fixup (struct arm_it* insn)
037e8744 14131{
88714cb8
DG
14132 unsigned int i = insn->instruction;
14133 insn->is_neon = 1;
14134
037e8744
JB
14135 if (thumb_mode)
14136 {
14137 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14138 if (i & (1 << 24))
477330fc 14139 i |= 1 << 28;
5f4273c7 14140
037e8744 14141 i &= ~(1 << 24);
5f4273c7 14142
037e8744
JB
14143 i |= 0xef000000;
14144 }
14145 else
14146 i |= 0xf2000000;
5f4273c7 14147
88714cb8 14148 insn->instruction = i;
037e8744
JB
14149}
14150
14151/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14152 (0, 1, 2, 3). */
14153
14154static unsigned
14155neon_logbits (unsigned x)
14156{
14157 return ffs (x) - 4;
14158}
14159
14160#define LOW4(R) ((R) & 0xf)
14161#define HI1(R) (((R) >> 4) & 1)
14162
14163/* Encode insns with bit pattern:
14164
14165 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14166 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14167
037e8744
JB
14168 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14169 different meaning for some instruction. */
14170
14171static void
14172neon_three_same (int isquad, int ubit, int size)
14173{
14174 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14175 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14176 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14177 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14178 inst.instruction |= LOW4 (inst.operands[2].reg);
14179 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14180 inst.instruction |= (isquad != 0) << 6;
14181 inst.instruction |= (ubit != 0) << 24;
14182 if (size != -1)
14183 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14184
88714cb8 14185 neon_dp_fixup (&inst);
037e8744
JB
14186}
14187
14188/* Encode instructions of the form:
14189
14190 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14191 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14192
14193 Don't write size if SIZE == -1. */
14194
14195static void
14196neon_two_same (int qbit, int ubit, int size)
14197{
14198 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14199 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14200 inst.instruction |= LOW4 (inst.operands[1].reg);
14201 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14202 inst.instruction |= (qbit != 0) << 6;
14203 inst.instruction |= (ubit != 0) << 24;
14204
14205 if (size != -1)
14206 inst.instruction |= neon_logbits (size) << 18;
14207
88714cb8 14208 neon_dp_fixup (&inst);
5287ad62
JB
14209}
14210
14211/* Neon instruction encoders, in approximate order of appearance. */
14212
14213static void
14214do_neon_dyadic_i_su (void)
14215{
037e8744 14216 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14217 struct neon_type_el et = neon_check_type (3, rs,
14218 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14219 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14220}
14221
14222static void
14223do_neon_dyadic_i64_su (void)
14224{
037e8744 14225 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14226 struct neon_type_el et = neon_check_type (3, rs,
14227 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14228 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14229}
14230
14231static void
14232neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14233 unsigned immbits)
5287ad62
JB
14234{
14235 unsigned size = et.size >> 3;
14236 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14237 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14238 inst.instruction |= LOW4 (inst.operands[1].reg);
14239 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14240 inst.instruction |= (isquad != 0) << 6;
14241 inst.instruction |= immbits << 16;
14242 inst.instruction |= (size >> 3) << 7;
14243 inst.instruction |= (size & 0x7) << 19;
14244 if (write_ubit)
14245 inst.instruction |= (uval != 0) << 24;
14246
88714cb8 14247 neon_dp_fixup (&inst);
5287ad62
JB
14248}
14249
14250static void
14251do_neon_shl_imm (void)
14252{
14253 if (!inst.operands[2].isreg)
14254 {
037e8744 14255 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14256 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14257 int imm = inst.operands[2].imm;
14258
14259 constraint (imm < 0 || (unsigned)imm >= et.size,
14260 _("immediate out of range for shift"));
88714cb8 14261 NEON_ENCODE (IMMED, inst);
cb3b1e65 14262 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14263 }
14264 else
14265 {
037e8744 14266 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14267 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14268 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14269 unsigned int tmp;
14270
14271 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14272 vshl.xx Dd, Dm, Dn
14273 whereas other 3-register operations encoded by neon_three_same have
14274 syntax like:
14275 vadd.xx Dd, Dn, Dm
14276 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14277 here. */
627907b7
JB
14278 tmp = inst.operands[2].reg;
14279 inst.operands[2].reg = inst.operands[1].reg;
14280 inst.operands[1].reg = tmp;
88714cb8 14281 NEON_ENCODE (INTEGER, inst);
037e8744 14282 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14283 }
14284}
14285
14286static void
14287do_neon_qshl_imm (void)
14288{
14289 if (!inst.operands[2].isreg)
14290 {
037e8744 14291 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14292 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14293 int imm = inst.operands[2].imm;
627907b7 14294
cb3b1e65
JB
14295 constraint (imm < 0 || (unsigned)imm >= et.size,
14296 _("immediate out of range for shift"));
88714cb8 14297 NEON_ENCODE (IMMED, inst);
cb3b1e65 14298 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14299 }
14300 else
14301 {
037e8744 14302 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14303 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14304 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14305 unsigned int tmp;
14306
14307 /* See note in do_neon_shl_imm. */
14308 tmp = inst.operands[2].reg;
14309 inst.operands[2].reg = inst.operands[1].reg;
14310 inst.operands[1].reg = tmp;
88714cb8 14311 NEON_ENCODE (INTEGER, inst);
037e8744 14312 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14313 }
14314}
14315
627907b7
JB
14316static void
14317do_neon_rshl (void)
14318{
14319 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14320 struct neon_type_el et = neon_check_type (3, rs,
14321 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14322 unsigned int tmp;
14323
14324 tmp = inst.operands[2].reg;
14325 inst.operands[2].reg = inst.operands[1].reg;
14326 inst.operands[1].reg = tmp;
14327 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14328}
14329
5287ad62
JB
14330static int
14331neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14332{
036dc3f7
PB
14333 /* Handle .I8 pseudo-instructions. */
14334 if (size == 8)
5287ad62 14335 {
5287ad62 14336 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14337 FIXME is this the intended semantics? There doesn't seem much point in
14338 accepting .I8 if so. */
5287ad62
JB
14339 immediate |= immediate << 8;
14340 size = 16;
036dc3f7
PB
14341 }
14342
14343 if (size >= 32)
14344 {
14345 if (immediate == (immediate & 0x000000ff))
14346 {
14347 *immbits = immediate;
14348 return 0x1;
14349 }
14350 else if (immediate == (immediate & 0x0000ff00))
14351 {
14352 *immbits = immediate >> 8;
14353 return 0x3;
14354 }
14355 else if (immediate == (immediate & 0x00ff0000))
14356 {
14357 *immbits = immediate >> 16;
14358 return 0x5;
14359 }
14360 else if (immediate == (immediate & 0xff000000))
14361 {
14362 *immbits = immediate >> 24;
14363 return 0x7;
14364 }
14365 if ((immediate & 0xffff) != (immediate >> 16))
14366 goto bad_immediate;
14367 immediate &= 0xffff;
5287ad62
JB
14368 }
14369
14370 if (immediate == (immediate & 0x000000ff))
14371 {
14372 *immbits = immediate;
036dc3f7 14373 return 0x9;
5287ad62
JB
14374 }
14375 else if (immediate == (immediate & 0x0000ff00))
14376 {
14377 *immbits = immediate >> 8;
036dc3f7 14378 return 0xb;
5287ad62
JB
14379 }
14380
14381 bad_immediate:
dcbf9037 14382 first_error (_("immediate value out of range"));
5287ad62
JB
14383 return FAIL;
14384}
14385
5287ad62
JB
14386static void
14387do_neon_logic (void)
14388{
14389 if (inst.operands[2].present && inst.operands[2].isreg)
14390 {
037e8744 14391 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14392 neon_check_type (3, rs, N_IGNORE_TYPE);
14393 /* U bit and size field were set as part of the bitmask. */
88714cb8 14394 NEON_ENCODE (INTEGER, inst);
037e8744 14395 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14396 }
14397 else
14398 {
4316f0d2
DG
14399 const int three_ops_form = (inst.operands[2].present
14400 && !inst.operands[2].isreg);
14401 const int immoperand = (three_ops_form ? 2 : 1);
14402 enum neon_shape rs = (three_ops_form
14403 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14404 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14405 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14406 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14407 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14408 unsigned immbits;
14409 int cmode;
5f4273c7 14410
5287ad62 14411 if (et.type == NT_invtype)
477330fc 14412 return;
5f4273c7 14413
4316f0d2
DG
14414 if (three_ops_form)
14415 constraint (inst.operands[0].reg != inst.operands[1].reg,
14416 _("first and second operands shall be the same register"));
14417
88714cb8 14418 NEON_ENCODE (IMMED, inst);
5287ad62 14419
4316f0d2 14420 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14421 if (et.size == 64)
14422 {
14423 /* .i64 is a pseudo-op, so the immediate must be a repeating
14424 pattern. */
4316f0d2
DG
14425 if (immbits != (inst.operands[immoperand].regisimm ?
14426 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14427 {
14428 /* Set immbits to an invalid constant. */
14429 immbits = 0xdeadbeef;
14430 }
14431 }
14432
5287ad62 14433 switch (opcode)
477330fc
RM
14434 {
14435 case N_MNEM_vbic:
14436 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14437 break;
14438
14439 case N_MNEM_vorr:
14440 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14441 break;
14442
14443 case N_MNEM_vand:
14444 /* Pseudo-instruction for VBIC. */
14445 neon_invert_size (&immbits, 0, et.size);
14446 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14447 break;
14448
14449 case N_MNEM_vorn:
14450 /* Pseudo-instruction for VORR. */
14451 neon_invert_size (&immbits, 0, et.size);
14452 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14453 break;
14454
14455 default:
14456 abort ();
14457 }
5287ad62
JB
14458
14459 if (cmode == FAIL)
477330fc 14460 return;
5287ad62 14461
037e8744 14462 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14463 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14464 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14465 inst.instruction |= cmode << 8;
14466 neon_write_immbits (immbits);
5f4273c7 14467
88714cb8 14468 neon_dp_fixup (&inst);
5287ad62
JB
14469 }
14470}
14471
14472static void
14473do_neon_bitfield (void)
14474{
037e8744 14475 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14476 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14477 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14478}
14479
14480static void
dcbf9037 14481neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14482 unsigned destbits)
5287ad62 14483{
037e8744 14484 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14485 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14486 types | N_KEY);
5287ad62
JB
14487 if (et.type == NT_float)
14488 {
88714cb8 14489 NEON_ENCODE (FLOAT, inst);
037e8744 14490 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14491 }
14492 else
14493 {
88714cb8 14494 NEON_ENCODE (INTEGER, inst);
037e8744 14495 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14496 }
14497}
14498
14499static void
14500do_neon_dyadic_if_su (void)
14501{
dcbf9037 14502 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14503}
14504
14505static void
14506do_neon_dyadic_if_su_d (void)
14507{
14508 /* This version only allow D registers, but that constraint is enforced during
14509 operand parsing so we don't need to do anything extra here. */
dcbf9037 14510 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14511}
14512
5287ad62
JB
14513static void
14514do_neon_dyadic_if_i_d (void)
14515{
428e3f1f
PB
14516 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14517 affected if we specify unsigned args. */
14518 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14519}
14520
037e8744
JB
14521enum vfp_or_neon_is_neon_bits
14522{
14523 NEON_CHECK_CC = 1,
73924fbc
MGD
14524 NEON_CHECK_ARCH = 2,
14525 NEON_CHECK_ARCH8 = 4
037e8744
JB
14526};
14527
14528/* Call this function if an instruction which may have belonged to the VFP or
14529 Neon instruction sets, but turned out to be a Neon instruction (due to the
14530 operand types involved, etc.). We have to check and/or fix-up a couple of
14531 things:
14532
14533 - Make sure the user hasn't attempted to make a Neon instruction
14534 conditional.
14535 - Alter the value in the condition code field if necessary.
14536 - Make sure that the arch supports Neon instructions.
14537
14538 Which of these operations take place depends on bits from enum
14539 vfp_or_neon_is_neon_bits.
14540
14541 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14542 current instruction's condition is COND_ALWAYS, the condition field is
14543 changed to inst.uncond_value. This is necessary because instructions shared
14544 between VFP and Neon may be conditional for the VFP variants only, and the
14545 unconditional Neon version must have, e.g., 0xF in the condition field. */
14546
14547static int
14548vfp_or_neon_is_neon (unsigned check)
14549{
14550 /* Conditions are always legal in Thumb mode (IT blocks). */
14551 if (!thumb_mode && (check & NEON_CHECK_CC))
14552 {
14553 if (inst.cond != COND_ALWAYS)
477330fc
RM
14554 {
14555 first_error (_(BAD_COND));
14556 return FAIL;
14557 }
037e8744 14558 if (inst.uncond_value != -1)
477330fc 14559 inst.instruction |= inst.uncond_value << 28;
037e8744 14560 }
5f4273c7 14561
037e8744 14562 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14563 && !mark_feature_used (&fpu_neon_ext_v1))
14564 {
14565 first_error (_(BAD_FPU));
14566 return FAIL;
14567 }
14568
14569 if ((check & NEON_CHECK_ARCH8)
14570 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
14571 {
14572 first_error (_(BAD_FPU));
14573 return FAIL;
14574 }
5f4273c7 14575
037e8744
JB
14576 return SUCCESS;
14577}
14578
5287ad62
JB
14579static void
14580do_neon_addsub_if_i (void)
14581{
037e8744
JB
14582 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14583 return;
14584
14585 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14586 return;
14587
5287ad62
JB
14588 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14589 affected if we specify unsigned args. */
dcbf9037 14590 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
14591}
14592
14593/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14594 result to be:
14595 V<op> A,B (A is operand 0, B is operand 2)
14596 to mean:
14597 V<op> A,B,A
14598 not:
14599 V<op> A,B,B
14600 so handle that case specially. */
14601
14602static void
14603neon_exchange_operands (void)
14604{
14605 void *scratch = alloca (sizeof (inst.operands[0]));
14606 if (inst.operands[1].present)
14607 {
14608 /* Swap operands[1] and operands[2]. */
14609 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14610 inst.operands[1] = inst.operands[2];
14611 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
14612 }
14613 else
14614 {
14615 inst.operands[1] = inst.operands[2];
14616 inst.operands[2] = inst.operands[0];
14617 }
14618}
14619
14620static void
14621neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14622{
14623 if (inst.operands[2].isreg)
14624 {
14625 if (invert)
477330fc 14626 neon_exchange_operands ();
dcbf9037 14627 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
14628 }
14629 else
14630 {
037e8744 14631 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 14632 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14633 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 14634
88714cb8 14635 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14636 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14637 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14638 inst.instruction |= LOW4 (inst.operands[1].reg);
14639 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14640 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14641 inst.instruction |= (et.type == NT_float) << 10;
14642 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14643
88714cb8 14644 neon_dp_fixup (&inst);
5287ad62
JB
14645 }
14646}
14647
14648static void
14649do_neon_cmp (void)
14650{
14651 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
14652}
14653
14654static void
14655do_neon_cmp_inv (void)
14656{
14657 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
14658}
14659
14660static void
14661do_neon_ceq (void)
14662{
14663 neon_compare (N_IF_32, N_IF_32, FALSE);
14664}
14665
14666/* For multiply instructions, we have the possibility of 16-bit or 32-bit
14667 scalars, which are encoded in 5 bits, M : Rm.
14668 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
14669 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
14670 index in M. */
14671
14672static unsigned
14673neon_scalar_for_mul (unsigned scalar, unsigned elsize)
14674{
dcbf9037
JB
14675 unsigned regno = NEON_SCALAR_REG (scalar);
14676 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
14677
14678 switch (elsize)
14679 {
14680 case 16:
14681 if (regno > 7 || elno > 3)
477330fc 14682 goto bad_scalar;
5287ad62 14683 return regno | (elno << 3);
5f4273c7 14684
5287ad62
JB
14685 case 32:
14686 if (regno > 15 || elno > 1)
477330fc 14687 goto bad_scalar;
5287ad62
JB
14688 return regno | (elno << 4);
14689
14690 default:
14691 bad_scalar:
dcbf9037 14692 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
14693 }
14694
14695 return 0;
14696}
14697
14698/* Encode multiply / multiply-accumulate scalar instructions. */
14699
14700static void
14701neon_mul_mac (struct neon_type_el et, int ubit)
14702{
dcbf9037
JB
14703 unsigned scalar;
14704
14705 /* Give a more helpful error message if we have an invalid type. */
14706 if (et.type == NT_invtype)
14707 return;
5f4273c7 14708
dcbf9037 14709 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
14710 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14711 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14712 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14713 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14714 inst.instruction |= LOW4 (scalar);
14715 inst.instruction |= HI1 (scalar) << 5;
14716 inst.instruction |= (et.type == NT_float) << 8;
14717 inst.instruction |= neon_logbits (et.size) << 20;
14718 inst.instruction |= (ubit != 0) << 24;
14719
88714cb8 14720 neon_dp_fixup (&inst);
5287ad62
JB
14721}
14722
14723static void
14724do_neon_mac_maybe_scalar (void)
14725{
037e8744
JB
14726 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
14727 return;
14728
14729 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14730 return;
14731
5287ad62
JB
14732 if (inst.operands[2].isscalar)
14733 {
037e8744 14734 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 14735 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14736 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
88714cb8 14737 NEON_ENCODE (SCALAR, inst);
037e8744 14738 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
14739 }
14740 else
428e3f1f
PB
14741 {
14742 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14743 affected if we specify unsigned args. */
14744 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14745 }
5287ad62
JB
14746}
14747
62f3b8c8
PB
14748static void
14749do_neon_fmac (void)
14750{
14751 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
14752 return;
14753
14754 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14755 return;
14756
14757 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14758}
14759
5287ad62
JB
14760static void
14761do_neon_tst (void)
14762{
037e8744 14763 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14764 struct neon_type_el et = neon_check_type (3, rs,
14765 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 14766 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
14767}
14768
14769/* VMUL with 3 registers allows the P8 type. The scalar version supports the
14770 same types as the MAC equivalents. The polynomial type for this instruction
14771 is encoded the same as the integer type. */
14772
14773static void
14774do_neon_mul (void)
14775{
037e8744
JB
14776 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
14777 return;
14778
14779 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14780 return;
14781
5287ad62
JB
14782 if (inst.operands[2].isscalar)
14783 do_neon_mac_maybe_scalar ();
14784 else
dcbf9037 14785 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
14786}
14787
14788static void
14789do_neon_qdmulh (void)
14790{
14791 if (inst.operands[2].isscalar)
14792 {
037e8744 14793 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 14794 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14795 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 14796 NEON_ENCODE (SCALAR, inst);
037e8744 14797 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
14798 }
14799 else
14800 {
037e8744 14801 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14802 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14803 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 14804 NEON_ENCODE (INTEGER, inst);
5287ad62 14805 /* The U bit (rounding) comes from bit mask. */
037e8744 14806 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
14807 }
14808}
14809
14810static void
14811do_neon_fcmp_absolute (void)
14812{
037e8744 14813 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14814 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
14815 /* Size field comes from bit mask. */
037e8744 14816 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
14817}
14818
14819static void
14820do_neon_fcmp_absolute_inv (void)
14821{
14822 neon_exchange_operands ();
14823 do_neon_fcmp_absolute ();
14824}
14825
14826static void
14827do_neon_step (void)
14828{
037e8744 14829 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14830 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 14831 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14832}
14833
14834static void
14835do_neon_abs_neg (void)
14836{
037e8744
JB
14837 enum neon_shape rs;
14838 struct neon_type_el et;
5f4273c7 14839
037e8744
JB
14840 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
14841 return;
14842
14843 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14844 return;
14845
14846 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14847 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 14848
5287ad62
JB
14849 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14850 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14851 inst.instruction |= LOW4 (inst.operands[1].reg);
14852 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14853 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14854 inst.instruction |= (et.type == NT_float) << 10;
14855 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14856
88714cb8 14857 neon_dp_fixup (&inst);
5287ad62
JB
14858}
14859
14860static void
14861do_neon_sli (void)
14862{
037e8744 14863 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14864 struct neon_type_el et = neon_check_type (2, rs,
14865 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14866 int imm = inst.operands[2].imm;
14867 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 14868 _("immediate out of range for insert"));
037e8744 14869 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14870}
14871
14872static void
14873do_neon_sri (void)
14874{
037e8744 14875 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14876 struct neon_type_el et = neon_check_type (2, rs,
14877 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14878 int imm = inst.operands[2].imm;
14879 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 14880 _("immediate out of range for insert"));
037e8744 14881 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
14882}
14883
14884static void
14885do_neon_qshlu_imm (void)
14886{
037e8744 14887 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14888 struct neon_type_el et = neon_check_type (2, rs,
14889 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
14890 int imm = inst.operands[2].imm;
14891 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 14892 _("immediate out of range for shift"));
5287ad62
JB
14893 /* Only encodes the 'U present' variant of the instruction.
14894 In this case, signed types have OP (bit 8) set to 0.
14895 Unsigned types have OP set to 1. */
14896 inst.instruction |= (et.type == NT_unsigned) << 8;
14897 /* The rest of the bits are the same as other immediate shifts. */
037e8744 14898 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14899}
14900
14901static void
14902do_neon_qmovn (void)
14903{
14904 struct neon_type_el et = neon_check_type (2, NS_DQ,
14905 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14906 /* Saturating move where operands can be signed or unsigned, and the
14907 destination has the same signedness. */
88714cb8 14908 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14909 if (et.type == NT_unsigned)
14910 inst.instruction |= 0xc0;
14911 else
14912 inst.instruction |= 0x80;
14913 neon_two_same (0, 1, et.size / 2);
14914}
14915
14916static void
14917do_neon_qmovun (void)
14918{
14919 struct neon_type_el et = neon_check_type (2, NS_DQ,
14920 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14921 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 14922 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14923 neon_two_same (0, 1, et.size / 2);
14924}
14925
14926static void
14927do_neon_rshift_sat_narrow (void)
14928{
14929 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14930 or unsigned. If operands are unsigned, results must also be unsigned. */
14931 struct neon_type_el et = neon_check_type (2, NS_DQI,
14932 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14933 int imm = inst.operands[2].imm;
14934 /* This gets the bounds check, size encoding and immediate bits calculation
14935 right. */
14936 et.size /= 2;
5f4273c7 14937
5287ad62
JB
14938 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
14939 VQMOVN.I<size> <Dd>, <Qm>. */
14940 if (imm == 0)
14941 {
14942 inst.operands[2].present = 0;
14943 inst.instruction = N_MNEM_vqmovn;
14944 do_neon_qmovn ();
14945 return;
14946 }
5f4273c7 14947
5287ad62 14948 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 14949 _("immediate out of range"));
5287ad62
JB
14950 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
14951}
14952
14953static void
14954do_neon_rshift_sat_narrow_u (void)
14955{
14956 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14957 or unsigned. If operands are unsigned, results must also be unsigned. */
14958 struct neon_type_el et = neon_check_type (2, NS_DQI,
14959 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14960 int imm = inst.operands[2].imm;
14961 /* This gets the bounds check, size encoding and immediate bits calculation
14962 right. */
14963 et.size /= 2;
14964
14965 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
14966 VQMOVUN.I<size> <Dd>, <Qm>. */
14967 if (imm == 0)
14968 {
14969 inst.operands[2].present = 0;
14970 inst.instruction = N_MNEM_vqmovun;
14971 do_neon_qmovun ();
14972 return;
14973 }
14974
14975 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 14976 _("immediate out of range"));
5287ad62
JB
14977 /* FIXME: The manual is kind of unclear about what value U should have in
14978 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
14979 must be 1. */
14980 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
14981}
14982
14983static void
14984do_neon_movn (void)
14985{
14986 struct neon_type_el et = neon_check_type (2, NS_DQ,
14987 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 14988 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
14989 neon_two_same (0, 1, et.size / 2);
14990}
14991
14992static void
14993do_neon_rshift_narrow (void)
14994{
14995 struct neon_type_el et = neon_check_type (2, NS_DQI,
14996 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
14997 int imm = inst.operands[2].imm;
14998 /* This gets the bounds check, size encoding and immediate bits calculation
14999 right. */
15000 et.size /= 2;
5f4273c7 15001
5287ad62
JB
15002 /* If immediate is zero then we are a pseudo-instruction for
15003 VMOVN.I<size> <Dd>, <Qm> */
15004 if (imm == 0)
15005 {
15006 inst.operands[2].present = 0;
15007 inst.instruction = N_MNEM_vmovn;
15008 do_neon_movn ();
15009 return;
15010 }
5f4273c7 15011
5287ad62 15012 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15013 _("immediate out of range for narrowing operation"));
5287ad62
JB
15014 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15015}
15016
15017static void
15018do_neon_shll (void)
15019{
15020 /* FIXME: Type checking when lengthening. */
15021 struct neon_type_el et = neon_check_type (2, NS_QDI,
15022 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15023 unsigned imm = inst.operands[2].imm;
15024
15025 if (imm == et.size)
15026 {
15027 /* Maximum shift variant. */
88714cb8 15028 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15029 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15030 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15031 inst.instruction |= LOW4 (inst.operands[1].reg);
15032 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15033 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15034
88714cb8 15035 neon_dp_fixup (&inst);
5287ad62
JB
15036 }
15037 else
15038 {
15039 /* A more-specific type check for non-max versions. */
15040 et = neon_check_type (2, NS_QDI,
477330fc 15041 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15042 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15043 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15044 }
15045}
15046
037e8744 15047/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15048 the current instruction is. */
15049
6b9a8b67
MGD
15050#define CVT_FLAVOUR_VAR \
15051 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15052 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15053 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15054 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15055 /* Half-precision conversions. */ \
15056 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15057 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
15058 /* VFP instructions. */ \
15059 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15060 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15061 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15062 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15063 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15064 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15065 /* VFP instructions with bitshift. */ \
15066 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15067 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15068 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15069 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15070 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15071 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15072 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15073 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15074
15075#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15076 neon_cvt_flavour_##C,
15077
15078/* The different types of conversions we can do. */
15079enum neon_cvt_flavour
15080{
15081 CVT_FLAVOUR_VAR
15082 neon_cvt_flavour_invalid,
15083 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15084};
15085
15086#undef CVT_VAR
15087
15088static enum neon_cvt_flavour
15089get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15090{
6b9a8b67
MGD
15091#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15092 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15093 if (et.type != NT_invtype) \
15094 { \
15095 inst.error = NULL; \
15096 return (neon_cvt_flavour_##C); \
5287ad62 15097 }
6b9a8b67 15098
5287ad62 15099 struct neon_type_el et;
037e8744 15100 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15101 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15102 /* The instruction versions which take an immediate take one register
15103 argument, which is extended to the width of the full register. Thus the
15104 "source" and "destination" registers must have the same width. Hack that
15105 here by making the size equal to the key (wider, in this case) operand. */
15106 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15107
6b9a8b67
MGD
15108 CVT_FLAVOUR_VAR;
15109
15110 return neon_cvt_flavour_invalid;
5287ad62
JB
15111#undef CVT_VAR
15112}
15113
7e8e6784
MGD
15114enum neon_cvt_mode
15115{
15116 neon_cvt_mode_a,
15117 neon_cvt_mode_n,
15118 neon_cvt_mode_p,
15119 neon_cvt_mode_m,
15120 neon_cvt_mode_z,
30bdf752
MGD
15121 neon_cvt_mode_x,
15122 neon_cvt_mode_r
7e8e6784
MGD
15123};
15124
037e8744
JB
15125/* Neon-syntax VFP conversions. */
15126
5287ad62 15127static void
6b9a8b67 15128do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15129{
037e8744 15130 const char *opname = 0;
5f4273c7 15131
037e8744 15132 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 15133 {
037e8744
JB
15134 /* Conversions with immediate bitshift. */
15135 const char *enc[] =
477330fc 15136 {
6b9a8b67
MGD
15137#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15138 CVT_FLAVOUR_VAR
15139 NULL
15140#undef CVT_VAR
477330fc 15141 };
037e8744 15142
6b9a8b67 15143 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15144 {
15145 opname = enc[flavour];
15146 constraint (inst.operands[0].reg != inst.operands[1].reg,
15147 _("operands 0 and 1 must be the same register"));
15148 inst.operands[1] = inst.operands[2];
15149 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15150 }
5287ad62
JB
15151 }
15152 else
15153 {
037e8744
JB
15154 /* Conversions without bitshift. */
15155 const char *enc[] =
477330fc 15156 {
6b9a8b67
MGD
15157#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15158 CVT_FLAVOUR_VAR
15159 NULL
15160#undef CVT_VAR
477330fc 15161 };
037e8744 15162
6b9a8b67 15163 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15164 opname = enc[flavour];
037e8744
JB
15165 }
15166
15167 if (opname)
15168 do_vfp_nsyn_opcode (opname);
15169}
15170
15171static void
15172do_vfp_nsyn_cvtz (void)
15173{
15174 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
6b9a8b67 15175 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15176 const char *enc[] =
15177 {
6b9a8b67
MGD
15178#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15179 CVT_FLAVOUR_VAR
15180 NULL
15181#undef CVT_VAR
037e8744
JB
15182 };
15183
6b9a8b67 15184 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15185 do_vfp_nsyn_opcode (enc[flavour]);
15186}
f31fef98 15187
037e8744 15188static void
bacebabc 15189do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15190 enum neon_cvt_mode mode)
15191{
15192 int sz, op;
15193 int rm;
15194
a715796b
TG
15195 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15196 D register operands. */
15197 if (flavour == neon_cvt_flavour_s32_f64
15198 || flavour == neon_cvt_flavour_u32_f64)
15199 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15200 _(BAD_FPU));
15201
7e8e6784
MGD
15202 set_it_insn_type (OUTSIDE_IT_INSN);
15203
15204 switch (flavour)
15205 {
15206 case neon_cvt_flavour_s32_f64:
15207 sz = 1;
827f64ff 15208 op = 1;
7e8e6784
MGD
15209 break;
15210 case neon_cvt_flavour_s32_f32:
15211 sz = 0;
15212 op = 1;
15213 break;
15214 case neon_cvt_flavour_u32_f64:
15215 sz = 1;
15216 op = 0;
15217 break;
15218 case neon_cvt_flavour_u32_f32:
15219 sz = 0;
15220 op = 0;
15221 break;
15222 default:
15223 first_error (_("invalid instruction shape"));
15224 return;
15225 }
15226
15227 switch (mode)
15228 {
15229 case neon_cvt_mode_a: rm = 0; break;
15230 case neon_cvt_mode_n: rm = 1; break;
15231 case neon_cvt_mode_p: rm = 2; break;
15232 case neon_cvt_mode_m: rm = 3; break;
15233 default: first_error (_("invalid rounding mode")); return;
15234 }
15235
15236 NEON_ENCODE (FPV8, inst);
15237 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15238 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15239 inst.instruction |= sz << 8;
15240 inst.instruction |= op << 7;
15241 inst.instruction |= rm << 16;
15242 inst.instruction |= 0xf0000000;
15243 inst.is_neon = TRUE;
15244}
15245
15246static void
15247do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15248{
15249 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 15250 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
6b9a8b67 15251 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15252
e3e535bc 15253 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15254 if (mode == neon_cvt_mode_z
e3e535bc 15255 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
bacebabc
RM
15256 && (flavour == neon_cvt_flavour_s32_f32
15257 || flavour == neon_cvt_flavour_u32_f32
15258 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15259 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15260 && (rs == NS_FD || rs == NS_FF))
15261 {
15262 do_vfp_nsyn_cvtz ();
15263 return;
15264 }
15265
037e8744 15266 /* VFP rather than Neon conversions. */
6b9a8b67 15267 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15268 {
7e8e6784
MGD
15269 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15270 do_vfp_nsyn_cvt (rs, flavour);
15271 else
15272 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15273
037e8744
JB
15274 return;
15275 }
15276
15277 switch (rs)
15278 {
15279 case NS_DDI:
15280 case NS_QQI:
15281 {
477330fc
RM
15282 unsigned immbits;
15283 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
35997600 15284
477330fc
RM
15285 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15286 return;
037e8744 15287
477330fc
RM
15288 /* Fixed-point conversion with #0 immediate is encoded as an
15289 integer conversion. */
15290 if (inst.operands[2].present && inst.operands[2].imm == 0)
15291 goto int_encode;
35997600 15292 immbits = 32 - inst.operands[2].imm;
477330fc
RM
15293 NEON_ENCODE (IMMED, inst);
15294 if (flavour != neon_cvt_flavour_invalid)
15295 inst.instruction |= enctab[flavour];
15296 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15297 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15298 inst.instruction |= LOW4 (inst.operands[1].reg);
15299 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15300 inst.instruction |= neon_quad (rs) << 6;
15301 inst.instruction |= 1 << 21;
15302 inst.instruction |= immbits << 16;
15303
15304 neon_dp_fixup (&inst);
037e8744
JB
15305 }
15306 break;
15307
15308 case NS_DD:
15309 case NS_QQ:
7e8e6784
MGD
15310 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15311 {
15312 NEON_ENCODE (FLOAT, inst);
15313 set_it_insn_type (OUTSIDE_IT_INSN);
15314
15315 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15316 return;
15317
15318 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15319 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15320 inst.instruction |= LOW4 (inst.operands[1].reg);
15321 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15322 inst.instruction |= neon_quad (rs) << 6;
15323 inst.instruction |= (flavour == neon_cvt_flavour_u32_f32) << 7;
15324 inst.instruction |= mode << 8;
15325 if (thumb_mode)
15326 inst.instruction |= 0xfc000000;
15327 else
15328 inst.instruction |= 0xf0000000;
15329 }
15330 else
15331 {
037e8744 15332 int_encode:
7e8e6784
MGD
15333 {
15334 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
037e8744 15335
7e8e6784 15336 NEON_ENCODE (INTEGER, inst);
037e8744 15337
7e8e6784
MGD
15338 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15339 return;
037e8744 15340
7e8e6784
MGD
15341 if (flavour != neon_cvt_flavour_invalid)
15342 inst.instruction |= enctab[flavour];
037e8744 15343
7e8e6784
MGD
15344 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15345 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15346 inst.instruction |= LOW4 (inst.operands[1].reg);
15347 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15348 inst.instruction |= neon_quad (rs) << 6;
15349 inst.instruction |= 2 << 18;
037e8744 15350
7e8e6784
MGD
15351 neon_dp_fixup (&inst);
15352 }
15353 }
15354 break;
037e8744 15355
8e79c3df
CM
15356 /* Half-precision conversions for Advanced SIMD -- neon. */
15357 case NS_QD:
15358 case NS_DQ:
15359
15360 if ((rs == NS_DQ)
15361 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15362 {
15363 as_bad (_("operand size must match register width"));
15364 break;
15365 }
15366
15367 if ((rs == NS_QD)
15368 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15369 {
15370 as_bad (_("operand size must match register width"));
15371 break;
15372 }
15373
15374 if (rs == NS_DQ)
477330fc 15375 inst.instruction = 0x3b60600;
8e79c3df
CM
15376 else
15377 inst.instruction = 0x3b60700;
15378
15379 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15380 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15381 inst.instruction |= LOW4 (inst.operands[1].reg);
15382 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15383 neon_dp_fixup (&inst);
8e79c3df
CM
15384 break;
15385
037e8744
JB
15386 default:
15387 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15388 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15389 do_vfp_nsyn_cvt (rs, flavour);
15390 else
15391 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15392 }
5287ad62
JB
15393}
15394
e3e535bc
NC
15395static void
15396do_neon_cvtr (void)
15397{
7e8e6784 15398 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15399}
15400
15401static void
15402do_neon_cvt (void)
15403{
7e8e6784
MGD
15404 do_neon_cvt_1 (neon_cvt_mode_z);
15405}
15406
15407static void
15408do_neon_cvta (void)
15409{
15410 do_neon_cvt_1 (neon_cvt_mode_a);
15411}
15412
15413static void
15414do_neon_cvtn (void)
15415{
15416 do_neon_cvt_1 (neon_cvt_mode_n);
15417}
15418
15419static void
15420do_neon_cvtp (void)
15421{
15422 do_neon_cvt_1 (neon_cvt_mode_p);
15423}
15424
15425static void
15426do_neon_cvtm (void)
15427{
15428 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15429}
15430
8e79c3df 15431static void
c70a8987 15432do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15433{
c70a8987
MGD
15434 if (is_double)
15435 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15436
c70a8987
MGD
15437 encode_arm_vfp_reg (inst.operands[0].reg,
15438 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15439 encode_arm_vfp_reg (inst.operands[1].reg,
15440 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15441 inst.instruction |= to ? 0x10000 : 0;
15442 inst.instruction |= t ? 0x80 : 0;
15443 inst.instruction |= is_double ? 0x100 : 0;
15444 do_vfp_cond_or_thumb ();
15445}
8e79c3df 15446
c70a8987
MGD
15447static void
15448do_neon_cvttb_1 (bfd_boolean t)
15449{
15450 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_DF, NS_NULL);
8e79c3df 15451
c70a8987
MGD
15452 if (rs == NS_NULL)
15453 return;
15454 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
15455 {
15456 inst.error = NULL;
15457 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
15458 }
15459 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
15460 {
15461 inst.error = NULL;
15462 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
15463 }
15464 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
15465 {
a715796b
TG
15466 /* The VCVTB and VCVTT instructions with D-register operands
15467 don't work for SP only targets. */
15468 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15469 _(BAD_FPU));
15470
c70a8987
MGD
15471 inst.error = NULL;
15472 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
15473 }
15474 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
15475 {
a715796b
TG
15476 /* The VCVTB and VCVTT instructions with D-register operands
15477 don't work for SP only targets. */
15478 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15479 _(BAD_FPU));
15480
c70a8987
MGD
15481 inst.error = NULL;
15482 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
15483 }
15484 else
15485 return;
15486}
15487
15488static void
15489do_neon_cvtb (void)
15490{
15491 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
15492}
15493
15494
15495static void
15496do_neon_cvtt (void)
15497{
c70a8987 15498 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
15499}
15500
5287ad62
JB
15501static void
15502neon_move_immediate (void)
15503{
037e8744
JB
15504 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
15505 struct neon_type_el et = neon_check_type (2, rs,
15506 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 15507 unsigned immlo, immhi = 0, immbits;
c96612cc 15508 int op, cmode, float_p;
5287ad62 15509
037e8744 15510 constraint (et.type == NT_invtype,
477330fc 15511 _("operand size must be specified for immediate VMOV"));
037e8744 15512
5287ad62
JB
15513 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
15514 op = (inst.instruction & (1 << 5)) != 0;
15515
15516 immlo = inst.operands[1].imm;
15517 if (inst.operands[1].regisimm)
15518 immhi = inst.operands[1].reg;
15519
15520 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 15521 _("immediate has bits set outside the operand size"));
5287ad62 15522
c96612cc
JB
15523 float_p = inst.operands[1].immisfloat;
15524
15525 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 15526 et.size, et.type)) == FAIL)
5287ad62
JB
15527 {
15528 /* Invert relevant bits only. */
15529 neon_invert_size (&immlo, &immhi, et.size);
15530 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
15531 with one or the other; those cases are caught by
15532 neon_cmode_for_move_imm. */
5287ad62 15533 op = !op;
c96612cc
JB
15534 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
15535 &op, et.size, et.type)) == FAIL)
477330fc
RM
15536 {
15537 first_error (_("immediate out of range"));
15538 return;
15539 }
5287ad62
JB
15540 }
15541
15542 inst.instruction &= ~(1 << 5);
15543 inst.instruction |= op << 5;
15544
15545 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15546 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 15547 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15548 inst.instruction |= cmode << 8;
15549
15550 neon_write_immbits (immbits);
15551}
15552
15553static void
15554do_neon_mvn (void)
15555{
15556 if (inst.operands[1].isreg)
15557 {
037e8744 15558 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 15559
88714cb8 15560 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15561 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15562 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15563 inst.instruction |= LOW4 (inst.operands[1].reg);
15564 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15565 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15566 }
15567 else
15568 {
88714cb8 15569 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15570 neon_move_immediate ();
15571 }
15572
88714cb8 15573 neon_dp_fixup (&inst);
5287ad62
JB
15574}
15575
15576/* Encode instructions of form:
15577
15578 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 15579 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
15580
15581static void
15582neon_mixed_length (struct neon_type_el et, unsigned size)
15583{
15584 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15585 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15586 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15587 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15588 inst.instruction |= LOW4 (inst.operands[2].reg);
15589 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15590 inst.instruction |= (et.type == NT_unsigned) << 24;
15591 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 15592
88714cb8 15593 neon_dp_fixup (&inst);
5287ad62
JB
15594}
15595
15596static void
15597do_neon_dyadic_long (void)
15598{
15599 /* FIXME: Type checking for lengthening op. */
15600 struct neon_type_el et = neon_check_type (3, NS_QDD,
15601 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
15602 neon_mixed_length (et, et.size);
15603}
15604
15605static void
15606do_neon_abal (void)
15607{
15608 struct neon_type_el et = neon_check_type (3, NS_QDD,
15609 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
15610 neon_mixed_length (et, et.size);
15611}
15612
15613static void
15614neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
15615{
15616 if (inst.operands[2].isscalar)
15617 {
dcbf9037 15618 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 15619 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 15620 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
15621 neon_mul_mac (et, et.type == NT_unsigned);
15622 }
15623 else
15624 {
15625 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 15626 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 15627 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15628 neon_mixed_length (et, et.size);
15629 }
15630}
15631
15632static void
15633do_neon_mac_maybe_scalar_long (void)
15634{
15635 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
15636}
15637
15638static void
15639do_neon_dyadic_wide (void)
15640{
15641 struct neon_type_el et = neon_check_type (3, NS_QQD,
15642 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
15643 neon_mixed_length (et, et.size);
15644}
15645
15646static void
15647do_neon_dyadic_narrow (void)
15648{
15649 struct neon_type_el et = neon_check_type (3, NS_QDD,
15650 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
15651 /* Operand sign is unimportant, and the U bit is part of the opcode,
15652 so force the operand type to integer. */
15653 et.type = NT_integer;
5287ad62
JB
15654 neon_mixed_length (et, et.size / 2);
15655}
15656
15657static void
15658do_neon_mul_sat_scalar_long (void)
15659{
15660 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
15661}
15662
15663static void
15664do_neon_vmull (void)
15665{
15666 if (inst.operands[2].isscalar)
15667 do_neon_mac_maybe_scalar_long ();
15668 else
15669 {
15670 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 15671 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 15672
5287ad62 15673 if (et.type == NT_poly)
477330fc 15674 NEON_ENCODE (POLY, inst);
5287ad62 15675 else
477330fc 15676 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
15677
15678 /* For polynomial encoding the U bit must be zero, and the size must
15679 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
15680 obviously, as 0b10). */
15681 if (et.size == 64)
15682 {
15683 /* Check we're on the correct architecture. */
15684 if (!mark_feature_used (&fpu_crypto_ext_armv8))
15685 inst.error =
15686 _("Instruction form not available on this architecture.");
15687
15688 et.size = 32;
15689 }
15690
5287ad62
JB
15691 neon_mixed_length (et, et.size);
15692 }
15693}
15694
15695static void
15696do_neon_ext (void)
15697{
037e8744 15698 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
15699 struct neon_type_el et = neon_check_type (3, rs,
15700 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15701 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
15702
15703 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
15704 _("shift out of range"));
5287ad62
JB
15705 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15706 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15707 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15708 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15709 inst.instruction |= LOW4 (inst.operands[2].reg);
15710 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 15711 inst.instruction |= neon_quad (rs) << 6;
5287ad62 15712 inst.instruction |= imm << 8;
5f4273c7 15713
88714cb8 15714 neon_dp_fixup (&inst);
5287ad62
JB
15715}
15716
15717static void
15718do_neon_rev (void)
15719{
037e8744 15720 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
15721 struct neon_type_el et = neon_check_type (2, rs,
15722 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15723 unsigned op = (inst.instruction >> 7) & 3;
15724 /* N (width of reversed regions) is encoded as part of the bitmask. We
15725 extract it here to check the elements to be reversed are smaller.
15726 Otherwise we'd get a reserved instruction. */
15727 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 15728 gas_assert (elsize != 0);
5287ad62 15729 constraint (et.size >= elsize,
477330fc 15730 _("elements must be smaller than reversal region"));
037e8744 15731 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
15732}
15733
15734static void
15735do_neon_dup (void)
15736{
15737 if (inst.operands[1].isscalar)
15738 {
037e8744 15739 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 15740 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15741 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 15742 unsigned sizebits = et.size >> 3;
dcbf9037 15743 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 15744 int logsize = neon_logbits (et.size);
dcbf9037 15745 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
15746
15747 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 15748 return;
037e8744 15749
88714cb8 15750 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
15751 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15752 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15753 inst.instruction |= LOW4 (dm);
15754 inst.instruction |= HI1 (dm) << 5;
037e8744 15755 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15756 inst.instruction |= x << 17;
15757 inst.instruction |= sizebits << 16;
5f4273c7 15758
88714cb8 15759 neon_dp_fixup (&inst);
5287ad62
JB
15760 }
15761 else
15762 {
037e8744
JB
15763 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
15764 struct neon_type_el et = neon_check_type (2, rs,
477330fc 15765 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 15766 /* Duplicate ARM register to lanes of vector. */
88714cb8 15767 NEON_ENCODE (ARMREG, inst);
5287ad62 15768 switch (et.size)
477330fc
RM
15769 {
15770 case 8: inst.instruction |= 0x400000; break;
15771 case 16: inst.instruction |= 0x000020; break;
15772 case 32: inst.instruction |= 0x000000; break;
15773 default: break;
15774 }
5287ad62
JB
15775 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15776 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
15777 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 15778 inst.instruction |= neon_quad (rs) << 21;
5287ad62 15779 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 15780 variants, except for the condition field. */
037e8744 15781 do_vfp_cond_or_thumb ();
5287ad62
JB
15782 }
15783}
15784
15785/* VMOV has particularly many variations. It can be one of:
15786 0. VMOV<c><q> <Qd>, <Qm>
15787 1. VMOV<c><q> <Dd>, <Dm>
15788 (Register operations, which are VORR with Rm = Rn.)
15789 2. VMOV<c><q>.<dt> <Qd>, #<imm>
15790 3. VMOV<c><q>.<dt> <Dd>, #<imm>
15791 (Immediate loads.)
15792 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
15793 (ARM register to scalar.)
15794 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
15795 (Two ARM registers to vector.)
15796 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
15797 (Scalar to ARM register.)
15798 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
15799 (Vector to two ARM registers.)
037e8744
JB
15800 8. VMOV.F32 <Sd>, <Sm>
15801 9. VMOV.F64 <Dd>, <Dm>
15802 (VFP register moves.)
15803 10. VMOV.F32 <Sd>, #imm
15804 11. VMOV.F64 <Dd>, #imm
15805 (VFP float immediate load.)
15806 12. VMOV <Rd>, <Sm>
15807 (VFP single to ARM reg.)
15808 13. VMOV <Sd>, <Rm>
15809 (ARM reg to VFP single.)
15810 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
15811 (Two ARM regs to two VFP singles.)
15812 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
15813 (Two VFP singles to two ARM regs.)
5f4273c7 15814
037e8744
JB
15815 These cases can be disambiguated using neon_select_shape, except cases 1/9
15816 and 3/11 which depend on the operand type too.
5f4273c7 15817
5287ad62 15818 All the encoded bits are hardcoded by this function.
5f4273c7 15819
b7fc2769
JB
15820 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
15821 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 15822
5287ad62 15823 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 15824 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
15825
15826static void
15827do_neon_mov (void)
15828{
037e8744
JB
15829 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
15830 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
15831 NS_NULL);
15832 struct neon_type_el et;
15833 const char *ldconst = 0;
5287ad62 15834
037e8744 15835 switch (rs)
5287ad62 15836 {
037e8744
JB
15837 case NS_DD: /* case 1/9. */
15838 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15839 /* It is not an error here if no type is given. */
15840 inst.error = NULL;
15841 if (et.type == NT_float && et.size == 64)
477330fc
RM
15842 {
15843 do_vfp_nsyn_opcode ("fcpyd");
15844 break;
15845 }
037e8744 15846 /* fall through. */
5287ad62 15847
037e8744
JB
15848 case NS_QQ: /* case 0/1. */
15849 {
477330fc
RM
15850 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15851 return;
15852 /* The architecture manual I have doesn't explicitly state which
15853 value the U bit should have for register->register moves, but
15854 the equivalent VORR instruction has U = 0, so do that. */
15855 inst.instruction = 0x0200110;
15856 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15857 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15858 inst.instruction |= LOW4 (inst.operands[1].reg);
15859 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15860 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15861 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15862 inst.instruction |= neon_quad (rs) << 6;
15863
15864 neon_dp_fixup (&inst);
037e8744
JB
15865 }
15866 break;
5f4273c7 15867
037e8744
JB
15868 case NS_DI: /* case 3/11. */
15869 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15870 inst.error = NULL;
15871 if (et.type == NT_float && et.size == 64)
477330fc
RM
15872 {
15873 /* case 11 (fconstd). */
15874 ldconst = "fconstd";
15875 goto encode_fconstd;
15876 }
037e8744
JB
15877 /* fall through. */
15878
15879 case NS_QI: /* case 2/3. */
15880 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 15881 return;
037e8744
JB
15882 inst.instruction = 0x0800010;
15883 neon_move_immediate ();
88714cb8 15884 neon_dp_fixup (&inst);
5287ad62 15885 break;
5f4273c7 15886
037e8744
JB
15887 case NS_SR: /* case 4. */
15888 {
477330fc
RM
15889 unsigned bcdebits = 0;
15890 int logsize;
15891 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
15892 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 15893
05ac0ffb
JB
15894 /* .<size> is optional here, defaulting to .32. */
15895 if (inst.vectype.elems == 0
15896 && inst.operands[0].vectype.type == NT_invtype
15897 && inst.operands[1].vectype.type == NT_invtype)
15898 {
15899 inst.vectype.el[0].type = NT_untyped;
15900 inst.vectype.el[0].size = 32;
15901 inst.vectype.elems = 1;
15902 }
15903
477330fc
RM
15904 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
15905 logsize = neon_logbits (et.size);
15906
15907 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15908 _(BAD_FPU));
15909 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15910 && et.size != 32, _(BAD_FPU));
15911 constraint (et.type == NT_invtype, _("bad type for scalar"));
15912 constraint (x >= 64 / et.size, _("scalar index out of range"));
15913
15914 switch (et.size)
15915 {
15916 case 8: bcdebits = 0x8; break;
15917 case 16: bcdebits = 0x1; break;
15918 case 32: bcdebits = 0x0; break;
15919 default: ;
15920 }
15921
15922 bcdebits |= x << logsize;
15923
15924 inst.instruction = 0xe000b10;
15925 do_vfp_cond_or_thumb ();
15926 inst.instruction |= LOW4 (dn) << 16;
15927 inst.instruction |= HI1 (dn) << 7;
15928 inst.instruction |= inst.operands[1].reg << 12;
15929 inst.instruction |= (bcdebits & 3) << 5;
15930 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
15931 }
15932 break;
5f4273c7 15933
037e8744 15934 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 15935 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 15936 _(BAD_FPU));
b7fc2769 15937
037e8744
JB
15938 inst.instruction = 0xc400b10;
15939 do_vfp_cond_or_thumb ();
15940 inst.instruction |= LOW4 (inst.operands[0].reg);
15941 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
15942 inst.instruction |= inst.operands[1].reg << 12;
15943 inst.instruction |= inst.operands[2].reg << 16;
15944 break;
5f4273c7 15945
037e8744
JB
15946 case NS_RS: /* case 6. */
15947 {
477330fc
RM
15948 unsigned logsize;
15949 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
15950 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
15951 unsigned abcdebits = 0;
037e8744 15952
05ac0ffb
JB
15953 /* .<dt> is optional here, defaulting to .32. */
15954 if (inst.vectype.elems == 0
15955 && inst.operands[0].vectype.type == NT_invtype
15956 && inst.operands[1].vectype.type == NT_invtype)
15957 {
15958 inst.vectype.el[0].type = NT_untyped;
15959 inst.vectype.el[0].size = 32;
15960 inst.vectype.elems = 1;
15961 }
15962
91d6fa6a
NC
15963 et = neon_check_type (2, NS_NULL,
15964 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
15965 logsize = neon_logbits (et.size);
15966
15967 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15968 _(BAD_FPU));
15969 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15970 && et.size != 32, _(BAD_FPU));
15971 constraint (et.type == NT_invtype, _("bad type for scalar"));
15972 constraint (x >= 64 / et.size, _("scalar index out of range"));
15973
15974 switch (et.size)
15975 {
15976 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
15977 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
15978 case 32: abcdebits = 0x00; break;
15979 default: ;
15980 }
15981
15982 abcdebits |= x << logsize;
15983 inst.instruction = 0xe100b10;
15984 do_vfp_cond_or_thumb ();
15985 inst.instruction |= LOW4 (dn) << 16;
15986 inst.instruction |= HI1 (dn) << 7;
15987 inst.instruction |= inst.operands[0].reg << 12;
15988 inst.instruction |= (abcdebits & 3) << 5;
15989 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
15990 }
15991 break;
5f4273c7 15992
037e8744
JB
15993 case NS_RRD: /* case 7 (fmrrd). */
15994 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 15995 _(BAD_FPU));
037e8744
JB
15996
15997 inst.instruction = 0xc500b10;
15998 do_vfp_cond_or_thumb ();
15999 inst.instruction |= inst.operands[0].reg << 12;
16000 inst.instruction |= inst.operands[1].reg << 16;
16001 inst.instruction |= LOW4 (inst.operands[2].reg);
16002 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16003 break;
5f4273c7 16004
037e8744
JB
16005 case NS_FF: /* case 8 (fcpys). */
16006 do_vfp_nsyn_opcode ("fcpys");
16007 break;
5f4273c7 16008
037e8744
JB
16009 case NS_FI: /* case 10 (fconsts). */
16010 ldconst = "fconsts";
16011 encode_fconstd:
16012 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16013 {
16014 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16015 do_vfp_nsyn_opcode (ldconst);
16016 }
5287ad62 16017 else
477330fc 16018 first_error (_("immediate out of range"));
037e8744 16019 break;
5f4273c7 16020
037e8744
JB
16021 case NS_RF: /* case 12 (fmrs). */
16022 do_vfp_nsyn_opcode ("fmrs");
16023 break;
5f4273c7 16024
037e8744
JB
16025 case NS_FR: /* case 13 (fmsr). */
16026 do_vfp_nsyn_opcode ("fmsr");
16027 break;
5f4273c7 16028
037e8744
JB
16029 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16030 (one of which is a list), but we have parsed four. Do some fiddling to
16031 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16032 expect. */
16033 case NS_RRFF: /* case 14 (fmrrs). */
16034 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16035 _("VFP registers must be adjacent"));
037e8744
JB
16036 inst.operands[2].imm = 2;
16037 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16038 do_vfp_nsyn_opcode ("fmrrs");
16039 break;
5f4273c7 16040
037e8744
JB
16041 case NS_FFRR: /* case 15 (fmsrr). */
16042 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16043 _("VFP registers must be adjacent"));
037e8744
JB
16044 inst.operands[1] = inst.operands[2];
16045 inst.operands[2] = inst.operands[3];
16046 inst.operands[0].imm = 2;
16047 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16048 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16049 break;
5f4273c7 16050
4c261dff
NC
16051 case NS_NULL:
16052 /* neon_select_shape has determined that the instruction
16053 shape is wrong and has already set the error message. */
16054 break;
16055
5287ad62
JB
16056 default:
16057 abort ();
16058 }
16059}
16060
16061static void
16062do_neon_rshift_round_imm (void)
16063{
037e8744 16064 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16065 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16066 int imm = inst.operands[2].imm;
16067
16068 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16069 if (imm == 0)
16070 {
16071 inst.operands[2].present = 0;
16072 do_neon_mov ();
16073 return;
16074 }
16075
16076 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16077 _("immediate out of range for shift"));
037e8744 16078 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16079 et.size - imm);
5287ad62
JB
16080}
16081
16082static void
16083do_neon_movl (void)
16084{
16085 struct neon_type_el et = neon_check_type (2, NS_QD,
16086 N_EQK | N_DBL, N_SU_32 | N_KEY);
16087 unsigned sizebits = et.size >> 3;
16088 inst.instruction |= sizebits << 19;
16089 neon_two_same (0, et.type == NT_unsigned, -1);
16090}
16091
16092static void
16093do_neon_trn (void)
16094{
037e8744 16095 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16096 struct neon_type_el et = neon_check_type (2, rs,
16097 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16098 NEON_ENCODE (INTEGER, inst);
037e8744 16099 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16100}
16101
16102static void
16103do_neon_zip_uzp (void)
16104{
037e8744 16105 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16106 struct neon_type_el et = neon_check_type (2, rs,
16107 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16108 if (rs == NS_DD && et.size == 32)
16109 {
16110 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16111 inst.instruction = N_MNEM_vtrn;
16112 do_neon_trn ();
16113 return;
16114 }
037e8744 16115 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16116}
16117
16118static void
16119do_neon_sat_abs_neg (void)
16120{
037e8744 16121 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16122 struct neon_type_el et = neon_check_type (2, rs,
16123 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16124 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16125}
16126
16127static void
16128do_neon_pair_long (void)
16129{
037e8744 16130 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16131 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16132 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16133 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16134 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16135}
16136
16137static void
16138do_neon_recip_est (void)
16139{
037e8744 16140 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16141 struct neon_type_el et = neon_check_type (2, rs,
16142 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
16143 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16144 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16145}
16146
16147static void
16148do_neon_cls (void)
16149{
037e8744 16150 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16151 struct neon_type_el et = neon_check_type (2, rs,
16152 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16153 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16154}
16155
16156static void
16157do_neon_clz (void)
16158{
037e8744 16159 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16160 struct neon_type_el et = neon_check_type (2, rs,
16161 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16162 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16163}
16164
16165static void
16166do_neon_cnt (void)
16167{
037e8744 16168 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16169 struct neon_type_el et = neon_check_type (2, rs,
16170 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16171 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16172}
16173
16174static void
16175do_neon_swp (void)
16176{
037e8744
JB
16177 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16178 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16179}
16180
16181static void
16182do_neon_tbl_tbx (void)
16183{
16184 unsigned listlenbits;
dcbf9037 16185 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16186
5287ad62
JB
16187 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16188 {
dcbf9037 16189 first_error (_("bad list length for table lookup"));
5287ad62
JB
16190 return;
16191 }
5f4273c7 16192
5287ad62
JB
16193 listlenbits = inst.operands[1].imm - 1;
16194 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16195 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16196 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16197 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16198 inst.instruction |= LOW4 (inst.operands[2].reg);
16199 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16200 inst.instruction |= listlenbits << 8;
5f4273c7 16201
88714cb8 16202 neon_dp_fixup (&inst);
5287ad62
JB
16203}
16204
16205static void
16206do_neon_ldm_stm (void)
16207{
16208 /* P, U and L bits are part of bitmask. */
16209 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16210 unsigned offsetbits = inst.operands[1].imm * 2;
16211
037e8744
JB
16212 if (inst.operands[1].issingle)
16213 {
16214 do_vfp_nsyn_ldm_stm (is_dbmode);
16215 return;
16216 }
16217
5287ad62 16218 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16219 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16220
16221 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16222 _("register list must contain at least 1 and at most 16 "
16223 "registers"));
5287ad62
JB
16224
16225 inst.instruction |= inst.operands[0].reg << 16;
16226 inst.instruction |= inst.operands[0].writeback << 21;
16227 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16228 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16229
16230 inst.instruction |= offsetbits;
5f4273c7 16231
037e8744 16232 do_vfp_cond_or_thumb ();
5287ad62
JB
16233}
16234
16235static void
16236do_neon_ldr_str (void)
16237{
5287ad62 16238 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16239
6844b2c2
MGD
16240 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16241 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16242 if (!is_ldr
6844b2c2 16243 && inst.operands[1].reg == REG_PC
ba86b375 16244 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16245 {
94dcf8bf 16246 if (thumb_mode)
6844b2c2 16247 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 16248 else if (warn_on_deprecated)
5c3696f8 16249 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
16250 }
16251
037e8744
JB
16252 if (inst.operands[0].issingle)
16253 {
cd2f129f 16254 if (is_ldr)
477330fc 16255 do_vfp_nsyn_opcode ("flds");
cd2f129f 16256 else
477330fc 16257 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
16258 }
16259 else
5287ad62 16260 {
cd2f129f 16261 if (is_ldr)
477330fc 16262 do_vfp_nsyn_opcode ("fldd");
5287ad62 16263 else
477330fc 16264 do_vfp_nsyn_opcode ("fstd");
5287ad62 16265 }
5287ad62
JB
16266}
16267
16268/* "interleave" version also handles non-interleaving register VLD1/VST1
16269 instructions. */
16270
16271static void
16272do_neon_ld_st_interleave (void)
16273{
037e8744 16274 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 16275 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
16276 unsigned alignbits = 0;
16277 unsigned idx;
16278 /* The bits in this table go:
16279 0: register stride of one (0) or two (1)
16280 1,2: register list length, minus one (1, 2, 3, 4).
16281 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
16282 We use -1 for invalid entries. */
16283 const int typetable[] =
16284 {
16285 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
16286 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
16287 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
16288 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
16289 };
16290 int typebits;
16291
dcbf9037
JB
16292 if (et.type == NT_invtype)
16293 return;
16294
5287ad62
JB
16295 if (inst.operands[1].immisalign)
16296 switch (inst.operands[1].imm >> 8)
16297 {
16298 case 64: alignbits = 1; break;
16299 case 128:
477330fc 16300 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 16301 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
16302 goto bad_alignment;
16303 alignbits = 2;
16304 break;
5287ad62 16305 case 256:
477330fc
RM
16306 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
16307 goto bad_alignment;
16308 alignbits = 3;
16309 break;
5287ad62
JB
16310 default:
16311 bad_alignment:
477330fc
RM
16312 first_error (_("bad alignment"));
16313 return;
5287ad62
JB
16314 }
16315
16316 inst.instruction |= alignbits << 4;
16317 inst.instruction |= neon_logbits (et.size) << 6;
16318
16319 /* Bits [4:6] of the immediate in a list specifier encode register stride
16320 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
16321 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
16322 up the right value for "type" in a table based on this value and the given
16323 list style, then stick it back. */
16324 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 16325 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
16326
16327 typebits = typetable[idx];
5f4273c7 16328
5287ad62 16329 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
16330 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
16331 _("bad element type for instruction"));
5287ad62
JB
16332
16333 inst.instruction &= ~0xf00;
16334 inst.instruction |= typebits << 8;
16335}
16336
16337/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
16338 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
16339 otherwise. The variable arguments are a list of pairs of legal (size, align)
16340 values, terminated with -1. */
16341
16342static int
16343neon_alignment_bit (int size, int align, int *do_align, ...)
16344{
16345 va_list ap;
16346 int result = FAIL, thissize, thisalign;
5f4273c7 16347
5287ad62
JB
16348 if (!inst.operands[1].immisalign)
16349 {
16350 *do_align = 0;
16351 return SUCCESS;
16352 }
5f4273c7 16353
5287ad62
JB
16354 va_start (ap, do_align);
16355
16356 do
16357 {
16358 thissize = va_arg (ap, int);
16359 if (thissize == -1)
477330fc 16360 break;
5287ad62
JB
16361 thisalign = va_arg (ap, int);
16362
16363 if (size == thissize && align == thisalign)
477330fc 16364 result = SUCCESS;
5287ad62
JB
16365 }
16366 while (result != SUCCESS);
16367
16368 va_end (ap);
16369
16370 if (result == SUCCESS)
16371 *do_align = 1;
16372 else
dcbf9037 16373 first_error (_("unsupported alignment for instruction"));
5f4273c7 16374
5287ad62
JB
16375 return result;
16376}
16377
16378static void
16379do_neon_ld_st_lane (void)
16380{
037e8744 16381 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
16382 int align_good, do_align = 0;
16383 int logsize = neon_logbits (et.size);
16384 int align = inst.operands[1].imm >> 8;
16385 int n = (inst.instruction >> 8) & 3;
16386 int max_el = 64 / et.size;
5f4273c7 16387
dcbf9037
JB
16388 if (et.type == NT_invtype)
16389 return;
5f4273c7 16390
5287ad62 16391 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 16392 _("bad list length"));
5287ad62 16393 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 16394 _("scalar index out of range"));
5287ad62 16395 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
16396 && et.size == 8,
16397 _("stride of 2 unavailable when element size is 8"));
5f4273c7 16398
5287ad62
JB
16399 switch (n)
16400 {
16401 case 0: /* VLD1 / VST1. */
16402 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
477330fc 16403 32, 32, -1);
5287ad62 16404 if (align_good == FAIL)
477330fc 16405 return;
5287ad62 16406 if (do_align)
477330fc
RM
16407 {
16408 unsigned alignbits = 0;
16409 switch (et.size)
16410 {
16411 case 16: alignbits = 0x1; break;
16412 case 32: alignbits = 0x3; break;
16413 default: ;
16414 }
16415 inst.instruction |= alignbits << 4;
16416 }
5287ad62
JB
16417 break;
16418
16419 case 1: /* VLD2 / VST2. */
16420 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
477330fc 16421 32, 64, -1);
5287ad62 16422 if (align_good == FAIL)
477330fc 16423 return;
5287ad62 16424 if (do_align)
477330fc 16425 inst.instruction |= 1 << 4;
5287ad62
JB
16426 break;
16427
16428 case 2: /* VLD3 / VST3. */
16429 constraint (inst.operands[1].immisalign,
477330fc 16430 _("can't use alignment with this instruction"));
5287ad62
JB
16431 break;
16432
16433 case 3: /* VLD4 / VST4. */
16434 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
477330fc 16435 16, 64, 32, 64, 32, 128, -1);
5287ad62 16436 if (align_good == FAIL)
477330fc 16437 return;
5287ad62 16438 if (do_align)
477330fc
RM
16439 {
16440 unsigned alignbits = 0;
16441 switch (et.size)
16442 {
16443 case 8: alignbits = 0x1; break;
16444 case 16: alignbits = 0x1; break;
16445 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
16446 default: ;
16447 }
16448 inst.instruction |= alignbits << 4;
16449 }
5287ad62
JB
16450 break;
16451
16452 default: ;
16453 }
16454
16455 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
16456 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16457 inst.instruction |= 1 << (4 + logsize);
5f4273c7 16458
5287ad62
JB
16459 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
16460 inst.instruction |= logsize << 10;
16461}
16462
16463/* Encode single n-element structure to all lanes VLD<n> instructions. */
16464
16465static void
16466do_neon_ld_dup (void)
16467{
037e8744 16468 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
16469 int align_good, do_align = 0;
16470
dcbf9037
JB
16471 if (et.type == NT_invtype)
16472 return;
16473
5287ad62
JB
16474 switch ((inst.instruction >> 8) & 3)
16475 {
16476 case 0: /* VLD1. */
9c2799c2 16477 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 16478 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
477330fc 16479 &do_align, 16, 16, 32, 32, -1);
5287ad62 16480 if (align_good == FAIL)
477330fc 16481 return;
5287ad62 16482 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
16483 {
16484 case 1: break;
16485 case 2: inst.instruction |= 1 << 5; break;
16486 default: first_error (_("bad list length")); return;
16487 }
5287ad62
JB
16488 inst.instruction |= neon_logbits (et.size) << 6;
16489 break;
16490
16491 case 1: /* VLD2. */
16492 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
477330fc 16493 &do_align, 8, 16, 16, 32, 32, 64, -1);
5287ad62 16494 if (align_good == FAIL)
477330fc 16495 return;
5287ad62 16496 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 16497 _("bad list length"));
5287ad62 16498 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16499 inst.instruction |= 1 << 5;
5287ad62
JB
16500 inst.instruction |= neon_logbits (et.size) << 6;
16501 break;
16502
16503 case 2: /* VLD3. */
16504 constraint (inst.operands[1].immisalign,
477330fc 16505 _("can't use alignment with this instruction"));
5287ad62 16506 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 16507 _("bad list length"));
5287ad62 16508 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16509 inst.instruction |= 1 << 5;
5287ad62
JB
16510 inst.instruction |= neon_logbits (et.size) << 6;
16511 break;
16512
16513 case 3: /* VLD4. */
16514 {
477330fc
RM
16515 int align = inst.operands[1].imm >> 8;
16516 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
16517 16, 64, 32, 64, 32, 128, -1);
16518 if (align_good == FAIL)
16519 return;
16520 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
16521 _("bad list length"));
16522 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16523 inst.instruction |= 1 << 5;
16524 if (et.size == 32 && align == 128)
16525 inst.instruction |= 0x3 << 6;
16526 else
16527 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
16528 }
16529 break;
16530
16531 default: ;
16532 }
16533
16534 inst.instruction |= do_align << 4;
16535}
16536
16537/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
16538 apart from bits [11:4]. */
16539
16540static void
16541do_neon_ldx_stx (void)
16542{
b1a769ed
DG
16543 if (inst.operands[1].isreg)
16544 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16545
5287ad62
JB
16546 switch (NEON_LANE (inst.operands[0].imm))
16547 {
16548 case NEON_INTERLEAVE_LANES:
88714cb8 16549 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
16550 do_neon_ld_st_interleave ();
16551 break;
5f4273c7 16552
5287ad62 16553 case NEON_ALL_LANES:
88714cb8 16554 NEON_ENCODE (DUP, inst);
2d51fb74
JB
16555 if (inst.instruction == N_INV)
16556 {
16557 first_error ("only loads support such operands");
16558 break;
16559 }
5287ad62
JB
16560 do_neon_ld_dup ();
16561 break;
5f4273c7 16562
5287ad62 16563 default:
88714cb8 16564 NEON_ENCODE (LANE, inst);
5287ad62
JB
16565 do_neon_ld_st_lane ();
16566 }
16567
16568 /* L bit comes from bit mask. */
16569 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16570 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16571 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 16572
5287ad62
JB
16573 if (inst.operands[1].postind)
16574 {
16575 int postreg = inst.operands[1].imm & 0xf;
16576 constraint (!inst.operands[1].immisreg,
477330fc 16577 _("post-index must be a register"));
5287ad62 16578 constraint (postreg == 0xd || postreg == 0xf,
477330fc 16579 _("bad register for post-index"));
5287ad62
JB
16580 inst.instruction |= postreg;
16581 }
4f2374c7 16582 else
5287ad62 16583 {
4f2374c7
WN
16584 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
16585 constraint (inst.reloc.exp.X_op != O_constant
16586 || inst.reloc.exp.X_add_number != 0,
16587 BAD_ADDR_MODE);
16588
16589 if (inst.operands[1].writeback)
16590 {
16591 inst.instruction |= 0xd;
16592 }
16593 else
16594 inst.instruction |= 0xf;
5287ad62 16595 }
5f4273c7 16596
5287ad62
JB
16597 if (thumb_mode)
16598 inst.instruction |= 0xf9000000;
16599 else
16600 inst.instruction |= 0xf4000000;
16601}
33399f07
MGD
16602
16603/* FP v8. */
16604static void
16605do_vfp_nsyn_fpv8 (enum neon_shape rs)
16606{
a715796b
TG
16607 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
16608 D register operands. */
16609 if (neon_shape_class[rs] == SC_DOUBLE)
16610 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16611 _(BAD_FPU));
16612
33399f07
MGD
16613 NEON_ENCODE (FPV8, inst);
16614
16615 if (rs == NS_FFF)
16616 do_vfp_sp_dyadic ();
16617 else
16618 do_vfp_dp_rd_rn_rm ();
16619
16620 if (rs == NS_DDD)
16621 inst.instruction |= 0x100;
16622
16623 inst.instruction |= 0xf0000000;
16624}
16625
16626static void
16627do_vsel (void)
16628{
16629 set_it_insn_type (OUTSIDE_IT_INSN);
16630
16631 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
16632 first_error (_("invalid instruction shape"));
16633}
16634
73924fbc
MGD
16635static void
16636do_vmaxnm (void)
16637{
16638 set_it_insn_type (OUTSIDE_IT_INSN);
16639
16640 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
16641 return;
16642
16643 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16644 return;
16645
16646 neon_dyadic_misc (NT_untyped, N_F32, 0);
16647}
16648
30bdf752
MGD
16649static void
16650do_vrint_1 (enum neon_cvt_mode mode)
16651{
16652 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_QQ, NS_NULL);
16653 struct neon_type_el et;
16654
16655 if (rs == NS_NULL)
16656 return;
16657
a715796b
TG
16658 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
16659 D register operands. */
16660 if (neon_shape_class[rs] == SC_DOUBLE)
16661 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16662 _(BAD_FPU));
16663
30bdf752
MGD
16664 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
16665 if (et.type != NT_invtype)
16666 {
16667 /* VFP encodings. */
16668 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
16669 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
16670 set_it_insn_type (OUTSIDE_IT_INSN);
16671
16672 NEON_ENCODE (FPV8, inst);
16673 if (rs == NS_FF)
16674 do_vfp_sp_monadic ();
16675 else
16676 do_vfp_dp_rd_rm ();
16677
16678 switch (mode)
16679 {
16680 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
16681 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
16682 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
16683 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
16684 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
16685 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
16686 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
16687 default: abort ();
16688 }
16689
16690 inst.instruction |= (rs == NS_DD) << 8;
16691 do_vfp_cond_or_thumb ();
16692 }
16693 else
16694 {
16695 /* Neon encodings (or something broken...). */
16696 inst.error = NULL;
16697 et = neon_check_type (2, rs, N_EQK, N_F32 | N_KEY);
16698
16699 if (et.type == NT_invtype)
16700 return;
16701
16702 set_it_insn_type (OUTSIDE_IT_INSN);
16703 NEON_ENCODE (FLOAT, inst);
16704
16705 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
16706 return;
16707
16708 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16709 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16710 inst.instruction |= LOW4 (inst.operands[1].reg);
16711 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16712 inst.instruction |= neon_quad (rs) << 6;
16713 switch (mode)
16714 {
16715 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
16716 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
16717 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
16718 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
16719 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
16720 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
16721 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
16722 default: abort ();
16723 }
16724
16725 if (thumb_mode)
16726 inst.instruction |= 0xfc000000;
16727 else
16728 inst.instruction |= 0xf0000000;
16729 }
16730}
16731
16732static void
16733do_vrintx (void)
16734{
16735 do_vrint_1 (neon_cvt_mode_x);
16736}
16737
16738static void
16739do_vrintz (void)
16740{
16741 do_vrint_1 (neon_cvt_mode_z);
16742}
16743
16744static void
16745do_vrintr (void)
16746{
16747 do_vrint_1 (neon_cvt_mode_r);
16748}
16749
16750static void
16751do_vrinta (void)
16752{
16753 do_vrint_1 (neon_cvt_mode_a);
16754}
16755
16756static void
16757do_vrintn (void)
16758{
16759 do_vrint_1 (neon_cvt_mode_n);
16760}
16761
16762static void
16763do_vrintp (void)
16764{
16765 do_vrint_1 (neon_cvt_mode_p);
16766}
16767
16768static void
16769do_vrintm (void)
16770{
16771 do_vrint_1 (neon_cvt_mode_m);
16772}
16773
91ff7894
MGD
16774/* Crypto v1 instructions. */
16775static void
16776do_crypto_2op_1 (unsigned elttype, int op)
16777{
16778 set_it_insn_type (OUTSIDE_IT_INSN);
16779
16780 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
16781 == NT_invtype)
16782 return;
16783
16784 inst.error = NULL;
16785
16786 NEON_ENCODE (INTEGER, inst);
16787 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16788 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16789 inst.instruction |= LOW4 (inst.operands[1].reg);
16790 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16791 if (op != -1)
16792 inst.instruction |= op << 6;
16793
16794 if (thumb_mode)
16795 inst.instruction |= 0xfc000000;
16796 else
16797 inst.instruction |= 0xf0000000;
16798}
16799
48adcd8e
MGD
16800static void
16801do_crypto_3op_1 (int u, int op)
16802{
16803 set_it_insn_type (OUTSIDE_IT_INSN);
16804
16805 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
16806 N_32 | N_UNT | N_KEY).type == NT_invtype)
16807 return;
16808
16809 inst.error = NULL;
16810
16811 NEON_ENCODE (INTEGER, inst);
16812 neon_three_same (1, u, 8 << op);
16813}
16814
91ff7894
MGD
16815static void
16816do_aese (void)
16817{
16818 do_crypto_2op_1 (N_8, 0);
16819}
16820
16821static void
16822do_aesd (void)
16823{
16824 do_crypto_2op_1 (N_8, 1);
16825}
16826
16827static void
16828do_aesmc (void)
16829{
16830 do_crypto_2op_1 (N_8, 2);
16831}
16832
16833static void
16834do_aesimc (void)
16835{
16836 do_crypto_2op_1 (N_8, 3);
16837}
16838
48adcd8e
MGD
16839static void
16840do_sha1c (void)
16841{
16842 do_crypto_3op_1 (0, 0);
16843}
16844
16845static void
16846do_sha1p (void)
16847{
16848 do_crypto_3op_1 (0, 1);
16849}
16850
16851static void
16852do_sha1m (void)
16853{
16854 do_crypto_3op_1 (0, 2);
16855}
16856
16857static void
16858do_sha1su0 (void)
16859{
16860 do_crypto_3op_1 (0, 3);
16861}
91ff7894 16862
48adcd8e
MGD
16863static void
16864do_sha256h (void)
16865{
16866 do_crypto_3op_1 (1, 0);
16867}
16868
16869static void
16870do_sha256h2 (void)
16871{
16872 do_crypto_3op_1 (1, 1);
16873}
16874
16875static void
16876do_sha256su1 (void)
16877{
16878 do_crypto_3op_1 (1, 2);
16879}
3c9017d2
MGD
16880
16881static void
16882do_sha1h (void)
16883{
16884 do_crypto_2op_1 (N_32, -1);
16885}
16886
16887static void
16888do_sha1su1 (void)
16889{
16890 do_crypto_2op_1 (N_32, 0);
16891}
16892
16893static void
16894do_sha256su0 (void)
16895{
16896 do_crypto_2op_1 (N_32, 1);
16897}
dd5181d5
KT
16898
16899static void
16900do_crc32_1 (unsigned int poly, unsigned int sz)
16901{
16902 unsigned int Rd = inst.operands[0].reg;
16903 unsigned int Rn = inst.operands[1].reg;
16904 unsigned int Rm = inst.operands[2].reg;
16905
16906 set_it_insn_type (OUTSIDE_IT_INSN);
16907 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
16908 inst.instruction |= LOW4 (Rn) << 16;
16909 inst.instruction |= LOW4 (Rm);
16910 inst.instruction |= sz << (thumb_mode ? 4 : 21);
16911 inst.instruction |= poly << (thumb_mode ? 20 : 9);
16912
16913 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
16914 as_warn (UNPRED_REG ("r15"));
16915 if (thumb_mode && (Rd == REG_SP || Rn == REG_SP || Rm == REG_SP))
16916 as_warn (UNPRED_REG ("r13"));
16917}
16918
16919static void
16920do_crc32b (void)
16921{
16922 do_crc32_1 (0, 0);
16923}
16924
16925static void
16926do_crc32h (void)
16927{
16928 do_crc32_1 (0, 1);
16929}
16930
16931static void
16932do_crc32w (void)
16933{
16934 do_crc32_1 (0, 2);
16935}
16936
16937static void
16938do_crc32cb (void)
16939{
16940 do_crc32_1 (1, 0);
16941}
16942
16943static void
16944do_crc32ch (void)
16945{
16946 do_crc32_1 (1, 1);
16947}
16948
16949static void
16950do_crc32cw (void)
16951{
16952 do_crc32_1 (1, 2);
16953}
16954
5287ad62
JB
16955\f
16956/* Overall per-instruction processing. */
16957
16958/* We need to be able to fix up arbitrary expressions in some statements.
16959 This is so that we can handle symbols that are an arbitrary distance from
16960 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
16961 which returns part of an address in a form which will be valid for
16962 a data instruction. We do this by pushing the expression into a symbol
16963 in the expr_section, and creating a fix for that. */
16964
16965static void
16966fix_new_arm (fragS * frag,
16967 int where,
16968 short int size,
16969 expressionS * exp,
16970 int pc_rel,
16971 int reloc)
16972{
16973 fixS * new_fix;
16974
16975 switch (exp->X_op)
16976 {
16977 case O_constant:
6e7ce2cd
PB
16978 if (pc_rel)
16979 {
16980 /* Create an absolute valued symbol, so we have something to
477330fc
RM
16981 refer to in the object file. Unfortunately for us, gas's
16982 generic expression parsing will already have folded out
16983 any use of .set foo/.type foo %function that may have
16984 been used to set type information of the target location,
16985 that's being specified symbolically. We have to presume
16986 the user knows what they are doing. */
6e7ce2cd
PB
16987 char name[16 + 8];
16988 symbolS *symbol;
16989
16990 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
16991
16992 symbol = symbol_find_or_make (name);
16993 S_SET_SEGMENT (symbol, absolute_section);
16994 symbol_set_frag (symbol, &zero_address_frag);
16995 S_SET_VALUE (symbol, exp->X_add_number);
16996 exp->X_op = O_symbol;
16997 exp->X_add_symbol = symbol;
16998 exp->X_add_number = 0;
16999 }
17000 /* FALLTHROUGH */
5287ad62
JB
17001 case O_symbol:
17002 case O_add:
17003 case O_subtract:
21d799b5 17004 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 17005 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17006 break;
17007
17008 default:
21d799b5 17009 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 17010 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17011 break;
17012 }
17013
17014 /* Mark whether the fix is to a THUMB instruction, or an ARM
17015 instruction. */
17016 new_fix->tc_fix_data = thumb_mode;
17017}
17018
17019/* Create a frg for an instruction requiring relaxation. */
17020static void
17021output_relax_insn (void)
17022{
17023 char * to;
17024 symbolS *sym;
0110f2b8
PB
17025 int offset;
17026
6e1cb1a6
PB
17027 /* The size of the instruction is unknown, so tie the debug info to the
17028 start of the instruction. */
17029 dwarf2_emit_insn (0);
6e1cb1a6 17030
0110f2b8
PB
17031 switch (inst.reloc.exp.X_op)
17032 {
17033 case O_symbol:
17034 sym = inst.reloc.exp.X_add_symbol;
17035 offset = inst.reloc.exp.X_add_number;
17036 break;
17037 case O_constant:
17038 sym = NULL;
17039 offset = inst.reloc.exp.X_add_number;
17040 break;
17041 default:
17042 sym = make_expr_symbol (&inst.reloc.exp);
17043 offset = 0;
17044 break;
17045 }
17046 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17047 inst.relax, sym, offset, NULL/*offset, opcode*/);
17048 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
17049}
17050
17051/* Write a 32-bit thumb instruction to buf. */
17052static void
17053put_thumb32_insn (char * buf, unsigned long insn)
17054{
17055 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17056 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17057}
17058
b99bd4ef 17059static void
c19d1205 17060output_inst (const char * str)
b99bd4ef 17061{
c19d1205 17062 char * to = NULL;
b99bd4ef 17063
c19d1205 17064 if (inst.error)
b99bd4ef 17065 {
c19d1205 17066 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
17067 return;
17068 }
5f4273c7
NC
17069 if (inst.relax)
17070 {
17071 output_relax_insn ();
0110f2b8 17072 return;
5f4273c7 17073 }
c19d1205
ZW
17074 if (inst.size == 0)
17075 return;
b99bd4ef 17076
c19d1205 17077 to = frag_more (inst.size);
8dc2430f
NC
17078 /* PR 9814: Record the thumb mode into the current frag so that we know
17079 what type of NOP padding to use, if necessary. We override any previous
17080 setting so that if the mode has changed then the NOPS that we use will
17081 match the encoding of the last instruction in the frag. */
cd000bff 17082 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
17083
17084 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 17085 {
9c2799c2 17086 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 17087 put_thumb32_insn (to, inst.instruction);
b99bd4ef 17088 }
c19d1205 17089 else if (inst.size > INSN_SIZE)
b99bd4ef 17090 {
9c2799c2 17091 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
17092 md_number_to_chars (to, inst.instruction, INSN_SIZE);
17093 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 17094 }
c19d1205
ZW
17095 else
17096 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 17097
c19d1205
ZW
17098 if (inst.reloc.type != BFD_RELOC_UNUSED)
17099 fix_new_arm (frag_now, to - frag_now->fr_literal,
17100 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
17101 inst.reloc.type);
b99bd4ef 17102
c19d1205 17103 dwarf2_emit_insn (inst.size);
c19d1205 17104}
b99bd4ef 17105
e07e6e58
NC
17106static char *
17107output_it_inst (int cond, int mask, char * to)
17108{
17109 unsigned long instruction = 0xbf00;
17110
17111 mask &= 0xf;
17112 instruction |= mask;
17113 instruction |= cond << 4;
17114
17115 if (to == NULL)
17116 {
17117 to = frag_more (2);
17118#ifdef OBJ_ELF
17119 dwarf2_emit_insn (2);
17120#endif
17121 }
17122
17123 md_number_to_chars (to, instruction, 2);
17124
17125 return to;
17126}
17127
c19d1205
ZW
17128/* Tag values used in struct asm_opcode's tag field. */
17129enum opcode_tag
17130{
17131 OT_unconditional, /* Instruction cannot be conditionalized.
17132 The ARM condition field is still 0xE. */
17133 OT_unconditionalF, /* Instruction cannot be conditionalized
17134 and carries 0xF in its ARM condition field. */
17135 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 17136 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
17137 suffix, others place 0xF where the condition field
17138 would be. */
c19d1205
ZW
17139 OT_cinfix3, /* Instruction takes a conditional infix,
17140 beginning at character index 3. (In
17141 unified mode, it becomes a suffix.) */
088fa78e
KH
17142 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
17143 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
17144 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
17145 character index 3, even in unified mode. Used for
17146 legacy instructions where suffix and infix forms
17147 may be ambiguous. */
c19d1205 17148 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 17149 suffix or an infix at character index 3. */
c19d1205
ZW
17150 OT_odd_infix_unc, /* This is the unconditional variant of an
17151 instruction that takes a conditional infix
17152 at an unusual position. In unified mode,
17153 this variant will accept a suffix. */
17154 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
17155 are the conditional variants of instructions that
17156 take conditional infixes in unusual positions.
17157 The infix appears at character index
17158 (tag - OT_odd_infix_0). These are not accepted
17159 in unified mode. */
17160};
b99bd4ef 17161
c19d1205
ZW
17162/* Subroutine of md_assemble, responsible for looking up the primary
17163 opcode from the mnemonic the user wrote. STR points to the
17164 beginning of the mnemonic.
17165
17166 This is not simply a hash table lookup, because of conditional
17167 variants. Most instructions have conditional variants, which are
17168 expressed with a _conditional affix_ to the mnemonic. If we were
17169 to encode each conditional variant as a literal string in the opcode
17170 table, it would have approximately 20,000 entries.
17171
17172 Most mnemonics take this affix as a suffix, and in unified syntax,
17173 'most' is upgraded to 'all'. However, in the divided syntax, some
17174 instructions take the affix as an infix, notably the s-variants of
17175 the arithmetic instructions. Of those instructions, all but six
17176 have the infix appear after the third character of the mnemonic.
17177
17178 Accordingly, the algorithm for looking up primary opcodes given
17179 an identifier is:
17180
17181 1. Look up the identifier in the opcode table.
17182 If we find a match, go to step U.
17183
17184 2. Look up the last two characters of the identifier in the
17185 conditions table. If we find a match, look up the first N-2
17186 characters of the identifier in the opcode table. If we
17187 find a match, go to step CE.
17188
17189 3. Look up the fourth and fifth characters of the identifier in
17190 the conditions table. If we find a match, extract those
17191 characters from the identifier, and look up the remaining
17192 characters in the opcode table. If we find a match, go
17193 to step CM.
17194
17195 4. Fail.
17196
17197 U. Examine the tag field of the opcode structure, in case this is
17198 one of the six instructions with its conditional infix in an
17199 unusual place. If it is, the tag tells us where to find the
17200 infix; look it up in the conditions table and set inst.cond
17201 accordingly. Otherwise, this is an unconditional instruction.
17202 Again set inst.cond accordingly. Return the opcode structure.
17203
17204 CE. Examine the tag field to make sure this is an instruction that
17205 should receive a conditional suffix. If it is not, fail.
17206 Otherwise, set inst.cond from the suffix we already looked up,
17207 and return the opcode structure.
17208
17209 CM. Examine the tag field to make sure this is an instruction that
17210 should receive a conditional infix after the third character.
17211 If it is not, fail. Otherwise, undo the edits to the current
17212 line of input and proceed as for case CE. */
17213
17214static const struct asm_opcode *
17215opcode_lookup (char **str)
17216{
17217 char *end, *base;
17218 char *affix;
17219 const struct asm_opcode *opcode;
17220 const struct asm_cond *cond;
e3cb604e 17221 char save[2];
c19d1205
ZW
17222
17223 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 17224 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 17225 for (base = end = *str; *end != '\0'; end++)
721a8186 17226 if (*end == ' ' || *end == '.')
c19d1205 17227 break;
b99bd4ef 17228
c19d1205 17229 if (end == base)
c921be7d 17230 return NULL;
b99bd4ef 17231
5287ad62 17232 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 17233 if (end[0] == '.')
b99bd4ef 17234 {
5287ad62 17235 int offset = 2;
5f4273c7 17236
267d2029 17237 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 17238 use. */
267d2029 17239 if (unified_syntax && end[1] == 'w')
c19d1205 17240 inst.size_req = 4;
267d2029 17241 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
17242 inst.size_req = 2;
17243 else
477330fc 17244 offset = 0;
5287ad62
JB
17245
17246 inst.vectype.elems = 0;
17247
17248 *str = end + offset;
b99bd4ef 17249
5f4273c7 17250 if (end[offset] == '.')
5287ad62 17251 {
267d2029 17252 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
17253 non-unified ARM syntax mode). */
17254 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 17255 return NULL;
477330fc 17256 }
5287ad62 17257 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 17258 return NULL;
b99bd4ef 17259 }
c19d1205
ZW
17260 else
17261 *str = end;
b99bd4ef 17262
c19d1205 17263 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 17264 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17265 end - base);
c19d1205 17266 if (opcode)
b99bd4ef 17267 {
c19d1205
ZW
17268 /* step U */
17269 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 17270 {
c19d1205
ZW
17271 inst.cond = COND_ALWAYS;
17272 return opcode;
b99bd4ef 17273 }
b99bd4ef 17274
278df34e 17275 if (warn_on_deprecated && unified_syntax)
5c3696f8 17276 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 17277 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 17278 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 17279 gas_assert (cond);
b99bd4ef 17280
c19d1205
ZW
17281 inst.cond = cond->value;
17282 return opcode;
17283 }
b99bd4ef 17284
c19d1205
ZW
17285 /* Cannot have a conditional suffix on a mnemonic of less than two
17286 characters. */
17287 if (end - base < 3)
c921be7d 17288 return NULL;
b99bd4ef 17289
c19d1205
ZW
17290 /* Look for suffixed mnemonic. */
17291 affix = end - 2;
21d799b5
NC
17292 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
17293 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17294 affix - base);
c19d1205
ZW
17295 if (opcode && cond)
17296 {
17297 /* step CE */
17298 switch (opcode->tag)
17299 {
e3cb604e
PB
17300 case OT_cinfix3_legacy:
17301 /* Ignore conditional suffixes matched on infix only mnemonics. */
17302 break;
17303
c19d1205 17304 case OT_cinfix3:
088fa78e 17305 case OT_cinfix3_deprecated:
c19d1205
ZW
17306 case OT_odd_infix_unc:
17307 if (!unified_syntax)
e3cb604e 17308 return 0;
c19d1205
ZW
17309 /* else fall through */
17310
17311 case OT_csuffix:
477330fc 17312 case OT_csuffixF:
c19d1205
ZW
17313 case OT_csuf_or_in3:
17314 inst.cond = cond->value;
17315 return opcode;
17316
17317 case OT_unconditional:
17318 case OT_unconditionalF:
dfa9f0d5 17319 if (thumb_mode)
c921be7d 17320 inst.cond = cond->value;
dfa9f0d5
PB
17321 else
17322 {
c921be7d 17323 /* Delayed diagnostic. */
dfa9f0d5
PB
17324 inst.error = BAD_COND;
17325 inst.cond = COND_ALWAYS;
17326 }
c19d1205 17327 return opcode;
b99bd4ef 17328
c19d1205 17329 default:
c921be7d 17330 return NULL;
c19d1205
ZW
17331 }
17332 }
b99bd4ef 17333
c19d1205
ZW
17334 /* Cannot have a usual-position infix on a mnemonic of less than
17335 six characters (five would be a suffix). */
17336 if (end - base < 6)
c921be7d 17337 return NULL;
b99bd4ef 17338
c19d1205
ZW
17339 /* Look for infixed mnemonic in the usual position. */
17340 affix = base + 3;
21d799b5 17341 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 17342 if (!cond)
c921be7d 17343 return NULL;
e3cb604e
PB
17344
17345 memcpy (save, affix, 2);
17346 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 17347 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17348 (end - base) - 2);
e3cb604e
PB
17349 memmove (affix + 2, affix, (end - affix) - 2);
17350 memcpy (affix, save, 2);
17351
088fa78e
KH
17352 if (opcode
17353 && (opcode->tag == OT_cinfix3
17354 || opcode->tag == OT_cinfix3_deprecated
17355 || opcode->tag == OT_csuf_or_in3
17356 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 17357 {
c921be7d 17358 /* Step CM. */
278df34e 17359 if (warn_on_deprecated && unified_syntax
088fa78e
KH
17360 && (opcode->tag == OT_cinfix3
17361 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 17362 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
17363
17364 inst.cond = cond->value;
17365 return opcode;
b99bd4ef
NC
17366 }
17367
c921be7d 17368 return NULL;
b99bd4ef
NC
17369}
17370
e07e6e58
NC
17371/* This function generates an initial IT instruction, leaving its block
17372 virtually open for the new instructions. Eventually,
17373 the mask will be updated by now_it_add_mask () each time
17374 a new instruction needs to be included in the IT block.
17375 Finally, the block is closed with close_automatic_it_block ().
17376 The block closure can be requested either from md_assemble (),
17377 a tencode (), or due to a label hook. */
17378
17379static void
17380new_automatic_it_block (int cond)
17381{
17382 now_it.state = AUTOMATIC_IT_BLOCK;
17383 now_it.mask = 0x18;
17384 now_it.cc = cond;
17385 now_it.block_length = 1;
cd000bff 17386 mapping_state (MAP_THUMB);
e07e6e58 17387 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
17388 now_it.warn_deprecated = FALSE;
17389 now_it.insn_cond = TRUE;
e07e6e58
NC
17390}
17391
17392/* Close an automatic IT block.
17393 See comments in new_automatic_it_block (). */
17394
17395static void
17396close_automatic_it_block (void)
17397{
17398 now_it.mask = 0x10;
17399 now_it.block_length = 0;
17400}
17401
17402/* Update the mask of the current automatically-generated IT
17403 instruction. See comments in new_automatic_it_block (). */
17404
17405static void
17406now_it_add_mask (int cond)
17407{
17408#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
17409#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 17410 | ((bitvalue) << (nbit)))
e07e6e58 17411 const int resulting_bit = (cond & 1);
c921be7d 17412
e07e6e58
NC
17413 now_it.mask &= 0xf;
17414 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17415 resulting_bit,
17416 (5 - now_it.block_length));
e07e6e58 17417 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17418 1,
17419 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
17420 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
17421
17422#undef CLEAR_BIT
17423#undef SET_BIT_VALUE
e07e6e58
NC
17424}
17425
17426/* The IT blocks handling machinery is accessed through the these functions:
17427 it_fsm_pre_encode () from md_assemble ()
17428 set_it_insn_type () optional, from the tencode functions
17429 set_it_insn_type_last () ditto
17430 in_it_block () ditto
17431 it_fsm_post_encode () from md_assemble ()
17432 force_automatic_it_block_close () from label habdling functions
17433
17434 Rationale:
17435 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
17436 initializing the IT insn type with a generic initial value depending
17437 on the inst.condition.
e07e6e58 17438 2) During the tencode function, two things may happen:
477330fc
RM
17439 a) The tencode function overrides the IT insn type by
17440 calling either set_it_insn_type (type) or set_it_insn_type_last ().
17441 b) The tencode function queries the IT block state by
17442 calling in_it_block () (i.e. to determine narrow/not narrow mode).
17443
17444 Both set_it_insn_type and in_it_block run the internal FSM state
17445 handling function (handle_it_state), because: a) setting the IT insn
17446 type may incur in an invalid state (exiting the function),
17447 and b) querying the state requires the FSM to be updated.
17448 Specifically we want to avoid creating an IT block for conditional
17449 branches, so it_fsm_pre_encode is actually a guess and we can't
17450 determine whether an IT block is required until the tencode () routine
17451 has decided what type of instruction this actually it.
17452 Because of this, if set_it_insn_type and in_it_block have to be used,
17453 set_it_insn_type has to be called first.
17454
17455 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
17456 determines the insn IT type depending on the inst.cond code.
17457 When a tencode () routine encodes an instruction that can be
17458 either outside an IT block, or, in the case of being inside, has to be
17459 the last one, set_it_insn_type_last () will determine the proper
17460 IT instruction type based on the inst.cond code. Otherwise,
17461 set_it_insn_type can be called for overriding that logic or
17462 for covering other cases.
17463
17464 Calling handle_it_state () may not transition the IT block state to
17465 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
17466 still queried. Instead, if the FSM determines that the state should
17467 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
17468 after the tencode () function: that's what it_fsm_post_encode () does.
17469
17470 Since in_it_block () calls the state handling function to get an
17471 updated state, an error may occur (due to invalid insns combination).
17472 In that case, inst.error is set.
17473 Therefore, inst.error has to be checked after the execution of
17474 the tencode () routine.
e07e6e58
NC
17475
17476 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
17477 any pending state change (if any) that didn't take place in
17478 handle_it_state () as explained above. */
e07e6e58
NC
17479
17480static void
17481it_fsm_pre_encode (void)
17482{
17483 if (inst.cond != COND_ALWAYS)
17484 inst.it_insn_type = INSIDE_IT_INSN;
17485 else
17486 inst.it_insn_type = OUTSIDE_IT_INSN;
17487
17488 now_it.state_handled = 0;
17489}
17490
17491/* IT state FSM handling function. */
17492
17493static int
17494handle_it_state (void)
17495{
17496 now_it.state_handled = 1;
5a01bb1d 17497 now_it.insn_cond = FALSE;
e07e6e58
NC
17498
17499 switch (now_it.state)
17500 {
17501 case OUTSIDE_IT_BLOCK:
17502 switch (inst.it_insn_type)
17503 {
17504 case OUTSIDE_IT_INSN:
17505 break;
17506
17507 case INSIDE_IT_INSN:
17508 case INSIDE_IT_LAST_INSN:
17509 if (thumb_mode == 0)
17510 {
c921be7d 17511 if (unified_syntax
e07e6e58
NC
17512 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
17513 as_tsktsk (_("Warning: conditional outside an IT block"\
17514 " for Thumb."));
17515 }
17516 else
17517 {
17518 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
17519 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
17520 {
17521 /* Automatically generate the IT instruction. */
17522 new_automatic_it_block (inst.cond);
17523 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
17524 close_automatic_it_block ();
17525 }
17526 else
17527 {
17528 inst.error = BAD_OUT_IT;
17529 return FAIL;
17530 }
17531 }
17532 break;
17533
17534 case IF_INSIDE_IT_LAST_INSN:
17535 case NEUTRAL_IT_INSN:
17536 break;
17537
17538 case IT_INSN:
17539 now_it.state = MANUAL_IT_BLOCK;
17540 now_it.block_length = 0;
17541 break;
17542 }
17543 break;
17544
17545 case AUTOMATIC_IT_BLOCK:
17546 /* Three things may happen now:
17547 a) We should increment current it block size;
17548 b) We should close current it block (closing insn or 4 insns);
17549 c) We should close current it block and start a new one (due
17550 to incompatible conditions or
17551 4 insns-length block reached). */
17552
17553 switch (inst.it_insn_type)
17554 {
17555 case OUTSIDE_IT_INSN:
17556 /* The closure of the block shall happen immediatelly,
17557 so any in_it_block () call reports the block as closed. */
17558 force_automatic_it_block_close ();
17559 break;
17560
17561 case INSIDE_IT_INSN:
17562 case INSIDE_IT_LAST_INSN:
17563 case IF_INSIDE_IT_LAST_INSN:
17564 now_it.block_length++;
17565
17566 if (now_it.block_length > 4
17567 || !now_it_compatible (inst.cond))
17568 {
17569 force_automatic_it_block_close ();
17570 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
17571 new_automatic_it_block (inst.cond);
17572 }
17573 else
17574 {
5a01bb1d 17575 now_it.insn_cond = TRUE;
e07e6e58
NC
17576 now_it_add_mask (inst.cond);
17577 }
17578
17579 if (now_it.state == AUTOMATIC_IT_BLOCK
17580 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
17581 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
17582 close_automatic_it_block ();
17583 break;
17584
17585 case NEUTRAL_IT_INSN:
17586 now_it.block_length++;
5a01bb1d 17587 now_it.insn_cond = TRUE;
e07e6e58
NC
17588
17589 if (now_it.block_length > 4)
17590 force_automatic_it_block_close ();
17591 else
17592 now_it_add_mask (now_it.cc & 1);
17593 break;
17594
17595 case IT_INSN:
17596 close_automatic_it_block ();
17597 now_it.state = MANUAL_IT_BLOCK;
17598 break;
17599 }
17600 break;
17601
17602 case MANUAL_IT_BLOCK:
17603 {
17604 /* Check conditional suffixes. */
17605 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
17606 int is_last;
17607 now_it.mask <<= 1;
17608 now_it.mask &= 0x1f;
17609 is_last = (now_it.mask == 0x10);
5a01bb1d 17610 now_it.insn_cond = TRUE;
e07e6e58
NC
17611
17612 switch (inst.it_insn_type)
17613 {
17614 case OUTSIDE_IT_INSN:
17615 inst.error = BAD_NOT_IT;
17616 return FAIL;
17617
17618 case INSIDE_IT_INSN:
17619 if (cond != inst.cond)
17620 {
17621 inst.error = BAD_IT_COND;
17622 return FAIL;
17623 }
17624 break;
17625
17626 case INSIDE_IT_LAST_INSN:
17627 case IF_INSIDE_IT_LAST_INSN:
17628 if (cond != inst.cond)
17629 {
17630 inst.error = BAD_IT_COND;
17631 return FAIL;
17632 }
17633 if (!is_last)
17634 {
17635 inst.error = BAD_BRANCH;
17636 return FAIL;
17637 }
17638 break;
17639
17640 case NEUTRAL_IT_INSN:
17641 /* The BKPT instruction is unconditional even in an IT block. */
17642 break;
17643
17644 case IT_INSN:
17645 inst.error = BAD_IT_IT;
17646 return FAIL;
17647 }
17648 }
17649 break;
17650 }
17651
17652 return SUCCESS;
17653}
17654
5a01bb1d
MGD
17655struct depr_insn_mask
17656{
17657 unsigned long pattern;
17658 unsigned long mask;
17659 const char* description;
17660};
17661
17662/* List of 16-bit instruction patterns deprecated in an IT block in
17663 ARMv8. */
17664static const struct depr_insn_mask depr_it_insns[] = {
17665 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
17666 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
17667 { 0xa000, 0xb800, N_("ADR") },
17668 { 0x4800, 0xf800, N_("Literal loads") },
17669 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
17670 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
17671 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
17672 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
17673 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
17674 { 0, 0, NULL }
17675};
17676
e07e6e58
NC
17677static void
17678it_fsm_post_encode (void)
17679{
17680 int is_last;
17681
17682 if (!now_it.state_handled)
17683 handle_it_state ();
17684
5a01bb1d
MGD
17685 if (now_it.insn_cond
17686 && !now_it.warn_deprecated
17687 && warn_on_deprecated
17688 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
17689 {
17690 if (inst.instruction >= 0x10000)
17691 {
5c3696f8 17692 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
5a01bb1d
MGD
17693 "deprecated in ARMv8"));
17694 now_it.warn_deprecated = TRUE;
17695 }
17696 else
17697 {
17698 const struct depr_insn_mask *p = depr_it_insns;
17699
17700 while (p->mask != 0)
17701 {
17702 if ((inst.instruction & p->mask) == p->pattern)
17703 {
5c3696f8 17704 as_tsktsk (_("IT blocks containing 16-bit Thumb instructions "
5a01bb1d
MGD
17705 "of the following class are deprecated in ARMv8: "
17706 "%s"), p->description);
17707 now_it.warn_deprecated = TRUE;
17708 break;
17709 }
17710
17711 ++p;
17712 }
17713 }
17714
17715 if (now_it.block_length > 1)
17716 {
5c3696f8 17717 as_tsktsk (_("IT blocks containing more than one conditional "
0a8897c7 17718 "instruction are deprecated in ARMv8"));
5a01bb1d
MGD
17719 now_it.warn_deprecated = TRUE;
17720 }
17721 }
17722
e07e6e58
NC
17723 is_last = (now_it.mask == 0x10);
17724 if (is_last)
17725 {
17726 now_it.state = OUTSIDE_IT_BLOCK;
17727 now_it.mask = 0;
17728 }
17729}
17730
17731static void
17732force_automatic_it_block_close (void)
17733{
17734 if (now_it.state == AUTOMATIC_IT_BLOCK)
17735 {
17736 close_automatic_it_block ();
17737 now_it.state = OUTSIDE_IT_BLOCK;
17738 now_it.mask = 0;
17739 }
17740}
17741
17742static int
17743in_it_block (void)
17744{
17745 if (!now_it.state_handled)
17746 handle_it_state ();
17747
17748 return now_it.state != OUTSIDE_IT_BLOCK;
17749}
17750
c19d1205
ZW
17751void
17752md_assemble (char *str)
b99bd4ef 17753{
c19d1205
ZW
17754 char *p = str;
17755 const struct asm_opcode * opcode;
b99bd4ef 17756
c19d1205
ZW
17757 /* Align the previous label if needed. */
17758 if (last_label_seen != NULL)
b99bd4ef 17759 {
c19d1205
ZW
17760 symbol_set_frag (last_label_seen, frag_now);
17761 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
17762 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
17763 }
17764
c19d1205
ZW
17765 memset (&inst, '\0', sizeof (inst));
17766 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 17767
c19d1205
ZW
17768 opcode = opcode_lookup (&p);
17769 if (!opcode)
b99bd4ef 17770 {
c19d1205 17771 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 17772 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 17773 if (! create_register_alias (str, p)
477330fc 17774 && ! create_neon_reg_alias (str, p))
c19d1205 17775 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 17776
b99bd4ef
NC
17777 return;
17778 }
17779
278df34e 17780 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 17781 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 17782
037e8744
JB
17783 /* The value which unconditional instructions should have in place of the
17784 condition field. */
17785 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
17786
c19d1205 17787 if (thumb_mode)
b99bd4ef 17788 {
e74cfd16 17789 arm_feature_set variant;
8f06b2d8
PB
17790
17791 variant = cpu_variant;
17792 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
17793 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
17794 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 17795 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
17796 if (!opcode->tvariant
17797 || (thumb_mode == 1
17798 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 17799 {
bf3eeda7 17800 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
b99bd4ef
NC
17801 return;
17802 }
c19d1205
ZW
17803 if (inst.cond != COND_ALWAYS && !unified_syntax
17804 && opcode->tencode != do_t_branch)
b99bd4ef 17805 {
c19d1205 17806 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
17807 return;
17808 }
17809
752d5da4 17810 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
076d447c 17811 {
7e806470 17812 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
752d5da4
NC
17813 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
17814 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
17815 {
17816 /* Two things are addressed here.
17817 1) Implicit require narrow instructions on Thumb-1.
17818 This avoids relaxation accidentally introducing Thumb-2
17819 instructions.
17820 2) Reject wide instructions in non Thumb-2 cores. */
17821 if (inst.size_req == 0)
17822 inst.size_req = 2;
17823 else if (inst.size_req == 4)
17824 {
bf3eeda7 17825 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
752d5da4
NC
17826 return;
17827 }
17828 }
076d447c
PB
17829 }
17830
c19d1205
ZW
17831 inst.instruction = opcode->tvalue;
17832
5be8be5d 17833 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
17834 {
17835 /* Prepare the it_insn_type for those encodings that don't set
17836 it. */
17837 it_fsm_pre_encode ();
c19d1205 17838
477330fc 17839 opcode->tencode ();
e07e6e58 17840
477330fc
RM
17841 it_fsm_post_encode ();
17842 }
e27ec89e 17843
0110f2b8 17844 if (!(inst.error || inst.relax))
b99bd4ef 17845 {
9c2799c2 17846 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
17847 inst.size = (inst.instruction > 0xffff ? 4 : 2);
17848 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 17849 {
c19d1205 17850 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
17851 return;
17852 }
17853 }
076d447c
PB
17854
17855 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 17856 instruction. */
9c2799c2 17857 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 17858
e74cfd16
PB
17859 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
17860 *opcode->tvariant);
ee065d83 17861 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 17862 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 17863 anything other than bl/blx and v6-M instructions.
3cfdb781
TG
17864 The impact of relaxable instructions will be considered later after we
17865 finish all relaxation. */
17866 if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
e07e6e58
NC
17867 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
17868 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
17869 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
17870 arm_ext_v6t2);
cd000bff 17871
88714cb8
DG
17872 check_neon_suffixes;
17873
cd000bff 17874 if (!inst.error)
c877a2f2
NC
17875 {
17876 mapping_state (MAP_THUMB);
17877 }
c19d1205 17878 }
3e9e4fcf 17879 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 17880 {
845b51d6
PB
17881 bfd_boolean is_bx;
17882
17883 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
17884 is_bx = (opcode->aencode == do_bx);
17885
c19d1205 17886 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
17887 if (!(is_bx && fix_v4bx)
17888 && !(opcode->avariant &&
17889 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 17890 {
bf3eeda7 17891 as_bad (_("selected processor does not support ARM mode `%s'"), str);
c19d1205 17892 return;
b99bd4ef 17893 }
c19d1205 17894 if (inst.size_req)
b99bd4ef 17895 {
c19d1205
ZW
17896 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
17897 return;
b99bd4ef
NC
17898 }
17899
c19d1205
ZW
17900 inst.instruction = opcode->avalue;
17901 if (opcode->tag == OT_unconditionalF)
17902 inst.instruction |= 0xF << 28;
17903 else
17904 inst.instruction |= inst.cond << 28;
17905 inst.size = INSN_SIZE;
5be8be5d 17906 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
17907 {
17908 it_fsm_pre_encode ();
17909 opcode->aencode ();
17910 it_fsm_post_encode ();
17911 }
ee065d83 17912 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 17913 on a hypothetical non-thumb v5 core. */
845b51d6 17914 if (is_bx)
e74cfd16 17915 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 17916 else
e74cfd16
PB
17917 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
17918 *opcode->avariant);
88714cb8
DG
17919
17920 check_neon_suffixes;
17921
cd000bff 17922 if (!inst.error)
c877a2f2
NC
17923 {
17924 mapping_state (MAP_ARM);
17925 }
b99bd4ef 17926 }
3e9e4fcf
JB
17927 else
17928 {
17929 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
17930 "-- `%s'"), str);
17931 return;
17932 }
c19d1205
ZW
17933 output_inst (str);
17934}
b99bd4ef 17935
e07e6e58
NC
17936static void
17937check_it_blocks_finished (void)
17938{
17939#ifdef OBJ_ELF
17940 asection *sect;
17941
17942 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
17943 if (seg_info (sect)->tc_segment_info_data.current_it.state
17944 == MANUAL_IT_BLOCK)
17945 {
17946 as_warn (_("section '%s' finished with an open IT block."),
17947 sect->name);
17948 }
17949#else
17950 if (now_it.state == MANUAL_IT_BLOCK)
17951 as_warn (_("file finished with an open IT block."));
17952#endif
17953}
17954
c19d1205
ZW
17955/* Various frobbings of labels and their addresses. */
17956
17957void
17958arm_start_line_hook (void)
17959{
17960 last_label_seen = NULL;
b99bd4ef
NC
17961}
17962
c19d1205
ZW
17963void
17964arm_frob_label (symbolS * sym)
b99bd4ef 17965{
c19d1205 17966 last_label_seen = sym;
b99bd4ef 17967
c19d1205 17968 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 17969
c19d1205
ZW
17970#if defined OBJ_COFF || defined OBJ_ELF
17971 ARM_SET_INTERWORK (sym, support_interwork);
17972#endif
b99bd4ef 17973
e07e6e58
NC
17974 force_automatic_it_block_close ();
17975
5f4273c7 17976 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
17977 as Thumb functions. This is because these labels, whilst
17978 they exist inside Thumb code, are not the entry points for
17979 possible ARM->Thumb calls. Also, these labels can be used
17980 as part of a computed goto or switch statement. eg gcc
17981 can generate code that looks like this:
b99bd4ef 17982
c19d1205
ZW
17983 ldr r2, [pc, .Laaa]
17984 lsl r3, r3, #2
17985 ldr r2, [r3, r2]
17986 mov pc, r2
b99bd4ef 17987
c19d1205
ZW
17988 .Lbbb: .word .Lxxx
17989 .Lccc: .word .Lyyy
17990 ..etc...
17991 .Laaa: .word Lbbb
b99bd4ef 17992
c19d1205
ZW
17993 The first instruction loads the address of the jump table.
17994 The second instruction converts a table index into a byte offset.
17995 The third instruction gets the jump address out of the table.
17996 The fourth instruction performs the jump.
b99bd4ef 17997
c19d1205
ZW
17998 If the address stored at .Laaa is that of a symbol which has the
17999 Thumb_Func bit set, then the linker will arrange for this address
18000 to have the bottom bit set, which in turn would mean that the
18001 address computation performed by the third instruction would end
18002 up with the bottom bit set. Since the ARM is capable of unaligned
18003 word loads, the instruction would then load the incorrect address
18004 out of the jump table, and chaos would ensue. */
18005 if (label_is_thumb_function_name
18006 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18007 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 18008 {
c19d1205
ZW
18009 /* When the address of a Thumb function is taken the bottom
18010 bit of that address should be set. This will allow
18011 interworking between Arm and Thumb functions to work
18012 correctly. */
b99bd4ef 18013
c19d1205 18014 THUMB_SET_FUNC (sym, 1);
b99bd4ef 18015
c19d1205 18016 label_is_thumb_function_name = FALSE;
b99bd4ef 18017 }
07a53e5c 18018
07a53e5c 18019 dwarf2_emit_label (sym);
b99bd4ef
NC
18020}
18021
c921be7d 18022bfd_boolean
c19d1205 18023arm_data_in_code (void)
b99bd4ef 18024{
c19d1205 18025 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 18026 {
c19d1205
ZW
18027 *input_line_pointer = '/';
18028 input_line_pointer += 5;
18029 *input_line_pointer = 0;
c921be7d 18030 return TRUE;
b99bd4ef
NC
18031 }
18032
c921be7d 18033 return FALSE;
b99bd4ef
NC
18034}
18035
c19d1205
ZW
18036char *
18037arm_canonicalize_symbol_name (char * name)
b99bd4ef 18038{
c19d1205 18039 int len;
b99bd4ef 18040
c19d1205
ZW
18041 if (thumb_mode && (len = strlen (name)) > 5
18042 && streq (name + len - 5, "/data"))
18043 *(name + len - 5) = 0;
b99bd4ef 18044
c19d1205 18045 return name;
b99bd4ef 18046}
c19d1205
ZW
18047\f
18048/* Table of all register names defined by default. The user can
18049 define additional names with .req. Note that all register names
18050 should appear in both upper and lowercase variants. Some registers
18051 also have mixed-case names. */
b99bd4ef 18052
dcbf9037 18053#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 18054#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 18055#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
18056#define REGSET(p,t) \
18057 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
18058 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
18059 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
18060 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
18061#define REGSETH(p,t) \
18062 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
18063 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
18064 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
18065 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
18066#define REGSET2(p,t) \
18067 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
18068 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
18069 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
18070 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
18071#define SPLRBANK(base,bank,t) \
18072 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
18073 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
18074 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
18075 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
18076 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
18077 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 18078
c19d1205 18079static const struct reg_entry reg_names[] =
7ed4c4c5 18080{
c19d1205
ZW
18081 /* ARM integer registers. */
18082 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 18083
c19d1205
ZW
18084 /* ATPCS synonyms. */
18085 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
18086 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
18087 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 18088
c19d1205
ZW
18089 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
18090 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
18091 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 18092
c19d1205
ZW
18093 /* Well-known aliases. */
18094 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
18095 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
18096
18097 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
18098 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
18099
18100 /* Coprocessor numbers. */
18101 REGSET(p, CP), REGSET(P, CP),
18102
18103 /* Coprocessor register numbers. The "cr" variants are for backward
18104 compatibility. */
18105 REGSET(c, CN), REGSET(C, CN),
18106 REGSET(cr, CN), REGSET(CR, CN),
18107
90ec0d68
MGD
18108 /* ARM banked registers. */
18109 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
18110 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
18111 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
18112 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
18113 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
18114 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
18115 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
18116
18117 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
18118 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
18119 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
18120 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
18121 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 18122 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
18123 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
18124 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
18125
18126 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
18127 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
18128 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
18129 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
18130 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
18131 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
18132 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 18133 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
18134 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
18135
c19d1205
ZW
18136 /* FPA registers. */
18137 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
18138 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
18139
18140 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
18141 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
18142
18143 /* VFP SP registers. */
5287ad62
JB
18144 REGSET(s,VFS), REGSET(S,VFS),
18145 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
18146
18147 /* VFP DP Registers. */
5287ad62
JB
18148 REGSET(d,VFD), REGSET(D,VFD),
18149 /* Extra Neon DP registers. */
18150 REGSETH(d,VFD), REGSETH(D,VFD),
18151
18152 /* Neon QP registers. */
18153 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
18154
18155 /* VFP control registers. */
18156 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
18157 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
18158 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
18159 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
18160 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
18161 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
18162
18163 /* Maverick DSP coprocessor registers. */
18164 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
18165 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
18166
18167 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
18168 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
18169 REGDEF(dspsc,0,DSPSC),
18170
18171 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
18172 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
18173 REGDEF(DSPSC,0,DSPSC),
18174
18175 /* iWMMXt data registers - p0, c0-15. */
18176 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
18177
18178 /* iWMMXt control registers - p1, c0-3. */
18179 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
18180 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
18181 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
18182 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
18183
18184 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
18185 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
18186 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
18187 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
18188 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
18189
18190 /* XScale accumulator registers. */
18191 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
18192};
18193#undef REGDEF
18194#undef REGNUM
18195#undef REGSET
7ed4c4c5 18196
c19d1205
ZW
18197/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
18198 within psr_required_here. */
18199static const struct asm_psr psrs[] =
18200{
18201 /* Backward compatibility notation. Note that "all" is no longer
18202 truly all possible PSR bits. */
18203 {"all", PSR_c | PSR_f},
18204 {"flg", PSR_f},
18205 {"ctl", PSR_c},
18206
18207 /* Individual flags. */
18208 {"f", PSR_f},
18209 {"c", PSR_c},
18210 {"x", PSR_x},
18211 {"s", PSR_s},
59b42a0d 18212
c19d1205
ZW
18213 /* Combinations of flags. */
18214 {"fs", PSR_f | PSR_s},
18215 {"fx", PSR_f | PSR_x},
18216 {"fc", PSR_f | PSR_c},
18217 {"sf", PSR_s | PSR_f},
18218 {"sx", PSR_s | PSR_x},
18219 {"sc", PSR_s | PSR_c},
18220 {"xf", PSR_x | PSR_f},
18221 {"xs", PSR_x | PSR_s},
18222 {"xc", PSR_x | PSR_c},
18223 {"cf", PSR_c | PSR_f},
18224 {"cs", PSR_c | PSR_s},
18225 {"cx", PSR_c | PSR_x},
18226 {"fsx", PSR_f | PSR_s | PSR_x},
18227 {"fsc", PSR_f | PSR_s | PSR_c},
18228 {"fxs", PSR_f | PSR_x | PSR_s},
18229 {"fxc", PSR_f | PSR_x | PSR_c},
18230 {"fcs", PSR_f | PSR_c | PSR_s},
18231 {"fcx", PSR_f | PSR_c | PSR_x},
18232 {"sfx", PSR_s | PSR_f | PSR_x},
18233 {"sfc", PSR_s | PSR_f | PSR_c},
18234 {"sxf", PSR_s | PSR_x | PSR_f},
18235 {"sxc", PSR_s | PSR_x | PSR_c},
18236 {"scf", PSR_s | PSR_c | PSR_f},
18237 {"scx", PSR_s | PSR_c | PSR_x},
18238 {"xfs", PSR_x | PSR_f | PSR_s},
18239 {"xfc", PSR_x | PSR_f | PSR_c},
18240 {"xsf", PSR_x | PSR_s | PSR_f},
18241 {"xsc", PSR_x | PSR_s | PSR_c},
18242 {"xcf", PSR_x | PSR_c | PSR_f},
18243 {"xcs", PSR_x | PSR_c | PSR_s},
18244 {"cfs", PSR_c | PSR_f | PSR_s},
18245 {"cfx", PSR_c | PSR_f | PSR_x},
18246 {"csf", PSR_c | PSR_s | PSR_f},
18247 {"csx", PSR_c | PSR_s | PSR_x},
18248 {"cxf", PSR_c | PSR_x | PSR_f},
18249 {"cxs", PSR_c | PSR_x | PSR_s},
18250 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
18251 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
18252 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
18253 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
18254 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
18255 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
18256 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
18257 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
18258 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
18259 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
18260 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
18261 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
18262 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
18263 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
18264 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
18265 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
18266 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
18267 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
18268 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
18269 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
18270 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
18271 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
18272 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
18273 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
18274};
18275
62b3e311
PB
18276/* Table of V7M psr names. */
18277static const struct asm_psr v7m_psrs[] =
18278{
2b744c99
PB
18279 {"apsr", 0 }, {"APSR", 0 },
18280 {"iapsr", 1 }, {"IAPSR", 1 },
18281 {"eapsr", 2 }, {"EAPSR", 2 },
18282 {"psr", 3 }, {"PSR", 3 },
18283 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
18284 {"ipsr", 5 }, {"IPSR", 5 },
18285 {"epsr", 6 }, {"EPSR", 6 },
18286 {"iepsr", 7 }, {"IEPSR", 7 },
18287 {"msp", 8 }, {"MSP", 8 },
18288 {"psp", 9 }, {"PSP", 9 },
18289 {"primask", 16}, {"PRIMASK", 16},
18290 {"basepri", 17}, {"BASEPRI", 17},
00bbc0bd
NC
18291 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
18292 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
2b744c99
PB
18293 {"faultmask", 19}, {"FAULTMASK", 19},
18294 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
18295};
18296
c19d1205
ZW
18297/* Table of all shift-in-operand names. */
18298static const struct asm_shift_name shift_names [] =
b99bd4ef 18299{
c19d1205
ZW
18300 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
18301 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
18302 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
18303 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
18304 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
18305 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
18306};
b99bd4ef 18307
c19d1205
ZW
18308/* Table of all explicit relocation names. */
18309#ifdef OBJ_ELF
18310static struct reloc_entry reloc_names[] =
18311{
18312 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
18313 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
18314 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
18315 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
18316 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
18317 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
18318 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
18319 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
18320 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
18321 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 18322 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
18323 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
18324 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 18325 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 18326 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 18327 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 18328 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
477330fc 18329 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
18330};
18331#endif
b99bd4ef 18332
c19d1205
ZW
18333/* Table of all conditional affixes. 0xF is not defined as a condition code. */
18334static const struct asm_cond conds[] =
18335{
18336 {"eq", 0x0},
18337 {"ne", 0x1},
18338 {"cs", 0x2}, {"hs", 0x2},
18339 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
18340 {"mi", 0x4},
18341 {"pl", 0x5},
18342 {"vs", 0x6},
18343 {"vc", 0x7},
18344 {"hi", 0x8},
18345 {"ls", 0x9},
18346 {"ge", 0xa},
18347 {"lt", 0xb},
18348 {"gt", 0xc},
18349 {"le", 0xd},
18350 {"al", 0xe}
18351};
bfae80f2 18352
e797f7e0 18353#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
18354 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
18355 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 18356
62b3e311
PB
18357static struct asm_barrier_opt barrier_opt_names[] =
18358{
e797f7e0
MGD
18359 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
18360 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
18361 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
18362 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
18363 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
18364 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
18365 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
18366 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
18367 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
18368 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
18369 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
18370 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
18371 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
18372 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
18373 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
18374 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
18375};
18376
e797f7e0
MGD
18377#undef UL_BARRIER
18378
c19d1205
ZW
18379/* Table of ARM-format instructions. */
18380
18381/* Macros for gluing together operand strings. N.B. In all cases
18382 other than OPS0, the trailing OP_stop comes from default
18383 zero-initialization of the unspecified elements of the array. */
18384#define OPS0() { OP_stop, }
18385#define OPS1(a) { OP_##a, }
18386#define OPS2(a,b) { OP_##a,OP_##b, }
18387#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
18388#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
18389#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
18390#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
18391
5be8be5d
DG
18392/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
18393 This is useful when mixing operands for ARM and THUMB, i.e. using the
18394 MIX_ARM_THUMB_OPERANDS macro.
18395 In order to use these macros, prefix the number of operands with _
18396 e.g. _3. */
18397#define OPS_1(a) { a, }
18398#define OPS_2(a,b) { a,b, }
18399#define OPS_3(a,b,c) { a,b,c, }
18400#define OPS_4(a,b,c,d) { a,b,c,d, }
18401#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
18402#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
18403
c19d1205
ZW
18404/* These macros abstract out the exact format of the mnemonic table and
18405 save some repeated characters. */
18406
18407/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
18408#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18409 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 18410 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18411
18412/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
18413 a T_MNEM_xyz enumerator. */
18414#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18415 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18416#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18417 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
18418
18419/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
18420 infix after the third character. */
18421#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 18422 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 18423 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 18424#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 18425 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 18426 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18427#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18428 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 18429#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18430 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18431#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18432 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 18433#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18434 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 18435
c19d1205 18436/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
18437 field is still 0xE. Many of the Thumb variants can be executed
18438 conditionally, so this is checked separately. */
c19d1205 18439#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18440 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18441 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18442
dd5181d5
KT
18443/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
18444 Used by mnemonics that have very minimal differences in the encoding for
18445 ARM and Thumb variants and can be handled in a common function. */
18446#define TUEc(mnem, op, top, nops, ops, en) \
18447 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
18448 THUMB_VARIANT, do_##en, do_##en }
18449
c19d1205
ZW
18450/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
18451 condition code field. */
18452#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 18453 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18454 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18455
18456/* ARM-only variants of all the above. */
6a86118a 18457#define CE(mnem, op, nops, ops, ae) \
21d799b5 18458 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
18459
18460#define C3(mnem, op, nops, ops, ae) \
18461 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18462
e3cb604e
PB
18463/* Legacy mnemonics that always have conditional infix after the third
18464 character. */
18465#define CL(mnem, op, nops, ops, ae) \
21d799b5 18466 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
18467 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18468
8f06b2d8
PB
18469/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
18470#define cCE(mnem, op, nops, ops, ae) \
21d799b5 18471 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 18472
e3cb604e
PB
18473/* Legacy coprocessor instructions where conditional infix and conditional
18474 suffix are ambiguous. For consistency this includes all FPA instructions,
18475 not just the potentially ambiguous ones. */
18476#define cCL(mnem, op, nops, ops, ae) \
21d799b5 18477 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
18478 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
18479
18480/* Coprocessor, takes either a suffix or a position-3 infix
18481 (for an FPA corner case). */
18482#define C3E(mnem, op, nops, ops, ae) \
21d799b5 18483 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 18484 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 18485
6a86118a 18486#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
18487 { m1 #m2 m3, OPS##nops ops, \
18488 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
18489 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18490
18491#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
18492 xCM_ (m1, , m2, op, nops, ops, ae), \
18493 xCM_ (m1, eq, m2, op, nops, ops, ae), \
18494 xCM_ (m1, ne, m2, op, nops, ops, ae), \
18495 xCM_ (m1, cs, m2, op, nops, ops, ae), \
18496 xCM_ (m1, hs, m2, op, nops, ops, ae), \
18497 xCM_ (m1, cc, m2, op, nops, ops, ae), \
18498 xCM_ (m1, ul, m2, op, nops, ops, ae), \
18499 xCM_ (m1, lo, m2, op, nops, ops, ae), \
18500 xCM_ (m1, mi, m2, op, nops, ops, ae), \
18501 xCM_ (m1, pl, m2, op, nops, ops, ae), \
18502 xCM_ (m1, vs, m2, op, nops, ops, ae), \
18503 xCM_ (m1, vc, m2, op, nops, ops, ae), \
18504 xCM_ (m1, hi, m2, op, nops, ops, ae), \
18505 xCM_ (m1, ls, m2, op, nops, ops, ae), \
18506 xCM_ (m1, ge, m2, op, nops, ops, ae), \
18507 xCM_ (m1, lt, m2, op, nops, ops, ae), \
18508 xCM_ (m1, gt, m2, op, nops, ops, ae), \
18509 xCM_ (m1, le, m2, op, nops, ops, ae), \
18510 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
18511
18512#define UE(mnem, op, nops, ops, ae) \
18513 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
18514
18515#define UF(mnem, op, nops, ops, ae) \
18516 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
18517
5287ad62
JB
18518/* Neon data-processing. ARM versions are unconditional with cond=0xf.
18519 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
18520 use the same encoding function for each. */
18521#define NUF(mnem, op, nops, ops, enc) \
18522 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
18523 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18524
18525/* Neon data processing, version which indirects through neon_enc_tab for
18526 the various overloaded versions of opcodes. */
18527#define nUF(mnem, op, nops, ops, enc) \
21d799b5 18528 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
18529 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18530
18531/* Neon insn with conditional suffix for the ARM version, non-overloaded
18532 version. */
037e8744
JB
18533#define NCE_tag(mnem, op, nops, ops, enc, tag) \
18534 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
18535 THUMB_VARIANT, do_##enc, do_##enc }
18536
037e8744 18537#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 18538 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
18539
18540#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 18541 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 18542
5287ad62 18543/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 18544#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 18545 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
18546 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
18547
037e8744 18548#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 18549 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
18550
18551#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 18552 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 18553
c19d1205
ZW
18554#define do_0 0
18555
c19d1205 18556static const struct asm_opcode insns[] =
bfae80f2 18557{
74db7efb
NC
18558#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
18559#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
18560 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
18561 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
18562 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
18563 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
18564 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
18565 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
18566 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
18567 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
18568 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
18569 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
18570 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
18571 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
18572 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
18573 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
18574 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
18575 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
18576
18577 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
18578 for setting PSR flag bits. They are obsolete in V6 and do not
18579 have Thumb equivalents. */
21d799b5
NC
18580 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
18581 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
18582 CL("tstp", 110f000, 2, (RR, SH), cmp),
18583 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
18584 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
18585 CL("cmpp", 150f000, 2, (RR, SH), cmp),
18586 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
18587 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
18588 CL("cmnp", 170f000, 2, (RR, SH), cmp),
18589
18590 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
18591 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
18592 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
18593 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
18594
18595 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
18596 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
18597 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
18598 OP_RRnpc),
18599 OP_ADDRGLDR),ldst, t_ldst),
18600 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
18601
18602 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18603 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18604 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18605 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18606 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18607 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18608
18609 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
18610 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
18611 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
18612 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 18613
c19d1205 18614 /* Pseudo ops. */
21d799b5 18615 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 18616 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 18617 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 18618 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
18619
18620 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
18621 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
18622 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
18623 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
18624 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
18625 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
18626 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
18627 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
18628 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
18629 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
18630 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
18631 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
18632 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 18633
16a4cf17 18634 /* These may simplify to neg. */
21d799b5
NC
18635 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
18636 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 18637
c921be7d
NC
18638#undef THUMB_VARIANT
18639#define THUMB_VARIANT & arm_ext_v6
18640
21d799b5 18641 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
18642
18643 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
18644#undef THUMB_VARIANT
18645#define THUMB_VARIANT & arm_ext_v6t2
18646
21d799b5
NC
18647 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
18648 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
18649 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 18650
5be8be5d
DG
18651 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
18652 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
18653 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
18654 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 18655
21d799b5
NC
18656 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18657 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 18658
21d799b5
NC
18659 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
18660 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
18661
18662 /* V1 instructions with no Thumb analogue at all. */
21d799b5 18663 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
18664 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
18665
18666 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
18667 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
18668 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
18669 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
18670 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
18671 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
18672 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
18673 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
18674
c921be7d
NC
18675#undef ARM_VARIANT
18676#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
18677#undef THUMB_VARIANT
18678#define THUMB_VARIANT & arm_ext_v4t
18679
21d799b5
NC
18680 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
18681 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 18682
c921be7d
NC
18683#undef THUMB_VARIANT
18684#define THUMB_VARIANT & arm_ext_v6t2
18685
21d799b5 18686 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
18687 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
18688
18689 /* Generic coprocessor instructions. */
21d799b5
NC
18690 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
18691 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18692 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18693 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18694 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18695 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 18696 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 18697
c921be7d
NC
18698#undef ARM_VARIANT
18699#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
18700
21d799b5 18701 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
18702 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
18703
c921be7d
NC
18704#undef ARM_VARIANT
18705#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
18706#undef THUMB_VARIANT
18707#define THUMB_VARIANT & arm_ext_msr
18708
d2cd1205
JB
18709 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
18710 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 18711
c921be7d
NC
18712#undef ARM_VARIANT
18713#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
18714#undef THUMB_VARIANT
18715#define THUMB_VARIANT & arm_ext_v6t2
18716
21d799b5
NC
18717 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18718 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18719 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18720 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18721 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18722 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
18723 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
18724 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 18725
c921be7d
NC
18726#undef ARM_VARIANT
18727#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
18728#undef THUMB_VARIANT
18729#define THUMB_VARIANT & arm_ext_v4t
18730
5be8be5d
DG
18731 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18732 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18733 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18734 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
18735 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
18736 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 18737
c921be7d
NC
18738#undef ARM_VARIANT
18739#define ARM_VARIANT & arm_ext_v4t_5
18740
c19d1205
ZW
18741 /* ARM Architecture 4T. */
18742 /* Note: bx (and blx) are required on V5, even if the processor does
18743 not support Thumb. */
21d799b5 18744 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 18745
c921be7d
NC
18746#undef ARM_VARIANT
18747#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
18748#undef THUMB_VARIANT
18749#define THUMB_VARIANT & arm_ext_v5t
18750
c19d1205
ZW
18751 /* Note: blx has 2 variants; the .value coded here is for
18752 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
18753 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
18754 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 18755
c921be7d
NC
18756#undef THUMB_VARIANT
18757#define THUMB_VARIANT & arm_ext_v6t2
18758
21d799b5
NC
18759 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
18760 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18761 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18762 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18763 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
18764 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
18765 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
18766 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 18767
c921be7d 18768#undef ARM_VARIANT
74db7efb
NC
18769#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
18770#undef THUMB_VARIANT
18771#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 18772
21d799b5
NC
18773 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18774 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18775 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18776 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 18777
21d799b5
NC
18778 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
18779 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 18780
21d799b5
NC
18781 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18782 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18783 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
18784 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 18785
21d799b5
NC
18786 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18787 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18788 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18789 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 18790
21d799b5
NC
18791 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18792 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 18793
03ee1b7f
NC
18794 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18795 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18796 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
18797 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 18798
c921be7d 18799#undef ARM_VARIANT
74db7efb
NC
18800#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
18801#undef THUMB_VARIANT
18802#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 18803
21d799b5 18804 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
18805 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
18806 ldrd, t_ldstd),
18807 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
18808 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 18809
21d799b5
NC
18810 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18811 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 18812
c921be7d
NC
18813#undef ARM_VARIANT
18814#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
18815
21d799b5 18816 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 18817
c921be7d
NC
18818#undef ARM_VARIANT
18819#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
18820#undef THUMB_VARIANT
18821#define THUMB_VARIANT & arm_ext_v6
18822
21d799b5
NC
18823 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
18824 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
18825 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18826 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18827 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
18828 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18829 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18830 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18831 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18832 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 18833
c921be7d
NC
18834#undef THUMB_VARIANT
18835#define THUMB_VARIANT & arm_ext_v6t2
18836
5be8be5d
DG
18837 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
18838 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
18839 strex, t_strex),
21d799b5
NC
18840 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
18841 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 18842
21d799b5
NC
18843 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
18844 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 18845
9e3c6df6 18846/* ARM V6 not included in V7M. */
c921be7d
NC
18847#undef THUMB_VARIANT
18848#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 18849 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 18850 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
18851 UF(rfeib, 9900a00, 1, (RRw), rfe),
18852 UF(rfeda, 8100a00, 1, (RRw), rfe),
18853 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
18854 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
18855 UF(rfefa, 8100a00, 1, (RRw), rfe),
18856 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
18857 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 18858 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
18859 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
18860 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 18861 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 18862 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 18863 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 18864 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 18865 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 18866 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c921be7d 18867
9e3c6df6
PB
18868/* ARM V6 not included in V7M (eg. integer SIMD). */
18869#undef THUMB_VARIANT
18870#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
18871 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
18872 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
18873 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
18874 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18875 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18876 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18877 /* Old name for QASX. */
74db7efb 18878 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 18879 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18880 /* Old name for QSAX. */
74db7efb 18881 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18882 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18883 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18884 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18885 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18886 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18887 /* Old name for SASX. */
74db7efb 18888 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18889 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18890 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 18891 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18892 /* Old name for SHASX. */
21d799b5 18893 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 18894 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18895 /* Old name for SHSAX. */
21d799b5
NC
18896 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18897 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18898 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18899 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18900 /* Old name for SSAX. */
74db7efb 18901 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18902 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18903 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18904 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18905 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18906 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18907 /* Old name for UASX. */
74db7efb 18908 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18909 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18910 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 18911 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18912 /* Old name for UHASX. */
21d799b5
NC
18913 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18914 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18915 /* Old name for UHSAX. */
21d799b5
NC
18916 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18917 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18918 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18919 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18920 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 18921 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18922 /* Old name for UQASX. */
21d799b5
NC
18923 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18924 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18925 /* Old name for UQSAX. */
21d799b5
NC
18926 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18927 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18928 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18929 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18930 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 18931 /* Old name for USAX. */
74db7efb 18932 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 18933 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
18934 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18935 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18936 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18937 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18938 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18939 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18940 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
18941 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
18942 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
18943 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18944 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18945 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18946 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18947 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18948 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18949 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18950 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
18951 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18952 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18953 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18954 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18955 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18956 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18957 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18958 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18959 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18960 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
18961 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
18962 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
18963 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
18964 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
18965 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 18966
c921be7d
NC
18967#undef ARM_VARIANT
18968#define ARM_VARIANT & arm_ext_v6k
18969#undef THUMB_VARIANT
18970#define THUMB_VARIANT & arm_ext_v6k
18971
21d799b5
NC
18972 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
18973 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
18974 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
18975 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 18976
c921be7d
NC
18977#undef THUMB_VARIANT
18978#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
18979 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
18980 ldrexd, t_ldrexd),
18981 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
18982 RRnpcb), strexd, t_strexd),
ebdca51a 18983
c921be7d
NC
18984#undef THUMB_VARIANT
18985#define THUMB_VARIANT & arm_ext_v6t2
5be8be5d
DG
18986 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
18987 rd_rn, rd_rn),
18988 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
18989 rd_rn, rd_rn),
18990 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 18991 strex, t_strexbh),
5be8be5d 18992 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 18993 strex, t_strexbh),
21d799b5 18994 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 18995
c921be7d 18996#undef ARM_VARIANT
f4c65163 18997#define ARM_VARIANT & arm_ext_sec
74db7efb 18998#undef THUMB_VARIANT
f4c65163 18999#define THUMB_VARIANT & arm_ext_sec
c921be7d 19000
21d799b5 19001 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 19002
90ec0d68
MGD
19003#undef ARM_VARIANT
19004#define ARM_VARIANT & arm_ext_virt
19005#undef THUMB_VARIANT
19006#define THUMB_VARIANT & arm_ext_virt
19007
19008 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
19009 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
19010
ddfded2f
MW
19011#undef ARM_VARIANT
19012#define ARM_VARIANT & arm_ext_pan
19013#undef THUMB_VARIANT
19014#define THUMB_VARIANT & arm_ext_pan
19015
19016 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
19017
c921be7d 19018#undef ARM_VARIANT
74db7efb 19019#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
19020#undef THUMB_VARIANT
19021#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19022
21d799b5
NC
19023 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
19024 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
19025 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
19026 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 19027
21d799b5
NC
19028 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
19029 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
19030 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
19031 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 19032
5be8be5d
DG
19033 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19034 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19035 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19036 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 19037
bf3eeda7 19038 /* Thumb-only instructions. */
74db7efb 19039#undef ARM_VARIANT
bf3eeda7
NS
19040#define ARM_VARIANT NULL
19041 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
19042 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
19043
19044 /* ARM does not really have an IT instruction, so always allow it.
19045 The opcode is copied from Thumb in order to allow warnings in
19046 -mimplicit-it=[never | arm] modes. */
19047#undef ARM_VARIANT
19048#define ARM_VARIANT & arm_ext_v1
19049
21d799b5
NC
19050 TUE("it", bf08, bf08, 1, (COND), it, t_it),
19051 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
19052 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
19053 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
19054 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
19055 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
19056 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
19057 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
19058 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
19059 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
19060 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
19061 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
19062 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
19063 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
19064 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 19065 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
19066 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
19067 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 19068
92e90b6e 19069 /* Thumb2 only instructions. */
c921be7d
NC
19070#undef ARM_VARIANT
19071#define ARM_VARIANT NULL
92e90b6e 19072
21d799b5
NC
19073 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19074 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19075 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
19076 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
19077 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
19078 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 19079
eea54501
MGD
19080 /* Hardware division instructions. */
19081#undef ARM_VARIANT
19082#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
19083#undef THUMB_VARIANT
19084#define THUMB_VARIANT & arm_ext_div
19085
eea54501
MGD
19086 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
19087 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 19088
7e806470 19089 /* ARM V6M/V7 instructions. */
c921be7d
NC
19090#undef ARM_VARIANT
19091#define ARM_VARIANT & arm_ext_barrier
19092#undef THUMB_VARIANT
19093#define THUMB_VARIANT & arm_ext_barrier
19094
ccb84d65
JB
19095 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
19096 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
19097 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 19098
62b3e311 19099 /* ARM V7 instructions. */
c921be7d
NC
19100#undef ARM_VARIANT
19101#define ARM_VARIANT & arm_ext_v7
19102#undef THUMB_VARIANT
19103#define THUMB_VARIANT & arm_ext_v7
19104
21d799b5
NC
19105 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
19106 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 19107
74db7efb 19108#undef ARM_VARIANT
60e5ef9f 19109#define ARM_VARIANT & arm_ext_mp
74db7efb 19110#undef THUMB_VARIANT
60e5ef9f
MGD
19111#define THUMB_VARIANT & arm_ext_mp
19112
19113 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
19114
53c4b28b
MGD
19115 /* AArchv8 instructions. */
19116#undef ARM_VARIANT
19117#define ARM_VARIANT & arm_ext_v8
19118#undef THUMB_VARIANT
19119#define THUMB_VARIANT & arm_ext_v8
19120
19121 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
8884b720 19122 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
4b8c8c02
RE
19123 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19124 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
9eb6c0f1 19125 ldrexd, t_ldrexd),
4b8c8c02
RE
19126 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
19127 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19128 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
19129 stlex, t_stlex),
19130 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
9eb6c0f1 19131 strexd, t_strexd),
4b8c8c02
RE
19132 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
19133 stlex, t_stlex),
19134 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
19135 stlex, t_stlex),
19136 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19137 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19138 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19139 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19140 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19141 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
53c4b28b 19142
8884b720 19143 /* ARMv8 T32 only. */
74db7efb 19144#undef ARM_VARIANT
b79f7053
MGD
19145#define ARM_VARIANT NULL
19146 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
19147 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
19148 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
19149
33399f07
MGD
19150 /* FP for ARMv8. */
19151#undef ARM_VARIANT
a715796b 19152#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 19153#undef THUMB_VARIANT
a715796b 19154#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
19155
19156 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
19157 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
19158 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
19159 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
19160 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
19161 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
19162 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
19163 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
19164 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
19165 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
19166 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
19167 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
19168 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
19169 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
19170 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
19171 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
19172 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 19173
91ff7894
MGD
19174 /* Crypto v1 extensions. */
19175#undef ARM_VARIANT
19176#define ARM_VARIANT & fpu_crypto_ext_armv8
19177#undef THUMB_VARIANT
19178#define THUMB_VARIANT & fpu_crypto_ext_armv8
19179
19180 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
19181 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
19182 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
19183 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
19184 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
19185 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
19186 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
19187 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
19188 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
19189 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
19190 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
19191 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
19192 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
19193 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 19194
dd5181d5 19195#undef ARM_VARIANT
74db7efb 19196#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
19197#undef THUMB_VARIANT
19198#define THUMB_VARIANT & crc_ext_armv8
19199 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
19200 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
19201 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
19202 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
19203 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
19204 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
19205
c921be7d
NC
19206#undef ARM_VARIANT
19207#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
19208#undef THUMB_VARIANT
19209#define THUMB_VARIANT NULL
c921be7d 19210
21d799b5
NC
19211 cCE("wfs", e200110, 1, (RR), rd),
19212 cCE("rfs", e300110, 1, (RR), rd),
19213 cCE("wfc", e400110, 1, (RR), rd),
19214 cCE("rfc", e500110, 1, (RR), rd),
19215
19216 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
19217 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
19218 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
19219 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
19220
19221 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
19222 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
19223 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
19224 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
19225
19226 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
19227 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
19228 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
19229 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
19230 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
19231 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
19232 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
19233 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
19234 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
19235 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
19236 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
19237 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
19238
19239 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
19240 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
19241 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
19242 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
19243 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
19244 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
19245 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
19246 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
19247 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
19248 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
19249 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
19250 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
19251
19252 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
19253 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
19254 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
19255 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
19256 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
19257 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
19258 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
19259 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
19260 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
19261 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
19262 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
19263 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
19264
19265 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
19266 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
19267 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
19268 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
19269 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
19270 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
19271 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
19272 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
19273 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
19274 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
19275 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
19276 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
19277
19278 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
19279 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
19280 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
19281 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
19282 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
19283 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
19284 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
19285 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
19286 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
19287 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
19288 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
19289 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
19290
19291 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
19292 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
19293 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
19294 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
19295 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
19296 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
19297 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
19298 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
19299 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
19300 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
19301 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
19302 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
19303
19304 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
19305 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
19306 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
19307 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
19308 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
19309 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
19310 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
19311 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
19312 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
19313 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
19314 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
19315 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
19316
19317 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
19318 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
19319 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
19320 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
19321 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
19322 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
19323 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
19324 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
19325 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
19326 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
19327 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
19328 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
19329
19330 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
19331 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
19332 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
19333 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
19334 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
19335 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
19336 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
19337 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
19338 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
19339 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
19340 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
19341 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
19342
19343 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
19344 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
19345 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
19346 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
19347 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
19348 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
19349 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
19350 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
19351 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
19352 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
19353 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
19354 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
19355
19356 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
19357 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
19358 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
19359 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
19360 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
19361 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
19362 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
19363 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
19364 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
19365 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
19366 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
19367 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
19368
19369 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
19370 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
19371 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
19372 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
19373 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
19374 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
19375 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
19376 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
19377 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
19378 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
19379 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
19380 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
19381
19382 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
19383 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
19384 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
19385 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
19386 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
19387 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
19388 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
19389 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
19390 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
19391 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
19392 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
19393 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
19394
19395 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
19396 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
19397 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
19398 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
19399 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
19400 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
19401 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
19402 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
19403 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
19404 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
19405 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
19406 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
19407
19408 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
19409 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
19410 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
19411 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
19412 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
19413 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
19414 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
19415 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
19416 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
19417 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
19418 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
19419 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
19420
19421 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
19422 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
19423 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
19424 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
19425 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
19426 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
19427 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
19428 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
19429 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
19430 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
19431 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
19432 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
19433
19434 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
19435 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
19436 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
19437 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
19438 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
19439 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19440 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19441 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19442 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
19443 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
19444 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
19445 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
19446
19447 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
19448 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
19449 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
19450 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
19451 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
19452 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19453 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19454 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19455 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
19456 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
19457 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
19458 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
19459
19460 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
19461 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
19462 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
19463 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
19464 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
19465 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19466 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19467 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19468 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
19469 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
19470 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
19471 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
19472
19473 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
19474 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
19475 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
19476 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
19477 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
19478 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19479 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19480 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19481 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
19482 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
19483 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
19484 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
19485
19486 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
19487 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
19488 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
19489 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
19490 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
19491 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19492 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19493 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19494 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
19495 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
19496 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
19497 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
19498
19499 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
19500 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
19501 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
19502 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
19503 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
19504 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19505 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19506 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19507 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
19508 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
19509 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
19510 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
19511
19512 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
19513 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
19514 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
19515 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
19516 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
19517 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19518 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19519 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19520 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
19521 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
19522 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
19523 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
19524
19525 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
19526 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
19527 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
19528 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
19529 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
19530 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19531 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19532 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19533 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
19534 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
19535 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
19536 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
19537
19538 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
19539 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
19540 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
19541 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
19542 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
19543 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19544 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19545 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19546 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
19547 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
19548 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
19549 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
19550
19551 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
19552 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
19553 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
19554 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
19555 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
19556 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19557 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19558 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19559 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
19560 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
19561 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
19562 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
19563
19564 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19565 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19566 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19567 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19568 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19569 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19570 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19571 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19572 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19573 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19574 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19575 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19576
19577 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19578 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19579 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19580 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19581 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19582 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19583 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19584 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19585 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19586 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19587 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19588 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19589
19590 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
19591 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
19592 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
19593 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
19594 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
19595 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19596 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19597 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19598 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
19599 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
19600 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
19601 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
19602
19603 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
19604 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
19605 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
19606 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
19607
19608 cCL("flts", e000110, 2, (RF, RR), rn_rd),
19609 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
19610 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
19611 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
19612 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
19613 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
19614 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
19615 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
19616 cCL("flte", e080110, 2, (RF, RR), rn_rd),
19617 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
19618 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
19619 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 19620
c19d1205
ZW
19621 /* The implementation of the FIX instruction is broken on some
19622 assemblers, in that it accepts a precision specifier as well as a
19623 rounding specifier, despite the fact that this is meaningless.
19624 To be more compatible, we accept it as well, though of course it
19625 does not set any bits. */
21d799b5
NC
19626 cCE("fix", e100110, 2, (RR, RF), rd_rm),
19627 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
19628 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
19629 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
19630 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
19631 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
19632 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
19633 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
19634 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
19635 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
19636 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
19637 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
19638 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 19639
c19d1205 19640 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
19641#undef ARM_VARIANT
19642#define ARM_VARIANT & fpu_fpa_ext_v2
19643
21d799b5
NC
19644 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19645 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19646 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19647 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19648 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
19649 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 19650
c921be7d
NC
19651#undef ARM_VARIANT
19652#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
19653
c19d1205 19654 /* Moves and type conversions. */
21d799b5
NC
19655 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
19656 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
19657 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
19658 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
19659 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
19660 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
19661 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
19662 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
19663 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
19664 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
19665 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
19666 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
19667 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
19668 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
19669
19670 /* Memory operations. */
21d799b5
NC
19671 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
19672 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
19673 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19674 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19675 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19676 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19677 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19678 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19679 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19680 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19681 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19682 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
19683 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19684 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
19685 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19686 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
19687 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
19688 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 19689
c19d1205 19690 /* Monadic operations. */
21d799b5
NC
19691 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
19692 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
19693 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
19694
19695 /* Dyadic operations. */
21d799b5
NC
19696 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19697 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19698 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19699 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19700 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19701 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19702 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19703 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
19704 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 19705
c19d1205 19706 /* Comparisons. */
21d799b5
NC
19707 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
19708 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
19709 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
19710 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 19711
62f3b8c8
PB
19712 /* Double precision load/store are still present on single precision
19713 implementations. */
19714 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
19715 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
19716 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19717 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19718 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19719 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19720 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19721 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
19722 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
19723 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 19724
c921be7d
NC
19725#undef ARM_VARIANT
19726#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
19727
c19d1205 19728 /* Moves and type conversions. */
21d799b5
NC
19729 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19730 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
19731 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19732 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
19733 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
19734 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
19735 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
19736 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
19737 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
19738 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
19739 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
19740 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
19741 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 19742
c19d1205 19743 /* Monadic operations. */
21d799b5
NC
19744 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19745 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19746 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
19747
19748 /* Dyadic operations. */
21d799b5
NC
19749 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19750 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19751 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19752 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19753 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19754 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19755 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19756 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
19757 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 19758
c19d1205 19759 /* Comparisons. */
21d799b5
NC
19760 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
19761 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
19762 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
19763 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 19764
c921be7d
NC
19765#undef ARM_VARIANT
19766#define ARM_VARIANT & fpu_vfp_ext_v2
19767
21d799b5
NC
19768 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
19769 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
19770 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
19771 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 19772
037e8744
JB
19773/* Instructions which may belong to either the Neon or VFP instruction sets.
19774 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
19775#undef ARM_VARIANT
19776#define ARM_VARIANT & fpu_vfp_ext_v1xd
19777#undef THUMB_VARIANT
19778#define THUMB_VARIANT & fpu_vfp_ext_v1xd
19779
037e8744
JB
19780 /* These mnemonics are unique to VFP. */
19781 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
19782 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
19783 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19784 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
19785 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
19786 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
19787 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
19788 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
19789 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
19790 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
19791
19792 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
19793 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
19794 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
19795 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 19796
21d799b5
NC
19797 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
19798 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
19799
19800 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
19801 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
19802
55881a11
MGD
19803 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19804 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19805 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19806 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19807 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
19808 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
19809 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
19810 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 19811
5f1af56b 19812 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 19813 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
19814 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
19815 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 19816
037e8744
JB
19817
19818 /* NOTE: All VMOV encoding is special-cased! */
19819 NCE(vmov, 0, 1, (VMOV), neon_mov),
19820 NCE(vmovq, 0, 1, (VMOV), neon_mov),
19821
c921be7d
NC
19822#undef THUMB_VARIANT
19823#define THUMB_VARIANT & fpu_neon_ext_v1
19824#undef ARM_VARIANT
19825#define ARM_VARIANT & fpu_neon_ext_v1
19826
5287ad62
JB
19827 /* Data processing with three registers of the same length. */
19828 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
19829 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
19830 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
19831 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19832 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19833 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19834 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19835 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
19836 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
19837 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
19838 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
19839 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
19840 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
19841 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
19842 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
19843 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
19844 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
19845 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
19846 /* If not immediate, fall back to neon_dyadic_i64_su.
19847 shl_imm should accept I8 I16 I32 I64,
19848 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
19849 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
19850 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
19851 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
19852 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 19853 /* Logic ops, types optional & ignored. */
4316f0d2
DG
19854 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19855 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19856 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19857 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19858 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19859 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19860 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
19861 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
19862 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
19863 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
19864 /* Bitfield ops, untyped. */
19865 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19866 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19867 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19868 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19869 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
19870 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
19871 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
19872 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19873 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19874 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19875 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
19876 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
19877 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
19878 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
19879 back to neon_dyadic_if_su. */
21d799b5
NC
19880 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
19881 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
19882 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
19883 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
19884 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
19885 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
19886 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
19887 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 19888 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
19889 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
19890 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 19891 /* As above, D registers only. */
21d799b5
NC
19892 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
19893 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 19894 /* Int and float variants, signedness unimportant. */
21d799b5
NC
19895 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
19896 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
19897 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 19898 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
19899 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
19900 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
19901 /* vtst takes sizes 8, 16, 32. */
19902 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
19903 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
19904 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 19905 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 19906 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
19907 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19908 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
19909 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19910 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
19911 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
19912 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
19913 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
19914 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
19915 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
19916 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
19917 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
19918 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
19919 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
19920 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
19921 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
19922 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e
MW
19923 /* ARM v8.1 extension. */
19924 nUF(vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19925 nUF(vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
19926 nUF(vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
19927 nUF(vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
19928
19929 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 19930 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
19931 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
19932
19933 /* Data processing with two registers and a shift amount. */
19934 /* Right shifts, and variants with rounding.
19935 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
19936 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
19937 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
19938 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
19939 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
19940 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
19941 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
19942 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
19943 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
19944 /* Shift and insert. Sizes accepted 8 16 32 64. */
19945 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
19946 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
19947 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
19948 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
19949 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
19950 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
19951 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
19952 /* Right shift immediate, saturating & narrowing, with rounding variants.
19953 Types accepted S16 S32 S64 U16 U32 U64. */
19954 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
19955 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
19956 /* As above, unsigned. Types accepted S16 S32 S64. */
19957 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
19958 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
19959 /* Right shift narrowing. Types accepted I16 I32 I64. */
19960 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
19961 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
19962 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 19963 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 19964 /* CVT with optional immediate for fixed-point variant. */
21d799b5 19965 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 19966
4316f0d2
DG
19967 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
19968 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
19969
19970 /* Data processing, three registers of different lengths. */
19971 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
19972 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
19973 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
19974 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
19975 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
19976 /* If not scalar, fall back to neon_dyadic_long.
19977 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
19978 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
19979 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
19980 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
19981 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
19982 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
19983 /* Dyadic, narrowing insns. Types I16 I32 I64. */
19984 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19985 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19986 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19987 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
19988 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
19989 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
19990 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
19991 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
19992 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
19993 S16 S32 U16 U32. */
21d799b5 19994 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
19995
19996 /* Extract. Size 8. */
3b8d421e
PB
19997 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
19998 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
19999
20000 /* Two registers, miscellaneous. */
20001 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
20002 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
20003 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
20004 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
20005 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
20006 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
20007 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
20008 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
20009 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
20010 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
20011 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
20012 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
20013 /* VMOVN. Types I16 I32 I64. */
21d799b5 20014 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 20015 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 20016 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 20017 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 20018 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
20019 /* VZIP / VUZP. Sizes 8 16 32. */
20020 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
20021 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
20022 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
20023 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
20024 /* VQABS / VQNEG. Types S8 S16 S32. */
20025 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20026 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
20027 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20028 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
20029 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
20030 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
20031 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
20032 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
20033 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
20034 /* Reciprocal estimates. Types U32 F32. */
20035 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
20036 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
20037 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
20038 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
20039 /* VCLS. Types S8 S16 S32. */
20040 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
20041 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
20042 /* VCLZ. Types I8 I16 I32. */
20043 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
20044 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
20045 /* VCNT. Size 8. */
20046 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
20047 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
20048 /* Two address, untyped. */
20049 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
20050 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
20051 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
20052 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
20053 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
20054
20055 /* Table lookup. Size 8. */
20056 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20057 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20058
c921be7d
NC
20059#undef THUMB_VARIANT
20060#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
20061#undef ARM_VARIANT
20062#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
20063
5287ad62 20064 /* Neon element/structure load/store. */
21d799b5
NC
20065 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20066 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20067 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20068 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20069 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20070 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20071 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
20072 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 20073
c921be7d 20074#undef THUMB_VARIANT
74db7efb
NC
20075#define THUMB_VARIANT & fpu_vfp_ext_v3xd
20076#undef ARM_VARIANT
20077#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
20078 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
20079 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20080 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20081 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20082 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20083 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20084 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20085 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20086 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20087
74db7efb 20088#undef THUMB_VARIANT
c921be7d
NC
20089#define THUMB_VARIANT & fpu_vfp_ext_v3
20090#undef ARM_VARIANT
20091#define ARM_VARIANT & fpu_vfp_ext_v3
20092
21d799b5 20093 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 20094 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20095 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20096 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20097 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20098 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20099 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20100 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20101 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 20102
74db7efb
NC
20103#undef ARM_VARIANT
20104#define ARM_VARIANT & fpu_vfp_ext_fma
20105#undef THUMB_VARIANT
20106#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
20107 /* Mnemonics shared by Neon and VFP. These are included in the
20108 VFP FMA variant; NEON and VFP FMA always includes the NEON
20109 FMA instructions. */
20110 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20111 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20112 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
20113 the v form should always be used. */
20114 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20115 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20116 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20117 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20118 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20119 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20120
5287ad62 20121#undef THUMB_VARIANT
c921be7d
NC
20122#undef ARM_VARIANT
20123#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
20124
21d799b5
NC
20125 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20126 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20127 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20128 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20129 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20130 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20131 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
20132 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 20133
c921be7d
NC
20134#undef ARM_VARIANT
20135#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
20136
21d799b5
NC
20137 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
20138 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
20139 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
20140 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
20141 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
20142 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
20143 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
20144 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
20145 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
20146 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20147 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20148 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20149 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20150 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20151 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
20152 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20153 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20154 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20155 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
20156 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
20157 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20158 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20159 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20160 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20161 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20162 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
20163 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
20164 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
20165 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
20166 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
20167 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
20168 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
20169 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
20170 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
20171 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
20172 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
20173 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
20174 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20175 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20176 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20177 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20178 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20179 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20180 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20181 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20182 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20183 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
20184 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20185 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20186 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20187 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20188 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20189 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20190 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20191 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20192 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20193 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20194 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20195 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20196 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20197 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20198 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20199 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20200 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20201 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20202 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20203 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20204 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20205 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20206 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20207 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20208 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20209 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20210 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20211 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20212 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20213 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20214 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20215 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20216 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20217 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20218 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20219 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20220 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20221 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20222 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20223 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20224 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20225 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
20226 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20227 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20228 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20229 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20230 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20231 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20232 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20233 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20234 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20235 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20236 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20237 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20238 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20239 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20240 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20241 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20242 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20243 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20244 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20245 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20246 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20247 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
20248 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20249 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20250 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20251 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20252 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20253 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20254 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20255 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20256 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20257 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20258 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20259 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20260 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20261 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20262 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20263 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20264 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20265 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20266 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20267 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20268 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20269 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20270 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20271 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20272 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20273 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20274 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20275 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20276 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20277 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20278 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20279 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
20280 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
20281 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
20282 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
20283 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
20284 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
20285 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20286 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20287 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20288 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
20289 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
20290 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
20291 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
20292 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
20293 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
20294 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20295 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20296 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20297 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20298 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 20299
c921be7d
NC
20300#undef ARM_VARIANT
20301#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
20302
21d799b5
NC
20303 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
20304 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
20305 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
20306 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
20307 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
20308 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
20309 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20310 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20311 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20312 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20313 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20314 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20315 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20316 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20317 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20318 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20319 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20320 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20321 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20322 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20323 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
20324 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20325 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20326 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20327 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20328 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20329 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20330 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20331 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20332 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20333 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20334 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20335 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20336 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20337 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20338 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20339 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20340 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20341 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20342 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20343 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20344 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20345 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20346 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20347 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20348 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20349 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20350 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20351 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20352 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20353 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20354 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20355 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20356 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20357 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20358 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20359 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 20360
c921be7d
NC
20361#undef ARM_VARIANT
20362#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
20363
21d799b5
NC
20364 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20365 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20366 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20367 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20368 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20369 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20370 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20371 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20372 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
20373 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
20374 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
20375 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
20376 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
20377 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
20378 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
20379 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
20380 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
20381 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
20382 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
20383 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
20384 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
20385 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
20386 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
20387 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
20388 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
20389 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
20390 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
20391 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
20392 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
20393 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
20394 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
20395 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
20396 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
20397 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
20398 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
20399 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
20400 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
20401 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
20402 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
20403 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
20404 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
20405 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
20406 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
20407 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
20408 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
20409 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
20410 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
20411 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
20412 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
20413 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
20414 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
20415 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
20416 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
20417 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
20418 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
20419 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
20420 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
20421 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
20422 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
20423 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
20424 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
20425 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
20426 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
20427 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
20428 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20429 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20430 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20431 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20432 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20433 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20434 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20435 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
20436 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
20437 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
20438 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
20439 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
20440};
20441#undef ARM_VARIANT
20442#undef THUMB_VARIANT
20443#undef TCE
c19d1205
ZW
20444#undef TUE
20445#undef TUF
20446#undef TCC
8f06b2d8 20447#undef cCE
e3cb604e
PB
20448#undef cCL
20449#undef C3E
c19d1205
ZW
20450#undef CE
20451#undef CM
20452#undef UE
20453#undef UF
20454#undef UT
5287ad62
JB
20455#undef NUF
20456#undef nUF
20457#undef NCE
20458#undef nCE
c19d1205
ZW
20459#undef OPS0
20460#undef OPS1
20461#undef OPS2
20462#undef OPS3
20463#undef OPS4
20464#undef OPS5
20465#undef OPS6
20466#undef do_0
20467\f
20468/* MD interface: bits in the object file. */
bfae80f2 20469
c19d1205
ZW
20470/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
20471 for use in the a.out file, and stores them in the array pointed to by buf.
20472 This knows about the endian-ness of the target machine and does
20473 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
20474 2 (short) and 4 (long) Floating numbers are put out as a series of
20475 LITTLENUMS (shorts, here at least). */
b99bd4ef 20476
c19d1205
ZW
20477void
20478md_number_to_chars (char * buf, valueT val, int n)
20479{
20480 if (target_big_endian)
20481 number_to_chars_bigendian (buf, val, n);
20482 else
20483 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
20484}
20485
c19d1205
ZW
20486static valueT
20487md_chars_to_number (char * buf, int n)
bfae80f2 20488{
c19d1205
ZW
20489 valueT result = 0;
20490 unsigned char * where = (unsigned char *) buf;
bfae80f2 20491
c19d1205 20492 if (target_big_endian)
b99bd4ef 20493 {
c19d1205
ZW
20494 while (n--)
20495 {
20496 result <<= 8;
20497 result |= (*where++ & 255);
20498 }
b99bd4ef 20499 }
c19d1205 20500 else
b99bd4ef 20501 {
c19d1205
ZW
20502 while (n--)
20503 {
20504 result <<= 8;
20505 result |= (where[n] & 255);
20506 }
bfae80f2 20507 }
b99bd4ef 20508
c19d1205 20509 return result;
bfae80f2 20510}
b99bd4ef 20511
c19d1205 20512/* MD interface: Sections. */
b99bd4ef 20513
fa94de6b
RM
20514/* Calculate the maximum variable size (i.e., excluding fr_fix)
20515 that an rs_machine_dependent frag may reach. */
20516
20517unsigned int
20518arm_frag_max_var (fragS *fragp)
20519{
20520 /* We only use rs_machine_dependent for variable-size Thumb instructions,
20521 which are either THUMB_SIZE (2) or INSN_SIZE (4).
20522
20523 Note that we generate relaxable instructions even for cases that don't
20524 really need it, like an immediate that's a trivial constant. So we're
20525 overestimating the instruction size for some of those cases. Rather
20526 than putting more intelligence here, it would probably be better to
20527 avoid generating a relaxation frag in the first place when it can be
20528 determined up front that a short instruction will suffice. */
20529
20530 gas_assert (fragp->fr_type == rs_machine_dependent);
20531 return INSN_SIZE;
20532}
20533
0110f2b8
PB
20534/* Estimate the size of a frag before relaxing. Assume everything fits in
20535 2 bytes. */
20536
c19d1205 20537int
0110f2b8 20538md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
20539 segT segtype ATTRIBUTE_UNUSED)
20540{
0110f2b8
PB
20541 fragp->fr_var = 2;
20542 return 2;
20543}
20544
20545/* Convert a machine dependent frag. */
20546
20547void
20548md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
20549{
20550 unsigned long insn;
20551 unsigned long old_op;
20552 char *buf;
20553 expressionS exp;
20554 fixS *fixp;
20555 int reloc_type;
20556 int pc_rel;
20557 int opcode;
20558
20559 buf = fragp->fr_literal + fragp->fr_fix;
20560
20561 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
20562 if (fragp->fr_symbol)
20563 {
0110f2b8
PB
20564 exp.X_op = O_symbol;
20565 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
20566 }
20567 else
20568 {
0110f2b8 20569 exp.X_op = O_constant;
5f4273c7 20570 }
0110f2b8
PB
20571 exp.X_add_number = fragp->fr_offset;
20572 opcode = fragp->fr_subtype;
20573 switch (opcode)
20574 {
20575 case T_MNEM_ldr_pc:
20576 case T_MNEM_ldr_pc2:
20577 case T_MNEM_ldr_sp:
20578 case T_MNEM_str_sp:
20579 case T_MNEM_ldr:
20580 case T_MNEM_ldrb:
20581 case T_MNEM_ldrh:
20582 case T_MNEM_str:
20583 case T_MNEM_strb:
20584 case T_MNEM_strh:
20585 if (fragp->fr_var == 4)
20586 {
5f4273c7 20587 insn = THUMB_OP32 (opcode);
0110f2b8
PB
20588 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
20589 {
20590 insn |= (old_op & 0x700) << 4;
20591 }
20592 else
20593 {
20594 insn |= (old_op & 7) << 12;
20595 insn |= (old_op & 0x38) << 13;
20596 }
20597 insn |= 0x00000c00;
20598 put_thumb32_insn (buf, insn);
20599 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
20600 }
20601 else
20602 {
20603 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
20604 }
20605 pc_rel = (opcode == T_MNEM_ldr_pc2);
20606 break;
20607 case T_MNEM_adr:
20608 if (fragp->fr_var == 4)
20609 {
20610 insn = THUMB_OP32 (opcode);
20611 insn |= (old_op & 0xf0) << 4;
20612 put_thumb32_insn (buf, insn);
20613 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
20614 }
20615 else
20616 {
20617 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20618 exp.X_add_number -= 4;
20619 }
20620 pc_rel = 1;
20621 break;
20622 case T_MNEM_mov:
20623 case T_MNEM_movs:
20624 case T_MNEM_cmp:
20625 case T_MNEM_cmn:
20626 if (fragp->fr_var == 4)
20627 {
20628 int r0off = (opcode == T_MNEM_mov
20629 || opcode == T_MNEM_movs) ? 0 : 8;
20630 insn = THUMB_OP32 (opcode);
20631 insn = (insn & 0xe1ffffff) | 0x10000000;
20632 insn |= (old_op & 0x700) << r0off;
20633 put_thumb32_insn (buf, insn);
20634 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
20635 }
20636 else
20637 {
20638 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
20639 }
20640 pc_rel = 0;
20641 break;
20642 case T_MNEM_b:
20643 if (fragp->fr_var == 4)
20644 {
20645 insn = THUMB_OP32(opcode);
20646 put_thumb32_insn (buf, insn);
20647 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
20648 }
20649 else
20650 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
20651 pc_rel = 1;
20652 break;
20653 case T_MNEM_bcond:
20654 if (fragp->fr_var == 4)
20655 {
20656 insn = THUMB_OP32(opcode);
20657 insn |= (old_op & 0xf00) << 14;
20658 put_thumb32_insn (buf, insn);
20659 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
20660 }
20661 else
20662 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
20663 pc_rel = 1;
20664 break;
20665 case T_MNEM_add_sp:
20666 case T_MNEM_add_pc:
20667 case T_MNEM_inc_sp:
20668 case T_MNEM_dec_sp:
20669 if (fragp->fr_var == 4)
20670 {
20671 /* ??? Choose between add and addw. */
20672 insn = THUMB_OP32 (opcode);
20673 insn |= (old_op & 0xf0) << 4;
20674 put_thumb32_insn (buf, insn);
16805f35
PB
20675 if (opcode == T_MNEM_add_pc)
20676 reloc_type = BFD_RELOC_ARM_T32_IMM12;
20677 else
20678 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
20679 }
20680 else
20681 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20682 pc_rel = 0;
20683 break;
20684
20685 case T_MNEM_addi:
20686 case T_MNEM_addis:
20687 case T_MNEM_subi:
20688 case T_MNEM_subis:
20689 if (fragp->fr_var == 4)
20690 {
20691 insn = THUMB_OP32 (opcode);
20692 insn |= (old_op & 0xf0) << 4;
20693 insn |= (old_op & 0xf) << 16;
20694 put_thumb32_insn (buf, insn);
16805f35
PB
20695 if (insn & (1 << 20))
20696 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
20697 else
20698 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
20699 }
20700 else
20701 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
20702 pc_rel = 0;
20703 break;
20704 default:
5f4273c7 20705 abort ();
0110f2b8
PB
20706 }
20707 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 20708 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
20709 fixp->fx_file = fragp->fr_file;
20710 fixp->fx_line = fragp->fr_line;
20711 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
20712
20713 /* Set whether we use thumb-2 ISA based on final relaxation results. */
20714 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
20715 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
20716 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
20717}
20718
20719/* Return the size of a relaxable immediate operand instruction.
20720 SHIFT and SIZE specify the form of the allowable immediate. */
20721static int
20722relax_immediate (fragS *fragp, int size, int shift)
20723{
20724 offsetT offset;
20725 offsetT mask;
20726 offsetT low;
20727
20728 /* ??? Should be able to do better than this. */
20729 if (fragp->fr_symbol)
20730 return 4;
20731
20732 low = (1 << shift) - 1;
20733 mask = (1 << (shift + size)) - (1 << shift);
20734 offset = fragp->fr_offset;
20735 /* Force misaligned offsets to 32-bit variant. */
20736 if (offset & low)
5e77afaa 20737 return 4;
0110f2b8
PB
20738 if (offset & ~mask)
20739 return 4;
20740 return 2;
20741}
20742
5e77afaa
PB
20743/* Get the address of a symbol during relaxation. */
20744static addressT
5f4273c7 20745relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
20746{
20747 fragS *sym_frag;
20748 addressT addr;
20749 symbolS *sym;
20750
20751 sym = fragp->fr_symbol;
20752 sym_frag = symbol_get_frag (sym);
20753 know (S_GET_SEGMENT (sym) != absolute_section
20754 || sym_frag == &zero_address_frag);
20755 addr = S_GET_VALUE (sym) + fragp->fr_offset;
20756
20757 /* If frag has yet to be reached on this pass, assume it will
20758 move by STRETCH just as we did. If this is not so, it will
20759 be because some frag between grows, and that will force
20760 another pass. */
20761
20762 if (stretch != 0
20763 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
20764 {
20765 fragS *f;
20766
20767 /* Adjust stretch for any alignment frag. Note that if have
20768 been expanding the earlier code, the symbol may be
20769 defined in what appears to be an earlier frag. FIXME:
20770 This doesn't handle the fr_subtype field, which specifies
20771 a maximum number of bytes to skip when doing an
20772 alignment. */
20773 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
20774 {
20775 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
20776 {
20777 if (stretch < 0)
20778 stretch = - ((- stretch)
20779 & ~ ((1 << (int) f->fr_offset) - 1));
20780 else
20781 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
20782 if (stretch == 0)
20783 break;
20784 }
20785 }
20786 if (f != NULL)
20787 addr += stretch;
20788 }
5e77afaa
PB
20789
20790 return addr;
20791}
20792
0110f2b8
PB
20793/* Return the size of a relaxable adr pseudo-instruction or PC-relative
20794 load. */
20795static int
5e77afaa 20796relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
20797{
20798 addressT addr;
20799 offsetT val;
20800
20801 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
20802 if (fragp->fr_symbol == NULL
20803 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
20804 || sec != S_GET_SEGMENT (fragp->fr_symbol)
20805 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
20806 return 4;
20807
5f4273c7 20808 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
20809 addr = fragp->fr_address + fragp->fr_fix;
20810 addr = (addr + 4) & ~3;
5e77afaa 20811 /* Force misaligned targets to 32-bit variant. */
0110f2b8 20812 if (val & 3)
5e77afaa 20813 return 4;
0110f2b8
PB
20814 val -= addr;
20815 if (val < 0 || val > 1020)
20816 return 4;
20817 return 2;
20818}
20819
20820/* Return the size of a relaxable add/sub immediate instruction. */
20821static int
20822relax_addsub (fragS *fragp, asection *sec)
20823{
20824 char *buf;
20825 int op;
20826
20827 buf = fragp->fr_literal + fragp->fr_fix;
20828 op = bfd_get_16(sec->owner, buf);
20829 if ((op & 0xf) == ((op >> 4) & 0xf))
20830 return relax_immediate (fragp, 8, 0);
20831 else
20832 return relax_immediate (fragp, 3, 0);
20833}
20834
e83a675f
RE
20835/* Return TRUE iff the definition of symbol S could be pre-empted
20836 (overridden) at link or load time. */
20837static bfd_boolean
20838symbol_preemptible (symbolS *s)
20839{
20840 /* Weak symbols can always be pre-empted. */
20841 if (S_IS_WEAK (s))
20842 return TRUE;
20843
20844 /* Non-global symbols cannot be pre-empted. */
20845 if (! S_IS_EXTERNAL (s))
20846 return FALSE;
20847
20848#ifdef OBJ_ELF
20849 /* In ELF, a global symbol can be marked protected, or private. In that
20850 case it can't be pre-empted (other definitions in the same link unit
20851 would violate the ODR). */
20852 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
20853 return FALSE;
20854#endif
20855
20856 /* Other global symbols might be pre-empted. */
20857 return TRUE;
20858}
0110f2b8
PB
20859
20860/* Return the size of a relaxable branch instruction. BITS is the
20861 size of the offset field in the narrow instruction. */
20862
20863static int
5e77afaa 20864relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
20865{
20866 addressT addr;
20867 offsetT val;
20868 offsetT limit;
20869
20870 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 20871 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
20872 || sec != S_GET_SEGMENT (fragp->fr_symbol)
20873 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
20874 return 4;
20875
267bf995 20876#ifdef OBJ_ELF
e83a675f 20877 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
20878 if (S_IS_DEFINED (fragp->fr_symbol)
20879 && ARM_IS_FUNC (fragp->fr_symbol))
20880 return 4;
e83a675f 20881#endif
0d9b4b55 20882
e83a675f 20883 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 20884 return 4;
267bf995 20885
5f4273c7 20886 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
20887 addr = fragp->fr_address + fragp->fr_fix + 4;
20888 val -= addr;
20889
20890 /* Offset is a signed value *2 */
20891 limit = 1 << bits;
20892 if (val >= limit || val < -limit)
20893 return 4;
20894 return 2;
20895}
20896
20897
20898/* Relax a machine dependent frag. This returns the amount by which
20899 the current size of the frag should change. */
20900
20901int
5e77afaa 20902arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
20903{
20904 int oldsize;
20905 int newsize;
20906
20907 oldsize = fragp->fr_var;
20908 switch (fragp->fr_subtype)
20909 {
20910 case T_MNEM_ldr_pc2:
5f4273c7 20911 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
20912 break;
20913 case T_MNEM_ldr_pc:
20914 case T_MNEM_ldr_sp:
20915 case T_MNEM_str_sp:
5f4273c7 20916 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
20917 break;
20918 case T_MNEM_ldr:
20919 case T_MNEM_str:
5f4273c7 20920 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
20921 break;
20922 case T_MNEM_ldrh:
20923 case T_MNEM_strh:
5f4273c7 20924 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
20925 break;
20926 case T_MNEM_ldrb:
20927 case T_MNEM_strb:
5f4273c7 20928 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
20929 break;
20930 case T_MNEM_adr:
5f4273c7 20931 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
20932 break;
20933 case T_MNEM_mov:
20934 case T_MNEM_movs:
20935 case T_MNEM_cmp:
20936 case T_MNEM_cmn:
5f4273c7 20937 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
20938 break;
20939 case T_MNEM_b:
5f4273c7 20940 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
20941 break;
20942 case T_MNEM_bcond:
5f4273c7 20943 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
20944 break;
20945 case T_MNEM_add_sp:
20946 case T_MNEM_add_pc:
20947 newsize = relax_immediate (fragp, 8, 2);
20948 break;
20949 case T_MNEM_inc_sp:
20950 case T_MNEM_dec_sp:
20951 newsize = relax_immediate (fragp, 7, 2);
20952 break;
20953 case T_MNEM_addi:
20954 case T_MNEM_addis:
20955 case T_MNEM_subi:
20956 case T_MNEM_subis:
20957 newsize = relax_addsub (fragp, sec);
20958 break;
20959 default:
5f4273c7 20960 abort ();
0110f2b8 20961 }
5e77afaa
PB
20962
20963 fragp->fr_var = newsize;
20964 /* Freeze wide instructions that are at or before the same location as
20965 in the previous pass. This avoids infinite loops.
5f4273c7
NC
20966 Don't freeze them unconditionally because targets may be artificially
20967 misaligned by the expansion of preceding frags. */
5e77afaa 20968 if (stretch <= 0 && newsize > 2)
0110f2b8 20969 {
0110f2b8 20970 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 20971 frag_wane (fragp);
0110f2b8 20972 }
5e77afaa 20973
0110f2b8 20974 return newsize - oldsize;
c19d1205 20975}
b99bd4ef 20976
c19d1205 20977/* Round up a section size to the appropriate boundary. */
b99bd4ef 20978
c19d1205
ZW
20979valueT
20980md_section_align (segT segment ATTRIBUTE_UNUSED,
20981 valueT size)
20982{
f0927246
NC
20983#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
20984 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
20985 {
20986 /* For a.out, force the section size to be aligned. If we don't do
20987 this, BFD will align it for us, but it will not write out the
20988 final bytes of the section. This may be a bug in BFD, but it is
20989 easier to fix it here since that is how the other a.out targets
20990 work. */
20991 int align;
20992
20993 align = bfd_get_section_alignment (stdoutput, segment);
20994 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
20995 }
c19d1205 20996#endif
f0927246
NC
20997
20998 return size;
bfae80f2 20999}
b99bd4ef 21000
c19d1205
ZW
21001/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
21002 of an rs_align_code fragment. */
21003
21004void
21005arm_handle_align (fragS * fragP)
bfae80f2 21006{
e7495e45
NS
21007 static char const arm_noop[2][2][4] =
21008 {
21009 { /* ARMv1 */
21010 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
21011 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
21012 },
21013 { /* ARMv6k */
21014 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
21015 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
21016 },
21017 };
21018 static char const thumb_noop[2][2][2] =
21019 {
21020 { /* Thumb-1 */
21021 {0xc0, 0x46}, /* LE */
21022 {0x46, 0xc0}, /* BE */
21023 },
21024 { /* Thumb-2 */
21025 {0x00, 0xbf}, /* LE */
21026 {0xbf, 0x00} /* BE */
21027 }
21028 };
21029 static char const wide_thumb_noop[2][4] =
21030 { /* Wide Thumb-2 */
21031 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
21032 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
21033 };
c921be7d 21034
e7495e45 21035 unsigned bytes, fix, noop_size;
c19d1205
ZW
21036 char * p;
21037 const char * noop;
e7495e45 21038 const char *narrow_noop = NULL;
cd000bff
DJ
21039#ifdef OBJ_ELF
21040 enum mstate state;
21041#endif
bfae80f2 21042
c19d1205 21043 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
21044 return;
21045
c19d1205
ZW
21046 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
21047 p = fragP->fr_literal + fragP->fr_fix;
21048 fix = 0;
bfae80f2 21049
c19d1205
ZW
21050 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
21051 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 21052
cd000bff 21053 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 21054
cd000bff 21055 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 21056 {
7f78eb34
JW
21057 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21058 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
21059 {
21060 narrow_noop = thumb_noop[1][target_big_endian];
21061 noop = wide_thumb_noop[target_big_endian];
21062 }
c19d1205 21063 else
e7495e45
NS
21064 noop = thumb_noop[0][target_big_endian];
21065 noop_size = 2;
cd000bff
DJ
21066#ifdef OBJ_ELF
21067 state = MAP_THUMB;
21068#endif
7ed4c4c5
NC
21069 }
21070 else
21071 {
7f78eb34
JW
21072 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21073 ? selected_cpu : arm_arch_none,
21074 arm_ext_v6k) != 0]
e7495e45
NS
21075 [target_big_endian];
21076 noop_size = 4;
cd000bff
DJ
21077#ifdef OBJ_ELF
21078 state = MAP_ARM;
21079#endif
7ed4c4c5 21080 }
c921be7d 21081
e7495e45 21082 fragP->fr_var = noop_size;
c921be7d 21083
c19d1205 21084 if (bytes & (noop_size - 1))
7ed4c4c5 21085 {
c19d1205 21086 fix = bytes & (noop_size - 1);
cd000bff
DJ
21087#ifdef OBJ_ELF
21088 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
21089#endif
c19d1205
ZW
21090 memset (p, 0, fix);
21091 p += fix;
21092 bytes -= fix;
a737bd4d 21093 }
a737bd4d 21094
e7495e45
NS
21095 if (narrow_noop)
21096 {
21097 if (bytes & noop_size)
21098 {
21099 /* Insert a narrow noop. */
21100 memcpy (p, narrow_noop, noop_size);
21101 p += noop_size;
21102 bytes -= noop_size;
21103 fix += noop_size;
21104 }
21105
21106 /* Use wide noops for the remainder */
21107 noop_size = 4;
21108 }
21109
c19d1205 21110 while (bytes >= noop_size)
a737bd4d 21111 {
c19d1205
ZW
21112 memcpy (p, noop, noop_size);
21113 p += noop_size;
21114 bytes -= noop_size;
21115 fix += noop_size;
a737bd4d
NC
21116 }
21117
c19d1205 21118 fragP->fr_fix += fix;
a737bd4d
NC
21119}
21120
c19d1205
ZW
21121/* Called from md_do_align. Used to create an alignment
21122 frag in a code section. */
21123
21124void
21125arm_frag_align_code (int n, int max)
bfae80f2 21126{
c19d1205 21127 char * p;
7ed4c4c5 21128
c19d1205 21129 /* We assume that there will never be a requirement
6ec8e702 21130 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 21131 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
21132 {
21133 char err_msg[128];
21134
fa94de6b 21135 sprintf (err_msg,
477330fc
RM
21136 _("alignments greater than %d bytes not supported in .text sections."),
21137 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 21138 as_fatal ("%s", err_msg);
6ec8e702 21139 }
bfae80f2 21140
c19d1205
ZW
21141 p = frag_var (rs_align_code,
21142 MAX_MEM_FOR_RS_ALIGN_CODE,
21143 1,
21144 (relax_substateT) max,
21145 (symbolS *) NULL,
21146 (offsetT) n,
21147 (char *) NULL);
21148 *p = 0;
21149}
bfae80f2 21150
8dc2430f
NC
21151/* Perform target specific initialisation of a frag.
21152 Note - despite the name this initialisation is not done when the frag
21153 is created, but only when its type is assigned. A frag can be created
21154 and used a long time before its type is set, so beware of assuming that
21155 this initialisationis performed first. */
bfae80f2 21156
cd000bff
DJ
21157#ifndef OBJ_ELF
21158void
21159arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
21160{
21161 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 21162 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
21163}
21164
21165#else /* OBJ_ELF is defined. */
c19d1205 21166void
cd000bff 21167arm_init_frag (fragS * fragP, int max_chars)
c19d1205 21168{
b968d18a
JW
21169 int frag_thumb_mode;
21170
8dc2430f
NC
21171 /* If the current ARM vs THUMB mode has not already
21172 been recorded into this frag then do so now. */
cd000bff 21173 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
21174 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
21175
21176 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 21177
f9c1b181
RL
21178 /* Record a mapping symbol for alignment frags. We will delete this
21179 later if the alignment ends up empty. */
21180 switch (fragP->fr_type)
21181 {
21182 case rs_align:
21183 case rs_align_test:
21184 case rs_fill:
21185 mapping_state_2 (MAP_DATA, max_chars);
21186 break;
21187 case rs_align_code:
b968d18a 21188 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
21189 break;
21190 default:
21191 break;
cd000bff 21192 }
bfae80f2
RE
21193}
21194
c19d1205
ZW
21195/* When we change sections we need to issue a new mapping symbol. */
21196
21197void
21198arm_elf_change_section (void)
bfae80f2 21199{
c19d1205
ZW
21200 /* Link an unlinked unwind index table section to the .text section. */
21201 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
21202 && elf_linked_to_section (now_seg) == NULL)
21203 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
21204}
21205
c19d1205
ZW
21206int
21207arm_elf_section_type (const char * str, size_t len)
e45d0630 21208{
c19d1205
ZW
21209 if (len == 5 && strncmp (str, "exidx", 5) == 0)
21210 return SHT_ARM_EXIDX;
e45d0630 21211
c19d1205
ZW
21212 return -1;
21213}
21214\f
21215/* Code to deal with unwinding tables. */
e45d0630 21216
c19d1205 21217static void add_unwind_adjustsp (offsetT);
e45d0630 21218
5f4273c7 21219/* Generate any deferred unwind frame offset. */
e45d0630 21220
bfae80f2 21221static void
c19d1205 21222flush_pending_unwind (void)
bfae80f2 21223{
c19d1205 21224 offsetT offset;
bfae80f2 21225
c19d1205
ZW
21226 offset = unwind.pending_offset;
21227 unwind.pending_offset = 0;
21228 if (offset != 0)
21229 add_unwind_adjustsp (offset);
bfae80f2
RE
21230}
21231
c19d1205
ZW
21232/* Add an opcode to this list for this function. Two-byte opcodes should
21233 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
21234 order. */
21235
bfae80f2 21236static void
c19d1205 21237add_unwind_opcode (valueT op, int length)
bfae80f2 21238{
c19d1205
ZW
21239 /* Add any deferred stack adjustment. */
21240 if (unwind.pending_offset)
21241 flush_pending_unwind ();
bfae80f2 21242
c19d1205 21243 unwind.sp_restored = 0;
bfae80f2 21244
c19d1205 21245 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 21246 {
c19d1205
ZW
21247 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
21248 if (unwind.opcodes)
21d799b5 21249 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
477330fc 21250 unwind.opcode_alloc);
c19d1205 21251 else
21d799b5 21252 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 21253 }
c19d1205 21254 while (length > 0)
bfae80f2 21255 {
c19d1205
ZW
21256 length--;
21257 unwind.opcodes[unwind.opcode_count] = op & 0xff;
21258 op >>= 8;
21259 unwind.opcode_count++;
bfae80f2 21260 }
bfae80f2
RE
21261}
21262
c19d1205
ZW
21263/* Add unwind opcodes to adjust the stack pointer. */
21264
bfae80f2 21265static void
c19d1205 21266add_unwind_adjustsp (offsetT offset)
bfae80f2 21267{
c19d1205 21268 valueT op;
bfae80f2 21269
c19d1205 21270 if (offset > 0x200)
bfae80f2 21271 {
c19d1205
ZW
21272 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
21273 char bytes[5];
21274 int n;
21275 valueT o;
bfae80f2 21276
c19d1205
ZW
21277 /* Long form: 0xb2, uleb128. */
21278 /* This might not fit in a word so add the individual bytes,
21279 remembering the list is built in reverse order. */
21280 o = (valueT) ((offset - 0x204) >> 2);
21281 if (o == 0)
21282 add_unwind_opcode (0, 1);
bfae80f2 21283
c19d1205
ZW
21284 /* Calculate the uleb128 encoding of the offset. */
21285 n = 0;
21286 while (o)
21287 {
21288 bytes[n] = o & 0x7f;
21289 o >>= 7;
21290 if (o)
21291 bytes[n] |= 0x80;
21292 n++;
21293 }
21294 /* Add the insn. */
21295 for (; n; n--)
21296 add_unwind_opcode (bytes[n - 1], 1);
21297 add_unwind_opcode (0xb2, 1);
21298 }
21299 else if (offset > 0x100)
bfae80f2 21300 {
c19d1205
ZW
21301 /* Two short opcodes. */
21302 add_unwind_opcode (0x3f, 1);
21303 op = (offset - 0x104) >> 2;
21304 add_unwind_opcode (op, 1);
bfae80f2 21305 }
c19d1205
ZW
21306 else if (offset > 0)
21307 {
21308 /* Short opcode. */
21309 op = (offset - 4) >> 2;
21310 add_unwind_opcode (op, 1);
21311 }
21312 else if (offset < 0)
bfae80f2 21313 {
c19d1205
ZW
21314 offset = -offset;
21315 while (offset > 0x100)
bfae80f2 21316 {
c19d1205
ZW
21317 add_unwind_opcode (0x7f, 1);
21318 offset -= 0x100;
bfae80f2 21319 }
c19d1205
ZW
21320 op = ((offset - 4) >> 2) | 0x40;
21321 add_unwind_opcode (op, 1);
bfae80f2 21322 }
bfae80f2
RE
21323}
21324
c19d1205
ZW
21325/* Finish the list of unwind opcodes for this function. */
21326static void
21327finish_unwind_opcodes (void)
bfae80f2 21328{
c19d1205 21329 valueT op;
bfae80f2 21330
c19d1205 21331 if (unwind.fp_used)
bfae80f2 21332 {
708587a4 21333 /* Adjust sp as necessary. */
c19d1205
ZW
21334 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
21335 flush_pending_unwind ();
bfae80f2 21336
c19d1205
ZW
21337 /* After restoring sp from the frame pointer. */
21338 op = 0x90 | unwind.fp_reg;
21339 add_unwind_opcode (op, 1);
21340 }
21341 else
21342 flush_pending_unwind ();
bfae80f2
RE
21343}
21344
bfae80f2 21345
c19d1205
ZW
21346/* Start an exception table entry. If idx is nonzero this is an index table
21347 entry. */
bfae80f2
RE
21348
21349static void
c19d1205 21350start_unwind_section (const segT text_seg, int idx)
bfae80f2 21351{
c19d1205
ZW
21352 const char * text_name;
21353 const char * prefix;
21354 const char * prefix_once;
21355 const char * group_name;
21356 size_t prefix_len;
21357 size_t text_len;
21358 char * sec_name;
21359 size_t sec_name_len;
21360 int type;
21361 int flags;
21362 int linkonce;
bfae80f2 21363
c19d1205 21364 if (idx)
bfae80f2 21365 {
c19d1205
ZW
21366 prefix = ELF_STRING_ARM_unwind;
21367 prefix_once = ELF_STRING_ARM_unwind_once;
21368 type = SHT_ARM_EXIDX;
bfae80f2 21369 }
c19d1205 21370 else
bfae80f2 21371 {
c19d1205
ZW
21372 prefix = ELF_STRING_ARM_unwind_info;
21373 prefix_once = ELF_STRING_ARM_unwind_info_once;
21374 type = SHT_PROGBITS;
bfae80f2
RE
21375 }
21376
c19d1205
ZW
21377 text_name = segment_name (text_seg);
21378 if (streq (text_name, ".text"))
21379 text_name = "";
21380
21381 if (strncmp (text_name, ".gnu.linkonce.t.",
21382 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 21383 {
c19d1205
ZW
21384 prefix = prefix_once;
21385 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
21386 }
21387
c19d1205
ZW
21388 prefix_len = strlen (prefix);
21389 text_len = strlen (text_name);
21390 sec_name_len = prefix_len + text_len;
21d799b5 21391 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
21392 memcpy (sec_name, prefix, prefix_len);
21393 memcpy (sec_name + prefix_len, text_name, text_len);
21394 sec_name[prefix_len + text_len] = '\0';
bfae80f2 21395
c19d1205
ZW
21396 flags = SHF_ALLOC;
21397 linkonce = 0;
21398 group_name = 0;
bfae80f2 21399
c19d1205
ZW
21400 /* Handle COMDAT group. */
21401 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 21402 {
c19d1205
ZW
21403 group_name = elf_group_name (text_seg);
21404 if (group_name == NULL)
21405 {
bd3ba5d1 21406 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
21407 segment_name (text_seg));
21408 ignore_rest_of_line ();
21409 return;
21410 }
21411 flags |= SHF_GROUP;
21412 linkonce = 1;
bfae80f2
RE
21413 }
21414
c19d1205 21415 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 21416
5f4273c7 21417 /* Set the section link for index tables. */
c19d1205
ZW
21418 if (idx)
21419 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
21420}
21421
bfae80f2 21422
c19d1205
ZW
21423/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
21424 personality routine data. Returns zero, or the index table value for
cad0da33 21425 an inline entry. */
c19d1205
ZW
21426
21427static valueT
21428create_unwind_entry (int have_data)
bfae80f2 21429{
c19d1205
ZW
21430 int size;
21431 addressT where;
21432 char *ptr;
21433 /* The current word of data. */
21434 valueT data;
21435 /* The number of bytes left in this word. */
21436 int n;
bfae80f2 21437
c19d1205 21438 finish_unwind_opcodes ();
bfae80f2 21439
c19d1205
ZW
21440 /* Remember the current text section. */
21441 unwind.saved_seg = now_seg;
21442 unwind.saved_subseg = now_subseg;
bfae80f2 21443
c19d1205 21444 start_unwind_section (now_seg, 0);
bfae80f2 21445
c19d1205 21446 if (unwind.personality_routine == NULL)
bfae80f2 21447 {
c19d1205
ZW
21448 if (unwind.personality_index == -2)
21449 {
21450 if (have_data)
5f4273c7 21451 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
21452 return 1; /* EXIDX_CANTUNWIND. */
21453 }
bfae80f2 21454
c19d1205
ZW
21455 /* Use a default personality routine if none is specified. */
21456 if (unwind.personality_index == -1)
21457 {
21458 if (unwind.opcode_count > 3)
21459 unwind.personality_index = 1;
21460 else
21461 unwind.personality_index = 0;
21462 }
bfae80f2 21463
c19d1205
ZW
21464 /* Space for the personality routine entry. */
21465 if (unwind.personality_index == 0)
21466 {
21467 if (unwind.opcode_count > 3)
21468 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 21469
c19d1205
ZW
21470 if (!have_data)
21471 {
21472 /* All the data is inline in the index table. */
21473 data = 0x80;
21474 n = 3;
21475 while (unwind.opcode_count > 0)
21476 {
21477 unwind.opcode_count--;
21478 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
21479 n--;
21480 }
bfae80f2 21481
c19d1205
ZW
21482 /* Pad with "finish" opcodes. */
21483 while (n--)
21484 data = (data << 8) | 0xb0;
bfae80f2 21485
c19d1205
ZW
21486 return data;
21487 }
21488 size = 0;
21489 }
21490 else
21491 /* We get two opcodes "free" in the first word. */
21492 size = unwind.opcode_count - 2;
21493 }
21494 else
5011093d 21495 {
cad0da33
NC
21496 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
21497 if (unwind.personality_index != -1)
21498 {
21499 as_bad (_("attempt to recreate an unwind entry"));
21500 return 1;
21501 }
5011093d
NC
21502
21503 /* An extra byte is required for the opcode count. */
21504 size = unwind.opcode_count + 1;
21505 }
bfae80f2 21506
c19d1205
ZW
21507 size = (size + 3) >> 2;
21508 if (size > 0xff)
21509 as_bad (_("too many unwind opcodes"));
bfae80f2 21510
c19d1205
ZW
21511 frag_align (2, 0, 0);
21512 record_alignment (now_seg, 2);
21513 unwind.table_entry = expr_build_dot ();
21514
21515 /* Allocate the table entry. */
21516 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
21517 /* PR 13449: Zero the table entries in case some of them are not used. */
21518 memset (ptr, 0, (size << 2) + 4);
c19d1205 21519 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 21520
c19d1205 21521 switch (unwind.personality_index)
bfae80f2 21522 {
c19d1205
ZW
21523 case -1:
21524 /* ??? Should this be a PLT generating relocation? */
21525 /* Custom personality routine. */
21526 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
21527 BFD_RELOC_ARM_PREL31);
bfae80f2 21528
c19d1205
ZW
21529 where += 4;
21530 ptr += 4;
bfae80f2 21531
c19d1205 21532 /* Set the first byte to the number of additional words. */
5011093d 21533 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
21534 n = 3;
21535 break;
bfae80f2 21536
c19d1205
ZW
21537 /* ABI defined personality routines. */
21538 case 0:
21539 /* Three opcodes bytes are packed into the first word. */
21540 data = 0x80;
21541 n = 3;
21542 break;
bfae80f2 21543
c19d1205
ZW
21544 case 1:
21545 case 2:
21546 /* The size and first two opcode bytes go in the first word. */
21547 data = ((0x80 + unwind.personality_index) << 8) | size;
21548 n = 2;
21549 break;
bfae80f2 21550
c19d1205
ZW
21551 default:
21552 /* Should never happen. */
21553 abort ();
21554 }
bfae80f2 21555
c19d1205
ZW
21556 /* Pack the opcodes into words (MSB first), reversing the list at the same
21557 time. */
21558 while (unwind.opcode_count > 0)
21559 {
21560 if (n == 0)
21561 {
21562 md_number_to_chars (ptr, data, 4);
21563 ptr += 4;
21564 n = 4;
21565 data = 0;
21566 }
21567 unwind.opcode_count--;
21568 n--;
21569 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
21570 }
21571
21572 /* Finish off the last word. */
21573 if (n < 4)
21574 {
21575 /* Pad with "finish" opcodes. */
21576 while (n--)
21577 data = (data << 8) | 0xb0;
21578
21579 md_number_to_chars (ptr, data, 4);
21580 }
21581
21582 if (!have_data)
21583 {
21584 /* Add an empty descriptor if there is no user-specified data. */
21585 ptr = frag_more (4);
21586 md_number_to_chars (ptr, 0, 4);
21587 }
21588
21589 return 0;
bfae80f2
RE
21590}
21591
f0927246
NC
21592
21593/* Initialize the DWARF-2 unwind information for this procedure. */
21594
21595void
21596tc_arm_frame_initial_instructions (void)
21597{
21598 cfi_add_CFA_def_cfa (REG_SP, 0);
21599}
21600#endif /* OBJ_ELF */
21601
c19d1205
ZW
21602/* Convert REGNAME to a DWARF-2 register number. */
21603
21604int
1df69f4f 21605tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 21606{
1df69f4f 21607 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
21608 if (reg != FAIL)
21609 return reg;
c19d1205 21610
1f5afe1c
NC
21611 /* PR 16694: Allow VFP registers as well. */
21612 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
21613 if (reg != FAIL)
21614 return 64 + reg;
c19d1205 21615
1f5afe1c
NC
21616 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
21617 if (reg != FAIL)
21618 return reg + 256;
21619
21620 return -1;
bfae80f2
RE
21621}
21622
f0927246 21623#ifdef TE_PE
c19d1205 21624void
f0927246 21625tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 21626{
91d6fa6a 21627 expressionS exp;
bfae80f2 21628
91d6fa6a
NC
21629 exp.X_op = O_secrel;
21630 exp.X_add_symbol = symbol;
21631 exp.X_add_number = 0;
21632 emit_expr (&exp, size);
f0927246
NC
21633}
21634#endif
bfae80f2 21635
c19d1205 21636/* MD interface: Symbol and relocation handling. */
bfae80f2 21637
2fc8bdac
ZW
21638/* Return the address within the segment that a PC-relative fixup is
21639 relative to. For ARM, PC-relative fixups applied to instructions
21640 are generally relative to the location of the fixup plus 8 bytes.
21641 Thumb branches are offset by 4, and Thumb loads relative to PC
21642 require special handling. */
bfae80f2 21643
c19d1205 21644long
2fc8bdac 21645md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 21646{
2fc8bdac
ZW
21647 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
21648
21649 /* If this is pc-relative and we are going to emit a relocation
21650 then we just want to put out any pipeline compensation that the linker
53baae48
NC
21651 will need. Otherwise we want to use the calculated base.
21652 For WinCE we skip the bias for externals as well, since this
21653 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 21654 if (fixP->fx_pcrel
2fc8bdac 21655 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
21656 || (arm_force_relocation (fixP)
21657#ifdef TE_WINCE
21658 && !S_IS_EXTERNAL (fixP->fx_addsy)
21659#endif
21660 )))
2fc8bdac 21661 base = 0;
bfae80f2 21662
267bf995 21663
c19d1205 21664 switch (fixP->fx_r_type)
bfae80f2 21665 {
2fc8bdac
ZW
21666 /* PC relative addressing on the Thumb is slightly odd as the
21667 bottom two bits of the PC are forced to zero for the
21668 calculation. This happens *after* application of the
21669 pipeline offset. However, Thumb adrl already adjusts for
21670 this, so we need not do it again. */
c19d1205 21671 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 21672 return base & ~3;
c19d1205
ZW
21673
21674 case BFD_RELOC_ARM_THUMB_OFFSET:
21675 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 21676 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 21677 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 21678 return (base + 4) & ~3;
c19d1205 21679
2fc8bdac
ZW
21680 /* Thumb branches are simply offset by +4. */
21681 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21682 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21683 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21684 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 21685 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 21686 return base + 4;
bfae80f2 21687
267bf995 21688 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
21689 if (fixP->fx_addsy
21690 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21691 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 21692 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
21693 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21694 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
21695 return base + 4;
21696
00adf2d4
JB
21697 /* BLX is like branches above, but forces the low two bits of PC to
21698 zero. */
486499d0
CL
21699 case BFD_RELOC_THUMB_PCREL_BLX:
21700 if (fixP->fx_addsy
21701 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21702 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
21703 && THUMB_IS_FUNC (fixP->fx_addsy)
21704 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21705 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
21706 return (base + 4) & ~3;
21707
2fc8bdac
ZW
21708 /* ARM mode branches are offset by +8. However, the Windows CE
21709 loader expects the relocation not to take this into account. */
267bf995 21710 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
21711 if (fixP->fx_addsy
21712 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21713 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
21714 && ARM_IS_FUNC (fixP->fx_addsy)
21715 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21716 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 21717 return base + 8;
267bf995 21718
486499d0
CL
21719 case BFD_RELOC_ARM_PCREL_CALL:
21720 if (fixP->fx_addsy
21721 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 21722 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
21723 && THUMB_IS_FUNC (fixP->fx_addsy)
21724 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21725 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 21726 return base + 8;
267bf995 21727
2fc8bdac 21728 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 21729 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 21730 case BFD_RELOC_ARM_PLT32:
c19d1205 21731#ifdef TE_WINCE
5f4273c7 21732 /* When handling fixups immediately, because we have already
477330fc 21733 discovered the value of a symbol, or the address of the frag involved
53baae48 21734 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
21735 see fixup_segment() in write.c
21736 The S_IS_EXTERNAL test handles the case of global symbols.
21737 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
21738 if (fixP->fx_pcrel
21739 && fixP->fx_addsy != NULL
21740 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21741 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
21742 return base + 8;
2fc8bdac 21743 return base;
c19d1205 21744#else
2fc8bdac 21745 return base + 8;
c19d1205 21746#endif
2fc8bdac 21747
267bf995 21748
2fc8bdac
ZW
21749 /* ARM mode loads relative to PC are also offset by +8. Unlike
21750 branches, the Windows CE loader *does* expect the relocation
21751 to take this into account. */
21752 case BFD_RELOC_ARM_OFFSET_IMM:
21753 case BFD_RELOC_ARM_OFFSET_IMM8:
21754 case BFD_RELOC_ARM_HWLITERAL:
21755 case BFD_RELOC_ARM_LITERAL:
21756 case BFD_RELOC_ARM_CP_OFF_IMM:
21757 return base + 8;
21758
21759
21760 /* Other PC-relative relocations are un-offset. */
21761 default:
21762 return base;
21763 }
bfae80f2
RE
21764}
21765
8b2d793c
NC
21766static bfd_boolean flag_warn_syms = TRUE;
21767
ae8714c2
NC
21768bfd_boolean
21769arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 21770{
8b2d793c
NC
21771 /* PR 18347 - Warn if the user attempts to create a symbol with the same
21772 name as an ARM instruction. Whilst strictly speaking it is allowed, it
21773 does mean that the resulting code might be very confusing to the reader.
21774 Also this warning can be triggered if the user omits an operand before
21775 an immediate address, eg:
21776
21777 LDR =foo
21778
21779 GAS treats this as an assignment of the value of the symbol foo to a
21780 symbol LDR, and so (without this code) it will not issue any kind of
21781 warning or error message.
21782
21783 Note - ARM instructions are case-insensitive but the strings in the hash
21784 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
21785 lower case too. */
21786 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
21787 {
21788 char * nbuf = strdup (name);
21789 char * p;
21790
21791 for (p = nbuf; *p; p++)
21792 *p = TOLOWER (*p);
21793 if (hash_find (arm_ops_hsh, nbuf) != NULL)
21794 {
21795 static struct hash_control * already_warned = NULL;
21796
21797 if (already_warned == NULL)
21798 already_warned = hash_new ();
21799 /* Only warn about the symbol once. To keep the code
21800 simple we let hash_insert do the lookup for us. */
21801 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 21802 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
21803 }
21804 else
21805 free (nbuf);
21806 }
21807
ae8714c2
NC
21808 return FALSE;
21809}
21810
21811/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
21812 Otherwise we have no need to default values of symbols. */
21813
21814symbolS *
21815md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
21816{
21817#ifdef OBJ_ELF
21818 if (name[0] == '_' && name[1] == 'G'
21819 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
21820 {
21821 if (!GOT_symbol)
21822 {
21823 if (symbol_find (name))
21824 as_bad (_("GOT already in the symbol table"));
21825
21826 GOT_symbol = symbol_new (name, undefined_section,
21827 (valueT) 0, & zero_address_frag);
21828 }
21829
21830 return GOT_symbol;
21831 }
21832#endif
21833
c921be7d 21834 return NULL;
bfae80f2
RE
21835}
21836
55cf6793 21837/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
21838 computed as two separate immediate values, added together. We
21839 already know that this value cannot be computed by just one ARM
21840 instruction. */
21841
21842static unsigned int
21843validate_immediate_twopart (unsigned int val,
21844 unsigned int * highpart)
bfae80f2 21845{
c19d1205
ZW
21846 unsigned int a;
21847 unsigned int i;
bfae80f2 21848
c19d1205
ZW
21849 for (i = 0; i < 32; i += 2)
21850 if (((a = rotate_left (val, i)) & 0xff) != 0)
21851 {
21852 if (a & 0xff00)
21853 {
21854 if (a & ~ 0xffff)
21855 continue;
21856 * highpart = (a >> 8) | ((i + 24) << 7);
21857 }
21858 else if (a & 0xff0000)
21859 {
21860 if (a & 0xff000000)
21861 continue;
21862 * highpart = (a >> 16) | ((i + 16) << 7);
21863 }
21864 else
21865 {
9c2799c2 21866 gas_assert (a & 0xff000000);
c19d1205
ZW
21867 * highpart = (a >> 24) | ((i + 8) << 7);
21868 }
bfae80f2 21869
c19d1205
ZW
21870 return (a & 0xff) | (i << 7);
21871 }
bfae80f2 21872
c19d1205 21873 return FAIL;
bfae80f2
RE
21874}
21875
c19d1205
ZW
21876static int
21877validate_offset_imm (unsigned int val, int hwse)
21878{
21879 if ((hwse && val > 255) || val > 4095)
21880 return FAIL;
21881 return val;
21882}
bfae80f2 21883
55cf6793 21884/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
21885 negative immediate constant by altering the instruction. A bit of
21886 a hack really.
21887 MOV <-> MVN
21888 AND <-> BIC
21889 ADC <-> SBC
21890 by inverting the second operand, and
21891 ADD <-> SUB
21892 CMP <-> CMN
21893 by negating the second operand. */
bfae80f2 21894
c19d1205
ZW
21895static int
21896negate_data_op (unsigned long * instruction,
21897 unsigned long value)
bfae80f2 21898{
c19d1205
ZW
21899 int op, new_inst;
21900 unsigned long negated, inverted;
bfae80f2 21901
c19d1205
ZW
21902 negated = encode_arm_immediate (-value);
21903 inverted = encode_arm_immediate (~value);
bfae80f2 21904
c19d1205
ZW
21905 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
21906 switch (op)
bfae80f2 21907 {
c19d1205
ZW
21908 /* First negates. */
21909 case OPCODE_SUB: /* ADD <-> SUB */
21910 new_inst = OPCODE_ADD;
21911 value = negated;
21912 break;
bfae80f2 21913
c19d1205
ZW
21914 case OPCODE_ADD:
21915 new_inst = OPCODE_SUB;
21916 value = negated;
21917 break;
bfae80f2 21918
c19d1205
ZW
21919 case OPCODE_CMP: /* CMP <-> CMN */
21920 new_inst = OPCODE_CMN;
21921 value = negated;
21922 break;
bfae80f2 21923
c19d1205
ZW
21924 case OPCODE_CMN:
21925 new_inst = OPCODE_CMP;
21926 value = negated;
21927 break;
bfae80f2 21928
c19d1205
ZW
21929 /* Now Inverted ops. */
21930 case OPCODE_MOV: /* MOV <-> MVN */
21931 new_inst = OPCODE_MVN;
21932 value = inverted;
21933 break;
bfae80f2 21934
c19d1205
ZW
21935 case OPCODE_MVN:
21936 new_inst = OPCODE_MOV;
21937 value = inverted;
21938 break;
bfae80f2 21939
c19d1205
ZW
21940 case OPCODE_AND: /* AND <-> BIC */
21941 new_inst = OPCODE_BIC;
21942 value = inverted;
21943 break;
bfae80f2 21944
c19d1205
ZW
21945 case OPCODE_BIC:
21946 new_inst = OPCODE_AND;
21947 value = inverted;
21948 break;
bfae80f2 21949
c19d1205
ZW
21950 case OPCODE_ADC: /* ADC <-> SBC */
21951 new_inst = OPCODE_SBC;
21952 value = inverted;
21953 break;
bfae80f2 21954
c19d1205
ZW
21955 case OPCODE_SBC:
21956 new_inst = OPCODE_ADC;
21957 value = inverted;
21958 break;
bfae80f2 21959
c19d1205
ZW
21960 /* We cannot do anything. */
21961 default:
21962 return FAIL;
b99bd4ef
NC
21963 }
21964
c19d1205
ZW
21965 if (value == (unsigned) FAIL)
21966 return FAIL;
21967
21968 *instruction &= OPCODE_MASK;
21969 *instruction |= new_inst << DATA_OP_SHIFT;
21970 return value;
b99bd4ef
NC
21971}
21972
ef8d22e6
PB
21973/* Like negate_data_op, but for Thumb-2. */
21974
21975static unsigned int
16dd5e42 21976thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
21977{
21978 int op, new_inst;
21979 int rd;
16dd5e42 21980 unsigned int negated, inverted;
ef8d22e6
PB
21981
21982 negated = encode_thumb32_immediate (-value);
21983 inverted = encode_thumb32_immediate (~value);
21984
21985 rd = (*instruction >> 8) & 0xf;
21986 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
21987 switch (op)
21988 {
21989 /* ADD <-> SUB. Includes CMP <-> CMN. */
21990 case T2_OPCODE_SUB:
21991 new_inst = T2_OPCODE_ADD;
21992 value = negated;
21993 break;
21994
21995 case T2_OPCODE_ADD:
21996 new_inst = T2_OPCODE_SUB;
21997 value = negated;
21998 break;
21999
22000 /* ORR <-> ORN. Includes MOV <-> MVN. */
22001 case T2_OPCODE_ORR:
22002 new_inst = T2_OPCODE_ORN;
22003 value = inverted;
22004 break;
22005
22006 case T2_OPCODE_ORN:
22007 new_inst = T2_OPCODE_ORR;
22008 value = inverted;
22009 break;
22010
22011 /* AND <-> BIC. TST has no inverted equivalent. */
22012 case T2_OPCODE_AND:
22013 new_inst = T2_OPCODE_BIC;
22014 if (rd == 15)
22015 value = FAIL;
22016 else
22017 value = inverted;
22018 break;
22019
22020 case T2_OPCODE_BIC:
22021 new_inst = T2_OPCODE_AND;
22022 value = inverted;
22023 break;
22024
22025 /* ADC <-> SBC */
22026 case T2_OPCODE_ADC:
22027 new_inst = T2_OPCODE_SBC;
22028 value = inverted;
22029 break;
22030
22031 case T2_OPCODE_SBC:
22032 new_inst = T2_OPCODE_ADC;
22033 value = inverted;
22034 break;
22035
22036 /* We cannot do anything. */
22037 default:
22038 return FAIL;
22039 }
22040
16dd5e42 22041 if (value == (unsigned int)FAIL)
ef8d22e6
PB
22042 return FAIL;
22043
22044 *instruction &= T2_OPCODE_MASK;
22045 *instruction |= new_inst << T2_DATA_OP_SHIFT;
22046 return value;
22047}
22048
8f06b2d8
PB
22049/* Read a 32-bit thumb instruction from buf. */
22050static unsigned long
22051get_thumb32_insn (char * buf)
22052{
22053 unsigned long insn;
22054 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
22055 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22056
22057 return insn;
22058}
22059
a8bc6c78
PB
22060
22061/* We usually want to set the low bit on the address of thumb function
22062 symbols. In particular .word foo - . should have the low bit set.
22063 Generic code tries to fold the difference of two symbols to
22064 a constant. Prevent this and force a relocation when the first symbols
22065 is a thumb function. */
c921be7d
NC
22066
22067bfd_boolean
a8bc6c78
PB
22068arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
22069{
22070 if (op == O_subtract
22071 && l->X_op == O_symbol
22072 && r->X_op == O_symbol
22073 && THUMB_IS_FUNC (l->X_add_symbol))
22074 {
22075 l->X_op = O_subtract;
22076 l->X_op_symbol = r->X_add_symbol;
22077 l->X_add_number -= r->X_add_number;
c921be7d 22078 return TRUE;
a8bc6c78 22079 }
c921be7d 22080
a8bc6c78 22081 /* Process as normal. */
c921be7d 22082 return FALSE;
a8bc6c78
PB
22083}
22084
4a42ebbc
RR
22085/* Encode Thumb2 unconditional branches and calls. The encoding
22086 for the 2 are identical for the immediate values. */
22087
22088static void
22089encode_thumb2_b_bl_offset (char * buf, offsetT value)
22090{
22091#define T2I1I2MASK ((1 << 13) | (1 << 11))
22092 offsetT newval;
22093 offsetT newval2;
22094 addressT S, I1, I2, lo, hi;
22095
22096 S = (value >> 24) & 0x01;
22097 I1 = (value >> 23) & 0x01;
22098 I2 = (value >> 22) & 0x01;
22099 hi = (value >> 12) & 0x3ff;
fa94de6b 22100 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
22101 newval = md_chars_to_number (buf, THUMB_SIZE);
22102 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22103 newval |= (S << 10) | hi;
22104 newval2 &= ~T2I1I2MASK;
22105 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
22106 md_number_to_chars (buf, newval, THUMB_SIZE);
22107 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22108}
22109
c19d1205 22110void
55cf6793 22111md_apply_fix (fixS * fixP,
c19d1205
ZW
22112 valueT * valP,
22113 segT seg)
22114{
22115 offsetT value = * valP;
22116 offsetT newval;
22117 unsigned int newimm;
22118 unsigned long temp;
22119 int sign;
22120 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 22121
9c2799c2 22122 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 22123
c19d1205 22124 /* Note whether this will delete the relocation. */
4962c51a 22125
c19d1205
ZW
22126 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
22127 fixP->fx_done = 1;
b99bd4ef 22128
adbaf948 22129 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 22130 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
22131 for emit_reloc. */
22132 value &= 0xffffffff;
22133 value ^= 0x80000000;
5f4273c7 22134 value -= 0x80000000;
adbaf948
ZW
22135
22136 *valP = value;
c19d1205 22137 fixP->fx_addnumber = value;
b99bd4ef 22138
adbaf948
ZW
22139 /* Same treatment for fixP->fx_offset. */
22140 fixP->fx_offset &= 0xffffffff;
22141 fixP->fx_offset ^= 0x80000000;
22142 fixP->fx_offset -= 0x80000000;
22143
c19d1205 22144 switch (fixP->fx_r_type)
b99bd4ef 22145 {
c19d1205
ZW
22146 case BFD_RELOC_NONE:
22147 /* This will need to go in the object file. */
22148 fixP->fx_done = 0;
22149 break;
b99bd4ef 22150
c19d1205
ZW
22151 case BFD_RELOC_ARM_IMMEDIATE:
22152 /* We claim that this fixup has been processed here,
22153 even if in fact we generate an error because we do
22154 not have a reloc for it, so tc_gen_reloc will reject it. */
22155 fixP->fx_done = 1;
b99bd4ef 22156
77db8e2e 22157 if (fixP->fx_addsy)
b99bd4ef 22158 {
77db8e2e 22159 const char *msg = 0;
b99bd4ef 22160
77db8e2e
NC
22161 if (! S_IS_DEFINED (fixP->fx_addsy))
22162 msg = _("undefined symbol %s used as an immediate value");
22163 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22164 msg = _("symbol %s is in a different section");
22165 else if (S_IS_WEAK (fixP->fx_addsy))
22166 msg = _("symbol %s is weak and may be overridden later");
22167
22168 if (msg)
22169 {
22170 as_bad_where (fixP->fx_file, fixP->fx_line,
22171 msg, S_GET_NAME (fixP->fx_addsy));
22172 break;
22173 }
42e5fcbf
AS
22174 }
22175
c19d1205
ZW
22176 temp = md_chars_to_number (buf, INSN_SIZE);
22177
5e73442d
SL
22178 /* If the offset is negative, we should use encoding A2 for ADR. */
22179 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
22180 newimm = negate_data_op (&temp, value);
22181 else
22182 {
22183 newimm = encode_arm_immediate (value);
22184
22185 /* If the instruction will fail, see if we can fix things up by
22186 changing the opcode. */
22187 if (newimm == (unsigned int) FAIL)
22188 newimm = negate_data_op (&temp, value);
22189 }
22190
22191 if (newimm == (unsigned int) FAIL)
b99bd4ef 22192 {
c19d1205
ZW
22193 as_bad_where (fixP->fx_file, fixP->fx_line,
22194 _("invalid constant (%lx) after fixup"),
22195 (unsigned long) value);
22196 break;
b99bd4ef 22197 }
b99bd4ef 22198
c19d1205
ZW
22199 newimm |= (temp & 0xfffff000);
22200 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
22201 break;
b99bd4ef 22202
c19d1205
ZW
22203 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22204 {
22205 unsigned int highpart = 0;
22206 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 22207
77db8e2e 22208 if (fixP->fx_addsy)
42e5fcbf 22209 {
77db8e2e 22210 const char *msg = 0;
42e5fcbf 22211
77db8e2e
NC
22212 if (! S_IS_DEFINED (fixP->fx_addsy))
22213 msg = _("undefined symbol %s used as an immediate value");
22214 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22215 msg = _("symbol %s is in a different section");
22216 else if (S_IS_WEAK (fixP->fx_addsy))
22217 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 22218
77db8e2e
NC
22219 if (msg)
22220 {
22221 as_bad_where (fixP->fx_file, fixP->fx_line,
22222 msg, S_GET_NAME (fixP->fx_addsy));
22223 break;
22224 }
22225 }
fa94de6b 22226
c19d1205
ZW
22227 newimm = encode_arm_immediate (value);
22228 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 22229
c19d1205
ZW
22230 /* If the instruction will fail, see if we can fix things up by
22231 changing the opcode. */
22232 if (newimm == (unsigned int) FAIL
22233 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
22234 {
22235 /* No ? OK - try using two ADD instructions to generate
22236 the value. */
22237 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 22238
c19d1205
ZW
22239 /* Yes - then make sure that the second instruction is
22240 also an add. */
22241 if (newimm != (unsigned int) FAIL)
22242 newinsn = temp;
22243 /* Still No ? Try using a negated value. */
22244 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
22245 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
22246 /* Otherwise - give up. */
22247 else
22248 {
22249 as_bad_where (fixP->fx_file, fixP->fx_line,
22250 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
22251 (long) value);
22252 break;
22253 }
b99bd4ef 22254
c19d1205
ZW
22255 /* Replace the first operand in the 2nd instruction (which
22256 is the PC) with the destination register. We have
22257 already added in the PC in the first instruction and we
22258 do not want to do it again. */
22259 newinsn &= ~ 0xf0000;
22260 newinsn |= ((newinsn & 0x0f000) << 4);
22261 }
b99bd4ef 22262
c19d1205
ZW
22263 newimm |= (temp & 0xfffff000);
22264 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 22265
c19d1205
ZW
22266 highpart |= (newinsn & 0xfffff000);
22267 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
22268 }
22269 break;
b99bd4ef 22270
c19d1205 22271 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
22272 if (!fixP->fx_done && seg->use_rela_p)
22273 value = 0;
22274
c19d1205 22275 case BFD_RELOC_ARM_LITERAL:
26d97720 22276 sign = value > 0;
b99bd4ef 22277
c19d1205
ZW
22278 if (value < 0)
22279 value = - value;
b99bd4ef 22280
c19d1205 22281 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 22282 {
c19d1205
ZW
22283 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
22284 as_bad_where (fixP->fx_file, fixP->fx_line,
22285 _("invalid literal constant: pool needs to be closer"));
22286 else
22287 as_bad_where (fixP->fx_file, fixP->fx_line,
22288 _("bad immediate value for offset (%ld)"),
22289 (long) value);
22290 break;
f03698e6
RE
22291 }
22292
c19d1205 22293 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
22294 if (value == 0)
22295 newval &= 0xfffff000;
22296 else
22297 {
22298 newval &= 0xff7ff000;
22299 newval |= value | (sign ? INDEX_UP : 0);
22300 }
c19d1205
ZW
22301 md_number_to_chars (buf, newval, INSN_SIZE);
22302 break;
b99bd4ef 22303
c19d1205
ZW
22304 case BFD_RELOC_ARM_OFFSET_IMM8:
22305 case BFD_RELOC_ARM_HWLITERAL:
26d97720 22306 sign = value > 0;
b99bd4ef 22307
c19d1205
ZW
22308 if (value < 0)
22309 value = - value;
b99bd4ef 22310
c19d1205 22311 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 22312 {
c19d1205
ZW
22313 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
22314 as_bad_where (fixP->fx_file, fixP->fx_line,
22315 _("invalid literal constant: pool needs to be closer"));
22316 else
427d0db6
RM
22317 as_bad_where (fixP->fx_file, fixP->fx_line,
22318 _("bad immediate value for 8-bit offset (%ld)"),
22319 (long) value);
c19d1205 22320 break;
b99bd4ef
NC
22321 }
22322
c19d1205 22323 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
22324 if (value == 0)
22325 newval &= 0xfffff0f0;
22326 else
22327 {
22328 newval &= 0xff7ff0f0;
22329 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
22330 }
c19d1205
ZW
22331 md_number_to_chars (buf, newval, INSN_SIZE);
22332 break;
b99bd4ef 22333
c19d1205
ZW
22334 case BFD_RELOC_ARM_T32_OFFSET_U8:
22335 if (value < 0 || value > 1020 || value % 4 != 0)
22336 as_bad_where (fixP->fx_file, fixP->fx_line,
22337 _("bad immediate value for offset (%ld)"), (long) value);
22338 value /= 4;
b99bd4ef 22339
c19d1205 22340 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
22341 newval |= value;
22342 md_number_to_chars (buf+2, newval, THUMB_SIZE);
22343 break;
b99bd4ef 22344
c19d1205
ZW
22345 case BFD_RELOC_ARM_T32_OFFSET_IMM:
22346 /* This is a complicated relocation used for all varieties of Thumb32
22347 load/store instruction with immediate offset:
22348
22349 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 22350 *4, optional writeback(W)
c19d1205
ZW
22351 (doubleword load/store)
22352
22353 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
22354 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
22355 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
22356 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
22357 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
22358
22359 Uppercase letters indicate bits that are already encoded at
22360 this point. Lowercase letters are our problem. For the
22361 second block of instructions, the secondary opcode nybble
22362 (bits 8..11) is present, and bit 23 is zero, even if this is
22363 a PC-relative operation. */
22364 newval = md_chars_to_number (buf, THUMB_SIZE);
22365 newval <<= 16;
22366 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 22367
c19d1205 22368 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 22369 {
c19d1205
ZW
22370 /* Doubleword load/store: 8-bit offset, scaled by 4. */
22371 if (value >= 0)
22372 newval |= (1 << 23);
22373 else
22374 value = -value;
22375 if (value % 4 != 0)
22376 {
22377 as_bad_where (fixP->fx_file, fixP->fx_line,
22378 _("offset not a multiple of 4"));
22379 break;
22380 }
22381 value /= 4;
216d22bc 22382 if (value > 0xff)
c19d1205
ZW
22383 {
22384 as_bad_where (fixP->fx_file, fixP->fx_line,
22385 _("offset out of range"));
22386 break;
22387 }
22388 newval &= ~0xff;
b99bd4ef 22389 }
c19d1205 22390 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 22391 {
c19d1205
ZW
22392 /* PC-relative, 12-bit offset. */
22393 if (value >= 0)
22394 newval |= (1 << 23);
22395 else
22396 value = -value;
216d22bc 22397 if (value > 0xfff)
c19d1205
ZW
22398 {
22399 as_bad_where (fixP->fx_file, fixP->fx_line,
22400 _("offset out of range"));
22401 break;
22402 }
22403 newval &= ~0xfff;
b99bd4ef 22404 }
c19d1205 22405 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 22406 {
c19d1205
ZW
22407 /* Writeback: 8-bit, +/- offset. */
22408 if (value >= 0)
22409 newval |= (1 << 9);
22410 else
22411 value = -value;
216d22bc 22412 if (value > 0xff)
c19d1205
ZW
22413 {
22414 as_bad_where (fixP->fx_file, fixP->fx_line,
22415 _("offset out of range"));
22416 break;
22417 }
22418 newval &= ~0xff;
b99bd4ef 22419 }
c19d1205 22420 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 22421 {
c19d1205 22422 /* T-instruction: positive 8-bit offset. */
216d22bc 22423 if (value < 0 || value > 0xff)
b99bd4ef 22424 {
c19d1205
ZW
22425 as_bad_where (fixP->fx_file, fixP->fx_line,
22426 _("offset out of range"));
22427 break;
b99bd4ef 22428 }
c19d1205
ZW
22429 newval &= ~0xff;
22430 newval |= value;
b99bd4ef
NC
22431 }
22432 else
b99bd4ef 22433 {
c19d1205
ZW
22434 /* Positive 12-bit or negative 8-bit offset. */
22435 int limit;
22436 if (value >= 0)
b99bd4ef 22437 {
c19d1205
ZW
22438 newval |= (1 << 23);
22439 limit = 0xfff;
22440 }
22441 else
22442 {
22443 value = -value;
22444 limit = 0xff;
22445 }
22446 if (value > limit)
22447 {
22448 as_bad_where (fixP->fx_file, fixP->fx_line,
22449 _("offset out of range"));
22450 break;
b99bd4ef 22451 }
c19d1205 22452 newval &= ~limit;
b99bd4ef 22453 }
b99bd4ef 22454
c19d1205
ZW
22455 newval |= value;
22456 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
22457 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
22458 break;
404ff6b5 22459
c19d1205
ZW
22460 case BFD_RELOC_ARM_SHIFT_IMM:
22461 newval = md_chars_to_number (buf, INSN_SIZE);
22462 if (((unsigned long) value) > 32
22463 || (value == 32
22464 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
22465 {
22466 as_bad_where (fixP->fx_file, fixP->fx_line,
22467 _("shift expression is too large"));
22468 break;
22469 }
404ff6b5 22470
c19d1205
ZW
22471 if (value == 0)
22472 /* Shifts of zero must be done as lsl. */
22473 newval &= ~0x60;
22474 else if (value == 32)
22475 value = 0;
22476 newval &= 0xfffff07f;
22477 newval |= (value & 0x1f) << 7;
22478 md_number_to_chars (buf, newval, INSN_SIZE);
22479 break;
404ff6b5 22480
c19d1205 22481 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 22482 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 22483 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 22484 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
22485 /* We claim that this fixup has been processed here,
22486 even if in fact we generate an error because we do
22487 not have a reloc for it, so tc_gen_reloc will reject it. */
22488 fixP->fx_done = 1;
404ff6b5 22489
c19d1205
ZW
22490 if (fixP->fx_addsy
22491 && ! S_IS_DEFINED (fixP->fx_addsy))
22492 {
22493 as_bad_where (fixP->fx_file, fixP->fx_line,
22494 _("undefined symbol %s used as an immediate value"),
22495 S_GET_NAME (fixP->fx_addsy));
22496 break;
22497 }
404ff6b5 22498
c19d1205
ZW
22499 newval = md_chars_to_number (buf, THUMB_SIZE);
22500 newval <<= 16;
22501 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 22502
16805f35
PB
22503 newimm = FAIL;
22504 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
22505 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
22506 {
22507 newimm = encode_thumb32_immediate (value);
22508 if (newimm == (unsigned int) FAIL)
22509 newimm = thumb32_negate_data_op (&newval, value);
22510 }
16805f35
PB
22511 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
22512 && newimm == (unsigned int) FAIL)
92e90b6e 22513 {
16805f35
PB
22514 /* Turn add/sum into addw/subw. */
22515 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
22516 newval = (newval & 0xfeffffff) | 0x02000000;
40f246e3
NC
22517 /* No flat 12-bit imm encoding for addsw/subsw. */
22518 if ((newval & 0x00100000) == 0)
e9f89963 22519 {
40f246e3
NC
22520 /* 12 bit immediate for addw/subw. */
22521 if (value < 0)
22522 {
22523 value = -value;
22524 newval ^= 0x00a00000;
22525 }
22526 if (value > 0xfff)
22527 newimm = (unsigned int) FAIL;
22528 else
22529 newimm = value;
e9f89963 22530 }
92e90b6e 22531 }
cc8a6dd0 22532
c19d1205 22533 if (newimm == (unsigned int)FAIL)
3631a3c8 22534 {
c19d1205
ZW
22535 as_bad_where (fixP->fx_file, fixP->fx_line,
22536 _("invalid constant (%lx) after fixup"),
22537 (unsigned long) value);
22538 break;
3631a3c8
NC
22539 }
22540
c19d1205
ZW
22541 newval |= (newimm & 0x800) << 15;
22542 newval |= (newimm & 0x700) << 4;
22543 newval |= (newimm & 0x0ff);
cc8a6dd0 22544
c19d1205
ZW
22545 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
22546 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
22547 break;
a737bd4d 22548
3eb17e6b 22549 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
22550 if (((unsigned long) value) > 0xffff)
22551 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 22552 _("invalid smc expression"));
2fc8bdac 22553 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
22554 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
22555 md_number_to_chars (buf, newval, INSN_SIZE);
22556 break;
a737bd4d 22557
90ec0d68
MGD
22558 case BFD_RELOC_ARM_HVC:
22559 if (((unsigned long) value) > 0xffff)
22560 as_bad_where (fixP->fx_file, fixP->fx_line,
22561 _("invalid hvc expression"));
22562 newval = md_chars_to_number (buf, INSN_SIZE);
22563 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
22564 md_number_to_chars (buf, newval, INSN_SIZE);
22565 break;
22566
c19d1205 22567 case BFD_RELOC_ARM_SWI:
adbaf948 22568 if (fixP->tc_fix_data != 0)
c19d1205
ZW
22569 {
22570 if (((unsigned long) value) > 0xff)
22571 as_bad_where (fixP->fx_file, fixP->fx_line,
22572 _("invalid swi expression"));
2fc8bdac 22573 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
22574 newval |= value;
22575 md_number_to_chars (buf, newval, THUMB_SIZE);
22576 }
22577 else
22578 {
22579 if (((unsigned long) value) > 0x00ffffff)
22580 as_bad_where (fixP->fx_file, fixP->fx_line,
22581 _("invalid swi expression"));
2fc8bdac 22582 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
22583 newval |= value;
22584 md_number_to_chars (buf, newval, INSN_SIZE);
22585 }
22586 break;
a737bd4d 22587
c19d1205
ZW
22588 case BFD_RELOC_ARM_MULTI:
22589 if (((unsigned long) value) > 0xffff)
22590 as_bad_where (fixP->fx_file, fixP->fx_line,
22591 _("invalid expression in load/store multiple"));
22592 newval = value | md_chars_to_number (buf, INSN_SIZE);
22593 md_number_to_chars (buf, newval, INSN_SIZE);
22594 break;
a737bd4d 22595
c19d1205 22596#ifdef OBJ_ELF
39b41c9c 22597 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
22598
22599 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22600 && fixP->fx_addsy
34e77a92 22601 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22602 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22603 && THUMB_IS_FUNC (fixP->fx_addsy))
22604 /* Flip the bl to blx. This is a simple flip
22605 bit here because we generate PCREL_CALL for
22606 unconditional bls. */
22607 {
22608 newval = md_chars_to_number (buf, INSN_SIZE);
22609 newval = newval | 0x10000000;
22610 md_number_to_chars (buf, newval, INSN_SIZE);
22611 temp = 1;
22612 fixP->fx_done = 1;
22613 }
39b41c9c
PB
22614 else
22615 temp = 3;
22616 goto arm_branch_common;
22617
22618 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
22619 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22620 && fixP->fx_addsy
34e77a92 22621 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22622 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22623 && THUMB_IS_FUNC (fixP->fx_addsy))
22624 {
22625 /* This would map to a bl<cond>, b<cond>,
22626 b<always> to a Thumb function. We
22627 need to force a relocation for this particular
22628 case. */
22629 newval = md_chars_to_number (buf, INSN_SIZE);
22630 fixP->fx_done = 0;
22631 }
22632
2fc8bdac 22633 case BFD_RELOC_ARM_PLT32:
c19d1205 22634#endif
39b41c9c
PB
22635 case BFD_RELOC_ARM_PCREL_BRANCH:
22636 temp = 3;
22637 goto arm_branch_common;
a737bd4d 22638
39b41c9c 22639 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 22640
39b41c9c 22641 temp = 1;
267bf995
RR
22642 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22643 && fixP->fx_addsy
34e77a92 22644 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22645 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22646 && ARM_IS_FUNC (fixP->fx_addsy))
22647 {
22648 /* Flip the blx to a bl and warn. */
22649 const char *name = S_GET_NAME (fixP->fx_addsy);
22650 newval = 0xeb000000;
22651 as_warn_where (fixP->fx_file, fixP->fx_line,
22652 _("blx to '%s' an ARM ISA state function changed to bl"),
22653 name);
22654 md_number_to_chars (buf, newval, INSN_SIZE);
22655 temp = 3;
22656 fixP->fx_done = 1;
22657 }
22658
22659#ifdef OBJ_ELF
22660 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 22661 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
22662#endif
22663
39b41c9c 22664 arm_branch_common:
c19d1205 22665 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
22666 instruction, in a 24 bit, signed field. Bits 26 through 32 either
22667 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
22668 also be be clear. */
22669 if (value & temp)
c19d1205 22670 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
22671 _("misaligned branch destination"));
22672 if ((value & (offsetT)0xfe000000) != (offsetT)0
22673 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 22674 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 22675
2fc8bdac 22676 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 22677 {
2fc8bdac
ZW
22678 newval = md_chars_to_number (buf, INSN_SIZE);
22679 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
22680 /* Set the H bit on BLX instructions. */
22681 if (temp == 1)
22682 {
22683 if (value & 2)
22684 newval |= 0x01000000;
22685 else
22686 newval &= ~0x01000000;
22687 }
2fc8bdac 22688 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 22689 }
c19d1205 22690 break;
a737bd4d 22691
25fe350b
MS
22692 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
22693 /* CBZ can only branch forward. */
a737bd4d 22694
738755b0 22695 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
22696 (which, strictly speaking, are prohibited) will be turned into
22697 no-ops.
738755b0
MS
22698
22699 FIXME: It may be better to remove the instruction completely and
22700 perform relaxation. */
22701 if (value == -2)
2fc8bdac
ZW
22702 {
22703 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 22704 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
22705 md_number_to_chars (buf, newval, THUMB_SIZE);
22706 }
738755b0
MS
22707 else
22708 {
22709 if (value & ~0x7e)
08f10d51 22710 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 22711
477330fc 22712 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
22713 {
22714 newval = md_chars_to_number (buf, THUMB_SIZE);
22715 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
22716 md_number_to_chars (buf, newval, THUMB_SIZE);
22717 }
22718 }
c19d1205 22719 break;
a737bd4d 22720
c19d1205 22721 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 22722 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 22723 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 22724
2fc8bdac
ZW
22725 if (fixP->fx_done || !seg->use_rela_p)
22726 {
22727 newval = md_chars_to_number (buf, THUMB_SIZE);
22728 newval |= (value & 0x1ff) >> 1;
22729 md_number_to_chars (buf, newval, THUMB_SIZE);
22730 }
c19d1205 22731 break;
a737bd4d 22732
c19d1205 22733 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 22734 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 22735 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 22736
2fc8bdac
ZW
22737 if (fixP->fx_done || !seg->use_rela_p)
22738 {
22739 newval = md_chars_to_number (buf, THUMB_SIZE);
22740 newval |= (value & 0xfff) >> 1;
22741 md_number_to_chars (buf, newval, THUMB_SIZE);
22742 }
c19d1205 22743 break;
a737bd4d 22744
c19d1205 22745 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
22746 if (fixP->fx_addsy
22747 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22748 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22749 && ARM_IS_FUNC (fixP->fx_addsy)
22750 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22751 {
22752 /* Force a relocation for a branch 20 bits wide. */
22753 fixP->fx_done = 0;
22754 }
08f10d51 22755 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
22756 as_bad_where (fixP->fx_file, fixP->fx_line,
22757 _("conditional branch out of range"));
404ff6b5 22758
2fc8bdac
ZW
22759 if (fixP->fx_done || !seg->use_rela_p)
22760 {
22761 offsetT newval2;
22762 addressT S, J1, J2, lo, hi;
404ff6b5 22763
2fc8bdac
ZW
22764 S = (value & 0x00100000) >> 20;
22765 J2 = (value & 0x00080000) >> 19;
22766 J1 = (value & 0x00040000) >> 18;
22767 hi = (value & 0x0003f000) >> 12;
22768 lo = (value & 0x00000ffe) >> 1;
6c43fab6 22769
2fc8bdac
ZW
22770 newval = md_chars_to_number (buf, THUMB_SIZE);
22771 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22772 newval |= (S << 10) | hi;
22773 newval2 |= (J1 << 13) | (J2 << 11) | lo;
22774 md_number_to_chars (buf, newval, THUMB_SIZE);
22775 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22776 }
c19d1205 22777 break;
6c43fab6 22778
c19d1205 22779 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
22780 /* If there is a blx from a thumb state function to
22781 another thumb function flip this to a bl and warn
22782 about it. */
22783
22784 if (fixP->fx_addsy
34e77a92 22785 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22786 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22787 && THUMB_IS_FUNC (fixP->fx_addsy))
22788 {
22789 const char *name = S_GET_NAME (fixP->fx_addsy);
22790 as_warn_where (fixP->fx_file, fixP->fx_line,
22791 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
22792 name);
22793 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22794 newval = newval | 0x1000;
22795 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
22796 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
22797 fixP->fx_done = 1;
22798 }
22799
22800
22801 goto thumb_bl_common;
22802
c19d1205 22803 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
22804 /* A bl from Thumb state ISA to an internal ARM state function
22805 is converted to a blx. */
22806 if (fixP->fx_addsy
22807 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22808 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
22809 && ARM_IS_FUNC (fixP->fx_addsy)
22810 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22811 {
22812 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22813 newval = newval & ~0x1000;
22814 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
22815 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
22816 fixP->fx_done = 1;
22817 }
22818
22819 thumb_bl_common:
22820
2fc8bdac
ZW
22821 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
22822 /* For a BLX instruction, make sure that the relocation is rounded up
22823 to a word boundary. This follows the semantics of the instruction
22824 which specifies that bit 1 of the target address will come from bit
22825 1 of the base address. */
d406f3e4
JB
22826 value = (value + 3) & ~ 3;
22827
22828#ifdef OBJ_ELF
22829 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
22830 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
22831 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
22832#endif
404ff6b5 22833
2b2f5df9
NC
22834 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
22835 {
22836 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
22837 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
22838 else if ((value & ~0x1ffffff)
22839 && ((value & ~0x1ffffff) != ~0x1ffffff))
22840 as_bad_where (fixP->fx_file, fixP->fx_line,
22841 _("Thumb2 branch out of range"));
22842 }
4a42ebbc
RR
22843
22844 if (fixP->fx_done || !seg->use_rela_p)
22845 encode_thumb2_b_bl_offset (buf, value);
22846
c19d1205 22847 break;
404ff6b5 22848
c19d1205 22849 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
22850 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
22851 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 22852
2fc8bdac 22853 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 22854 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 22855
2fc8bdac 22856 break;
a737bd4d 22857
2fc8bdac
ZW
22858 case BFD_RELOC_8:
22859 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 22860 *buf = value;
c19d1205 22861 break;
a737bd4d 22862
c19d1205 22863 case BFD_RELOC_16:
2fc8bdac 22864 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 22865 md_number_to_chars (buf, value, 2);
c19d1205 22866 break;
a737bd4d 22867
c19d1205 22868#ifdef OBJ_ELF
0855e32b
NS
22869 case BFD_RELOC_ARM_TLS_CALL:
22870 case BFD_RELOC_ARM_THM_TLS_CALL:
22871 case BFD_RELOC_ARM_TLS_DESCSEQ:
22872 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 22873 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
22874 case BFD_RELOC_ARM_TLS_GD32:
22875 case BFD_RELOC_ARM_TLS_LE32:
22876 case BFD_RELOC_ARM_TLS_IE32:
22877 case BFD_RELOC_ARM_TLS_LDM32:
22878 case BFD_RELOC_ARM_TLS_LDO32:
22879 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 22880 break;
6c43fab6 22881
c19d1205
ZW
22882 case BFD_RELOC_ARM_GOT32:
22883 case BFD_RELOC_ARM_GOTOFF:
c19d1205 22884 break;
b43420e6
NC
22885
22886 case BFD_RELOC_ARM_GOT_PREL:
22887 if (fixP->fx_done || !seg->use_rela_p)
477330fc 22888 md_number_to_chars (buf, value, 4);
b43420e6
NC
22889 break;
22890
9a6f4e97
NS
22891 case BFD_RELOC_ARM_TARGET2:
22892 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
22893 addend here for REL targets, because it won't be written out
22894 during reloc processing later. */
9a6f4e97
NS
22895 if (fixP->fx_done || !seg->use_rela_p)
22896 md_number_to_chars (buf, fixP->fx_offset, 4);
22897 break;
c19d1205 22898#endif
6c43fab6 22899
c19d1205
ZW
22900 case BFD_RELOC_RVA:
22901 case BFD_RELOC_32:
22902 case BFD_RELOC_ARM_TARGET1:
22903 case BFD_RELOC_ARM_ROSEGREL32:
22904 case BFD_RELOC_ARM_SBREL32:
22905 case BFD_RELOC_32_PCREL:
f0927246
NC
22906#ifdef TE_PE
22907 case BFD_RELOC_32_SECREL:
22908#endif
2fc8bdac 22909 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
22910#ifdef TE_WINCE
22911 /* For WinCE we only do this for pcrel fixups. */
22912 if (fixP->fx_done || fixP->fx_pcrel)
22913#endif
22914 md_number_to_chars (buf, value, 4);
c19d1205 22915 break;
6c43fab6 22916
c19d1205
ZW
22917#ifdef OBJ_ELF
22918 case BFD_RELOC_ARM_PREL31:
2fc8bdac 22919 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
22920 {
22921 newval = md_chars_to_number (buf, 4) & 0x80000000;
22922 if ((value ^ (value >> 1)) & 0x40000000)
22923 {
22924 as_bad_where (fixP->fx_file, fixP->fx_line,
22925 _("rel31 relocation overflow"));
22926 }
22927 newval |= value & 0x7fffffff;
22928 md_number_to_chars (buf, newval, 4);
22929 }
22930 break;
c19d1205 22931#endif
a737bd4d 22932
c19d1205 22933 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 22934 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
22935 if (value < -1023 || value > 1023 || (value & 3))
22936 as_bad_where (fixP->fx_file, fixP->fx_line,
22937 _("co-processor offset out of range"));
22938 cp_off_common:
26d97720 22939 sign = value > 0;
c19d1205
ZW
22940 if (value < 0)
22941 value = -value;
8f06b2d8
PB
22942 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22943 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
22944 newval = md_chars_to_number (buf, INSN_SIZE);
22945 else
22946 newval = get_thumb32_insn (buf);
26d97720
NS
22947 if (value == 0)
22948 newval &= 0xffffff00;
22949 else
22950 {
22951 newval &= 0xff7fff00;
22952 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
22953 }
8f06b2d8
PB
22954 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22955 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
22956 md_number_to_chars (buf, newval, INSN_SIZE);
22957 else
22958 put_thumb32_insn (buf, newval);
c19d1205 22959 break;
a737bd4d 22960
c19d1205 22961 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 22962 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
22963 if (value < -255 || value > 255)
22964 as_bad_where (fixP->fx_file, fixP->fx_line,
22965 _("co-processor offset out of range"));
df7849c5 22966 value *= 4;
c19d1205 22967 goto cp_off_common;
6c43fab6 22968
c19d1205
ZW
22969 case BFD_RELOC_ARM_THUMB_OFFSET:
22970 newval = md_chars_to_number (buf, THUMB_SIZE);
22971 /* Exactly what ranges, and where the offset is inserted depends
22972 on the type of instruction, we can establish this from the
22973 top 4 bits. */
22974 switch (newval >> 12)
22975 {
22976 case 4: /* PC load. */
22977 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
22978 forced to zero for these loads; md_pcrel_from has already
22979 compensated for this. */
22980 if (value & 3)
22981 as_bad_where (fixP->fx_file, fixP->fx_line,
22982 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
22983 (((unsigned long) fixP->fx_frag->fr_address
22984 + (unsigned long) fixP->fx_where) & ~3)
22985 + (unsigned long) value);
a737bd4d 22986
c19d1205
ZW
22987 if (value & ~0x3fc)
22988 as_bad_where (fixP->fx_file, fixP->fx_line,
22989 _("invalid offset, value too big (0x%08lX)"),
22990 (long) value);
a737bd4d 22991
c19d1205
ZW
22992 newval |= value >> 2;
22993 break;
a737bd4d 22994
c19d1205
ZW
22995 case 9: /* SP load/store. */
22996 if (value & ~0x3fc)
22997 as_bad_where (fixP->fx_file, fixP->fx_line,
22998 _("invalid offset, value too big (0x%08lX)"),
22999 (long) value);
23000 newval |= value >> 2;
23001 break;
6c43fab6 23002
c19d1205
ZW
23003 case 6: /* Word load/store. */
23004 if (value & ~0x7c)
23005 as_bad_where (fixP->fx_file, fixP->fx_line,
23006 _("invalid offset, value too big (0x%08lX)"),
23007 (long) value);
23008 newval |= value << 4; /* 6 - 2. */
23009 break;
a737bd4d 23010
c19d1205
ZW
23011 case 7: /* Byte load/store. */
23012 if (value & ~0x1f)
23013 as_bad_where (fixP->fx_file, fixP->fx_line,
23014 _("invalid offset, value too big (0x%08lX)"),
23015 (long) value);
23016 newval |= value << 6;
23017 break;
a737bd4d 23018
c19d1205
ZW
23019 case 8: /* Halfword load/store. */
23020 if (value & ~0x3e)
23021 as_bad_where (fixP->fx_file, fixP->fx_line,
23022 _("invalid offset, value too big (0x%08lX)"),
23023 (long) value);
23024 newval |= value << 5; /* 6 - 1. */
23025 break;
a737bd4d 23026
c19d1205
ZW
23027 default:
23028 as_bad_where (fixP->fx_file, fixP->fx_line,
23029 "Unable to process relocation for thumb opcode: %lx",
23030 (unsigned long) newval);
23031 break;
23032 }
23033 md_number_to_chars (buf, newval, THUMB_SIZE);
23034 break;
a737bd4d 23035
c19d1205
ZW
23036 case BFD_RELOC_ARM_THUMB_ADD:
23037 /* This is a complicated relocation, since we use it for all of
23038 the following immediate relocations:
a737bd4d 23039
c19d1205
ZW
23040 3bit ADD/SUB
23041 8bit ADD/SUB
23042 9bit ADD/SUB SP word-aligned
23043 10bit ADD PC/SP word-aligned
a737bd4d 23044
c19d1205
ZW
23045 The type of instruction being processed is encoded in the
23046 instruction field:
a737bd4d 23047
c19d1205
ZW
23048 0x8000 SUB
23049 0x00F0 Rd
23050 0x000F Rs
23051 */
23052 newval = md_chars_to_number (buf, THUMB_SIZE);
23053 {
23054 int rd = (newval >> 4) & 0xf;
23055 int rs = newval & 0xf;
23056 int subtract = !!(newval & 0x8000);
a737bd4d 23057
c19d1205
ZW
23058 /* Check for HI regs, only very restricted cases allowed:
23059 Adjusting SP, and using PC or SP to get an address. */
23060 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
23061 || (rs > 7 && rs != REG_SP && rs != REG_PC))
23062 as_bad_where (fixP->fx_file, fixP->fx_line,
23063 _("invalid Hi register with immediate"));
a737bd4d 23064
c19d1205
ZW
23065 /* If value is negative, choose the opposite instruction. */
23066 if (value < 0)
23067 {
23068 value = -value;
23069 subtract = !subtract;
23070 if (value < 0)
23071 as_bad_where (fixP->fx_file, fixP->fx_line,
23072 _("immediate value out of range"));
23073 }
a737bd4d 23074
c19d1205
ZW
23075 if (rd == REG_SP)
23076 {
23077 if (value & ~0x1fc)
23078 as_bad_where (fixP->fx_file, fixP->fx_line,
23079 _("invalid immediate for stack address calculation"));
23080 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
23081 newval |= value >> 2;
23082 }
23083 else if (rs == REG_PC || rs == REG_SP)
23084 {
23085 if (subtract || value & ~0x3fc)
23086 as_bad_where (fixP->fx_file, fixP->fx_line,
23087 _("invalid immediate for address calculation (value = 0x%08lX)"),
23088 (unsigned long) value);
23089 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
23090 newval |= rd << 8;
23091 newval |= value >> 2;
23092 }
23093 else if (rs == rd)
23094 {
23095 if (value & ~0xff)
23096 as_bad_where (fixP->fx_file, fixP->fx_line,
23097 _("immediate value out of range"));
23098 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
23099 newval |= (rd << 8) | value;
23100 }
23101 else
23102 {
23103 if (value & ~0x7)
23104 as_bad_where (fixP->fx_file, fixP->fx_line,
23105 _("immediate value out of range"));
23106 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
23107 newval |= rd | (rs << 3) | (value << 6);
23108 }
23109 }
23110 md_number_to_chars (buf, newval, THUMB_SIZE);
23111 break;
a737bd4d 23112
c19d1205
ZW
23113 case BFD_RELOC_ARM_THUMB_IMM:
23114 newval = md_chars_to_number (buf, THUMB_SIZE);
23115 if (value < 0 || value > 255)
23116 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 23117 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
23118 (long) value);
23119 newval |= value;
23120 md_number_to_chars (buf, newval, THUMB_SIZE);
23121 break;
a737bd4d 23122
c19d1205
ZW
23123 case BFD_RELOC_ARM_THUMB_SHIFT:
23124 /* 5bit shift value (0..32). LSL cannot take 32. */
23125 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
23126 temp = newval & 0xf800;
23127 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
23128 as_bad_where (fixP->fx_file, fixP->fx_line,
23129 _("invalid shift value: %ld"), (long) value);
23130 /* Shifts of zero must be encoded as LSL. */
23131 if (value == 0)
23132 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
23133 /* Shifts of 32 are encoded as zero. */
23134 else if (value == 32)
23135 value = 0;
23136 newval |= value << 6;
23137 md_number_to_chars (buf, newval, THUMB_SIZE);
23138 break;
a737bd4d 23139
c19d1205
ZW
23140 case BFD_RELOC_VTABLE_INHERIT:
23141 case BFD_RELOC_VTABLE_ENTRY:
23142 fixP->fx_done = 0;
23143 return;
6c43fab6 23144
b6895b4f
PB
23145 case BFD_RELOC_ARM_MOVW:
23146 case BFD_RELOC_ARM_MOVT:
23147 case BFD_RELOC_ARM_THUMB_MOVW:
23148 case BFD_RELOC_ARM_THUMB_MOVT:
23149 if (fixP->fx_done || !seg->use_rela_p)
23150 {
23151 /* REL format relocations are limited to a 16-bit addend. */
23152 if (!fixP->fx_done)
23153 {
39623e12 23154 if (value < -0x8000 || value > 0x7fff)
b6895b4f 23155 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 23156 _("offset out of range"));
b6895b4f
PB
23157 }
23158 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23159 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23160 {
23161 value >>= 16;
23162 }
23163
23164 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23165 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23166 {
23167 newval = get_thumb32_insn (buf);
23168 newval &= 0xfbf08f00;
23169 newval |= (value & 0xf000) << 4;
23170 newval |= (value & 0x0800) << 15;
23171 newval |= (value & 0x0700) << 4;
23172 newval |= (value & 0x00ff);
23173 put_thumb32_insn (buf, newval);
23174 }
23175 else
23176 {
23177 newval = md_chars_to_number (buf, 4);
23178 newval &= 0xfff0f000;
23179 newval |= value & 0x0fff;
23180 newval |= (value & 0xf000) << 4;
23181 md_number_to_chars (buf, newval, 4);
23182 }
23183 }
23184 return;
23185
4962c51a
MS
23186 case BFD_RELOC_ARM_ALU_PC_G0_NC:
23187 case BFD_RELOC_ARM_ALU_PC_G0:
23188 case BFD_RELOC_ARM_ALU_PC_G1_NC:
23189 case BFD_RELOC_ARM_ALU_PC_G1:
23190 case BFD_RELOC_ARM_ALU_PC_G2:
23191 case BFD_RELOC_ARM_ALU_SB_G0_NC:
23192 case BFD_RELOC_ARM_ALU_SB_G0:
23193 case BFD_RELOC_ARM_ALU_SB_G1_NC:
23194 case BFD_RELOC_ARM_ALU_SB_G1:
23195 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 23196 gas_assert (!fixP->fx_done);
4962c51a
MS
23197 if (!seg->use_rela_p)
23198 {
477330fc
RM
23199 bfd_vma insn;
23200 bfd_vma encoded_addend;
23201 bfd_vma addend_abs = abs (value);
23202
23203 /* Check that the absolute value of the addend can be
23204 expressed as an 8-bit constant plus a rotation. */
23205 encoded_addend = encode_arm_immediate (addend_abs);
23206 if (encoded_addend == (unsigned int) FAIL)
4962c51a 23207 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23208 _("the offset 0x%08lX is not representable"),
23209 (unsigned long) addend_abs);
23210
23211 /* Extract the instruction. */
23212 insn = md_chars_to_number (buf, INSN_SIZE);
23213
23214 /* If the addend is positive, use an ADD instruction.
23215 Otherwise use a SUB. Take care not to destroy the S bit. */
23216 insn &= 0xff1fffff;
23217 if (value < 0)
23218 insn |= 1 << 22;
23219 else
23220 insn |= 1 << 23;
23221
23222 /* Place the encoded addend into the first 12 bits of the
23223 instruction. */
23224 insn &= 0xfffff000;
23225 insn |= encoded_addend;
23226
23227 /* Update the instruction. */
23228 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
23229 }
23230 break;
23231
23232 case BFD_RELOC_ARM_LDR_PC_G0:
23233 case BFD_RELOC_ARM_LDR_PC_G1:
23234 case BFD_RELOC_ARM_LDR_PC_G2:
23235 case BFD_RELOC_ARM_LDR_SB_G0:
23236 case BFD_RELOC_ARM_LDR_SB_G1:
23237 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 23238 gas_assert (!fixP->fx_done);
4962c51a 23239 if (!seg->use_rela_p)
477330fc
RM
23240 {
23241 bfd_vma insn;
23242 bfd_vma addend_abs = abs (value);
4962c51a 23243
477330fc
RM
23244 /* Check that the absolute value of the addend can be
23245 encoded in 12 bits. */
23246 if (addend_abs >= 0x1000)
4962c51a 23247 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23248 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
23249 (unsigned long) addend_abs);
23250
23251 /* Extract the instruction. */
23252 insn = md_chars_to_number (buf, INSN_SIZE);
23253
23254 /* If the addend is negative, clear bit 23 of the instruction.
23255 Otherwise set it. */
23256 if (value < 0)
23257 insn &= ~(1 << 23);
23258 else
23259 insn |= 1 << 23;
23260
23261 /* Place the absolute value of the addend into the first 12 bits
23262 of the instruction. */
23263 insn &= 0xfffff000;
23264 insn |= addend_abs;
23265
23266 /* Update the instruction. */
23267 md_number_to_chars (buf, insn, INSN_SIZE);
23268 }
4962c51a
MS
23269 break;
23270
23271 case BFD_RELOC_ARM_LDRS_PC_G0:
23272 case BFD_RELOC_ARM_LDRS_PC_G1:
23273 case BFD_RELOC_ARM_LDRS_PC_G2:
23274 case BFD_RELOC_ARM_LDRS_SB_G0:
23275 case BFD_RELOC_ARM_LDRS_SB_G1:
23276 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 23277 gas_assert (!fixP->fx_done);
4962c51a 23278 if (!seg->use_rela_p)
477330fc
RM
23279 {
23280 bfd_vma insn;
23281 bfd_vma addend_abs = abs (value);
4962c51a 23282
477330fc
RM
23283 /* Check that the absolute value of the addend can be
23284 encoded in 8 bits. */
23285 if (addend_abs >= 0x100)
4962c51a 23286 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23287 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
23288 (unsigned long) addend_abs);
23289
23290 /* Extract the instruction. */
23291 insn = md_chars_to_number (buf, INSN_SIZE);
23292
23293 /* If the addend is negative, clear bit 23 of the instruction.
23294 Otherwise set it. */
23295 if (value < 0)
23296 insn &= ~(1 << 23);
23297 else
23298 insn |= 1 << 23;
23299
23300 /* Place the first four bits of the absolute value of the addend
23301 into the first 4 bits of the instruction, and the remaining
23302 four into bits 8 .. 11. */
23303 insn &= 0xfffff0f0;
23304 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
23305
23306 /* Update the instruction. */
23307 md_number_to_chars (buf, insn, INSN_SIZE);
23308 }
4962c51a
MS
23309 break;
23310
23311 case BFD_RELOC_ARM_LDC_PC_G0:
23312 case BFD_RELOC_ARM_LDC_PC_G1:
23313 case BFD_RELOC_ARM_LDC_PC_G2:
23314 case BFD_RELOC_ARM_LDC_SB_G0:
23315 case BFD_RELOC_ARM_LDC_SB_G1:
23316 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 23317 gas_assert (!fixP->fx_done);
4962c51a 23318 if (!seg->use_rela_p)
477330fc
RM
23319 {
23320 bfd_vma insn;
23321 bfd_vma addend_abs = abs (value);
4962c51a 23322
477330fc
RM
23323 /* Check that the absolute value of the addend is a multiple of
23324 four and, when divided by four, fits in 8 bits. */
23325 if (addend_abs & 0x3)
4962c51a 23326 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23327 _("bad offset 0x%08lX (must be word-aligned)"),
23328 (unsigned long) addend_abs);
4962c51a 23329
477330fc 23330 if ((addend_abs >> 2) > 0xff)
4962c51a 23331 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23332 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
23333 (unsigned long) addend_abs);
23334
23335 /* Extract the instruction. */
23336 insn = md_chars_to_number (buf, INSN_SIZE);
23337
23338 /* If the addend is negative, clear bit 23 of the instruction.
23339 Otherwise set it. */
23340 if (value < 0)
23341 insn &= ~(1 << 23);
23342 else
23343 insn |= 1 << 23;
23344
23345 /* Place the addend (divided by four) into the first eight
23346 bits of the instruction. */
23347 insn &= 0xfffffff0;
23348 insn |= addend_abs >> 2;
23349
23350 /* Update the instruction. */
23351 md_number_to_chars (buf, insn, INSN_SIZE);
23352 }
4962c51a
MS
23353 break;
23354
845b51d6
PB
23355 case BFD_RELOC_ARM_V4BX:
23356 /* This will need to go in the object file. */
23357 fixP->fx_done = 0;
23358 break;
23359
c19d1205
ZW
23360 case BFD_RELOC_UNUSED:
23361 default:
23362 as_bad_where (fixP->fx_file, fixP->fx_line,
23363 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
23364 }
6c43fab6
RE
23365}
23366
c19d1205
ZW
23367/* Translate internal representation of relocation info to BFD target
23368 format. */
a737bd4d 23369
c19d1205 23370arelent *
00a97672 23371tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 23372{
c19d1205
ZW
23373 arelent * reloc;
23374 bfd_reloc_code_real_type code;
a737bd4d 23375
21d799b5 23376 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 23377
21d799b5 23378 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
23379 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
23380 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 23381
2fc8bdac 23382 if (fixp->fx_pcrel)
00a97672
RS
23383 {
23384 if (section->use_rela_p)
23385 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
23386 else
23387 fixp->fx_offset = reloc->address;
23388 }
c19d1205 23389 reloc->addend = fixp->fx_offset;
a737bd4d 23390
c19d1205 23391 switch (fixp->fx_r_type)
a737bd4d 23392 {
c19d1205
ZW
23393 case BFD_RELOC_8:
23394 if (fixp->fx_pcrel)
23395 {
23396 code = BFD_RELOC_8_PCREL;
23397 break;
23398 }
a737bd4d 23399
c19d1205
ZW
23400 case BFD_RELOC_16:
23401 if (fixp->fx_pcrel)
23402 {
23403 code = BFD_RELOC_16_PCREL;
23404 break;
23405 }
6c43fab6 23406
c19d1205
ZW
23407 case BFD_RELOC_32:
23408 if (fixp->fx_pcrel)
23409 {
23410 code = BFD_RELOC_32_PCREL;
23411 break;
23412 }
a737bd4d 23413
b6895b4f
PB
23414 case BFD_RELOC_ARM_MOVW:
23415 if (fixp->fx_pcrel)
23416 {
23417 code = BFD_RELOC_ARM_MOVW_PCREL;
23418 break;
23419 }
23420
23421 case BFD_RELOC_ARM_MOVT:
23422 if (fixp->fx_pcrel)
23423 {
23424 code = BFD_RELOC_ARM_MOVT_PCREL;
23425 break;
23426 }
23427
23428 case BFD_RELOC_ARM_THUMB_MOVW:
23429 if (fixp->fx_pcrel)
23430 {
23431 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
23432 break;
23433 }
23434
23435 case BFD_RELOC_ARM_THUMB_MOVT:
23436 if (fixp->fx_pcrel)
23437 {
23438 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
23439 break;
23440 }
23441
c19d1205
ZW
23442 case BFD_RELOC_NONE:
23443 case BFD_RELOC_ARM_PCREL_BRANCH:
23444 case BFD_RELOC_ARM_PCREL_BLX:
23445 case BFD_RELOC_RVA:
23446 case BFD_RELOC_THUMB_PCREL_BRANCH7:
23447 case BFD_RELOC_THUMB_PCREL_BRANCH9:
23448 case BFD_RELOC_THUMB_PCREL_BRANCH12:
23449 case BFD_RELOC_THUMB_PCREL_BRANCH20:
23450 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23451 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
23452 case BFD_RELOC_VTABLE_ENTRY:
23453 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
23454#ifdef TE_PE
23455 case BFD_RELOC_32_SECREL:
23456#endif
c19d1205
ZW
23457 code = fixp->fx_r_type;
23458 break;
a737bd4d 23459
00adf2d4
JB
23460 case BFD_RELOC_THUMB_PCREL_BLX:
23461#ifdef OBJ_ELF
23462 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
23463 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
23464 else
23465#endif
23466 code = BFD_RELOC_THUMB_PCREL_BLX;
23467 break;
23468
c19d1205
ZW
23469 case BFD_RELOC_ARM_LITERAL:
23470 case BFD_RELOC_ARM_HWLITERAL:
23471 /* If this is called then the a literal has
23472 been referenced across a section boundary. */
23473 as_bad_where (fixp->fx_file, fixp->fx_line,
23474 _("literal referenced across section boundary"));
23475 return NULL;
a737bd4d 23476
c19d1205 23477#ifdef OBJ_ELF
0855e32b
NS
23478 case BFD_RELOC_ARM_TLS_CALL:
23479 case BFD_RELOC_ARM_THM_TLS_CALL:
23480 case BFD_RELOC_ARM_TLS_DESCSEQ:
23481 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
23482 case BFD_RELOC_ARM_GOT32:
23483 case BFD_RELOC_ARM_GOTOFF:
b43420e6 23484 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
23485 case BFD_RELOC_ARM_PLT32:
23486 case BFD_RELOC_ARM_TARGET1:
23487 case BFD_RELOC_ARM_ROSEGREL32:
23488 case BFD_RELOC_ARM_SBREL32:
23489 case BFD_RELOC_ARM_PREL31:
23490 case BFD_RELOC_ARM_TARGET2:
23491 case BFD_RELOC_ARM_TLS_LE32:
23492 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
23493 case BFD_RELOC_ARM_PCREL_CALL:
23494 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
23495 case BFD_RELOC_ARM_ALU_PC_G0_NC:
23496 case BFD_RELOC_ARM_ALU_PC_G0:
23497 case BFD_RELOC_ARM_ALU_PC_G1_NC:
23498 case BFD_RELOC_ARM_ALU_PC_G1:
23499 case BFD_RELOC_ARM_ALU_PC_G2:
23500 case BFD_RELOC_ARM_LDR_PC_G0:
23501 case BFD_RELOC_ARM_LDR_PC_G1:
23502 case BFD_RELOC_ARM_LDR_PC_G2:
23503 case BFD_RELOC_ARM_LDRS_PC_G0:
23504 case BFD_RELOC_ARM_LDRS_PC_G1:
23505 case BFD_RELOC_ARM_LDRS_PC_G2:
23506 case BFD_RELOC_ARM_LDC_PC_G0:
23507 case BFD_RELOC_ARM_LDC_PC_G1:
23508 case BFD_RELOC_ARM_LDC_PC_G2:
23509 case BFD_RELOC_ARM_ALU_SB_G0_NC:
23510 case BFD_RELOC_ARM_ALU_SB_G0:
23511 case BFD_RELOC_ARM_ALU_SB_G1_NC:
23512 case BFD_RELOC_ARM_ALU_SB_G1:
23513 case BFD_RELOC_ARM_ALU_SB_G2:
23514 case BFD_RELOC_ARM_LDR_SB_G0:
23515 case BFD_RELOC_ARM_LDR_SB_G1:
23516 case BFD_RELOC_ARM_LDR_SB_G2:
23517 case BFD_RELOC_ARM_LDRS_SB_G0:
23518 case BFD_RELOC_ARM_LDRS_SB_G1:
23519 case BFD_RELOC_ARM_LDRS_SB_G2:
23520 case BFD_RELOC_ARM_LDC_SB_G0:
23521 case BFD_RELOC_ARM_LDC_SB_G1:
23522 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 23523 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
23524 code = fixp->fx_r_type;
23525 break;
a737bd4d 23526
0855e32b 23527 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
23528 case BFD_RELOC_ARM_TLS_GD32:
23529 case BFD_RELOC_ARM_TLS_IE32:
23530 case BFD_RELOC_ARM_TLS_LDM32:
23531 /* BFD will include the symbol's address in the addend.
23532 But we don't want that, so subtract it out again here. */
23533 if (!S_IS_COMMON (fixp->fx_addsy))
23534 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
23535 code = fixp->fx_r_type;
23536 break;
23537#endif
a737bd4d 23538
c19d1205
ZW
23539 case BFD_RELOC_ARM_IMMEDIATE:
23540 as_bad_where (fixp->fx_file, fixp->fx_line,
23541 _("internal relocation (type: IMMEDIATE) not fixed up"));
23542 return NULL;
a737bd4d 23543
c19d1205
ZW
23544 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
23545 as_bad_where (fixp->fx_file, fixp->fx_line,
23546 _("ADRL used for a symbol not defined in the same file"));
23547 return NULL;
a737bd4d 23548
c19d1205 23549 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
23550 if (section->use_rela_p)
23551 {
23552 code = fixp->fx_r_type;
23553 break;
23554 }
23555
c19d1205
ZW
23556 if (fixp->fx_addsy != NULL
23557 && !S_IS_DEFINED (fixp->fx_addsy)
23558 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 23559 {
c19d1205
ZW
23560 as_bad_where (fixp->fx_file, fixp->fx_line,
23561 _("undefined local label `%s'"),
23562 S_GET_NAME (fixp->fx_addsy));
23563 return NULL;
a737bd4d
NC
23564 }
23565
c19d1205
ZW
23566 as_bad_where (fixp->fx_file, fixp->fx_line,
23567 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
23568 return NULL;
a737bd4d 23569
c19d1205
ZW
23570 default:
23571 {
23572 char * type;
6c43fab6 23573
c19d1205
ZW
23574 switch (fixp->fx_r_type)
23575 {
23576 case BFD_RELOC_NONE: type = "NONE"; break;
23577 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
23578 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 23579 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
23580 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
23581 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
23582 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 23583 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 23584 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
23585 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
23586 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
23587 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
23588 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
23589 default: type = _("<unknown>"); break;
23590 }
23591 as_bad_where (fixp->fx_file, fixp->fx_line,
23592 _("cannot represent %s relocation in this object file format"),
23593 type);
23594 return NULL;
23595 }
a737bd4d 23596 }
6c43fab6 23597
c19d1205
ZW
23598#ifdef OBJ_ELF
23599 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
23600 && GOT_symbol
23601 && fixp->fx_addsy == GOT_symbol)
23602 {
23603 code = BFD_RELOC_ARM_GOTPC;
23604 reloc->addend = fixp->fx_offset = reloc->address;
23605 }
23606#endif
6c43fab6 23607
c19d1205 23608 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 23609
c19d1205
ZW
23610 if (reloc->howto == NULL)
23611 {
23612 as_bad_where (fixp->fx_file, fixp->fx_line,
23613 _("cannot represent %s relocation in this object file format"),
23614 bfd_get_reloc_code_name (code));
23615 return NULL;
23616 }
6c43fab6 23617
c19d1205
ZW
23618 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
23619 vtable entry to be used in the relocation's section offset. */
23620 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
23621 reloc->address = fixp->fx_offset;
6c43fab6 23622
c19d1205 23623 return reloc;
6c43fab6
RE
23624}
23625
c19d1205 23626/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 23627
c19d1205
ZW
23628void
23629cons_fix_new_arm (fragS * frag,
23630 int where,
23631 int size,
62ebcb5c
AM
23632 expressionS * exp,
23633 bfd_reloc_code_real_type reloc)
6c43fab6 23634{
c19d1205 23635 int pcrel = 0;
6c43fab6 23636
c19d1205
ZW
23637 /* Pick a reloc.
23638 FIXME: @@ Should look at CPU word size. */
23639 switch (size)
23640 {
23641 case 1:
62ebcb5c 23642 reloc = BFD_RELOC_8;
c19d1205
ZW
23643 break;
23644 case 2:
62ebcb5c 23645 reloc = BFD_RELOC_16;
c19d1205
ZW
23646 break;
23647 case 4:
23648 default:
62ebcb5c 23649 reloc = BFD_RELOC_32;
c19d1205
ZW
23650 break;
23651 case 8:
62ebcb5c 23652 reloc = BFD_RELOC_64;
c19d1205
ZW
23653 break;
23654 }
6c43fab6 23655
f0927246
NC
23656#ifdef TE_PE
23657 if (exp->X_op == O_secrel)
23658 {
23659 exp->X_op = O_symbol;
62ebcb5c 23660 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
23661 }
23662#endif
23663
62ebcb5c 23664 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 23665}
6c43fab6 23666
4343666d 23667#if defined (OBJ_COFF)
c19d1205
ZW
23668void
23669arm_validate_fix (fixS * fixP)
6c43fab6 23670{
c19d1205
ZW
23671 /* If the destination of the branch is a defined symbol which does not have
23672 the THUMB_FUNC attribute, then we must be calling a function which has
23673 the (interfacearm) attribute. We look for the Thumb entry point to that
23674 function and change the branch to refer to that function instead. */
23675 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
23676 && fixP->fx_addsy != NULL
23677 && S_IS_DEFINED (fixP->fx_addsy)
23678 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 23679 {
c19d1205 23680 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 23681 }
c19d1205
ZW
23682}
23683#endif
6c43fab6 23684
267bf995 23685
c19d1205
ZW
23686int
23687arm_force_relocation (struct fix * fixp)
23688{
23689#if defined (OBJ_COFF) && defined (TE_PE)
23690 if (fixp->fx_r_type == BFD_RELOC_RVA)
23691 return 1;
23692#endif
6c43fab6 23693
267bf995
RR
23694 /* In case we have a call or a branch to a function in ARM ISA mode from
23695 a thumb function or vice-versa force the relocation. These relocations
23696 are cleared off for some cores that might have blx and simple transformations
23697 are possible. */
23698
23699#ifdef OBJ_ELF
23700 switch (fixp->fx_r_type)
23701 {
23702 case BFD_RELOC_ARM_PCREL_JUMP:
23703 case BFD_RELOC_ARM_PCREL_CALL:
23704 case BFD_RELOC_THUMB_PCREL_BLX:
23705 if (THUMB_IS_FUNC (fixp->fx_addsy))
23706 return 1;
23707 break;
23708
23709 case BFD_RELOC_ARM_PCREL_BLX:
23710 case BFD_RELOC_THUMB_PCREL_BRANCH25:
23711 case BFD_RELOC_THUMB_PCREL_BRANCH20:
23712 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23713 if (ARM_IS_FUNC (fixp->fx_addsy))
23714 return 1;
23715 break;
23716
23717 default:
23718 break;
23719 }
23720#endif
23721
b5884301
PB
23722 /* Resolve these relocations even if the symbol is extern or weak.
23723 Technically this is probably wrong due to symbol preemption.
23724 In practice these relocations do not have enough range to be useful
23725 at dynamic link time, and some code (e.g. in the Linux kernel)
23726 expects these references to be resolved. */
c19d1205
ZW
23727 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
23728 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 23729 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 23730 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
23731 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23732 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
23733 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 23734 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
23735 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23736 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
23737 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
23738 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
23739 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
23740 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 23741 return 0;
a737bd4d 23742
4962c51a
MS
23743 /* Always leave these relocations for the linker. */
23744 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
23745 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
23746 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
23747 return 1;
23748
f0291e4c
PB
23749 /* Always generate relocations against function symbols. */
23750 if (fixp->fx_r_type == BFD_RELOC_32
23751 && fixp->fx_addsy
23752 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
23753 return 1;
23754
c19d1205 23755 return generic_force_reloc (fixp);
404ff6b5
AH
23756}
23757
0ffdc86c 23758#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
23759/* Relocations against function names must be left unadjusted,
23760 so that the linker can use this information to generate interworking
23761 stubs. The MIPS version of this function
c19d1205
ZW
23762 also prevents relocations that are mips-16 specific, but I do not
23763 know why it does this.
404ff6b5 23764
c19d1205
ZW
23765 FIXME:
23766 There is one other problem that ought to be addressed here, but
23767 which currently is not: Taking the address of a label (rather
23768 than a function) and then later jumping to that address. Such
23769 addresses also ought to have their bottom bit set (assuming that
23770 they reside in Thumb code), but at the moment they will not. */
404ff6b5 23771
c19d1205
ZW
23772bfd_boolean
23773arm_fix_adjustable (fixS * fixP)
404ff6b5 23774{
c19d1205
ZW
23775 if (fixP->fx_addsy == NULL)
23776 return 1;
404ff6b5 23777
e28387c3
PB
23778 /* Preserve relocations against symbols with function type. */
23779 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 23780 return FALSE;
e28387c3 23781
c19d1205
ZW
23782 if (THUMB_IS_FUNC (fixP->fx_addsy)
23783 && fixP->fx_subsy == NULL)
c921be7d 23784 return FALSE;
a737bd4d 23785
c19d1205
ZW
23786 /* We need the symbol name for the VTABLE entries. */
23787 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
23788 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 23789 return FALSE;
404ff6b5 23790
c19d1205
ZW
23791 /* Don't allow symbols to be discarded on GOT related relocs. */
23792 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
23793 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
23794 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
23795 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
23796 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
23797 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
23798 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
23799 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
23800 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
23801 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
23802 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
23803 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
23804 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 23805 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 23806 return FALSE;
a737bd4d 23807
4962c51a
MS
23808 /* Similarly for group relocations. */
23809 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
23810 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
23811 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 23812 return FALSE;
4962c51a 23813
79947c54
CD
23814 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
23815 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
23816 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23817 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
23818 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
23819 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23820 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
23821 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
23822 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 23823 return FALSE;
79947c54 23824
c921be7d 23825 return TRUE;
a737bd4d 23826}
0ffdc86c
NC
23827#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
23828
23829#ifdef OBJ_ELF
404ff6b5 23830
c19d1205
ZW
23831const char *
23832elf32_arm_target_format (void)
404ff6b5 23833{
c19d1205
ZW
23834#ifdef TE_SYMBIAN
23835 return (target_big_endian
23836 ? "elf32-bigarm-symbian"
23837 : "elf32-littlearm-symbian");
23838#elif defined (TE_VXWORKS)
23839 return (target_big_endian
23840 ? "elf32-bigarm-vxworks"
23841 : "elf32-littlearm-vxworks");
b38cadfb
NC
23842#elif defined (TE_NACL)
23843 return (target_big_endian
23844 ? "elf32-bigarm-nacl"
23845 : "elf32-littlearm-nacl");
c19d1205
ZW
23846#else
23847 if (target_big_endian)
23848 return "elf32-bigarm";
23849 else
23850 return "elf32-littlearm";
23851#endif
404ff6b5
AH
23852}
23853
c19d1205
ZW
23854void
23855armelf_frob_symbol (symbolS * symp,
23856 int * puntp)
404ff6b5 23857{
c19d1205
ZW
23858 elf_frob_symbol (symp, puntp);
23859}
23860#endif
404ff6b5 23861
c19d1205 23862/* MD interface: Finalization. */
a737bd4d 23863
c19d1205
ZW
23864void
23865arm_cleanup (void)
23866{
23867 literal_pool * pool;
a737bd4d 23868
e07e6e58
NC
23869 /* Ensure that all the IT blocks are properly closed. */
23870 check_it_blocks_finished ();
23871
c19d1205
ZW
23872 for (pool = list_of_pools; pool; pool = pool->next)
23873 {
5f4273c7 23874 /* Put it at the end of the relevant section. */
c19d1205
ZW
23875 subseg_set (pool->section, pool->sub_section);
23876#ifdef OBJ_ELF
23877 arm_elf_change_section ();
23878#endif
23879 s_ltorg (0);
23880 }
404ff6b5
AH
23881}
23882
cd000bff
DJ
23883#ifdef OBJ_ELF
23884/* Remove any excess mapping symbols generated for alignment frags in
23885 SEC. We may have created a mapping symbol before a zero byte
23886 alignment; remove it if there's a mapping symbol after the
23887 alignment. */
23888static void
23889check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
23890 void *dummy ATTRIBUTE_UNUSED)
23891{
23892 segment_info_type *seginfo = seg_info (sec);
23893 fragS *fragp;
23894
23895 if (seginfo == NULL || seginfo->frchainP == NULL)
23896 return;
23897
23898 for (fragp = seginfo->frchainP->frch_root;
23899 fragp != NULL;
23900 fragp = fragp->fr_next)
23901 {
23902 symbolS *sym = fragp->tc_frag_data.last_map;
23903 fragS *next = fragp->fr_next;
23904
23905 /* Variable-sized frags have been converted to fixed size by
23906 this point. But if this was variable-sized to start with,
23907 there will be a fixed-size frag after it. So don't handle
23908 next == NULL. */
23909 if (sym == NULL || next == NULL)
23910 continue;
23911
23912 if (S_GET_VALUE (sym) < next->fr_address)
23913 /* Not at the end of this frag. */
23914 continue;
23915 know (S_GET_VALUE (sym) == next->fr_address);
23916
23917 do
23918 {
23919 if (next->tc_frag_data.first_map != NULL)
23920 {
23921 /* Next frag starts with a mapping symbol. Discard this
23922 one. */
23923 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
23924 break;
23925 }
23926
23927 if (next->fr_next == NULL)
23928 {
23929 /* This mapping symbol is at the end of the section. Discard
23930 it. */
23931 know (next->fr_fix == 0 && next->fr_var == 0);
23932 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
23933 break;
23934 }
23935
23936 /* As long as we have empty frags without any mapping symbols,
23937 keep looking. */
23938 /* If the next frag is non-empty and does not start with a
23939 mapping symbol, then this mapping symbol is required. */
23940 if (next->fr_address != next->fr_next->fr_address)
23941 break;
23942
23943 next = next->fr_next;
23944 }
23945 while (next != NULL);
23946 }
23947}
23948#endif
23949
c19d1205
ZW
23950/* Adjust the symbol table. This marks Thumb symbols as distinct from
23951 ARM ones. */
404ff6b5 23952
c19d1205
ZW
23953void
23954arm_adjust_symtab (void)
404ff6b5 23955{
c19d1205
ZW
23956#ifdef OBJ_COFF
23957 symbolS * sym;
404ff6b5 23958
c19d1205
ZW
23959 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
23960 {
23961 if (ARM_IS_THUMB (sym))
23962 {
23963 if (THUMB_IS_FUNC (sym))
23964 {
23965 /* Mark the symbol as a Thumb function. */
23966 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
23967 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
23968 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 23969
c19d1205
ZW
23970 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
23971 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
23972 else
23973 as_bad (_("%s: unexpected function type: %d"),
23974 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
23975 }
23976 else switch (S_GET_STORAGE_CLASS (sym))
23977 {
23978 case C_EXT:
23979 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
23980 break;
23981 case C_STAT:
23982 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
23983 break;
23984 case C_LABEL:
23985 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
23986 break;
23987 default:
23988 /* Do nothing. */
23989 break;
23990 }
23991 }
a737bd4d 23992
c19d1205
ZW
23993 if (ARM_IS_INTERWORK (sym))
23994 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 23995 }
c19d1205
ZW
23996#endif
23997#ifdef OBJ_ELF
23998 symbolS * sym;
23999 char bind;
404ff6b5 24000
c19d1205 24001 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 24002 {
c19d1205
ZW
24003 if (ARM_IS_THUMB (sym))
24004 {
24005 elf_symbol_type * elf_sym;
404ff6b5 24006
c19d1205
ZW
24007 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
24008 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 24009
b0796911
PB
24010 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
24011 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
24012 {
24013 /* If it's a .thumb_func, declare it as so,
24014 otherwise tag label as .code 16. */
24015 if (THUMB_IS_FUNC (sym))
35fc36a8
RS
24016 elf_sym->internal_elf_sym.st_target_internal
24017 = ST_BRANCH_TO_THUMB;
3ba67470 24018 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
24019 elf_sym->internal_elf_sym.st_info =
24020 ELF_ST_INFO (bind, STT_ARM_16BIT);
24021 }
24022 }
24023 }
cd000bff
DJ
24024
24025 /* Remove any overlapping mapping symbols generated by alignment frags. */
24026 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
24027 /* Now do generic ELF adjustments. */
24028 elf_adjust_symtab ();
c19d1205 24029#endif
404ff6b5
AH
24030}
24031
c19d1205 24032/* MD interface: Initialization. */
404ff6b5 24033
a737bd4d 24034static void
c19d1205 24035set_constant_flonums (void)
a737bd4d 24036{
c19d1205 24037 int i;
404ff6b5 24038
c19d1205
ZW
24039 for (i = 0; i < NUM_FLOAT_VALS; i++)
24040 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
24041 abort ();
a737bd4d 24042}
404ff6b5 24043
3e9e4fcf
JB
24044/* Auto-select Thumb mode if it's the only available instruction set for the
24045 given architecture. */
24046
24047static void
24048autoselect_thumb_from_cpu_variant (void)
24049{
24050 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
24051 opcode_select (16);
24052}
24053
c19d1205
ZW
24054void
24055md_begin (void)
a737bd4d 24056{
c19d1205
ZW
24057 unsigned mach;
24058 unsigned int i;
404ff6b5 24059
c19d1205
ZW
24060 if ( (arm_ops_hsh = hash_new ()) == NULL
24061 || (arm_cond_hsh = hash_new ()) == NULL
24062 || (arm_shift_hsh = hash_new ()) == NULL
24063 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 24064 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 24065 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
24066 || (arm_reloc_hsh = hash_new ()) == NULL
24067 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
24068 as_fatal (_("virtual memory exhausted"));
24069
24070 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 24071 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 24072 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 24073 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 24074 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 24075 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 24076 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24077 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 24078 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24079 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 24080 (void *) (v7m_psrs + i));
c19d1205 24081 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 24082 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
24083 for (i = 0;
24084 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
24085 i++)
d3ce72d0 24086 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 24087 (void *) (barrier_opt_names + i));
c19d1205 24088#ifdef OBJ_ELF
3da1d841
NC
24089 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
24090 {
24091 struct reloc_entry * entry = reloc_names + i;
24092
24093 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
24094 /* This makes encode_branch() use the EABI versions of this relocation. */
24095 entry->reloc = BFD_RELOC_UNUSED;
24096
24097 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
24098 }
c19d1205
ZW
24099#endif
24100
24101 set_constant_flonums ();
404ff6b5 24102
c19d1205
ZW
24103 /* Set the cpu variant based on the command-line options. We prefer
24104 -mcpu= over -march= if both are set (as for GCC); and we prefer
24105 -mfpu= over any other way of setting the floating point unit.
24106 Use of legacy options with new options are faulted. */
e74cfd16 24107 if (legacy_cpu)
404ff6b5 24108 {
e74cfd16 24109 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
24110 as_bad (_("use of old and new-style options to set CPU type"));
24111
24112 mcpu_cpu_opt = legacy_cpu;
404ff6b5 24113 }
e74cfd16 24114 else if (!mcpu_cpu_opt)
c19d1205 24115 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 24116
e74cfd16 24117 if (legacy_fpu)
c19d1205 24118 {
e74cfd16 24119 if (mfpu_opt)
c19d1205 24120 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
24121
24122 mfpu_opt = legacy_fpu;
24123 }
e74cfd16 24124 else if (!mfpu_opt)
03b1477f 24125 {
45eb4c1b
NS
24126#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
24127 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
24128 /* Some environments specify a default FPU. If they don't, infer it
24129 from the processor. */
e74cfd16 24130 if (mcpu_fpu_opt)
03b1477f
RE
24131 mfpu_opt = mcpu_fpu_opt;
24132 else
24133 mfpu_opt = march_fpu_opt;
39c2da32 24134#else
e74cfd16 24135 mfpu_opt = &fpu_default;
39c2da32 24136#endif
03b1477f
RE
24137 }
24138
e74cfd16 24139 if (!mfpu_opt)
03b1477f 24140 {
493cb6ef 24141 if (mcpu_cpu_opt != NULL)
e74cfd16 24142 mfpu_opt = &fpu_default;
493cb6ef 24143 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 24144 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 24145 else
e74cfd16 24146 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
24147 }
24148
ee065d83 24149#ifdef CPU_DEFAULT
e74cfd16 24150 if (!mcpu_cpu_opt)
ee065d83 24151 {
e74cfd16
PB
24152 mcpu_cpu_opt = &cpu_default;
24153 selected_cpu = cpu_default;
ee065d83 24154 }
73f43896
NC
24155 else if (no_cpu_selected ())
24156 selected_cpu = cpu_default;
e74cfd16
PB
24157#else
24158 if (mcpu_cpu_opt)
24159 selected_cpu = *mcpu_cpu_opt;
ee065d83 24160 else
e74cfd16 24161 mcpu_cpu_opt = &arm_arch_any;
ee065d83 24162#endif
03b1477f 24163
e74cfd16 24164 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 24165
3e9e4fcf
JB
24166 autoselect_thumb_from_cpu_variant ();
24167
e74cfd16 24168 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 24169
f17c130b 24170#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 24171 {
7cc69913
NC
24172 unsigned int flags = 0;
24173
24174#if defined OBJ_ELF
24175 flags = meabi_flags;
d507cf36
PB
24176
24177 switch (meabi_flags)
33a392fb 24178 {
d507cf36 24179 case EF_ARM_EABI_UNKNOWN:
7cc69913 24180#endif
d507cf36
PB
24181 /* Set the flags in the private structure. */
24182 if (uses_apcs_26) flags |= F_APCS26;
24183 if (support_interwork) flags |= F_INTERWORK;
24184 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 24185 if (pic_code) flags |= F_PIC;
e74cfd16 24186 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
24187 flags |= F_SOFT_FLOAT;
24188
d507cf36
PB
24189 switch (mfloat_abi_opt)
24190 {
24191 case ARM_FLOAT_ABI_SOFT:
24192 case ARM_FLOAT_ABI_SOFTFP:
24193 flags |= F_SOFT_FLOAT;
24194 break;
33a392fb 24195
d507cf36
PB
24196 case ARM_FLOAT_ABI_HARD:
24197 if (flags & F_SOFT_FLOAT)
24198 as_bad (_("hard-float conflicts with specified fpu"));
24199 break;
24200 }
03b1477f 24201
e74cfd16
PB
24202 /* Using pure-endian doubles (even if soft-float). */
24203 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 24204 flags |= F_VFP_FLOAT;
f17c130b 24205
fde78edd 24206#if defined OBJ_ELF
e74cfd16 24207 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 24208 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
24209 break;
24210
8cb51566 24211 case EF_ARM_EABI_VER4:
3a4a14e9 24212 case EF_ARM_EABI_VER5:
c19d1205 24213 /* No additional flags to set. */
d507cf36
PB
24214 break;
24215
24216 default:
24217 abort ();
24218 }
7cc69913 24219#endif
b99bd4ef
NC
24220 bfd_set_private_flags (stdoutput, flags);
24221
24222 /* We have run out flags in the COFF header to encode the
24223 status of ATPCS support, so instead we create a dummy,
c19d1205 24224 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
24225 if (atpcs)
24226 {
24227 asection * sec;
24228
24229 sec = bfd_make_section (stdoutput, ".arm.atpcs");
24230
24231 if (sec != NULL)
24232 {
24233 bfd_set_section_flags
24234 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
24235 bfd_set_section_size (stdoutput, sec, 0);
24236 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
24237 }
24238 }
7cc69913 24239 }
f17c130b 24240#endif
b99bd4ef
NC
24241
24242 /* Record the CPU type as well. */
2d447fca
JM
24243 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
24244 mach = bfd_mach_arm_iWMMXt2;
24245 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 24246 mach = bfd_mach_arm_iWMMXt;
e74cfd16 24247 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 24248 mach = bfd_mach_arm_XScale;
e74cfd16 24249 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 24250 mach = bfd_mach_arm_ep9312;
e74cfd16 24251 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 24252 mach = bfd_mach_arm_5TE;
e74cfd16 24253 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 24254 {
e74cfd16 24255 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
24256 mach = bfd_mach_arm_5T;
24257 else
24258 mach = bfd_mach_arm_5;
24259 }
e74cfd16 24260 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 24261 {
e74cfd16 24262 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
24263 mach = bfd_mach_arm_4T;
24264 else
24265 mach = bfd_mach_arm_4;
24266 }
e74cfd16 24267 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 24268 mach = bfd_mach_arm_3M;
e74cfd16
PB
24269 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
24270 mach = bfd_mach_arm_3;
24271 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
24272 mach = bfd_mach_arm_2a;
24273 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
24274 mach = bfd_mach_arm_2;
24275 else
24276 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
24277
24278 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
24279}
24280
c19d1205 24281/* Command line processing. */
b99bd4ef 24282
c19d1205
ZW
24283/* md_parse_option
24284 Invocation line includes a switch not recognized by the base assembler.
24285 See if it's a processor-specific option.
b99bd4ef 24286
c19d1205
ZW
24287 This routine is somewhat complicated by the need for backwards
24288 compatibility (since older releases of gcc can't be changed).
24289 The new options try to make the interface as compatible as
24290 possible with GCC.
b99bd4ef 24291
c19d1205 24292 New options (supported) are:
b99bd4ef 24293
c19d1205
ZW
24294 -mcpu=<cpu name> Assemble for selected processor
24295 -march=<architecture name> Assemble for selected architecture
24296 -mfpu=<fpu architecture> Assemble for selected FPU.
24297 -EB/-mbig-endian Big-endian
24298 -EL/-mlittle-endian Little-endian
24299 -k Generate PIC code
24300 -mthumb Start in Thumb mode
24301 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 24302
278df34e 24303 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 24304 -m[no-]warn-syms Warn when symbols match instructions
267bf995 24305
c19d1205 24306 For now we will also provide support for:
b99bd4ef 24307
c19d1205
ZW
24308 -mapcs-32 32-bit Program counter
24309 -mapcs-26 26-bit Program counter
24310 -macps-float Floats passed in FP registers
24311 -mapcs-reentrant Reentrant code
24312 -matpcs
24313 (sometime these will probably be replaced with -mapcs=<list of options>
24314 and -matpcs=<list of options>)
b99bd4ef 24315
c19d1205
ZW
24316 The remaining options are only supported for back-wards compatibility.
24317 Cpu variants, the arm part is optional:
24318 -m[arm]1 Currently not supported.
24319 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
24320 -m[arm]3 Arm 3 processor
24321 -m[arm]6[xx], Arm 6 processors
24322 -m[arm]7[xx][t][[d]m] Arm 7 processors
24323 -m[arm]8[10] Arm 8 processors
24324 -m[arm]9[20][tdmi] Arm 9 processors
24325 -mstrongarm[110[0]] StrongARM processors
24326 -mxscale XScale processors
24327 -m[arm]v[2345[t[e]]] Arm architectures
24328 -mall All (except the ARM1)
24329 FP variants:
24330 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
24331 -mfpe-old (No float load/store multiples)
24332 -mvfpxd VFP Single precision
24333 -mvfp All VFP
24334 -mno-fpu Disable all floating point instructions
b99bd4ef 24335
c19d1205
ZW
24336 The following CPU names are recognized:
24337 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
24338 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
24339 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
24340 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
24341 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
24342 arm10t arm10e, arm1020t, arm1020e, arm10200e,
24343 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 24344
c19d1205 24345 */
b99bd4ef 24346
c19d1205 24347const char * md_shortopts = "m:k";
b99bd4ef 24348
c19d1205
ZW
24349#ifdef ARM_BI_ENDIAN
24350#define OPTION_EB (OPTION_MD_BASE + 0)
24351#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 24352#else
c19d1205
ZW
24353#if TARGET_BYTES_BIG_ENDIAN
24354#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 24355#else
c19d1205
ZW
24356#define OPTION_EL (OPTION_MD_BASE + 1)
24357#endif
b99bd4ef 24358#endif
845b51d6 24359#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 24360
c19d1205 24361struct option md_longopts[] =
b99bd4ef 24362{
c19d1205
ZW
24363#ifdef OPTION_EB
24364 {"EB", no_argument, NULL, OPTION_EB},
24365#endif
24366#ifdef OPTION_EL
24367 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 24368#endif
845b51d6 24369 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
24370 {NULL, no_argument, NULL, 0}
24371};
b99bd4ef 24372
8b2d793c 24373
c19d1205 24374size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 24375
c19d1205 24376struct arm_option_table
b99bd4ef 24377{
c19d1205
ZW
24378 char *option; /* Option name to match. */
24379 char *help; /* Help information. */
24380 int *var; /* Variable to change. */
24381 int value; /* What to change it to. */
24382 char *deprecated; /* If non-null, print this message. */
24383};
b99bd4ef 24384
c19d1205
ZW
24385struct arm_option_table arm_opts[] =
24386{
24387 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
24388 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
24389 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
24390 &support_interwork, 1, NULL},
24391 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
24392 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
24393 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
24394 1, NULL},
24395 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
24396 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
24397 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
24398 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
24399 NULL},
b99bd4ef 24400
c19d1205
ZW
24401 /* These are recognized by the assembler, but have no affect on code. */
24402 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
24403 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
24404
24405 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
24406 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
24407 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
24408 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
24409 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
24410 {NULL, NULL, NULL, 0, NULL}
24411};
24412
24413struct arm_legacy_option_table
24414{
24415 char *option; /* Option name to match. */
24416 const arm_feature_set **var; /* Variable to change. */
24417 const arm_feature_set value; /* What to change it to. */
24418 char *deprecated; /* If non-null, print this message. */
24419};
b99bd4ef 24420
e74cfd16
PB
24421const struct arm_legacy_option_table arm_legacy_opts[] =
24422{
c19d1205
ZW
24423 /* DON'T add any new processors to this list -- we want the whole list
24424 to go away... Add them to the processors table instead. */
e74cfd16
PB
24425 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
24426 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
24427 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
24428 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
24429 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
24430 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
24431 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
24432 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
24433 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
24434 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
24435 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
24436 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
24437 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
24438 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
24439 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
24440 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
24441 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
24442 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
24443 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
24444 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
24445 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
24446 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
24447 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
24448 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
24449 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
24450 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
24451 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
24452 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
24453 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
24454 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
24455 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
24456 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
24457 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
24458 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
24459 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
24460 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
24461 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
24462 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
24463 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
24464 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
24465 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
24466 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
24467 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
24468 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
24469 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
24470 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
24471 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
24472 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
24473 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
24474 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
24475 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
24476 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
24477 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
24478 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
24479 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
24480 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
24481 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
24482 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
24483 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
24484 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
24485 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
24486 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
24487 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
24488 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
24489 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
24490 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
24491 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
24492 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
24493 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
24494 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 24495 N_("use -mcpu=strongarm110")},
e74cfd16 24496 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 24497 N_("use -mcpu=strongarm1100")},
e74cfd16 24498 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 24499 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
24500 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
24501 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
24502 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 24503
c19d1205 24504 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
24505 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
24506 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
24507 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
24508 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
24509 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
24510 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
24511 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
24512 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
24513 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
24514 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
24515 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
24516 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
24517 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
24518 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
24519 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
24520 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
24521 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
24522 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 24523
c19d1205 24524 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
24525 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
24526 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
24527 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
24528 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 24529 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 24530
e74cfd16 24531 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 24532};
7ed4c4c5 24533
c19d1205 24534struct arm_cpu_option_table
7ed4c4c5 24535{
c19d1205 24536 char *name;
f3bad469 24537 size_t name_len;
e74cfd16 24538 const arm_feature_set value;
c19d1205
ZW
24539 /* For some CPUs we assume an FPU unless the user explicitly sets
24540 -mfpu=... */
e74cfd16 24541 const arm_feature_set default_fpu;
ee065d83
PB
24542 /* The canonical name of the CPU, or NULL to use NAME converted to upper
24543 case. */
24544 const char *canonical_name;
c19d1205 24545};
7ed4c4c5 24546
c19d1205
ZW
24547/* This list should, at a minimum, contain all the cpu names
24548 recognized by GCC. */
f3bad469 24549#define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
e74cfd16 24550static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 24551{
f3bad469
MGD
24552 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
24553 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
24554 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
24555 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
24556 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
24557 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24558 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24559 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24560 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24561 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24562 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24563 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
24564 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24565 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
24566 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24567 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
24568 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24569 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24570 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24571 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24572 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24573 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24574 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24575 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24576 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24577 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24578 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24579 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
24580 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24581 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24582 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24583 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24584 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24585 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24586 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24587 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24588 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24589 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24590 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24591 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
24592 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24593 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24594 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24595 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
24596 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
24597 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
c19d1205
ZW
24598 /* For V5 or later processors we default to using VFP; but the user
24599 should really set the FPU type explicitly. */
f3bad469
MGD
24600 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
24601 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24602 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
24603 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
24604 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
24605 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
24606 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
24607 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24608 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
24609 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
24610 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24611 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24612 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
24613 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
24614 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24615 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
24616 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
24617 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24618 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24619 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
24620 "ARM1026EJ-S"),
24621 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
24622 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24623 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24624 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24625 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24626 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
24627 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
24628 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
24629 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
24630 "ARM1136JF-S"),
24631 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
24632 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
24633 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
24634 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
24635 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
24636 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL),
24637 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL),
24638 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
24639 FPU_NONE, "Cortex-A5"),
c9fb6e58 24640 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469
MGD
24641 "Cortex-A7"),
24642 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
823d2571 24643 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 24644 | FPU_NEON_EXT_V1),
f3bad469
MGD
24645 "Cortex-A8"),
24646 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
823d2571 24647 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 24648 | FPU_NEON_EXT_V1),
f3bad469 24649 "Cortex-A9"),
c9fb6e58 24650 ARM_CPU_OPT ("cortex-a12", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
63a4bc21 24651 "Cortex-A12"),
c9fb6e58 24652 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469 24653 "Cortex-A15"),
d7adf960
KT
24654 ARM_CPU_OPT ("cortex-a17", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
24655 "Cortex-A17"),
92eb40d9 24656 ARM_CPU_OPT ("cortex-a53", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 24657 "Cortex-A53"),
92eb40d9 24658 ARM_CPU_OPT ("cortex-a57", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 24659 "Cortex-A57"),
b19f47ad
JW
24660 ARM_CPU_OPT ("cortex-a72", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24661 "Cortex-A72"),
f3bad469
MGD
24662 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
24663 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
24664 "Cortex-R4F"),
24665 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
24666 FPU_NONE, "Cortex-R5"),
70a8bc5b 24667 ARM_CPU_OPT ("cortex-r7", ARM_ARCH_V7R_IDIV,
24668 FPU_ARCH_VFP_V3D16,
24669 "Cortex-R7"),
a715796b 24670 ARM_CPU_OPT ("cortex-m7", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M7"),
f3bad469
MGD
24671 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
24672 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
24673 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
24674 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
ce32bd10 24675 ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"),
246496bb
EM
24676 ARM_CPU_OPT ("exynos-m1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24677 "Samsung " \
24678 "Exynos M1"),
c19d1205 24679 /* ??? XSCALE is really an architecture. */
f3bad469 24680 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 24681 /* ??? iwmmxt is not a processor. */
f3bad469
MGD
24682 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
24683 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
24684 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 24685 /* Maverick */
823d2571 24686 ARM_CPU_OPT ("ep9312", ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
da4339ed
NC
24687 FPU_ARCH_MAVERICK, "ARM920T"),
24688 /* Marvell processors. */
823d2571
TG
24689 ARM_CPU_OPT ("marvell-pj4", ARM_FEATURE_CORE_LOW (ARM_AEXT_V7A | ARM_EXT_MP
24690 | ARM_EXT_SEC),
477330fc 24691 FPU_ARCH_VFP_V3D16, NULL),
823d2571
TG
24692 ARM_CPU_OPT ("marvell-whitney", ARM_FEATURE_CORE_LOW (ARM_AEXT_V7A | ARM_EXT_MP
24693 | ARM_EXT_SEC),
4347085a 24694 FPU_ARCH_NEON_VFP_V4, NULL),
ea0d6bb9
PT
24695 /* APM X-Gene family. */
24696 ARM_CPU_OPT ("xgene1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24697 "APM X-Gene 1"),
24698 ARM_CPU_OPT ("xgene2", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
24699 "APM X-Gene 2"),
da4339ed 24700
f3bad469 24701 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 24702};
f3bad469 24703#undef ARM_CPU_OPT
7ed4c4c5 24704
c19d1205 24705struct arm_arch_option_table
7ed4c4c5 24706{
c19d1205 24707 char *name;
f3bad469 24708 size_t name_len;
e74cfd16
PB
24709 const arm_feature_set value;
24710 const arm_feature_set default_fpu;
c19d1205 24711};
7ed4c4c5 24712
c19d1205
ZW
24713/* This list should, at a minimum, contain all the architecture names
24714 recognized by GCC. */
f3bad469 24715#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
e74cfd16 24716static const struct arm_arch_option_table arm_archs[] =
c19d1205 24717{
f3bad469
MGD
24718 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
24719 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
24720 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
24721 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
24722 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
24723 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
24724 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
24725 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
24726 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
24727 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
24728 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
24729 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
24730 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
24731 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
24732 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
24733 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
24734 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
24735 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
24736 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
24737 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
24738 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
24739 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP),
24740 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
24741 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
24742 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
24743 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP),
24744 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
24745 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
24746 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
24747 /* The official spelling of the ARMv7 profile variants is the dashed form.
24748 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 24749 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 24750 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
24751 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
24752 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
24753 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
24754 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
24755 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
24756 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
bca38921 24757 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
a5932920 24758 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
f3bad469
MGD
24759 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
24760 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
24761 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
24762 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 24763};
f3bad469 24764#undef ARM_ARCH_OPT
7ed4c4c5 24765
69133863
MGD
24766/* ISA extensions in the co-processor and main instruction set space. */
24767struct arm_option_extension_value_table
c19d1205
ZW
24768{
24769 char *name;
f3bad469 24770 size_t name_len;
5a70a223
JB
24771 const arm_feature_set merge_value;
24772 const arm_feature_set clear_value;
69133863 24773 const arm_feature_set allowed_archs;
c19d1205 24774};
7ed4c4c5 24775
69133863
MGD
24776/* The following table must be in alphabetical order with a NULL last entry.
24777 */
5a70a223 24778#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, AA }
69133863 24779static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 24780{
823d2571
TG
24781 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
24782 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 24783 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
24784 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
24785 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
24786 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
24787 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
24788 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
24789 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
24790 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A | ARM_EXT_V7R)),
24791 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
24792 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ANY),
24793 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
24794 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ANY),
24795 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
24796 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ANY),
24797 ARM_EXT_OPT ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
24798 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
24799 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A | ARM_EXT_V7R)),
bca38921 24800 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
823d2571
TG
24801 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
24802 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
24803 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
24804 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
24805 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
24806 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
24807 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
24808 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
24809 ARM_EXT_OPT ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
24810 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
24811 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V7A)),
24812 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
24813 | ARM_EXT_DIV),
24814 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
24815 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
d6b4b13e
MW
24816 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8,
24817 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
24818 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
24819 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
24820 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ANY),
5a70a223 24821 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE }
69133863 24822};
f3bad469 24823#undef ARM_EXT_OPT
69133863
MGD
24824
24825/* ISA floating-point and Advanced SIMD extensions. */
24826struct arm_option_fpu_value_table
24827{
24828 char *name;
24829 const arm_feature_set value;
c19d1205 24830};
7ed4c4c5 24831
c19d1205
ZW
24832/* This list should, at a minimum, contain all the fpu names
24833 recognized by GCC. */
69133863 24834static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
24835{
24836 {"softfpa", FPU_NONE},
24837 {"fpe", FPU_ARCH_FPE},
24838 {"fpe2", FPU_ARCH_FPE},
24839 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
24840 {"fpa", FPU_ARCH_FPA},
24841 {"fpa10", FPU_ARCH_FPA},
24842 {"fpa11", FPU_ARCH_FPA},
24843 {"arm7500fe", FPU_ARCH_FPA},
24844 {"softvfp", FPU_ARCH_VFP},
24845 {"softvfp+vfp", FPU_ARCH_VFP_V2},
24846 {"vfp", FPU_ARCH_VFP_V2},
24847 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 24848 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
24849 {"vfp10", FPU_ARCH_VFP_V2},
24850 {"vfp10-r0", FPU_ARCH_VFP_V1},
24851 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
24852 {"vfpv2", FPU_ARCH_VFP_V2},
24853 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 24854 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 24855 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
24856 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
24857 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
24858 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
24859 {"arm1020t", FPU_ARCH_VFP_V1},
24860 {"arm1020e", FPU_ARCH_VFP_V2},
24861 {"arm1136jfs", FPU_ARCH_VFP_V2},
24862 {"arm1136jf-s", FPU_ARCH_VFP_V2},
24863 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 24864 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 24865 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
24866 {"vfpv4", FPU_ARCH_VFP_V4},
24867 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 24868 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
24869 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
24870 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 24871 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
24872 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
24873 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
24874 {"crypto-neon-fp-armv8",
24875 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 24876 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
e74cfd16
PB
24877 {NULL, ARM_ARCH_NONE}
24878};
24879
24880struct arm_option_value_table
24881{
24882 char *name;
24883 long value;
c19d1205 24884};
7ed4c4c5 24885
e74cfd16 24886static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
24887{
24888 {"hard", ARM_FLOAT_ABI_HARD},
24889 {"softfp", ARM_FLOAT_ABI_SOFTFP},
24890 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 24891 {NULL, 0}
c19d1205 24892};
7ed4c4c5 24893
c19d1205 24894#ifdef OBJ_ELF
3a4a14e9 24895/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 24896static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
24897{
24898 {"gnu", EF_ARM_EABI_UNKNOWN},
24899 {"4", EF_ARM_EABI_VER4},
3a4a14e9 24900 {"5", EF_ARM_EABI_VER5},
e74cfd16 24901 {NULL, 0}
c19d1205
ZW
24902};
24903#endif
7ed4c4c5 24904
c19d1205
ZW
24905struct arm_long_option_table
24906{
24907 char * option; /* Substring to match. */
24908 char * help; /* Help information. */
24909 int (* func) (char * subopt); /* Function to decode sub-option. */
24910 char * deprecated; /* If non-null, print this message. */
24911};
7ed4c4c5 24912
c921be7d 24913static bfd_boolean
f3bad469 24914arm_parse_extension (char *str, const arm_feature_set **opt_p)
7ed4c4c5 24915{
21d799b5
NC
24916 arm_feature_set *ext_set = (arm_feature_set *)
24917 xmalloc (sizeof (arm_feature_set));
e74cfd16 24918
69133863 24919 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
24920 extensions being added before being removed. We achieve this by having
24921 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 24922 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 24923 or removing it (0) and only allowing it to change in the order
69133863
MGD
24924 -1 -> 1 -> 0. */
24925 const struct arm_option_extension_value_table * opt = NULL;
24926 int adding_value = -1;
24927
e74cfd16
PB
24928 /* Copy the feature set, so that we can modify it. */
24929 *ext_set = **opt_p;
24930 *opt_p = ext_set;
24931
c19d1205 24932 while (str != NULL && *str != 0)
7ed4c4c5 24933 {
f3bad469
MGD
24934 char *ext;
24935 size_t len;
7ed4c4c5 24936
c19d1205
ZW
24937 if (*str != '+')
24938 {
24939 as_bad (_("invalid architectural extension"));
c921be7d 24940 return FALSE;
c19d1205 24941 }
7ed4c4c5 24942
c19d1205
ZW
24943 str++;
24944 ext = strchr (str, '+');
7ed4c4c5 24945
c19d1205 24946 if (ext != NULL)
f3bad469 24947 len = ext - str;
c19d1205 24948 else
f3bad469 24949 len = strlen (str);
7ed4c4c5 24950
f3bad469 24951 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
24952 {
24953 if (adding_value != 0)
24954 {
24955 adding_value = 0;
24956 opt = arm_extensions;
24957 }
24958
f3bad469 24959 len -= 2;
69133863
MGD
24960 str += 2;
24961 }
f3bad469 24962 else if (len > 0)
69133863
MGD
24963 {
24964 if (adding_value == -1)
24965 {
24966 adding_value = 1;
24967 opt = arm_extensions;
24968 }
24969 else if (adding_value != 1)
24970 {
24971 as_bad (_("must specify extensions to add before specifying "
24972 "those to remove"));
24973 return FALSE;
24974 }
24975 }
24976
f3bad469 24977 if (len == 0)
c19d1205
ZW
24978 {
24979 as_bad (_("missing architectural extension"));
c921be7d 24980 return FALSE;
c19d1205 24981 }
7ed4c4c5 24982
69133863
MGD
24983 gas_assert (adding_value != -1);
24984 gas_assert (opt != NULL);
24985
24986 /* Scan over the options table trying to find an exact match. */
24987 for (; opt->name != NULL; opt++)
f3bad469 24988 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 24989 {
69133863
MGD
24990 /* Check we can apply the extension to this architecture. */
24991 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
24992 {
24993 as_bad (_("extension does not apply to the base architecture"));
24994 return FALSE;
24995 }
24996
24997 /* Add or remove the extension. */
24998 if (adding_value)
5a70a223 24999 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 25000 else
5a70a223 25001 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 25002
c19d1205
ZW
25003 break;
25004 }
7ed4c4c5 25005
c19d1205
ZW
25006 if (opt->name == NULL)
25007 {
69133863
MGD
25008 /* Did we fail to find an extension because it wasn't specified in
25009 alphabetical order, or because it does not exist? */
25010
25011 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 25012 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
25013 break;
25014
25015 if (opt->name == NULL)
25016 as_bad (_("unknown architectural extension `%s'"), str);
25017 else
25018 as_bad (_("architectural extensions must be specified in "
25019 "alphabetical order"));
25020
c921be7d 25021 return FALSE;
c19d1205 25022 }
69133863
MGD
25023 else
25024 {
25025 /* We should skip the extension we've just matched the next time
25026 round. */
25027 opt++;
25028 }
7ed4c4c5 25029
c19d1205
ZW
25030 str = ext;
25031 };
7ed4c4c5 25032
c921be7d 25033 return TRUE;
c19d1205 25034}
7ed4c4c5 25035
c921be7d 25036static bfd_boolean
f3bad469 25037arm_parse_cpu (char *str)
7ed4c4c5 25038{
f3bad469
MGD
25039 const struct arm_cpu_option_table *opt;
25040 char *ext = strchr (str, '+');
25041 size_t len;
7ed4c4c5 25042
c19d1205 25043 if (ext != NULL)
f3bad469 25044 len = ext - str;
7ed4c4c5 25045 else
f3bad469 25046 len = strlen (str);
7ed4c4c5 25047
f3bad469 25048 if (len == 0)
7ed4c4c5 25049 {
c19d1205 25050 as_bad (_("missing cpu name `%s'"), str);
c921be7d 25051 return FALSE;
7ed4c4c5
NC
25052 }
25053
c19d1205 25054 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 25055 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25056 {
e74cfd16
PB
25057 mcpu_cpu_opt = &opt->value;
25058 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 25059 if (opt->canonical_name)
5f4273c7 25060 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
25061 else
25062 {
f3bad469 25063 size_t i;
c921be7d 25064
f3bad469 25065 for (i = 0; i < len; i++)
ee065d83
PB
25066 selected_cpu_name[i] = TOUPPER (opt->name[i]);
25067 selected_cpu_name[i] = 0;
25068 }
7ed4c4c5 25069
c19d1205
ZW
25070 if (ext != NULL)
25071 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 25072
c921be7d 25073 return TRUE;
c19d1205 25074 }
7ed4c4c5 25075
c19d1205 25076 as_bad (_("unknown cpu `%s'"), str);
c921be7d 25077 return FALSE;
7ed4c4c5
NC
25078}
25079
c921be7d 25080static bfd_boolean
f3bad469 25081arm_parse_arch (char *str)
7ed4c4c5 25082{
e74cfd16 25083 const struct arm_arch_option_table *opt;
c19d1205 25084 char *ext = strchr (str, '+');
f3bad469 25085 size_t len;
7ed4c4c5 25086
c19d1205 25087 if (ext != NULL)
f3bad469 25088 len = ext - str;
7ed4c4c5 25089 else
f3bad469 25090 len = strlen (str);
7ed4c4c5 25091
f3bad469 25092 if (len == 0)
7ed4c4c5 25093 {
c19d1205 25094 as_bad (_("missing architecture name `%s'"), str);
c921be7d 25095 return FALSE;
7ed4c4c5
NC
25096 }
25097
c19d1205 25098 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 25099 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25100 {
e74cfd16
PB
25101 march_cpu_opt = &opt->value;
25102 march_fpu_opt = &opt->default_fpu;
5f4273c7 25103 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 25104
c19d1205
ZW
25105 if (ext != NULL)
25106 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 25107
c921be7d 25108 return TRUE;
c19d1205
ZW
25109 }
25110
25111 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 25112 return FALSE;
7ed4c4c5 25113}
eb043451 25114
c921be7d 25115static bfd_boolean
c19d1205
ZW
25116arm_parse_fpu (char * str)
25117{
69133863 25118 const struct arm_option_fpu_value_table * opt;
b99bd4ef 25119
c19d1205
ZW
25120 for (opt = arm_fpus; opt->name != NULL; opt++)
25121 if (streq (opt->name, str))
25122 {
e74cfd16 25123 mfpu_opt = &opt->value;
c921be7d 25124 return TRUE;
c19d1205 25125 }
b99bd4ef 25126
c19d1205 25127 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 25128 return FALSE;
c19d1205
ZW
25129}
25130
c921be7d 25131static bfd_boolean
c19d1205 25132arm_parse_float_abi (char * str)
b99bd4ef 25133{
e74cfd16 25134 const struct arm_option_value_table * opt;
b99bd4ef 25135
c19d1205
ZW
25136 for (opt = arm_float_abis; opt->name != NULL; opt++)
25137 if (streq (opt->name, str))
25138 {
25139 mfloat_abi_opt = opt->value;
c921be7d 25140 return TRUE;
c19d1205 25141 }
cc8a6dd0 25142
c19d1205 25143 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 25144 return FALSE;
c19d1205 25145}
b99bd4ef 25146
c19d1205 25147#ifdef OBJ_ELF
c921be7d 25148static bfd_boolean
c19d1205
ZW
25149arm_parse_eabi (char * str)
25150{
e74cfd16 25151 const struct arm_option_value_table *opt;
cc8a6dd0 25152
c19d1205
ZW
25153 for (opt = arm_eabis; opt->name != NULL; opt++)
25154 if (streq (opt->name, str))
25155 {
25156 meabi_flags = opt->value;
c921be7d 25157 return TRUE;
c19d1205
ZW
25158 }
25159 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 25160 return FALSE;
c19d1205
ZW
25161}
25162#endif
cc8a6dd0 25163
c921be7d 25164static bfd_boolean
e07e6e58
NC
25165arm_parse_it_mode (char * str)
25166{
c921be7d 25167 bfd_boolean ret = TRUE;
e07e6e58
NC
25168
25169 if (streq ("arm", str))
25170 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
25171 else if (streq ("thumb", str))
25172 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
25173 else if (streq ("always", str))
25174 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
25175 else if (streq ("never", str))
25176 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
25177 else
25178 {
25179 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 25180 "arm, thumb, always, or never."), str);
c921be7d 25181 ret = FALSE;
e07e6e58
NC
25182 }
25183
25184 return ret;
25185}
25186
2e6976a8
DG
25187static bfd_boolean
25188arm_ccs_mode (char * unused ATTRIBUTE_UNUSED)
25189{
25190 codecomposer_syntax = TRUE;
25191 arm_comment_chars[0] = ';';
25192 arm_line_separator_chars[0] = 0;
25193 return TRUE;
25194}
25195
c19d1205
ZW
25196struct arm_long_option_table arm_long_opts[] =
25197{
25198 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
25199 arm_parse_cpu, NULL},
25200 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
25201 arm_parse_arch, NULL},
25202 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
25203 arm_parse_fpu, NULL},
25204 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
25205 arm_parse_float_abi, NULL},
25206#ifdef OBJ_ELF
7fac0536 25207 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
25208 arm_parse_eabi, NULL},
25209#endif
e07e6e58
NC
25210 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
25211 arm_parse_it_mode, NULL},
2e6976a8
DG
25212 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
25213 arm_ccs_mode, NULL},
c19d1205
ZW
25214 {NULL, NULL, 0, NULL}
25215};
cc8a6dd0 25216
c19d1205
ZW
25217int
25218md_parse_option (int c, char * arg)
25219{
25220 struct arm_option_table *opt;
e74cfd16 25221 const struct arm_legacy_option_table *fopt;
c19d1205 25222 struct arm_long_option_table *lopt;
b99bd4ef 25223
c19d1205 25224 switch (c)
b99bd4ef 25225 {
c19d1205
ZW
25226#ifdef OPTION_EB
25227 case OPTION_EB:
25228 target_big_endian = 1;
25229 break;
25230#endif
cc8a6dd0 25231
c19d1205
ZW
25232#ifdef OPTION_EL
25233 case OPTION_EL:
25234 target_big_endian = 0;
25235 break;
25236#endif
b99bd4ef 25237
845b51d6
PB
25238 case OPTION_FIX_V4BX:
25239 fix_v4bx = TRUE;
25240 break;
25241
c19d1205
ZW
25242 case 'a':
25243 /* Listing option. Just ignore these, we don't support additional
25244 ones. */
25245 return 0;
b99bd4ef 25246
c19d1205
ZW
25247 default:
25248 for (opt = arm_opts; opt->option != NULL; opt++)
25249 {
25250 if (c == opt->option[0]
25251 && ((arg == NULL && opt->option[1] == 0)
25252 || streq (arg, opt->option + 1)))
25253 {
c19d1205 25254 /* If the option is deprecated, tell the user. */
278df34e 25255 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
25256 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
25257 arg ? arg : "", _(opt->deprecated));
b99bd4ef 25258
c19d1205
ZW
25259 if (opt->var != NULL)
25260 *opt->var = opt->value;
cc8a6dd0 25261
c19d1205
ZW
25262 return 1;
25263 }
25264 }
b99bd4ef 25265
e74cfd16
PB
25266 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
25267 {
25268 if (c == fopt->option[0]
25269 && ((arg == NULL && fopt->option[1] == 0)
25270 || streq (arg, fopt->option + 1)))
25271 {
e74cfd16 25272 /* If the option is deprecated, tell the user. */
278df34e 25273 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
25274 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
25275 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
25276
25277 if (fopt->var != NULL)
25278 *fopt->var = &fopt->value;
25279
25280 return 1;
25281 }
25282 }
25283
c19d1205
ZW
25284 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
25285 {
25286 /* These options are expected to have an argument. */
25287 if (c == lopt->option[0]
25288 && arg != NULL
25289 && strncmp (arg, lopt->option + 1,
25290 strlen (lopt->option + 1)) == 0)
25291 {
c19d1205 25292 /* If the option is deprecated, tell the user. */
278df34e 25293 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
25294 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
25295 _(lopt->deprecated));
b99bd4ef 25296
c19d1205
ZW
25297 /* Call the sup-option parser. */
25298 return lopt->func (arg + strlen (lopt->option) - 1);
25299 }
25300 }
a737bd4d 25301
c19d1205
ZW
25302 return 0;
25303 }
a394c00f 25304
c19d1205
ZW
25305 return 1;
25306}
a394c00f 25307
c19d1205
ZW
25308void
25309md_show_usage (FILE * fp)
a394c00f 25310{
c19d1205
ZW
25311 struct arm_option_table *opt;
25312 struct arm_long_option_table *lopt;
a394c00f 25313
c19d1205 25314 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 25315
c19d1205
ZW
25316 for (opt = arm_opts; opt->option != NULL; opt++)
25317 if (opt->help != NULL)
25318 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 25319
c19d1205
ZW
25320 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
25321 if (lopt->help != NULL)
25322 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 25323
c19d1205
ZW
25324#ifdef OPTION_EB
25325 fprintf (fp, _("\
25326 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
25327#endif
25328
c19d1205
ZW
25329#ifdef OPTION_EL
25330 fprintf (fp, _("\
25331 -EL assemble code for a little-endian cpu\n"));
a737bd4d 25332#endif
845b51d6
PB
25333
25334 fprintf (fp, _("\
25335 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 25336}
ee065d83
PB
25337
25338
25339#ifdef OBJ_ELF
62b3e311
PB
25340typedef struct
25341{
25342 int val;
25343 arm_feature_set flags;
25344} cpu_arch_ver_table;
25345
25346/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
25347 least features first. */
25348static const cpu_arch_ver_table cpu_arch_ver[] =
25349{
25350 {1, ARM_ARCH_V4},
25351 {2, ARM_ARCH_V4T},
25352 {3, ARM_ARCH_V5},
ee3c0378 25353 {3, ARM_ARCH_V5T},
62b3e311
PB
25354 {4, ARM_ARCH_V5TE},
25355 {5, ARM_ARCH_V5TEJ},
25356 {6, ARM_ARCH_V6},
7e806470 25357 {9, ARM_ARCH_V6K},
f4c65163 25358 {7, ARM_ARCH_V6Z},
91e22acd 25359 {11, ARM_ARCH_V6M},
b2a5fbdc 25360 {12, ARM_ARCH_V6SM},
7e806470 25361 {8, ARM_ARCH_V6T2},
c9fb6e58 25362 {10, ARM_ARCH_V7VE},
62b3e311
PB
25363 {10, ARM_ARCH_V7R},
25364 {10, ARM_ARCH_V7M},
bca38921 25365 {14, ARM_ARCH_V8A},
62b3e311
PB
25366 {0, ARM_ARCH_NONE}
25367};
25368
ee3c0378
AS
25369/* Set an attribute if it has not already been set by the user. */
25370static void
25371aeabi_set_attribute_int (int tag, int value)
25372{
25373 if (tag < 1
25374 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
25375 || !attributes_set_explicitly[tag])
25376 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
25377}
25378
25379static void
25380aeabi_set_attribute_string (int tag, const char *value)
25381{
25382 if (tag < 1
25383 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
25384 || !attributes_set_explicitly[tag])
25385 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
25386}
25387
ee065d83 25388/* Set the public EABI object attributes. */
3cfdb781 25389void
ee065d83
PB
25390aeabi_set_public_attributes (void)
25391{
25392 int arch;
69239280 25393 char profile;
90ec0d68 25394 int virt_sec = 0;
bca38921 25395 int fp16_optional = 0;
e74cfd16 25396 arm_feature_set flags;
62b3e311
PB
25397 arm_feature_set tmp;
25398 const cpu_arch_ver_table *p;
ee065d83
PB
25399
25400 /* Choose the architecture based on the capabilities of the requested cpu
25401 (if any) and/or the instructions actually used. */
e74cfd16
PB
25402 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
25403 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
25404 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
ddd7f988
RE
25405
25406 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
25407 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
25408
25409 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
25410 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
25411
7f78eb34
JW
25412 selected_cpu = flags;
25413
ddd7f988 25414 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
25415 if (object_arch)
25416 {
25417 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
25418 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
25419 }
25420
251665fc
MGD
25421 /* We need to make sure that the attributes do not identify us as v6S-M
25422 when the only v6S-M feature in use is the Operating System Extensions. */
25423 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
25424 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
477330fc 25425 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
251665fc 25426
62b3e311
PB
25427 tmp = flags;
25428 arch = 0;
25429 for (p = cpu_arch_ver; p->val; p++)
25430 {
25431 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
25432 {
25433 arch = p->val;
25434 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
25435 }
25436 }
ee065d83 25437
9e3c6df6
PB
25438 /* The table lookup above finds the last architecture to contribute
25439 a new feature. Unfortunately, Tag13 is a subset of the union of
25440 v6T2 and v7-M, so it is never seen as contributing a new feature.
25441 We can not search for the last entry which is entirely used,
25442 because if no CPU is specified we build up only those flags
25443 actually used. Perhaps we should separate out the specified
25444 and implicit cases. Avoid taking this path for -march=all by
25445 checking for contradictory v7-A / v7-M features. */
25446 if (arch == 10
25447 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
25448 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
25449 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
25450 arch = 13;
25451
ee065d83
PB
25452 /* Tag_CPU_name. */
25453 if (selected_cpu_name[0])
25454 {
91d6fa6a 25455 char *q;
ee065d83 25456
91d6fa6a
NC
25457 q = selected_cpu_name;
25458 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
25459 {
25460 int i;
5f4273c7 25461
91d6fa6a
NC
25462 q += 4;
25463 for (i = 0; q[i]; i++)
25464 q[i] = TOUPPER (q[i]);
ee065d83 25465 }
91d6fa6a 25466 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 25467 }
62f3b8c8 25468
ee065d83 25469 /* Tag_CPU_arch. */
ee3c0378 25470 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 25471
62b3e311
PB
25472 /* Tag_CPU_arch_profile. */
25473 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
69239280 25474 profile = 'A';
62b3e311 25475 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
69239280 25476 profile = 'R';
7e806470 25477 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
69239280
MGD
25478 profile = 'M';
25479 else
25480 profile = '\0';
25481
25482 if (profile != '\0')
25483 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 25484
ee065d83 25485 /* Tag_ARM_ISA_use. */
ee3c0378
AS
25486 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
25487 || arch == 0)
25488 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 25489
ee065d83 25490 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
25491 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
25492 || arch == 0)
25493 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
25494 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
62f3b8c8 25495
ee065d83 25496 /* Tag_VFP_arch. */
a715796b
TG
25497 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
25498 aeabi_set_attribute_int (Tag_VFP_arch,
25499 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
25500 ? 7 : 8);
bca38921 25501 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
25502 aeabi_set_attribute_int (Tag_VFP_arch,
25503 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
25504 ? 5 : 6);
25505 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
25506 {
25507 fp16_optional = 1;
25508 aeabi_set_attribute_int (Tag_VFP_arch, 3);
25509 }
ada65aa3 25510 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
25511 {
25512 aeabi_set_attribute_int (Tag_VFP_arch, 4);
25513 fp16_optional = 1;
25514 }
ee3c0378
AS
25515 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
25516 aeabi_set_attribute_int (Tag_VFP_arch, 2);
25517 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 25518 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 25519 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 25520
4547cb56
NC
25521 /* Tag_ABI_HardFP_use. */
25522 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
25523 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
25524 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
25525
ee065d83 25526 /* Tag_WMMX_arch. */
ee3c0378
AS
25527 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
25528 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
25529 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
25530 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 25531
ee3c0378 25532 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
bca38921
MGD
25533 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
25534 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
25535 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
25536 {
25537 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
25538 {
25539 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
25540 }
25541 else
25542 {
25543 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
25544 fp16_optional = 1;
25545 }
25546 }
fa94de6b 25547
ee3c0378 25548 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 25549 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 25550 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 25551
69239280
MGD
25552 /* Tag_DIV_use.
25553
25554 We set Tag_DIV_use to two when integer divide instructions have been used
25555 in ARM state, or when Thumb integer divide instructions have been used,
25556 but we have no architecture profile set, nor have we any ARM instructions.
25557
bca38921
MGD
25558 For ARMv8 we set the tag to 0 as integer divide is implied by the base
25559 architecture.
25560
69239280 25561 For new architectures we will have to check these tests. */
bca38921
MGD
25562 gas_assert (arch <= TAG_CPU_ARCH_V8);
25563 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8))
25564 aeabi_set_attribute_int (Tag_DIV_use, 0);
25565 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
25566 || (profile == '\0'
25567 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
25568 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 25569 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
25570
25571 /* Tag_MP_extension_use. */
25572 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
25573 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
25574
25575 /* Tag Virtualization_use. */
25576 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
25577 virt_sec |= 1;
25578 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
25579 virt_sec |= 2;
25580 if (virt_sec != 0)
25581 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
25582}
25583
104d59d1 25584/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
25585void
25586arm_md_end (void)
25587{
ee065d83
PB
25588 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
25589 return;
25590
25591 aeabi_set_public_attributes ();
ee065d83 25592}
8463be01 25593#endif /* OBJ_ELF */
ee065d83
PB
25594
25595
25596/* Parse a .cpu directive. */
25597
25598static void
25599s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
25600{
e74cfd16 25601 const struct arm_cpu_option_table *opt;
ee065d83
PB
25602 char *name;
25603 char saved_char;
25604
25605 name = input_line_pointer;
5f4273c7 25606 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
25607 input_line_pointer++;
25608 saved_char = *input_line_pointer;
25609 *input_line_pointer = 0;
25610
25611 /* Skip the first "all" entry. */
25612 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
25613 if (streq (opt->name, name))
25614 {
e74cfd16
PB
25615 mcpu_cpu_opt = &opt->value;
25616 selected_cpu = opt->value;
ee065d83 25617 if (opt->canonical_name)
5f4273c7 25618 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
25619 else
25620 {
25621 int i;
25622 for (i = 0; opt->name[i]; i++)
25623 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 25624
ee065d83
PB
25625 selected_cpu_name[i] = 0;
25626 }
e74cfd16 25627 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
25628 *input_line_pointer = saved_char;
25629 demand_empty_rest_of_line ();
25630 return;
25631 }
25632 as_bad (_("unknown cpu `%s'"), name);
25633 *input_line_pointer = saved_char;
25634 ignore_rest_of_line ();
25635}
25636
25637
25638/* Parse a .arch directive. */
25639
25640static void
25641s_arm_arch (int ignored ATTRIBUTE_UNUSED)
25642{
e74cfd16 25643 const struct arm_arch_option_table *opt;
ee065d83
PB
25644 char saved_char;
25645 char *name;
25646
25647 name = input_line_pointer;
5f4273c7 25648 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
25649 input_line_pointer++;
25650 saved_char = *input_line_pointer;
25651 *input_line_pointer = 0;
25652
25653 /* Skip the first "all" entry. */
25654 for (opt = arm_archs + 1; opt->name != NULL; opt++)
25655 if (streq (opt->name, name))
25656 {
e74cfd16
PB
25657 mcpu_cpu_opt = &opt->value;
25658 selected_cpu = opt->value;
5f4273c7 25659 strcpy (selected_cpu_name, opt->name);
e74cfd16 25660 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
25661 *input_line_pointer = saved_char;
25662 demand_empty_rest_of_line ();
25663 return;
25664 }
25665
25666 as_bad (_("unknown architecture `%s'\n"), name);
25667 *input_line_pointer = saved_char;
25668 ignore_rest_of_line ();
25669}
25670
25671
7a1d4c38
PB
25672/* Parse a .object_arch directive. */
25673
25674static void
25675s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
25676{
25677 const struct arm_arch_option_table *opt;
25678 char saved_char;
25679 char *name;
25680
25681 name = input_line_pointer;
5f4273c7 25682 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
25683 input_line_pointer++;
25684 saved_char = *input_line_pointer;
25685 *input_line_pointer = 0;
25686
25687 /* Skip the first "all" entry. */
25688 for (opt = arm_archs + 1; opt->name != NULL; opt++)
25689 if (streq (opt->name, name))
25690 {
25691 object_arch = &opt->value;
25692 *input_line_pointer = saved_char;
25693 demand_empty_rest_of_line ();
25694 return;
25695 }
25696
25697 as_bad (_("unknown architecture `%s'\n"), name);
25698 *input_line_pointer = saved_char;
25699 ignore_rest_of_line ();
25700}
25701
69133863
MGD
25702/* Parse a .arch_extension directive. */
25703
25704static void
25705s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
25706{
25707 const struct arm_option_extension_value_table *opt;
25708 char saved_char;
25709 char *name;
25710 int adding_value = 1;
25711
25712 name = input_line_pointer;
25713 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
25714 input_line_pointer++;
25715 saved_char = *input_line_pointer;
25716 *input_line_pointer = 0;
25717
25718 if (strlen (name) >= 2
25719 && strncmp (name, "no", 2) == 0)
25720 {
25721 adding_value = 0;
25722 name += 2;
25723 }
25724
25725 for (opt = arm_extensions; opt->name != NULL; opt++)
25726 if (streq (opt->name, name))
25727 {
25728 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
25729 {
25730 as_bad (_("architectural extension `%s' is not allowed for the "
25731 "current base architecture"), name);
25732 break;
25733 }
25734
25735 if (adding_value)
5a70a223
JB
25736 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu,
25737 opt->merge_value);
69133863 25738 else
5a70a223 25739 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->clear_value);
69133863
MGD
25740
25741 mcpu_cpu_opt = &selected_cpu;
25742 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
25743 *input_line_pointer = saved_char;
25744 demand_empty_rest_of_line ();
25745 return;
25746 }
25747
25748 if (opt->name == NULL)
e673710a 25749 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
25750
25751 *input_line_pointer = saved_char;
25752 ignore_rest_of_line ();
25753}
25754
ee065d83
PB
25755/* Parse a .fpu directive. */
25756
25757static void
25758s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
25759{
69133863 25760 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
25761 char saved_char;
25762 char *name;
25763
25764 name = input_line_pointer;
5f4273c7 25765 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
25766 input_line_pointer++;
25767 saved_char = *input_line_pointer;
25768 *input_line_pointer = 0;
5f4273c7 25769
ee065d83
PB
25770 for (opt = arm_fpus; opt->name != NULL; opt++)
25771 if (streq (opt->name, name))
25772 {
e74cfd16
PB
25773 mfpu_opt = &opt->value;
25774 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
25775 *input_line_pointer = saved_char;
25776 demand_empty_rest_of_line ();
25777 return;
25778 }
25779
25780 as_bad (_("unknown floating point format `%s'\n"), name);
25781 *input_line_pointer = saved_char;
25782 ignore_rest_of_line ();
25783}
ee065d83 25784
794ba86a 25785/* Copy symbol information. */
f31fef98 25786
794ba86a
DJ
25787void
25788arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
25789{
25790 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
25791}
e04befd0 25792
f31fef98 25793#ifdef OBJ_ELF
e04befd0
AS
25794/* Given a symbolic attribute NAME, return the proper integer value.
25795 Returns -1 if the attribute is not known. */
f31fef98 25796
e04befd0
AS
25797int
25798arm_convert_symbolic_attribute (const char *name)
25799{
f31fef98
NC
25800 static const struct
25801 {
25802 const char * name;
25803 const int tag;
25804 }
25805 attribute_table[] =
25806 {
25807 /* When you modify this table you should
25808 also modify the list in doc/c-arm.texi. */
e04befd0 25809#define T(tag) {#tag, tag}
f31fef98
NC
25810 T (Tag_CPU_raw_name),
25811 T (Tag_CPU_name),
25812 T (Tag_CPU_arch),
25813 T (Tag_CPU_arch_profile),
25814 T (Tag_ARM_ISA_use),
25815 T (Tag_THUMB_ISA_use),
75375b3e 25816 T (Tag_FP_arch),
f31fef98
NC
25817 T (Tag_VFP_arch),
25818 T (Tag_WMMX_arch),
25819 T (Tag_Advanced_SIMD_arch),
25820 T (Tag_PCS_config),
25821 T (Tag_ABI_PCS_R9_use),
25822 T (Tag_ABI_PCS_RW_data),
25823 T (Tag_ABI_PCS_RO_data),
25824 T (Tag_ABI_PCS_GOT_use),
25825 T (Tag_ABI_PCS_wchar_t),
25826 T (Tag_ABI_FP_rounding),
25827 T (Tag_ABI_FP_denormal),
25828 T (Tag_ABI_FP_exceptions),
25829 T (Tag_ABI_FP_user_exceptions),
25830 T (Tag_ABI_FP_number_model),
75375b3e 25831 T (Tag_ABI_align_needed),
f31fef98 25832 T (Tag_ABI_align8_needed),
75375b3e 25833 T (Tag_ABI_align_preserved),
f31fef98
NC
25834 T (Tag_ABI_align8_preserved),
25835 T (Tag_ABI_enum_size),
25836 T (Tag_ABI_HardFP_use),
25837 T (Tag_ABI_VFP_args),
25838 T (Tag_ABI_WMMX_args),
25839 T (Tag_ABI_optimization_goals),
25840 T (Tag_ABI_FP_optimization_goals),
25841 T (Tag_compatibility),
25842 T (Tag_CPU_unaligned_access),
75375b3e 25843 T (Tag_FP_HP_extension),
f31fef98
NC
25844 T (Tag_VFP_HP_extension),
25845 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
25846 T (Tag_MPextension_use),
25847 T (Tag_DIV_use),
f31fef98
NC
25848 T (Tag_nodefaults),
25849 T (Tag_also_compatible_with),
25850 T (Tag_conformance),
25851 T (Tag_T2EE_use),
25852 T (Tag_Virtualization_use),
cd21e546 25853 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 25854#undef T
f31fef98 25855 };
e04befd0
AS
25856 unsigned int i;
25857
25858 if (name == NULL)
25859 return -1;
25860
f31fef98 25861 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 25862 if (streq (name, attribute_table[i].name))
e04befd0
AS
25863 return attribute_table[i].tag;
25864
25865 return -1;
25866}
267bf995
RR
25867
25868
93ef582d
NC
25869/* Apply sym value for relocations only in the case that they are for
25870 local symbols in the same segment as the fixup and you have the
25871 respective architectural feature for blx and simple switches. */
267bf995 25872int
93ef582d 25873arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
25874{
25875 if (fixP->fx_addsy
25876 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
25877 /* PR 17444: If the local symbol is in a different section then a reloc
25878 will always be generated for it, so applying the symbol value now
25879 will result in a double offset being stored in the relocation. */
25880 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 25881 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
25882 {
25883 switch (fixP->fx_r_type)
25884 {
25885 case BFD_RELOC_ARM_PCREL_BLX:
25886 case BFD_RELOC_THUMB_PCREL_BRANCH23:
25887 if (ARM_IS_FUNC (fixP->fx_addsy))
25888 return 1;
25889 break;
25890
25891 case BFD_RELOC_ARM_PCREL_CALL:
25892 case BFD_RELOC_THUMB_PCREL_BLX:
25893 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 25894 return 1;
267bf995
RR
25895 break;
25896
25897 default:
25898 break;
25899 }
25900
25901 }
25902 return 0;
25903}
f31fef98 25904#endif /* OBJ_ELF */