]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
x32: Fix gdb.trace/mi-trace-frame-collected.exp
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
6f2750fe 2 Copyright (C) 1994-2016 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;
f85d59c3 158static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1;
e74cfd16 159static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
f85d59c3
KT
160static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3;
161static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = 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;
69c9e028 164#ifdef OBJ_ELF
e74cfd16 165static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
69c9e028 166#endif
e74cfd16
PB
167static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
168
169#ifdef CPU_DEFAULT
170static const arm_feature_set cpu_default = CPU_DEFAULT;
171#endif
172
823d2571
TG
173static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
174static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
175static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
176static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
177static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
178static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
179static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
180static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
e74cfd16 181static const arm_feature_set arm_ext_v4t_5 =
823d2571
TG
182 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
183static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
184static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
185static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
186static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
187static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
188static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
189static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
190static const arm_feature_set arm_ext_v6m = ARM_FEATURE_CORE_LOW (ARM_EXT_V6M);
191static const arm_feature_set arm_ext_v6_notm =
192 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
193static const arm_feature_set arm_ext_v6_dsp =
194 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
195static const arm_feature_set arm_ext_barrier =
196 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
197static const arm_feature_set arm_ext_msr =
198 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
199static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
200static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
201static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
202static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
69c9e028 203#ifdef OBJ_ELF
823d2571 204static const arm_feature_set arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
69c9e028 205#endif
823d2571 206static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
7e806470 207static const arm_feature_set arm_ext_m =
16a1fa25
TP
208 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M,
209 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
823d2571
TG
210static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
211static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
212static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
213static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
214static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
ddfded2f 215static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
4ed7ed8d 216static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
16a1fa25
TP
217static const arm_feature_set arm_ext_v8m_main =
218 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
219/* Instructions in ARMv8-M only found in M profile architectures. */
220static const arm_feature_set arm_ext_v8m_m_only =
221 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
ff8646ee
TP
222static const arm_feature_set arm_ext_v6t2_v8m =
223 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
4ed7ed8d
TP
224/* Instructions shared between ARMv8-A and ARMv8-M. */
225static const arm_feature_set arm_ext_atomics =
226 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
69c9e028 227#ifdef OBJ_ELF
15afaa63
TP
228/* DSP instructions Tag_DSP_extension refers to. */
229static const arm_feature_set arm_ext_dsp =
230 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
69c9e028 231#endif
4d1464f2
MW
232static const arm_feature_set arm_ext_ras =
233 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
b8ec4e87
JW
234/* FP16 instructions. */
235static const arm_feature_set arm_ext_fp16 =
236 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
e74cfd16
PB
237
238static const arm_feature_set arm_arch_any = ARM_ANY;
f85d59c3 239static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
240static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
241static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
69c9e028 242#ifdef OBJ_ELF
251665fc 243static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
69c9e028 244#endif
e74cfd16 245
2d447fca 246static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 247 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 248static const arm_feature_set arm_cext_iwmmxt =
823d2571 249 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 250static const arm_feature_set arm_cext_xscale =
823d2571 251 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 252static const arm_feature_set arm_cext_maverick =
823d2571
TG
253 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
254static const arm_feature_set fpu_fpa_ext_v1 =
255 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
256static const arm_feature_set fpu_fpa_ext_v2 =
257 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 258static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
259 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
260static const arm_feature_set fpu_vfp_ext_v1 =
261 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
262static const arm_feature_set fpu_vfp_ext_v2 =
263 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
264static const arm_feature_set fpu_vfp_ext_v3xd =
265 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
266static const arm_feature_set fpu_vfp_ext_v3 =
267 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 268static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
269 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
270static const arm_feature_set fpu_neon_ext_v1 =
271 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 272static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571 273 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
69c9e028 274#ifdef OBJ_ELF
823d2571
TG
275static const arm_feature_set fpu_vfp_fp16 =
276 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
277static const arm_feature_set fpu_neon_ext_fma =
278 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 279#endif
823d2571
TG
280static const arm_feature_set fpu_vfp_ext_fma =
281 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 282static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 283 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 284static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 285 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 286static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 287 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 288static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 289 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 290static const arm_feature_set crc_ext_armv8 =
823d2571 291 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e 292static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 293 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
e74cfd16 294
33a392fb 295static int mfloat_abi_opt = -1;
e74cfd16
PB
296/* Record user cpu selection for object attributes. */
297static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83 298/* Must be long enough to hold any of the names in arm_cpus. */
ef8e6722 299static char selected_cpu_name[20];
8d67f500 300
aacf0b33
KT
301extern FLONUM_TYPE generic_floating_point_number;
302
8d67f500
NC
303/* Return if no cpu was selected on command-line. */
304static bfd_boolean
305no_cpu_selected (void)
306{
823d2571 307 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
308}
309
7cc69913 310#ifdef OBJ_ELF
deeaaff8
DJ
311# ifdef EABI_DEFAULT
312static int meabi_flags = EABI_DEFAULT;
313# else
d507cf36 314static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 315# endif
e1da3f5b 316
ee3c0378
AS
317static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
318
e1da3f5b 319bfd_boolean
5f4273c7 320arm_is_eabi (void)
e1da3f5b
PB
321{
322 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
323}
7cc69913 324#endif
b99bd4ef 325
b99bd4ef 326#ifdef OBJ_ELF
c19d1205 327/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
328symbolS * GOT_symbol;
329#endif
330
b99bd4ef
NC
331/* 0: assemble for ARM,
332 1: assemble for Thumb,
333 2: assemble for Thumb even though target CPU does not support thumb
334 instructions. */
335static int thumb_mode = 0;
8dc2430f
NC
336/* A value distinct from the possible values for thumb_mode that we
337 can use to record whether thumb_mode has been copied into the
338 tc_frag_data field of a frag. */
339#define MODE_RECORDED (1 << 4)
b99bd4ef 340
e07e6e58
NC
341/* Specifies the intrinsic IT insn behavior mode. */
342enum implicit_it_mode
343{
344 IMPLICIT_IT_MODE_NEVER = 0x00,
345 IMPLICIT_IT_MODE_ARM = 0x01,
346 IMPLICIT_IT_MODE_THUMB = 0x02,
347 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
348};
349static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
350
c19d1205
ZW
351/* If unified_syntax is true, we are processing the new unified
352 ARM/Thumb syntax. Important differences from the old ARM mode:
353
354 - Immediate operands do not require a # prefix.
355 - Conditional affixes always appear at the end of the
356 instruction. (For backward compatibility, those instructions
357 that formerly had them in the middle, continue to accept them
358 there.)
359 - The IT instruction may appear, and if it does is validated
360 against subsequent conditional affixes. It does not generate
361 machine code.
362
363 Important differences from the old Thumb mode:
364
365 - Immediate operands do not require a # prefix.
366 - Most of the V6T2 instructions are only available in unified mode.
367 - The .N and .W suffixes are recognized and honored (it is an error
368 if they cannot be honored).
369 - All instructions set the flags if and only if they have an 's' affix.
370 - Conditional affixes may be used. They are validated against
371 preceding IT instructions. Unlike ARM mode, you cannot use a
372 conditional affix except in the scope of an IT instruction. */
373
374static bfd_boolean unified_syntax = FALSE;
b99bd4ef 375
bacebabc
RM
376/* An immediate operand can start with #, and ld*, st*, pld operands
377 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
378 before a [, which can appear as the first operand for pld.
379 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
380const char arm_symbol_chars[] = "#[]{}";
bacebabc 381
5287ad62
JB
382enum neon_el_type
383{
dcbf9037 384 NT_invtype,
5287ad62
JB
385 NT_untyped,
386 NT_integer,
387 NT_float,
388 NT_poly,
389 NT_signed,
dcbf9037 390 NT_unsigned
5287ad62
JB
391};
392
393struct neon_type_el
394{
395 enum neon_el_type type;
396 unsigned size;
397};
398
399#define NEON_MAX_TYPE_ELS 4
400
401struct neon_type
402{
403 struct neon_type_el el[NEON_MAX_TYPE_ELS];
404 unsigned elems;
405};
406
e07e6e58
NC
407enum it_instruction_type
408{
409 OUTSIDE_IT_INSN,
410 INSIDE_IT_INSN,
411 INSIDE_IT_LAST_INSN,
412 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 413 if inside, should be the last one. */
e07e6e58 414 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 415 i.e. BKPT and NOP. */
e07e6e58
NC
416 IT_INSN /* The IT insn has been parsed. */
417};
418
ad6cec43
MGD
419/* The maximum number of operands we need. */
420#define ARM_IT_MAX_OPERANDS 6
421
b99bd4ef
NC
422struct arm_it
423{
c19d1205 424 const char * error;
b99bd4ef 425 unsigned long instruction;
c19d1205
ZW
426 int size;
427 int size_req;
428 int cond;
037e8744
JB
429 /* "uncond_value" is set to the value in place of the conditional field in
430 unconditional versions of the instruction, or -1 if nothing is
431 appropriate. */
432 int uncond_value;
5287ad62 433 struct neon_type vectype;
88714cb8
DG
434 /* This does not indicate an actual NEON instruction, only that
435 the mnemonic accepts neon-style type suffixes. */
436 int is_neon;
0110f2b8
PB
437 /* Set to the opcode if the instruction needs relaxation.
438 Zero if the instruction is not relaxed. */
439 unsigned long relax;
b99bd4ef
NC
440 struct
441 {
442 bfd_reloc_code_real_type type;
c19d1205
ZW
443 expressionS exp;
444 int pc_rel;
b99bd4ef 445 } reloc;
b99bd4ef 446
e07e6e58
NC
447 enum it_instruction_type it_insn_type;
448
c19d1205
ZW
449 struct
450 {
451 unsigned reg;
ca3f61f7 452 signed int imm;
dcbf9037 453 struct neon_type_el vectype;
ca3f61f7
NC
454 unsigned present : 1; /* Operand present. */
455 unsigned isreg : 1; /* Operand was a register. */
456 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
457 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
458 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 459 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
460 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
461 instructions. This allows us to disambiguate ARM <-> vector insns. */
462 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 463 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 464 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 465 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
466 unsigned hasreloc : 1; /* Operand has relocation suffix. */
467 unsigned writeback : 1; /* Operand has trailing ! */
468 unsigned preind : 1; /* Preindexed address. */
469 unsigned postind : 1; /* Postindexed address. */
470 unsigned negative : 1; /* Index register was negated. */
471 unsigned shifted : 1; /* Shift applied to operation. */
472 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 473 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
474};
475
c19d1205 476static struct arm_it inst;
b99bd4ef
NC
477
478#define NUM_FLOAT_VALS 8
479
05d2d07e 480const char * fp_const[] =
b99bd4ef
NC
481{
482 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
483};
484
c19d1205 485/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
486#define MAX_LITTLENUMS 6
487
488LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
489
490#define FAIL (-1)
491#define SUCCESS (0)
492
493#define SUFF_S 1
494#define SUFF_D 2
495#define SUFF_E 3
496#define SUFF_P 4
497
c19d1205
ZW
498#define CP_T_X 0x00008000
499#define CP_T_Y 0x00400000
b99bd4ef 500
c19d1205
ZW
501#define CONDS_BIT 0x00100000
502#define LOAD_BIT 0x00100000
b99bd4ef
NC
503
504#define DOUBLE_LOAD_FLAG 0x00000001
505
506struct asm_cond
507{
d3ce72d0 508 const char * template_name;
c921be7d 509 unsigned long value;
b99bd4ef
NC
510};
511
c19d1205 512#define COND_ALWAYS 0xE
b99bd4ef 513
b99bd4ef
NC
514struct asm_psr
515{
d3ce72d0 516 const char * template_name;
c921be7d 517 unsigned long field;
b99bd4ef
NC
518};
519
62b3e311
PB
520struct asm_barrier_opt
521{
e797f7e0
MGD
522 const char * template_name;
523 unsigned long value;
524 const arm_feature_set arch;
62b3e311
PB
525};
526
2d2255b5 527/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
528#define SPSR_BIT (1 << 22)
529
c19d1205
ZW
530/* The individual PSR flag bits. */
531#define PSR_c (1 << 16)
532#define PSR_x (1 << 17)
533#define PSR_s (1 << 18)
534#define PSR_f (1 << 19)
b99bd4ef 535
c19d1205 536struct reloc_entry
bfae80f2 537{
e0471c16 538 const char * name;
c921be7d 539 bfd_reloc_code_real_type reloc;
bfae80f2
RE
540};
541
5287ad62 542enum vfp_reg_pos
bfae80f2 543{
5287ad62
JB
544 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
545 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
546};
547
548enum vfp_ldstm_type
549{
550 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
551};
552
dcbf9037
JB
553/* Bits for DEFINED field in neon_typed_alias. */
554#define NTA_HASTYPE 1
555#define NTA_HASINDEX 2
556
557struct neon_typed_alias
558{
c921be7d
NC
559 unsigned char defined;
560 unsigned char index;
561 struct neon_type_el eltype;
dcbf9037
JB
562};
563
c19d1205
ZW
564/* ARM register categories. This includes coprocessor numbers and various
565 architecture extensions' registers. */
566enum arm_reg_type
bfae80f2 567{
c19d1205
ZW
568 REG_TYPE_RN,
569 REG_TYPE_CP,
570 REG_TYPE_CN,
571 REG_TYPE_FN,
572 REG_TYPE_VFS,
573 REG_TYPE_VFD,
5287ad62 574 REG_TYPE_NQ,
037e8744 575 REG_TYPE_VFSD,
5287ad62 576 REG_TYPE_NDQ,
037e8744 577 REG_TYPE_NSDQ,
c19d1205
ZW
578 REG_TYPE_VFC,
579 REG_TYPE_MVF,
580 REG_TYPE_MVD,
581 REG_TYPE_MVFX,
582 REG_TYPE_MVDX,
583 REG_TYPE_MVAX,
584 REG_TYPE_DSPSC,
585 REG_TYPE_MMXWR,
586 REG_TYPE_MMXWC,
587 REG_TYPE_MMXWCG,
588 REG_TYPE_XSCALE,
90ec0d68 589 REG_TYPE_RNB
bfae80f2
RE
590};
591
dcbf9037
JB
592/* Structure for a hash table entry for a register.
593 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
594 information which states whether a vector type or index is specified (for a
595 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
596struct reg_entry
597{
c921be7d 598 const char * name;
90ec0d68 599 unsigned int number;
c921be7d
NC
600 unsigned char type;
601 unsigned char builtin;
602 struct neon_typed_alias * neon;
6c43fab6
RE
603};
604
c19d1205 605/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 606const char * const reg_expected_msgs[] =
c19d1205
ZW
607{
608 N_("ARM register expected"),
609 N_("bad or missing co-processor number"),
610 N_("co-processor register expected"),
611 N_("FPA register expected"),
612 N_("VFP single precision register expected"),
5287ad62
JB
613 N_("VFP/Neon double precision register expected"),
614 N_("Neon quad precision register expected"),
037e8744 615 N_("VFP single or double precision register expected"),
5287ad62 616 N_("Neon double or quad precision register expected"),
037e8744 617 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
618 N_("VFP system register expected"),
619 N_("Maverick MVF register expected"),
620 N_("Maverick MVD register expected"),
621 N_("Maverick MVFX register expected"),
622 N_("Maverick MVDX register expected"),
623 N_("Maverick MVAX register expected"),
624 N_("Maverick DSPSC register expected"),
625 N_("iWMMXt data register expected"),
626 N_("iWMMXt control register expected"),
627 N_("iWMMXt scalar register expected"),
628 N_("XScale accumulator register expected"),
6c43fab6
RE
629};
630
c19d1205 631/* Some well known registers that we refer to directly elsewhere. */
bd340a04 632#define REG_R12 12
c19d1205
ZW
633#define REG_SP 13
634#define REG_LR 14
635#define REG_PC 15
404ff6b5 636
b99bd4ef
NC
637/* ARM instructions take 4bytes in the object file, Thumb instructions
638 take 2: */
c19d1205 639#define INSN_SIZE 4
b99bd4ef
NC
640
641struct asm_opcode
642{
643 /* Basic string to match. */
d3ce72d0 644 const char * template_name;
c19d1205
ZW
645
646 /* Parameters to instruction. */
5be8be5d 647 unsigned int operands[8];
c19d1205
ZW
648
649 /* Conditional tag - see opcode_lookup. */
650 unsigned int tag : 4;
b99bd4ef
NC
651
652 /* Basic instruction code. */
c19d1205 653 unsigned int avalue : 28;
b99bd4ef 654
c19d1205
ZW
655 /* Thumb-format instruction code. */
656 unsigned int tvalue;
b99bd4ef 657
90e4755a 658 /* Which architecture variant provides this instruction. */
c921be7d
NC
659 const arm_feature_set * avariant;
660 const arm_feature_set * tvariant;
c19d1205
ZW
661
662 /* Function to call to encode instruction in ARM format. */
663 void (* aencode) (void);
b99bd4ef 664
c19d1205
ZW
665 /* Function to call to encode instruction in Thumb format. */
666 void (* tencode) (void);
b99bd4ef
NC
667};
668
a737bd4d
NC
669/* Defines for various bits that we will want to toggle. */
670#define INST_IMMEDIATE 0x02000000
671#define OFFSET_REG 0x02000000
c19d1205 672#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
673#define SHIFT_BY_REG 0x00000010
674#define PRE_INDEX 0x01000000
675#define INDEX_UP 0x00800000
676#define WRITE_BACK 0x00200000
677#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 678#define CPSI_MMOD 0x00020000
90e4755a 679
a737bd4d
NC
680#define LITERAL_MASK 0xf000f000
681#define OPCODE_MASK 0xfe1fffff
682#define V4_STR_BIT 0x00000020
8335d6aa 683#define VLDR_VMOV_SAME 0x0040f000
90e4755a 684
efd81785
PB
685#define T2_SUBS_PC_LR 0xf3de8f00
686
a737bd4d 687#define DATA_OP_SHIFT 21
90e4755a 688
ef8d22e6
PB
689#define T2_OPCODE_MASK 0xfe1fffff
690#define T2_DATA_OP_SHIFT 21
691
6530b175
NC
692#define A_COND_MASK 0xf0000000
693#define A_PUSH_POP_OP_MASK 0x0fff0000
694
695/* Opcodes for pushing/poping registers to/from the stack. */
696#define A1_OPCODE_PUSH 0x092d0000
697#define A2_OPCODE_PUSH 0x052d0004
698#define A2_OPCODE_POP 0x049d0004
699
a737bd4d
NC
700/* Codes to distinguish the arithmetic instructions. */
701#define OPCODE_AND 0
702#define OPCODE_EOR 1
703#define OPCODE_SUB 2
704#define OPCODE_RSB 3
705#define OPCODE_ADD 4
706#define OPCODE_ADC 5
707#define OPCODE_SBC 6
708#define OPCODE_RSC 7
709#define OPCODE_TST 8
710#define OPCODE_TEQ 9
711#define OPCODE_CMP 10
712#define OPCODE_CMN 11
713#define OPCODE_ORR 12
714#define OPCODE_MOV 13
715#define OPCODE_BIC 14
716#define OPCODE_MVN 15
90e4755a 717
ef8d22e6
PB
718#define T2_OPCODE_AND 0
719#define T2_OPCODE_BIC 1
720#define T2_OPCODE_ORR 2
721#define T2_OPCODE_ORN 3
722#define T2_OPCODE_EOR 4
723#define T2_OPCODE_ADD 8
724#define T2_OPCODE_ADC 10
725#define T2_OPCODE_SBC 11
726#define T2_OPCODE_SUB 13
727#define T2_OPCODE_RSB 14
728
a737bd4d
NC
729#define T_OPCODE_MUL 0x4340
730#define T_OPCODE_TST 0x4200
731#define T_OPCODE_CMN 0x42c0
732#define T_OPCODE_NEG 0x4240
733#define T_OPCODE_MVN 0x43c0
90e4755a 734
a737bd4d
NC
735#define T_OPCODE_ADD_R3 0x1800
736#define T_OPCODE_SUB_R3 0x1a00
737#define T_OPCODE_ADD_HI 0x4400
738#define T_OPCODE_ADD_ST 0xb000
739#define T_OPCODE_SUB_ST 0xb080
740#define T_OPCODE_ADD_SP 0xa800
741#define T_OPCODE_ADD_PC 0xa000
742#define T_OPCODE_ADD_I8 0x3000
743#define T_OPCODE_SUB_I8 0x3800
744#define T_OPCODE_ADD_I3 0x1c00
745#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 746
a737bd4d
NC
747#define T_OPCODE_ASR_R 0x4100
748#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
749#define T_OPCODE_LSR_R 0x40c0
750#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
751#define T_OPCODE_ASR_I 0x1000
752#define T_OPCODE_LSL_I 0x0000
753#define T_OPCODE_LSR_I 0x0800
b99bd4ef 754
a737bd4d
NC
755#define T_OPCODE_MOV_I8 0x2000
756#define T_OPCODE_CMP_I8 0x2800
757#define T_OPCODE_CMP_LR 0x4280
758#define T_OPCODE_MOV_HR 0x4600
759#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 760
a737bd4d
NC
761#define T_OPCODE_LDR_PC 0x4800
762#define T_OPCODE_LDR_SP 0x9800
763#define T_OPCODE_STR_SP 0x9000
764#define T_OPCODE_LDR_IW 0x6800
765#define T_OPCODE_STR_IW 0x6000
766#define T_OPCODE_LDR_IH 0x8800
767#define T_OPCODE_STR_IH 0x8000
768#define T_OPCODE_LDR_IB 0x7800
769#define T_OPCODE_STR_IB 0x7000
770#define T_OPCODE_LDR_RW 0x5800
771#define T_OPCODE_STR_RW 0x5000
772#define T_OPCODE_LDR_RH 0x5a00
773#define T_OPCODE_STR_RH 0x5200
774#define T_OPCODE_LDR_RB 0x5c00
775#define T_OPCODE_STR_RB 0x5400
c9b604bd 776
a737bd4d
NC
777#define T_OPCODE_PUSH 0xb400
778#define T_OPCODE_POP 0xbc00
b99bd4ef 779
2fc8bdac 780#define T_OPCODE_BRANCH 0xe000
b99bd4ef 781
a737bd4d 782#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 783#define THUMB_PP_PC_LR 0x0100
c19d1205 784#define THUMB_LOAD_BIT 0x0800
53365c0d 785#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
786
787#define BAD_ARGS _("bad arguments to instruction")
fdfde340 788#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
789#define BAD_PC _("r15 not allowed here")
790#define BAD_COND _("instruction cannot be conditional")
791#define BAD_OVERLAP _("registers may not be the same")
792#define BAD_HIREG _("lo register required")
793#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 794#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
795#define BAD_BRANCH _("branch must be last instruction in IT block")
796#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 797#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
798#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
799#define BAD_IT_COND _("incorrect condition in IT block")
800#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 801#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
802#define BAD_PC_ADDRESSING \
803 _("cannot use register index with PC-relative addressing")
804#define BAD_PC_WRITEBACK \
805 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
806#define BAD_RANGE _("branch out of range")
807#define BAD_FP16 _("selected processor does not support fp16 instruction")
dd5181d5 808#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 809#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
c19d1205 810
c921be7d
NC
811static struct hash_control * arm_ops_hsh;
812static struct hash_control * arm_cond_hsh;
813static struct hash_control * arm_shift_hsh;
814static struct hash_control * arm_psr_hsh;
815static struct hash_control * arm_v7m_psr_hsh;
816static struct hash_control * arm_reg_hsh;
817static struct hash_control * arm_reloc_hsh;
818static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 819
b99bd4ef
NC
820/* Stuff needed to resolve the label ambiguity
821 As:
822 ...
823 label: <insn>
824 may differ from:
825 ...
826 label:
5f4273c7 827 <insn> */
b99bd4ef
NC
828
829symbolS * last_label_seen;
b34976b6 830static int label_is_thumb_function_name = FALSE;
e07e6e58 831
3d0c9500
NC
832/* Literal pool structure. Held on a per-section
833 and per-sub-section basis. */
a737bd4d 834
c19d1205 835#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 836typedef struct literal_pool
b99bd4ef 837{
c921be7d
NC
838 expressionS literals [MAX_LITERAL_POOL_SIZE];
839 unsigned int next_free_entry;
840 unsigned int id;
841 symbolS * symbol;
842 segT section;
843 subsegT sub_section;
a8040cf2
NC
844#ifdef OBJ_ELF
845 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
846#endif
c921be7d 847 struct literal_pool * next;
8335d6aa 848 unsigned int alignment;
3d0c9500 849} literal_pool;
b99bd4ef 850
3d0c9500
NC
851/* Pointer to a linked list of literal pools. */
852literal_pool * list_of_pools = NULL;
e27ec89e 853
2e6976a8
DG
854typedef enum asmfunc_states
855{
856 OUTSIDE_ASMFUNC,
857 WAITING_ASMFUNC_NAME,
858 WAITING_ENDASMFUNC
859} asmfunc_states;
860
861static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
862
e07e6e58
NC
863#ifdef OBJ_ELF
864# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
865#else
866static struct current_it now_it;
867#endif
868
869static inline int
870now_it_compatible (int cond)
871{
872 return (cond & ~1) == (now_it.cc & ~1);
873}
874
875static inline int
876conditional_insn (void)
877{
878 return inst.cond != COND_ALWAYS;
879}
880
881static int in_it_block (void);
882
883static int handle_it_state (void);
884
885static void force_automatic_it_block_close (void);
886
c921be7d
NC
887static void it_fsm_post_encode (void);
888
e07e6e58
NC
889#define set_it_insn_type(type) \
890 do \
891 { \
892 inst.it_insn_type = type; \
893 if (handle_it_state () == FAIL) \
477330fc 894 return; \
e07e6e58
NC
895 } \
896 while (0)
897
c921be7d
NC
898#define set_it_insn_type_nonvoid(type, failret) \
899 do \
900 { \
901 inst.it_insn_type = type; \
902 if (handle_it_state () == FAIL) \
477330fc 903 return failret; \
c921be7d
NC
904 } \
905 while(0)
906
e07e6e58
NC
907#define set_it_insn_type_last() \
908 do \
909 { \
910 if (inst.cond == COND_ALWAYS) \
477330fc 911 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 912 else \
477330fc 913 set_it_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
914 } \
915 while (0)
916
c19d1205 917/* Pure syntax. */
b99bd4ef 918
c19d1205
ZW
919/* This array holds the chars that always start a comment. If the
920 pre-processor is disabled, these aren't very useful. */
2e6976a8 921char arm_comment_chars[] = "@";
3d0c9500 922
c19d1205
ZW
923/* This array holds the chars that only start a comment at the beginning of
924 a line. If the line seems to have the form '# 123 filename'
925 .line and .file directives will appear in the pre-processed output. */
926/* Note that input_file.c hand checks for '#' at the beginning of the
927 first line of the input file. This is because the compiler outputs
928 #NO_APP at the beginning of its output. */
929/* Also note that comments like this one will always work. */
930const char line_comment_chars[] = "#";
3d0c9500 931
2e6976a8 932char arm_line_separator_chars[] = ";";
b99bd4ef 933
c19d1205
ZW
934/* Chars that can be used to separate mant
935 from exp in floating point numbers. */
936const char EXP_CHARS[] = "eE";
3d0c9500 937
c19d1205
ZW
938/* Chars that mean this number is a floating point constant. */
939/* As in 0f12.456 */
940/* or 0d1.2345e12 */
b99bd4ef 941
c19d1205 942const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 943
c19d1205
ZW
944/* Prefix characters that indicate the start of an immediate
945 value. */
946#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 947
c19d1205
ZW
948/* Separator character handling. */
949
950#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
951
952static inline int
953skip_past_char (char ** str, char c)
954{
8ab8155f
NC
955 /* PR gas/14987: Allow for whitespace before the expected character. */
956 skip_whitespace (*str);
427d0db6 957
c19d1205
ZW
958 if (**str == c)
959 {
960 (*str)++;
961 return SUCCESS;
3d0c9500 962 }
c19d1205
ZW
963 else
964 return FAIL;
965}
c921be7d 966
c19d1205 967#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 968
c19d1205
ZW
969/* Arithmetic expressions (possibly involving symbols). */
970
971/* Return TRUE if anything in the expression is a bignum. */
972
973static int
974walk_no_bignums (symbolS * sp)
975{
976 if (symbol_get_value_expression (sp)->X_op == O_big)
977 return 1;
978
979 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 980 {
c19d1205
ZW
981 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
982 || (symbol_get_value_expression (sp)->X_op_symbol
983 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
984 }
985
c19d1205 986 return 0;
3d0c9500
NC
987}
988
c19d1205
ZW
989static int in_my_get_expression = 0;
990
991/* Third argument to my_get_expression. */
992#define GE_NO_PREFIX 0
993#define GE_IMM_PREFIX 1
994#define GE_OPT_PREFIX 2
5287ad62
JB
995/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
996 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
997#define GE_OPT_PREFIX_BIG 3
a737bd4d 998
b99bd4ef 999static int
c19d1205 1000my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 1001{
c19d1205
ZW
1002 char * save_in;
1003 segT seg;
b99bd4ef 1004
c19d1205
ZW
1005 /* In unified syntax, all prefixes are optional. */
1006 if (unified_syntax)
5287ad62 1007 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 1008 : GE_OPT_PREFIX;
b99bd4ef 1009
c19d1205 1010 switch (prefix_mode)
b99bd4ef 1011 {
c19d1205
ZW
1012 case GE_NO_PREFIX: break;
1013 case GE_IMM_PREFIX:
1014 if (!is_immediate_prefix (**str))
1015 {
1016 inst.error = _("immediate expression requires a # prefix");
1017 return FAIL;
1018 }
1019 (*str)++;
1020 break;
1021 case GE_OPT_PREFIX:
5287ad62 1022 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1023 if (is_immediate_prefix (**str))
1024 (*str)++;
1025 break;
1026 default: abort ();
1027 }
b99bd4ef 1028
c19d1205 1029 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1030
c19d1205
ZW
1031 save_in = input_line_pointer;
1032 input_line_pointer = *str;
1033 in_my_get_expression = 1;
1034 seg = expression (ep);
1035 in_my_get_expression = 0;
1036
f86adc07 1037 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1038 {
f86adc07 1039 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1040 *str = input_line_pointer;
1041 input_line_pointer = save_in;
1042 if (inst.error == NULL)
f86adc07
NS
1043 inst.error = (ep->X_op == O_absent
1044 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1045 return 1;
1046 }
b99bd4ef 1047
c19d1205
ZW
1048#ifdef OBJ_AOUT
1049 if (seg != absolute_section
1050 && seg != text_section
1051 && seg != data_section
1052 && seg != bss_section
1053 && seg != undefined_section)
1054 {
1055 inst.error = _("bad segment");
1056 *str = input_line_pointer;
1057 input_line_pointer = save_in;
1058 return 1;
b99bd4ef 1059 }
87975d2a
AM
1060#else
1061 (void) seg;
c19d1205 1062#endif
b99bd4ef 1063
c19d1205
ZW
1064 /* Get rid of any bignums now, so that we don't generate an error for which
1065 we can't establish a line number later on. Big numbers are never valid
1066 in instructions, which is where this routine is always called. */
5287ad62
JB
1067 if (prefix_mode != GE_OPT_PREFIX_BIG
1068 && (ep->X_op == O_big
477330fc 1069 || (ep->X_add_symbol
5287ad62 1070 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1071 || (ep->X_op_symbol
5287ad62 1072 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1073 {
1074 inst.error = _("invalid constant");
1075 *str = input_line_pointer;
1076 input_line_pointer = save_in;
1077 return 1;
1078 }
b99bd4ef 1079
c19d1205
ZW
1080 *str = input_line_pointer;
1081 input_line_pointer = save_in;
1082 return 0;
b99bd4ef
NC
1083}
1084
c19d1205
ZW
1085/* Turn a string in input_line_pointer into a floating point constant
1086 of type TYPE, and store the appropriate bytes in *LITP. The number
1087 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1088 returned, or NULL on OK.
b99bd4ef 1089
c19d1205
ZW
1090 Note that fp constants aren't represent in the normal way on the ARM.
1091 In big endian mode, things are as expected. However, in little endian
1092 mode fp constants are big-endian word-wise, and little-endian byte-wise
1093 within the words. For example, (double) 1.1 in big endian mode is
1094 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1095 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1096
c19d1205 1097 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1098
6d4af3c2 1099const char *
c19d1205
ZW
1100md_atof (int type, char * litP, int * sizeP)
1101{
1102 int prec;
1103 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1104 char *t;
1105 int i;
b99bd4ef 1106
c19d1205
ZW
1107 switch (type)
1108 {
1109 case 'f':
1110 case 'F':
1111 case 's':
1112 case 'S':
1113 prec = 2;
1114 break;
b99bd4ef 1115
c19d1205
ZW
1116 case 'd':
1117 case 'D':
1118 case 'r':
1119 case 'R':
1120 prec = 4;
1121 break;
b99bd4ef 1122
c19d1205
ZW
1123 case 'x':
1124 case 'X':
499ac353 1125 prec = 5;
c19d1205 1126 break;
b99bd4ef 1127
c19d1205
ZW
1128 case 'p':
1129 case 'P':
499ac353 1130 prec = 5;
c19d1205 1131 break;
a737bd4d 1132
c19d1205
ZW
1133 default:
1134 *sizeP = 0;
499ac353 1135 return _("Unrecognized or unsupported floating point constant");
c19d1205 1136 }
b99bd4ef 1137
c19d1205
ZW
1138 t = atof_ieee (input_line_pointer, type, words);
1139 if (t)
1140 input_line_pointer = t;
499ac353 1141 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1142
c19d1205
ZW
1143 if (target_big_endian)
1144 {
1145 for (i = 0; i < prec; i++)
1146 {
499ac353
NC
1147 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1148 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1149 }
1150 }
1151 else
1152 {
e74cfd16 1153 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1154 for (i = prec - 1; i >= 0; i--)
1155 {
499ac353
NC
1156 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1157 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1158 }
1159 else
1160 /* For a 4 byte float the order of elements in `words' is 1 0.
1161 For an 8 byte float the order is 1 0 3 2. */
1162 for (i = 0; i < prec; i += 2)
1163 {
499ac353
NC
1164 md_number_to_chars (litP, (valueT) words[i + 1],
1165 sizeof (LITTLENUM_TYPE));
1166 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1167 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1168 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1169 }
1170 }
b99bd4ef 1171
499ac353 1172 return NULL;
c19d1205 1173}
b99bd4ef 1174
c19d1205
ZW
1175/* We handle all bad expressions here, so that we can report the faulty
1176 instruction in the error message. */
1177void
91d6fa6a 1178md_operand (expressionS * exp)
c19d1205
ZW
1179{
1180 if (in_my_get_expression)
91d6fa6a 1181 exp->X_op = O_illegal;
b99bd4ef
NC
1182}
1183
c19d1205 1184/* Immediate values. */
b99bd4ef 1185
c19d1205
ZW
1186/* Generic immediate-value read function for use in directives.
1187 Accepts anything that 'expression' can fold to a constant.
1188 *val receives the number. */
1189#ifdef OBJ_ELF
1190static int
1191immediate_for_directive (int *val)
b99bd4ef 1192{
c19d1205
ZW
1193 expressionS exp;
1194 exp.X_op = O_illegal;
b99bd4ef 1195
c19d1205
ZW
1196 if (is_immediate_prefix (*input_line_pointer))
1197 {
1198 input_line_pointer++;
1199 expression (&exp);
1200 }
b99bd4ef 1201
c19d1205
ZW
1202 if (exp.X_op != O_constant)
1203 {
1204 as_bad (_("expected #constant"));
1205 ignore_rest_of_line ();
1206 return FAIL;
1207 }
1208 *val = exp.X_add_number;
1209 return SUCCESS;
b99bd4ef 1210}
c19d1205 1211#endif
b99bd4ef 1212
c19d1205 1213/* Register parsing. */
b99bd4ef 1214
c19d1205
ZW
1215/* Generic register parser. CCP points to what should be the
1216 beginning of a register name. If it is indeed a valid register
1217 name, advance CCP over it and return the reg_entry structure;
1218 otherwise return NULL. Does not issue diagnostics. */
1219
1220static struct reg_entry *
1221arm_reg_parse_multi (char **ccp)
b99bd4ef 1222{
c19d1205
ZW
1223 char *start = *ccp;
1224 char *p;
1225 struct reg_entry *reg;
b99bd4ef 1226
477330fc
RM
1227 skip_whitespace (start);
1228
c19d1205
ZW
1229#ifdef REGISTER_PREFIX
1230 if (*start != REGISTER_PREFIX)
01cfc07f 1231 return NULL;
c19d1205
ZW
1232 start++;
1233#endif
1234#ifdef OPTIONAL_REGISTER_PREFIX
1235 if (*start == OPTIONAL_REGISTER_PREFIX)
1236 start++;
1237#endif
b99bd4ef 1238
c19d1205
ZW
1239 p = start;
1240 if (!ISALPHA (*p) || !is_name_beginner (*p))
1241 return NULL;
b99bd4ef 1242
c19d1205
ZW
1243 do
1244 p++;
1245 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1246
1247 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1248
1249 if (!reg)
1250 return NULL;
1251
1252 *ccp = p;
1253 return reg;
b99bd4ef
NC
1254}
1255
1256static int
dcbf9037 1257arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1258 enum arm_reg_type type)
b99bd4ef 1259{
c19d1205
ZW
1260 /* Alternative syntaxes are accepted for a few register classes. */
1261 switch (type)
1262 {
1263 case REG_TYPE_MVF:
1264 case REG_TYPE_MVD:
1265 case REG_TYPE_MVFX:
1266 case REG_TYPE_MVDX:
1267 /* Generic coprocessor register names are allowed for these. */
79134647 1268 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1269 return reg->number;
1270 break;
69b97547 1271
c19d1205
ZW
1272 case REG_TYPE_CP:
1273 /* For backward compatibility, a bare number is valid here. */
1274 {
1275 unsigned long processor = strtoul (start, ccp, 10);
1276 if (*ccp != start && processor <= 15)
1277 return processor;
1278 }
6057a28f 1279
c19d1205
ZW
1280 case REG_TYPE_MMXWC:
1281 /* WC includes WCG. ??? I'm not sure this is true for all
1282 instructions that take WC registers. */
79134647 1283 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1284 return reg->number;
6057a28f 1285 break;
c19d1205 1286
6057a28f 1287 default:
c19d1205 1288 break;
6057a28f
NC
1289 }
1290
dcbf9037
JB
1291 return FAIL;
1292}
1293
1294/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1295 return value is the register number or FAIL. */
1296
1297static int
1298arm_reg_parse (char **ccp, enum arm_reg_type type)
1299{
1300 char *start = *ccp;
1301 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1302 int ret;
1303
1304 /* Do not allow a scalar (reg+index) to parse as a register. */
1305 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1306 return FAIL;
1307
1308 if (reg && reg->type == type)
1309 return reg->number;
1310
1311 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1312 return ret;
1313
c19d1205
ZW
1314 *ccp = start;
1315 return FAIL;
1316}
69b97547 1317
dcbf9037
JB
1318/* Parse a Neon type specifier. *STR should point at the leading '.'
1319 character. Does no verification at this stage that the type fits the opcode
1320 properly. E.g.,
1321
1322 .i32.i32.s16
1323 .s32.f32
1324 .u16
1325
1326 Can all be legally parsed by this function.
1327
1328 Fills in neon_type struct pointer with parsed information, and updates STR
1329 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1330 type, FAIL if not. */
1331
1332static int
1333parse_neon_type (struct neon_type *type, char **str)
1334{
1335 char *ptr = *str;
1336
1337 if (type)
1338 type->elems = 0;
1339
1340 while (type->elems < NEON_MAX_TYPE_ELS)
1341 {
1342 enum neon_el_type thistype = NT_untyped;
1343 unsigned thissize = -1u;
1344
1345 if (*ptr != '.')
1346 break;
1347
1348 ptr++;
1349
1350 /* Just a size without an explicit type. */
1351 if (ISDIGIT (*ptr))
1352 goto parsesize;
1353
1354 switch (TOLOWER (*ptr))
1355 {
1356 case 'i': thistype = NT_integer; break;
1357 case 'f': thistype = NT_float; break;
1358 case 'p': thistype = NT_poly; break;
1359 case 's': thistype = NT_signed; break;
1360 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1361 case 'd':
1362 thistype = NT_float;
1363 thissize = 64;
1364 ptr++;
1365 goto done;
dcbf9037
JB
1366 default:
1367 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1368 return FAIL;
1369 }
1370
1371 ptr++;
1372
1373 /* .f is an abbreviation for .f32. */
1374 if (thistype == NT_float && !ISDIGIT (*ptr))
1375 thissize = 32;
1376 else
1377 {
1378 parsesize:
1379 thissize = strtoul (ptr, &ptr, 10);
1380
1381 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1382 && thissize != 64)
1383 {
1384 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1385 return FAIL;
1386 }
1387 }
1388
037e8744 1389 done:
dcbf9037 1390 if (type)
477330fc
RM
1391 {
1392 type->el[type->elems].type = thistype;
dcbf9037
JB
1393 type->el[type->elems].size = thissize;
1394 type->elems++;
1395 }
1396 }
1397
1398 /* Empty/missing type is not a successful parse. */
1399 if (type->elems == 0)
1400 return FAIL;
1401
1402 *str = ptr;
1403
1404 return SUCCESS;
1405}
1406
1407/* Errors may be set multiple times during parsing or bit encoding
1408 (particularly in the Neon bits), but usually the earliest error which is set
1409 will be the most meaningful. Avoid overwriting it with later (cascading)
1410 errors by calling this function. */
1411
1412static void
1413first_error (const char *err)
1414{
1415 if (!inst.error)
1416 inst.error = err;
1417}
1418
1419/* Parse a single type, e.g. ".s32", leading period included. */
1420static int
1421parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1422{
1423 char *str = *ccp;
1424 struct neon_type optype;
1425
1426 if (*str == '.')
1427 {
1428 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1429 {
1430 if (optype.elems == 1)
1431 *vectype = optype.el[0];
1432 else
1433 {
1434 first_error (_("only one type should be specified for operand"));
1435 return FAIL;
1436 }
1437 }
dcbf9037 1438 else
477330fc
RM
1439 {
1440 first_error (_("vector type expected"));
1441 return FAIL;
1442 }
dcbf9037
JB
1443 }
1444 else
1445 return FAIL;
5f4273c7 1446
dcbf9037 1447 *ccp = str;
5f4273c7 1448
dcbf9037
JB
1449 return SUCCESS;
1450}
1451
1452/* Special meanings for indices (which have a range of 0-7), which will fit into
1453 a 4-bit integer. */
1454
1455#define NEON_ALL_LANES 15
1456#define NEON_INTERLEAVE_LANES 14
1457
1458/* Parse either a register or a scalar, with an optional type. Return the
1459 register number, and optionally fill in the actual type of the register
1460 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1461 type/index information in *TYPEINFO. */
1462
1463static int
1464parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1465 enum arm_reg_type *rtype,
1466 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1467{
1468 char *str = *ccp;
1469 struct reg_entry *reg = arm_reg_parse_multi (&str);
1470 struct neon_typed_alias atype;
1471 struct neon_type_el parsetype;
1472
1473 atype.defined = 0;
1474 atype.index = -1;
1475 atype.eltype.type = NT_invtype;
1476 atype.eltype.size = -1;
1477
1478 /* Try alternate syntax for some types of register. Note these are mutually
1479 exclusive with the Neon syntax extensions. */
1480 if (reg == NULL)
1481 {
1482 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1483 if (altreg != FAIL)
477330fc 1484 *ccp = str;
dcbf9037 1485 if (typeinfo)
477330fc 1486 *typeinfo = atype;
dcbf9037
JB
1487 return altreg;
1488 }
1489
037e8744
JB
1490 /* Undo polymorphism when a set of register types may be accepted. */
1491 if ((type == REG_TYPE_NDQ
1492 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1493 || (type == REG_TYPE_VFSD
477330fc 1494 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1495 || (type == REG_TYPE_NSDQ
477330fc
RM
1496 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1497 || reg->type == REG_TYPE_NQ))
f512f76f
NC
1498 || (type == REG_TYPE_MMXWC
1499 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1500 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1501
1502 if (type != reg->type)
1503 return FAIL;
1504
1505 if (reg->neon)
1506 atype = *reg->neon;
5f4273c7 1507
dcbf9037
JB
1508 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1509 {
1510 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1511 {
1512 first_error (_("can't redefine type for operand"));
1513 return FAIL;
1514 }
dcbf9037
JB
1515 atype.defined |= NTA_HASTYPE;
1516 atype.eltype = parsetype;
1517 }
5f4273c7 1518
dcbf9037
JB
1519 if (skip_past_char (&str, '[') == SUCCESS)
1520 {
1521 if (type != REG_TYPE_VFD)
477330fc
RM
1522 {
1523 first_error (_("only D registers may be indexed"));
1524 return FAIL;
1525 }
5f4273c7 1526
dcbf9037 1527 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1528 {
1529 first_error (_("can't change index for operand"));
1530 return FAIL;
1531 }
dcbf9037
JB
1532
1533 atype.defined |= NTA_HASINDEX;
1534
1535 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1536 atype.index = NEON_ALL_LANES;
dcbf9037 1537 else
477330fc
RM
1538 {
1539 expressionS exp;
dcbf9037 1540
477330fc 1541 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1542
477330fc
RM
1543 if (exp.X_op != O_constant)
1544 {
1545 first_error (_("constant expression required"));
1546 return FAIL;
1547 }
dcbf9037 1548
477330fc
RM
1549 if (skip_past_char (&str, ']') == FAIL)
1550 return FAIL;
dcbf9037 1551
477330fc
RM
1552 atype.index = exp.X_add_number;
1553 }
dcbf9037 1554 }
5f4273c7 1555
dcbf9037
JB
1556 if (typeinfo)
1557 *typeinfo = atype;
5f4273c7 1558
dcbf9037
JB
1559 if (rtype)
1560 *rtype = type;
5f4273c7 1561
dcbf9037 1562 *ccp = str;
5f4273c7 1563
dcbf9037
JB
1564 return reg->number;
1565}
1566
1567/* Like arm_reg_parse, but allow allow the following extra features:
1568 - If RTYPE is non-zero, return the (possibly restricted) type of the
1569 register (e.g. Neon double or quad reg when either has been requested).
1570 - If this is a Neon vector type with additional type information, fill
1571 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1572 This function will fault on encountering a scalar. */
dcbf9037
JB
1573
1574static int
1575arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1576 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1577{
1578 struct neon_typed_alias atype;
1579 char *str = *ccp;
1580 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1581
1582 if (reg == FAIL)
1583 return FAIL;
1584
0855e32b
NS
1585 /* Do not allow regname(... to parse as a register. */
1586 if (*str == '(')
1587 return FAIL;
1588
dcbf9037
JB
1589 /* Do not allow a scalar (reg+index) to parse as a register. */
1590 if ((atype.defined & NTA_HASINDEX) != 0)
1591 {
1592 first_error (_("register operand expected, but got scalar"));
1593 return FAIL;
1594 }
1595
1596 if (vectype)
1597 *vectype = atype.eltype;
1598
1599 *ccp = str;
1600
1601 return reg;
1602}
1603
1604#define NEON_SCALAR_REG(X) ((X) >> 4)
1605#define NEON_SCALAR_INDEX(X) ((X) & 15)
1606
5287ad62
JB
1607/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1608 have enough information to be able to do a good job bounds-checking. So, we
1609 just do easy checks here, and do further checks later. */
1610
1611static int
dcbf9037 1612parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1613{
dcbf9037 1614 int reg;
5287ad62 1615 char *str = *ccp;
dcbf9037 1616 struct neon_typed_alias atype;
5f4273c7 1617
dcbf9037 1618 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1619
dcbf9037 1620 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1621 return FAIL;
5f4273c7 1622
dcbf9037 1623 if (atype.index == NEON_ALL_LANES)
5287ad62 1624 {
dcbf9037 1625 first_error (_("scalar must have an index"));
5287ad62
JB
1626 return FAIL;
1627 }
dcbf9037 1628 else if (atype.index >= 64 / elsize)
5287ad62 1629 {
dcbf9037 1630 first_error (_("scalar index out of range"));
5287ad62
JB
1631 return FAIL;
1632 }
5f4273c7 1633
dcbf9037
JB
1634 if (type)
1635 *type = atype.eltype;
5f4273c7 1636
5287ad62 1637 *ccp = str;
5f4273c7 1638
dcbf9037 1639 return reg * 16 + atype.index;
5287ad62
JB
1640}
1641
c19d1205 1642/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1643
c19d1205
ZW
1644static long
1645parse_reg_list (char ** strp)
1646{
1647 char * str = * strp;
1648 long range = 0;
1649 int another_range;
a737bd4d 1650
c19d1205
ZW
1651 /* We come back here if we get ranges concatenated by '+' or '|'. */
1652 do
6057a28f 1653 {
477330fc
RM
1654 skip_whitespace (str);
1655
c19d1205 1656 another_range = 0;
a737bd4d 1657
c19d1205
ZW
1658 if (*str == '{')
1659 {
1660 int in_range = 0;
1661 int cur_reg = -1;
a737bd4d 1662
c19d1205
ZW
1663 str++;
1664 do
1665 {
1666 int reg;
6057a28f 1667
dcbf9037 1668 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1669 {
dcbf9037 1670 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1671 return FAIL;
1672 }
a737bd4d 1673
c19d1205
ZW
1674 if (in_range)
1675 {
1676 int i;
a737bd4d 1677
c19d1205
ZW
1678 if (reg <= cur_reg)
1679 {
dcbf9037 1680 first_error (_("bad range in register list"));
c19d1205
ZW
1681 return FAIL;
1682 }
40a18ebd 1683
c19d1205
ZW
1684 for (i = cur_reg + 1; i < reg; i++)
1685 {
1686 if (range & (1 << i))
1687 as_tsktsk
1688 (_("Warning: duplicated register (r%d) in register list"),
1689 i);
1690 else
1691 range |= 1 << i;
1692 }
1693 in_range = 0;
1694 }
a737bd4d 1695
c19d1205
ZW
1696 if (range & (1 << reg))
1697 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1698 reg);
1699 else if (reg <= cur_reg)
1700 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1701
c19d1205
ZW
1702 range |= 1 << reg;
1703 cur_reg = reg;
1704 }
1705 while (skip_past_comma (&str) != FAIL
1706 || (in_range = 1, *str++ == '-'));
1707 str--;
a737bd4d 1708
d996d970 1709 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1710 {
dcbf9037 1711 first_error (_("missing `}'"));
c19d1205
ZW
1712 return FAIL;
1713 }
1714 }
1715 else
1716 {
91d6fa6a 1717 expressionS exp;
40a18ebd 1718
91d6fa6a 1719 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1720 return FAIL;
40a18ebd 1721
91d6fa6a 1722 if (exp.X_op == O_constant)
c19d1205 1723 {
91d6fa6a
NC
1724 if (exp.X_add_number
1725 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1726 {
1727 inst.error = _("invalid register mask");
1728 return FAIL;
1729 }
a737bd4d 1730
91d6fa6a 1731 if ((range & exp.X_add_number) != 0)
c19d1205 1732 {
91d6fa6a 1733 int regno = range & exp.X_add_number;
a737bd4d 1734
c19d1205
ZW
1735 regno &= -regno;
1736 regno = (1 << regno) - 1;
1737 as_tsktsk
1738 (_("Warning: duplicated register (r%d) in register list"),
1739 regno);
1740 }
a737bd4d 1741
91d6fa6a 1742 range |= exp.X_add_number;
c19d1205
ZW
1743 }
1744 else
1745 {
1746 if (inst.reloc.type != 0)
1747 {
1748 inst.error = _("expression too complex");
1749 return FAIL;
1750 }
a737bd4d 1751
91d6fa6a 1752 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1753 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1754 inst.reloc.pc_rel = 0;
1755 }
1756 }
a737bd4d 1757
c19d1205
ZW
1758 if (*str == '|' || *str == '+')
1759 {
1760 str++;
1761 another_range = 1;
1762 }
a737bd4d 1763 }
c19d1205 1764 while (another_range);
a737bd4d 1765
c19d1205
ZW
1766 *strp = str;
1767 return range;
a737bd4d
NC
1768}
1769
5287ad62
JB
1770/* Types of registers in a list. */
1771
1772enum reg_list_els
1773{
1774 REGLIST_VFP_S,
1775 REGLIST_VFP_D,
1776 REGLIST_NEON_D
1777};
1778
c19d1205
ZW
1779/* Parse a VFP register list. If the string is invalid return FAIL.
1780 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1781 register. Parses registers of type ETYPE.
1782 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1783 - Q registers can be used to specify pairs of D registers
1784 - { } can be omitted from around a singleton register list
477330fc
RM
1785 FIXME: This is not implemented, as it would require backtracking in
1786 some cases, e.g.:
1787 vtbl.8 d3,d4,d5
1788 This could be done (the meaning isn't really ambiguous), but doesn't
1789 fit in well with the current parsing framework.
dcbf9037
JB
1790 - 32 D registers may be used (also true for VFPv3).
1791 FIXME: Types are ignored in these register lists, which is probably a
1792 bug. */
6057a28f 1793
c19d1205 1794static int
037e8744 1795parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1796{
037e8744 1797 char *str = *ccp;
c19d1205
ZW
1798 int base_reg;
1799 int new_base;
21d799b5 1800 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1801 int max_regs = 0;
c19d1205
ZW
1802 int count = 0;
1803 int warned = 0;
1804 unsigned long mask = 0;
a737bd4d 1805 int i;
6057a28f 1806
477330fc 1807 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1808 {
1809 inst.error = _("expecting {");
1810 return FAIL;
1811 }
6057a28f 1812
5287ad62 1813 switch (etype)
c19d1205 1814 {
5287ad62 1815 case REGLIST_VFP_S:
c19d1205
ZW
1816 regtype = REG_TYPE_VFS;
1817 max_regs = 32;
5287ad62 1818 break;
5f4273c7 1819
5287ad62
JB
1820 case REGLIST_VFP_D:
1821 regtype = REG_TYPE_VFD;
b7fc2769 1822 break;
5f4273c7 1823
b7fc2769
JB
1824 case REGLIST_NEON_D:
1825 regtype = REG_TYPE_NDQ;
1826 break;
1827 }
1828
1829 if (etype != REGLIST_VFP_S)
1830 {
b1cc4aeb
PB
1831 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1832 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1833 {
1834 max_regs = 32;
1835 if (thumb_mode)
1836 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1837 fpu_vfp_ext_d32);
1838 else
1839 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1840 fpu_vfp_ext_d32);
1841 }
5287ad62 1842 else
477330fc 1843 max_regs = 16;
c19d1205 1844 }
6057a28f 1845
c19d1205 1846 base_reg = max_regs;
a737bd4d 1847
c19d1205
ZW
1848 do
1849 {
5287ad62 1850 int setmask = 1, addregs = 1;
dcbf9037 1851
037e8744 1852 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1853
c19d1205 1854 if (new_base == FAIL)
a737bd4d 1855 {
dcbf9037 1856 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1857 return FAIL;
1858 }
5f4273c7 1859
b7fc2769 1860 if (new_base >= max_regs)
477330fc
RM
1861 {
1862 first_error (_("register out of range in list"));
1863 return FAIL;
1864 }
5f4273c7 1865
5287ad62
JB
1866 /* Note: a value of 2 * n is returned for the register Q<n>. */
1867 if (regtype == REG_TYPE_NQ)
477330fc
RM
1868 {
1869 setmask = 3;
1870 addregs = 2;
1871 }
5287ad62 1872
c19d1205
ZW
1873 if (new_base < base_reg)
1874 base_reg = new_base;
a737bd4d 1875
5287ad62 1876 if (mask & (setmask << new_base))
c19d1205 1877 {
dcbf9037 1878 first_error (_("invalid register list"));
c19d1205 1879 return FAIL;
a737bd4d 1880 }
a737bd4d 1881
c19d1205
ZW
1882 if ((mask >> new_base) != 0 && ! warned)
1883 {
1884 as_tsktsk (_("register list not in ascending order"));
1885 warned = 1;
1886 }
0bbf2aa4 1887
5287ad62
JB
1888 mask |= setmask << new_base;
1889 count += addregs;
0bbf2aa4 1890
037e8744 1891 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1892 {
1893 int high_range;
0bbf2aa4 1894
037e8744 1895 str++;
0bbf2aa4 1896
037e8744 1897 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1898 == FAIL)
c19d1205
ZW
1899 {
1900 inst.error = gettext (reg_expected_msgs[regtype]);
1901 return FAIL;
1902 }
0bbf2aa4 1903
477330fc
RM
1904 if (high_range >= max_regs)
1905 {
1906 first_error (_("register out of range in list"));
1907 return FAIL;
1908 }
b7fc2769 1909
477330fc
RM
1910 if (regtype == REG_TYPE_NQ)
1911 high_range = high_range + 1;
5287ad62 1912
c19d1205
ZW
1913 if (high_range <= new_base)
1914 {
1915 inst.error = _("register range not in ascending order");
1916 return FAIL;
1917 }
0bbf2aa4 1918
5287ad62 1919 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1920 {
5287ad62 1921 if (mask & (setmask << new_base))
0bbf2aa4 1922 {
c19d1205
ZW
1923 inst.error = _("invalid register list");
1924 return FAIL;
0bbf2aa4 1925 }
c19d1205 1926
5287ad62
JB
1927 mask |= setmask << new_base;
1928 count += addregs;
0bbf2aa4 1929 }
0bbf2aa4 1930 }
0bbf2aa4 1931 }
037e8744 1932 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1933
037e8744 1934 str++;
0bbf2aa4 1935
c19d1205
ZW
1936 /* Sanity check -- should have raised a parse error above. */
1937 if (count == 0 || count > max_regs)
1938 abort ();
1939
1940 *pbase = base_reg;
1941
1942 /* Final test -- the registers must be consecutive. */
1943 mask >>= base_reg;
1944 for (i = 0; i < count; i++)
1945 {
1946 if ((mask & (1u << i)) == 0)
1947 {
1948 inst.error = _("non-contiguous register range");
1949 return FAIL;
1950 }
1951 }
1952
037e8744
JB
1953 *ccp = str;
1954
c19d1205 1955 return count;
b99bd4ef
NC
1956}
1957
dcbf9037
JB
1958/* True if two alias types are the same. */
1959
c921be7d 1960static bfd_boolean
dcbf9037
JB
1961neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1962{
1963 if (!a && !b)
c921be7d 1964 return TRUE;
5f4273c7 1965
dcbf9037 1966 if (!a || !b)
c921be7d 1967 return FALSE;
dcbf9037
JB
1968
1969 if (a->defined != b->defined)
c921be7d 1970 return FALSE;
5f4273c7 1971
dcbf9037
JB
1972 if ((a->defined & NTA_HASTYPE) != 0
1973 && (a->eltype.type != b->eltype.type
477330fc 1974 || a->eltype.size != b->eltype.size))
c921be7d 1975 return FALSE;
dcbf9037
JB
1976
1977 if ((a->defined & NTA_HASINDEX) != 0
1978 && (a->index != b->index))
c921be7d 1979 return FALSE;
5f4273c7 1980
c921be7d 1981 return TRUE;
dcbf9037
JB
1982}
1983
5287ad62
JB
1984/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1985 The base register is put in *PBASE.
dcbf9037 1986 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1987 the return value.
1988 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1989 Bits [6:5] encode the list length (minus one).
1990 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1991
5287ad62 1992#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1993#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1994#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1995
1996static int
dcbf9037 1997parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 1998 struct neon_type_el *eltype)
5287ad62
JB
1999{
2000 char *ptr = *str;
2001 int base_reg = -1;
2002 int reg_incr = -1;
2003 int count = 0;
2004 int lane = -1;
2005 int leading_brace = 0;
2006 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
2007 const char *const incr_error = _("register stride must be 1 or 2");
2008 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2009 struct neon_typed_alias firsttype;
f85d59c3
KT
2010 firsttype.defined = 0;
2011 firsttype.eltype.type = NT_invtype;
2012 firsttype.eltype.size = -1;
2013 firsttype.index = -1;
5f4273c7 2014
5287ad62
JB
2015 if (skip_past_char (&ptr, '{') == SUCCESS)
2016 leading_brace = 1;
5f4273c7 2017
5287ad62
JB
2018 do
2019 {
dcbf9037
JB
2020 struct neon_typed_alias atype;
2021 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2022
5287ad62 2023 if (getreg == FAIL)
477330fc
RM
2024 {
2025 first_error (_(reg_expected_msgs[rtype]));
2026 return FAIL;
2027 }
5f4273c7 2028
5287ad62 2029 if (base_reg == -1)
477330fc
RM
2030 {
2031 base_reg = getreg;
2032 if (rtype == REG_TYPE_NQ)
2033 {
2034 reg_incr = 1;
2035 }
2036 firsttype = atype;
2037 }
5287ad62 2038 else if (reg_incr == -1)
477330fc
RM
2039 {
2040 reg_incr = getreg - base_reg;
2041 if (reg_incr < 1 || reg_incr > 2)
2042 {
2043 first_error (_(incr_error));
2044 return FAIL;
2045 }
2046 }
5287ad62 2047 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2048 {
2049 first_error (_(incr_error));
2050 return FAIL;
2051 }
dcbf9037 2052
c921be7d 2053 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2054 {
2055 first_error (_(type_error));
2056 return FAIL;
2057 }
5f4273c7 2058
5287ad62 2059 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2060 modes. */
5287ad62 2061 if (ptr[0] == '-')
477330fc
RM
2062 {
2063 struct neon_typed_alias htype;
2064 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2065 if (lane == -1)
2066 lane = NEON_INTERLEAVE_LANES;
2067 else if (lane != NEON_INTERLEAVE_LANES)
2068 {
2069 first_error (_(type_error));
2070 return FAIL;
2071 }
2072 if (reg_incr == -1)
2073 reg_incr = 1;
2074 else if (reg_incr != 1)
2075 {
2076 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2077 return FAIL;
2078 }
2079 ptr++;
2080 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2081 if (hireg == FAIL)
2082 {
2083 first_error (_(reg_expected_msgs[rtype]));
2084 return FAIL;
2085 }
2086 if (! neon_alias_types_same (&htype, &firsttype))
2087 {
2088 first_error (_(type_error));
2089 return FAIL;
2090 }
2091 count += hireg + dregs - getreg;
2092 continue;
2093 }
5f4273c7 2094
5287ad62
JB
2095 /* If we're using Q registers, we can't use [] or [n] syntax. */
2096 if (rtype == REG_TYPE_NQ)
477330fc
RM
2097 {
2098 count += 2;
2099 continue;
2100 }
5f4273c7 2101
dcbf9037 2102 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2103 {
2104 if (lane == -1)
2105 lane = atype.index;
2106 else if (lane != atype.index)
2107 {
2108 first_error (_(type_error));
2109 return FAIL;
2110 }
2111 }
5287ad62 2112 else if (lane == -1)
477330fc 2113 lane = NEON_INTERLEAVE_LANES;
5287ad62 2114 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2115 {
2116 first_error (_(type_error));
2117 return FAIL;
2118 }
5287ad62
JB
2119 count++;
2120 }
2121 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2122
5287ad62
JB
2123 /* No lane set by [x]. We must be interleaving structures. */
2124 if (lane == -1)
2125 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2126
5287ad62
JB
2127 /* Sanity check. */
2128 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2129 || (count > 1 && reg_incr == -1))
2130 {
dcbf9037 2131 first_error (_("error parsing element/structure list"));
5287ad62
JB
2132 return FAIL;
2133 }
2134
2135 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2136 {
dcbf9037 2137 first_error (_("expected }"));
5287ad62
JB
2138 return FAIL;
2139 }
5f4273c7 2140
5287ad62
JB
2141 if (reg_incr == -1)
2142 reg_incr = 1;
2143
dcbf9037
JB
2144 if (eltype)
2145 *eltype = firsttype.eltype;
2146
5287ad62
JB
2147 *pbase = base_reg;
2148 *str = ptr;
5f4273c7 2149
5287ad62
JB
2150 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2151}
2152
c19d1205
ZW
2153/* Parse an explicit relocation suffix on an expression. This is
2154 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2155 arm_reloc_hsh contains no entries, so this function can only
2156 succeed if there is no () after the word. Returns -1 on error,
2157 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2158
c19d1205
ZW
2159static int
2160parse_reloc (char **str)
b99bd4ef 2161{
c19d1205
ZW
2162 struct reloc_entry *r;
2163 char *p, *q;
b99bd4ef 2164
c19d1205
ZW
2165 if (**str != '(')
2166 return BFD_RELOC_UNUSED;
b99bd4ef 2167
c19d1205
ZW
2168 p = *str + 1;
2169 q = p;
2170
2171 while (*q && *q != ')' && *q != ',')
2172 q++;
2173 if (*q != ')')
2174 return -1;
2175
21d799b5
NC
2176 if ((r = (struct reloc_entry *)
2177 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2178 return -1;
2179
2180 *str = q + 1;
2181 return r->reloc;
b99bd4ef
NC
2182}
2183
c19d1205
ZW
2184/* Directives: register aliases. */
2185
dcbf9037 2186static struct reg_entry *
90ec0d68 2187insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2188{
d3ce72d0 2189 struct reg_entry *new_reg;
c19d1205 2190 const char *name;
b99bd4ef 2191
d3ce72d0 2192 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2193 {
d3ce72d0 2194 if (new_reg->builtin)
c19d1205 2195 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2196
c19d1205
ZW
2197 /* Only warn about a redefinition if it's not defined as the
2198 same register. */
d3ce72d0 2199 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2200 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2201
d929913e 2202 return NULL;
c19d1205 2203 }
b99bd4ef 2204
c19d1205 2205 name = xstrdup (str);
325801bd 2206 new_reg = XNEW (struct reg_entry);
b99bd4ef 2207
d3ce72d0
NC
2208 new_reg->name = name;
2209 new_reg->number = number;
2210 new_reg->type = type;
2211 new_reg->builtin = FALSE;
2212 new_reg->neon = NULL;
b99bd4ef 2213
d3ce72d0 2214 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2215 abort ();
5f4273c7 2216
d3ce72d0 2217 return new_reg;
dcbf9037
JB
2218}
2219
2220static void
2221insert_neon_reg_alias (char *str, int number, int type,
477330fc 2222 struct neon_typed_alias *atype)
dcbf9037
JB
2223{
2224 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2225
dcbf9037
JB
2226 if (!reg)
2227 {
2228 first_error (_("attempt to redefine typed alias"));
2229 return;
2230 }
5f4273c7 2231
dcbf9037
JB
2232 if (atype)
2233 {
325801bd 2234 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2235 *reg->neon = *atype;
2236 }
c19d1205 2237}
b99bd4ef 2238
c19d1205 2239/* Look for the .req directive. This is of the form:
b99bd4ef 2240
c19d1205 2241 new_register_name .req existing_register_name
b99bd4ef 2242
c19d1205 2243 If we find one, or if it looks sufficiently like one that we want to
d929913e 2244 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2245
d929913e 2246static bfd_boolean
c19d1205
ZW
2247create_register_alias (char * newname, char *p)
2248{
2249 struct reg_entry *old;
2250 char *oldname, *nbuf;
2251 size_t nlen;
b99bd4ef 2252
c19d1205
ZW
2253 /* The input scrubber ensures that whitespace after the mnemonic is
2254 collapsed to single spaces. */
2255 oldname = p;
2256 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2257 return FALSE;
b99bd4ef 2258
c19d1205
ZW
2259 oldname += 6;
2260 if (*oldname == '\0')
d929913e 2261 return FALSE;
b99bd4ef 2262
21d799b5 2263 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2264 if (!old)
b99bd4ef 2265 {
c19d1205 2266 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2267 return TRUE;
b99bd4ef
NC
2268 }
2269
c19d1205
ZW
2270 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2271 the desired alias name, and p points to its end. If not, then
2272 the desired alias name is in the global original_case_string. */
2273#ifdef TC_CASE_SENSITIVE
2274 nlen = p - newname;
2275#else
2276 newname = original_case_string;
2277 nlen = strlen (newname);
2278#endif
b99bd4ef 2279
29a2809e 2280 nbuf = xmemdup0 (newname, nlen);
b99bd4ef 2281
c19d1205
ZW
2282 /* Create aliases under the new name as stated; an all-lowercase
2283 version of the new name; and an all-uppercase version of the new
2284 name. */
d929913e
NC
2285 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2286 {
2287 for (p = nbuf; *p; p++)
2288 *p = TOUPPER (*p);
c19d1205 2289
d929913e
NC
2290 if (strncmp (nbuf, newname, nlen))
2291 {
2292 /* If this attempt to create an additional alias fails, do not bother
2293 trying to create the all-lower case alias. We will fail and issue
2294 a second, duplicate error message. This situation arises when the
2295 programmer does something like:
2296 foo .req r0
2297 Foo .req r1
2298 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2299 the artificial FOO alias because it has already been created by the
d929913e
NC
2300 first .req. */
2301 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2302 {
2303 free (nbuf);
2304 return TRUE;
2305 }
d929913e 2306 }
c19d1205 2307
d929913e
NC
2308 for (p = nbuf; *p; p++)
2309 *p = TOLOWER (*p);
c19d1205 2310
d929913e
NC
2311 if (strncmp (nbuf, newname, nlen))
2312 insert_reg_alias (nbuf, old->number, old->type);
2313 }
c19d1205 2314
e1fa0163 2315 free (nbuf);
d929913e 2316 return TRUE;
b99bd4ef
NC
2317}
2318
dcbf9037
JB
2319/* Create a Neon typed/indexed register alias using directives, e.g.:
2320 X .dn d5.s32[1]
2321 Y .qn 6.s16
2322 Z .dn d7
2323 T .dn Z[0]
2324 These typed registers can be used instead of the types specified after the
2325 Neon mnemonic, so long as all operands given have types. Types can also be
2326 specified directly, e.g.:
5f4273c7 2327 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2328
c921be7d 2329static bfd_boolean
dcbf9037
JB
2330create_neon_reg_alias (char *newname, char *p)
2331{
2332 enum arm_reg_type basetype;
2333 struct reg_entry *basereg;
2334 struct reg_entry mybasereg;
2335 struct neon_type ntype;
2336 struct neon_typed_alias typeinfo;
12d6b0b7 2337 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2338 int namelen;
5f4273c7 2339
dcbf9037
JB
2340 typeinfo.defined = 0;
2341 typeinfo.eltype.type = NT_invtype;
2342 typeinfo.eltype.size = -1;
2343 typeinfo.index = -1;
5f4273c7 2344
dcbf9037 2345 nameend = p;
5f4273c7 2346
dcbf9037
JB
2347 if (strncmp (p, " .dn ", 5) == 0)
2348 basetype = REG_TYPE_VFD;
2349 else if (strncmp (p, " .qn ", 5) == 0)
2350 basetype = REG_TYPE_NQ;
2351 else
c921be7d 2352 return FALSE;
5f4273c7 2353
dcbf9037 2354 p += 5;
5f4273c7 2355
dcbf9037 2356 if (*p == '\0')
c921be7d 2357 return FALSE;
5f4273c7 2358
dcbf9037
JB
2359 basereg = arm_reg_parse_multi (&p);
2360
2361 if (basereg && basereg->type != basetype)
2362 {
2363 as_bad (_("bad type for register"));
c921be7d 2364 return FALSE;
dcbf9037
JB
2365 }
2366
2367 if (basereg == NULL)
2368 {
2369 expressionS exp;
2370 /* Try parsing as an integer. */
2371 my_get_expression (&exp, &p, GE_NO_PREFIX);
2372 if (exp.X_op != O_constant)
477330fc
RM
2373 {
2374 as_bad (_("expression must be constant"));
2375 return FALSE;
2376 }
dcbf9037
JB
2377 basereg = &mybasereg;
2378 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2379 : exp.X_add_number;
dcbf9037
JB
2380 basereg->neon = 0;
2381 }
2382
2383 if (basereg->neon)
2384 typeinfo = *basereg->neon;
2385
2386 if (parse_neon_type (&ntype, &p) == SUCCESS)
2387 {
2388 /* We got a type. */
2389 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2390 {
2391 as_bad (_("can't redefine the type of a register alias"));
2392 return FALSE;
2393 }
5f4273c7 2394
dcbf9037
JB
2395 typeinfo.defined |= NTA_HASTYPE;
2396 if (ntype.elems != 1)
477330fc
RM
2397 {
2398 as_bad (_("you must specify a single type only"));
2399 return FALSE;
2400 }
dcbf9037
JB
2401 typeinfo.eltype = ntype.el[0];
2402 }
5f4273c7 2403
dcbf9037
JB
2404 if (skip_past_char (&p, '[') == SUCCESS)
2405 {
2406 expressionS exp;
2407 /* We got a scalar index. */
5f4273c7 2408
dcbf9037 2409 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2410 {
2411 as_bad (_("can't redefine the index of a scalar alias"));
2412 return FALSE;
2413 }
5f4273c7 2414
dcbf9037 2415 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2416
dcbf9037 2417 if (exp.X_op != O_constant)
477330fc
RM
2418 {
2419 as_bad (_("scalar index must be constant"));
2420 return FALSE;
2421 }
5f4273c7 2422
dcbf9037
JB
2423 typeinfo.defined |= NTA_HASINDEX;
2424 typeinfo.index = exp.X_add_number;
5f4273c7 2425
dcbf9037 2426 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2427 {
2428 as_bad (_("expecting ]"));
2429 return FALSE;
2430 }
dcbf9037
JB
2431 }
2432
15735687
NS
2433 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2434 the desired alias name, and p points to its end. If not, then
2435 the desired alias name is in the global original_case_string. */
2436#ifdef TC_CASE_SENSITIVE
dcbf9037 2437 namelen = nameend - newname;
15735687
NS
2438#else
2439 newname = original_case_string;
2440 namelen = strlen (newname);
2441#endif
2442
29a2809e 2443 namebuf = xmemdup0 (newname, namelen);
5f4273c7 2444
dcbf9037 2445 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2446 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2447
dcbf9037
JB
2448 /* Insert name in all uppercase. */
2449 for (p = namebuf; *p; p++)
2450 *p = TOUPPER (*p);
5f4273c7 2451
dcbf9037
JB
2452 if (strncmp (namebuf, newname, namelen))
2453 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2454 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2455
dcbf9037
JB
2456 /* Insert name in all lowercase. */
2457 for (p = namebuf; *p; p++)
2458 *p = TOLOWER (*p);
5f4273c7 2459
dcbf9037
JB
2460 if (strncmp (namebuf, newname, namelen))
2461 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2462 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2463
e1fa0163 2464 free (namebuf);
c921be7d 2465 return TRUE;
dcbf9037
JB
2466}
2467
c19d1205
ZW
2468/* Should never be called, as .req goes between the alias and the
2469 register name, not at the beginning of the line. */
c921be7d 2470
b99bd4ef 2471static void
c19d1205 2472s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2473{
c19d1205
ZW
2474 as_bad (_("invalid syntax for .req directive"));
2475}
b99bd4ef 2476
dcbf9037
JB
2477static void
2478s_dn (int a ATTRIBUTE_UNUSED)
2479{
2480 as_bad (_("invalid syntax for .dn directive"));
2481}
2482
2483static void
2484s_qn (int a ATTRIBUTE_UNUSED)
2485{
2486 as_bad (_("invalid syntax for .qn directive"));
2487}
2488
c19d1205
ZW
2489/* The .unreq directive deletes an alias which was previously defined
2490 by .req. For example:
b99bd4ef 2491
c19d1205
ZW
2492 my_alias .req r11
2493 .unreq my_alias */
b99bd4ef
NC
2494
2495static void
c19d1205 2496s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2497{
c19d1205
ZW
2498 char * name;
2499 char saved_char;
b99bd4ef 2500
c19d1205
ZW
2501 name = input_line_pointer;
2502
2503 while (*input_line_pointer != 0
2504 && *input_line_pointer != ' '
2505 && *input_line_pointer != '\n')
2506 ++input_line_pointer;
2507
2508 saved_char = *input_line_pointer;
2509 *input_line_pointer = 0;
2510
2511 if (!*name)
2512 as_bad (_("invalid syntax for .unreq directive"));
2513 else
2514 {
21d799b5 2515 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2516 name);
c19d1205
ZW
2517
2518 if (!reg)
2519 as_bad (_("unknown register alias '%s'"), name);
2520 else if (reg->builtin)
a1727c1a 2521 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2522 name);
2523 else
2524 {
d929913e
NC
2525 char * p;
2526 char * nbuf;
2527
db0bc284 2528 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2529 free ((char *) reg->name);
477330fc
RM
2530 if (reg->neon)
2531 free (reg->neon);
c19d1205 2532 free (reg);
d929913e
NC
2533
2534 /* Also locate the all upper case and all lower case versions.
2535 Do not complain if we cannot find one or the other as it
2536 was probably deleted above. */
5f4273c7 2537
d929913e
NC
2538 nbuf = strdup (name);
2539 for (p = nbuf; *p; p++)
2540 *p = TOUPPER (*p);
21d799b5 2541 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2542 if (reg)
2543 {
db0bc284 2544 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2545 free ((char *) reg->name);
2546 if (reg->neon)
2547 free (reg->neon);
2548 free (reg);
2549 }
2550
2551 for (p = nbuf; *p; p++)
2552 *p = TOLOWER (*p);
21d799b5 2553 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2554 if (reg)
2555 {
db0bc284 2556 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2557 free ((char *) reg->name);
2558 if (reg->neon)
2559 free (reg->neon);
2560 free (reg);
2561 }
2562
2563 free (nbuf);
c19d1205
ZW
2564 }
2565 }
b99bd4ef 2566
c19d1205 2567 *input_line_pointer = saved_char;
b99bd4ef
NC
2568 demand_empty_rest_of_line ();
2569}
2570
c19d1205
ZW
2571/* Directives: Instruction set selection. */
2572
2573#ifdef OBJ_ELF
2574/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2575 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2576 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2577 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2578
cd000bff
DJ
2579/* Create a new mapping symbol for the transition to STATE. */
2580
2581static void
2582make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2583{
a737bd4d 2584 symbolS * symbolP;
c19d1205
ZW
2585 const char * symname;
2586 int type;
b99bd4ef 2587
c19d1205 2588 switch (state)
b99bd4ef 2589 {
c19d1205
ZW
2590 case MAP_DATA:
2591 symname = "$d";
2592 type = BSF_NO_FLAGS;
2593 break;
2594 case MAP_ARM:
2595 symname = "$a";
2596 type = BSF_NO_FLAGS;
2597 break;
2598 case MAP_THUMB:
2599 symname = "$t";
2600 type = BSF_NO_FLAGS;
2601 break;
c19d1205
ZW
2602 default:
2603 abort ();
2604 }
2605
cd000bff 2606 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2607 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2608
2609 switch (state)
2610 {
2611 case MAP_ARM:
2612 THUMB_SET_FUNC (symbolP, 0);
2613 ARM_SET_THUMB (symbolP, 0);
2614 ARM_SET_INTERWORK (symbolP, support_interwork);
2615 break;
2616
2617 case MAP_THUMB:
2618 THUMB_SET_FUNC (symbolP, 1);
2619 ARM_SET_THUMB (symbolP, 1);
2620 ARM_SET_INTERWORK (symbolP, support_interwork);
2621 break;
2622
2623 case MAP_DATA:
2624 default:
cd000bff
DJ
2625 break;
2626 }
2627
2628 /* Save the mapping symbols for future reference. Also check that
2629 we do not place two mapping symbols at the same offset within a
2630 frag. We'll handle overlap between frags in
2de7820f
JZ
2631 check_mapping_symbols.
2632
2633 If .fill or other data filling directive generates zero sized data,
2634 the mapping symbol for the following code will have the same value
2635 as the one generated for the data filling directive. In this case,
2636 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2637 if (value == 0)
2638 {
2de7820f
JZ
2639 if (frag->tc_frag_data.first_map != NULL)
2640 {
2641 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2642 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2643 }
cd000bff
DJ
2644 frag->tc_frag_data.first_map = symbolP;
2645 }
2646 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2647 {
2648 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2649 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2650 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2651 }
cd000bff
DJ
2652 frag->tc_frag_data.last_map = symbolP;
2653}
2654
2655/* We must sometimes convert a region marked as code to data during
2656 code alignment, if an odd number of bytes have to be padded. The
2657 code mapping symbol is pushed to an aligned address. */
2658
2659static void
2660insert_data_mapping_symbol (enum mstate state,
2661 valueT value, fragS *frag, offsetT bytes)
2662{
2663 /* If there was already a mapping symbol, remove it. */
2664 if (frag->tc_frag_data.last_map != NULL
2665 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2666 {
2667 symbolS *symp = frag->tc_frag_data.last_map;
2668
2669 if (value == 0)
2670 {
2671 know (frag->tc_frag_data.first_map == symp);
2672 frag->tc_frag_data.first_map = NULL;
2673 }
2674 frag->tc_frag_data.last_map = NULL;
2675 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2676 }
cd000bff
DJ
2677
2678 make_mapping_symbol (MAP_DATA, value, frag);
2679 make_mapping_symbol (state, value + bytes, frag);
2680}
2681
2682static void mapping_state_2 (enum mstate state, int max_chars);
2683
2684/* Set the mapping state to STATE. Only call this when about to
2685 emit some STATE bytes to the file. */
2686
4e9aaefb 2687#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2688void
2689mapping_state (enum mstate state)
2690{
940b5ce0
DJ
2691 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2692
cd000bff
DJ
2693 if (mapstate == state)
2694 /* The mapping symbol has already been emitted.
2695 There is nothing else to do. */
2696 return;
49c62a33
NC
2697
2698 if (state == MAP_ARM || state == MAP_THUMB)
2699 /* PR gas/12931
2700 All ARM instructions require 4-byte alignment.
2701 (Almost) all Thumb instructions require 2-byte alignment.
2702
2703 When emitting instructions into any section, mark the section
2704 appropriately.
2705
2706 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2707 but themselves require 2-byte alignment; this applies to some
2708 PC- relative forms. However, these cases will invovle implicit
2709 literal pool generation or an explicit .align >=2, both of
2710 which will cause the section to me marked with sufficient
2711 alignment. Thus, we don't handle those cases here. */
2712 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2713
2714 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2715 /* This case will be evaluated later. */
cd000bff 2716 return;
cd000bff
DJ
2717
2718 mapping_state_2 (state, 0);
cd000bff
DJ
2719}
2720
2721/* Same as mapping_state, but MAX_CHARS bytes have already been
2722 allocated. Put the mapping symbol that far back. */
2723
2724static void
2725mapping_state_2 (enum mstate state, int max_chars)
2726{
940b5ce0
DJ
2727 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2728
2729 if (!SEG_NORMAL (now_seg))
2730 return;
2731
cd000bff
DJ
2732 if (mapstate == state)
2733 /* The mapping symbol has already been emitted.
2734 There is nothing else to do. */
2735 return;
2736
4e9aaefb
SA
2737 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2738 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2739 {
2740 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2741 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2742
2743 if (add_symbol)
2744 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2745 }
2746
cd000bff
DJ
2747 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2748 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2749}
4e9aaefb 2750#undef TRANSITION
c19d1205 2751#else
d3106081
NS
2752#define mapping_state(x) ((void)0)
2753#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2754#endif
2755
2756/* Find the real, Thumb encoded start of a Thumb function. */
2757
4343666d 2758#ifdef OBJ_COFF
c19d1205
ZW
2759static symbolS *
2760find_real_start (symbolS * symbolP)
2761{
2762 char * real_start;
2763 const char * name = S_GET_NAME (symbolP);
2764 symbolS * new_target;
2765
2766 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2767#define STUB_NAME ".real_start_of"
2768
2769 if (name == NULL)
2770 abort ();
2771
37f6032b
ZW
2772 /* The compiler may generate BL instructions to local labels because
2773 it needs to perform a branch to a far away location. These labels
2774 do not have a corresponding ".real_start_of" label. We check
2775 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2776 the ".real_start_of" convention for nonlocal branches. */
2777 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2778 return symbolP;
2779
e1fa0163 2780 real_start = concat (STUB_NAME, name, NULL);
c19d1205 2781 new_target = symbol_find (real_start);
e1fa0163 2782 free (real_start);
c19d1205
ZW
2783
2784 if (new_target == NULL)
2785 {
bd3ba5d1 2786 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2787 new_target = symbolP;
2788 }
2789
c19d1205
ZW
2790 return new_target;
2791}
4343666d 2792#endif
c19d1205
ZW
2793
2794static void
2795opcode_select (int width)
2796{
2797 switch (width)
2798 {
2799 case 16:
2800 if (! thumb_mode)
2801 {
e74cfd16 2802 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2803 as_bad (_("selected processor does not support THUMB opcodes"));
2804
2805 thumb_mode = 1;
2806 /* No need to force the alignment, since we will have been
2807 coming from ARM mode, which is word-aligned. */
2808 record_alignment (now_seg, 1);
2809 }
c19d1205
ZW
2810 break;
2811
2812 case 32:
2813 if (thumb_mode)
2814 {
e74cfd16 2815 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2816 as_bad (_("selected processor does not support ARM opcodes"));
2817
2818 thumb_mode = 0;
2819
2820 if (!need_pass_2)
2821 frag_align (2, 0, 0);
2822
2823 record_alignment (now_seg, 1);
2824 }
c19d1205
ZW
2825 break;
2826
2827 default:
2828 as_bad (_("invalid instruction size selected (%d)"), width);
2829 }
2830}
2831
2832static void
2833s_arm (int ignore ATTRIBUTE_UNUSED)
2834{
2835 opcode_select (32);
2836 demand_empty_rest_of_line ();
2837}
2838
2839static void
2840s_thumb (int ignore ATTRIBUTE_UNUSED)
2841{
2842 opcode_select (16);
2843 demand_empty_rest_of_line ();
2844}
2845
2846static void
2847s_code (int unused ATTRIBUTE_UNUSED)
2848{
2849 int temp;
2850
2851 temp = get_absolute_expression ();
2852 switch (temp)
2853 {
2854 case 16:
2855 case 32:
2856 opcode_select (temp);
2857 break;
2858
2859 default:
2860 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2861 }
2862}
2863
2864static void
2865s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2866{
2867 /* If we are not already in thumb mode go into it, EVEN if
2868 the target processor does not support thumb instructions.
2869 This is used by gcc/config/arm/lib1funcs.asm for example
2870 to compile interworking support functions even if the
2871 target processor should not support interworking. */
2872 if (! thumb_mode)
2873 {
2874 thumb_mode = 2;
2875 record_alignment (now_seg, 1);
2876 }
2877
2878 demand_empty_rest_of_line ();
2879}
2880
2881static void
2882s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2883{
2884 s_thumb (0);
2885
2886 /* The following label is the name/address of the start of a Thumb function.
2887 We need to know this for the interworking support. */
2888 label_is_thumb_function_name = TRUE;
2889}
2890
2891/* Perform a .set directive, but also mark the alias as
2892 being a thumb function. */
2893
2894static void
2895s_thumb_set (int equiv)
2896{
2897 /* XXX the following is a duplicate of the code for s_set() in read.c
2898 We cannot just call that code as we need to get at the symbol that
2899 is created. */
2900 char * name;
2901 char delim;
2902 char * end_name;
2903 symbolS * symbolP;
2904
2905 /* Especial apologies for the random logic:
2906 This just grew, and could be parsed much more simply!
2907 Dean - in haste. */
d02603dc 2908 delim = get_symbol_name (& name);
c19d1205 2909 end_name = input_line_pointer;
d02603dc 2910 (void) restore_line_pointer (delim);
c19d1205
ZW
2911
2912 if (*input_line_pointer != ',')
2913 {
2914 *end_name = 0;
2915 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2916 *end_name = delim;
2917 ignore_rest_of_line ();
2918 return;
2919 }
2920
2921 input_line_pointer++;
2922 *end_name = 0;
2923
2924 if (name[0] == '.' && name[1] == '\0')
2925 {
2926 /* XXX - this should not happen to .thumb_set. */
2927 abort ();
2928 }
2929
2930 if ((symbolP = symbol_find (name)) == NULL
2931 && (symbolP = md_undefined_symbol (name)) == NULL)
2932 {
2933#ifndef NO_LISTING
2934 /* When doing symbol listings, play games with dummy fragments living
2935 outside the normal fragment chain to record the file and line info
c19d1205 2936 for this symbol. */
b99bd4ef
NC
2937 if (listing & LISTING_SYMBOLS)
2938 {
2939 extern struct list_info_struct * listing_tail;
21d799b5 2940 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2941
2942 memset (dummy_frag, 0, sizeof (fragS));
2943 dummy_frag->fr_type = rs_fill;
2944 dummy_frag->line = listing_tail;
2945 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2946 dummy_frag->fr_symbol = symbolP;
2947 }
2948 else
2949#endif
2950 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2951
2952#ifdef OBJ_COFF
2953 /* "set" symbols are local unless otherwise specified. */
2954 SF_SET_LOCAL (symbolP);
2955#endif /* OBJ_COFF */
2956 } /* Make a new symbol. */
2957
2958 symbol_table_insert (symbolP);
2959
2960 * end_name = delim;
2961
2962 if (equiv
2963 && S_IS_DEFINED (symbolP)
2964 && S_GET_SEGMENT (symbolP) != reg_section)
2965 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2966
2967 pseudo_set (symbolP);
2968
2969 demand_empty_rest_of_line ();
2970
c19d1205 2971 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2972
2973 THUMB_SET_FUNC (symbolP, 1);
2974 ARM_SET_THUMB (symbolP, 1);
2975#if defined OBJ_ELF || defined OBJ_COFF
2976 ARM_SET_INTERWORK (symbolP, support_interwork);
2977#endif
2978}
2979
c19d1205 2980/* Directives: Mode selection. */
b99bd4ef 2981
c19d1205
ZW
2982/* .syntax [unified|divided] - choose the new unified syntax
2983 (same for Arm and Thumb encoding, modulo slight differences in what
2984 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2985static void
c19d1205 2986s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2987{
c19d1205
ZW
2988 char *name, delim;
2989
d02603dc 2990 delim = get_symbol_name (& name);
c19d1205
ZW
2991
2992 if (!strcasecmp (name, "unified"))
2993 unified_syntax = TRUE;
2994 else if (!strcasecmp (name, "divided"))
2995 unified_syntax = FALSE;
2996 else
2997 {
2998 as_bad (_("unrecognized syntax mode \"%s\""), name);
2999 return;
3000 }
d02603dc 3001 (void) restore_line_pointer (delim);
b99bd4ef
NC
3002 demand_empty_rest_of_line ();
3003}
3004
c19d1205
ZW
3005/* Directives: sectioning and alignment. */
3006
c19d1205
ZW
3007static void
3008s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3009{
c19d1205
ZW
3010 /* We don't support putting frags in the BSS segment, we fake it by
3011 marking in_bss, then looking at s_skip for clues. */
3012 subseg_set (bss_section, 0);
3013 demand_empty_rest_of_line ();
cd000bff
DJ
3014
3015#ifdef md_elf_section_change_hook
3016 md_elf_section_change_hook ();
3017#endif
c19d1205 3018}
b99bd4ef 3019
c19d1205
ZW
3020static void
3021s_even (int ignore ATTRIBUTE_UNUSED)
3022{
3023 /* Never make frag if expect extra pass. */
3024 if (!need_pass_2)
3025 frag_align (1, 0, 0);
b99bd4ef 3026
c19d1205 3027 record_alignment (now_seg, 1);
b99bd4ef 3028
c19d1205 3029 demand_empty_rest_of_line ();
b99bd4ef
NC
3030}
3031
2e6976a8
DG
3032/* Directives: CodeComposer Studio. */
3033
3034/* .ref (for CodeComposer Studio syntax only). */
3035static void
3036s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3037{
3038 if (codecomposer_syntax)
3039 ignore_rest_of_line ();
3040 else
3041 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3042}
3043
3044/* If name is not NULL, then it is used for marking the beginning of a
3045 function, wherease if it is NULL then it means the function end. */
3046static void
3047asmfunc_debug (const char * name)
3048{
3049 static const char * last_name = NULL;
3050
3051 if (name != NULL)
3052 {
3053 gas_assert (last_name == NULL);
3054 last_name = name;
3055
3056 if (debug_type == DEBUG_STABS)
3057 stabs_generate_asm_func (name, name);
3058 }
3059 else
3060 {
3061 gas_assert (last_name != NULL);
3062
3063 if (debug_type == DEBUG_STABS)
3064 stabs_generate_asm_endfunc (last_name, last_name);
3065
3066 last_name = NULL;
3067 }
3068}
3069
3070static void
3071s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3072{
3073 if (codecomposer_syntax)
3074 {
3075 switch (asmfunc_state)
3076 {
3077 case OUTSIDE_ASMFUNC:
3078 asmfunc_state = WAITING_ASMFUNC_NAME;
3079 break;
3080
3081 case WAITING_ASMFUNC_NAME:
3082 as_bad (_(".asmfunc repeated."));
3083 break;
3084
3085 case WAITING_ENDASMFUNC:
3086 as_bad (_(".asmfunc without function."));
3087 break;
3088 }
3089 demand_empty_rest_of_line ();
3090 }
3091 else
3092 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3093}
3094
3095static void
3096s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3097{
3098 if (codecomposer_syntax)
3099 {
3100 switch (asmfunc_state)
3101 {
3102 case OUTSIDE_ASMFUNC:
3103 as_bad (_(".endasmfunc without a .asmfunc."));
3104 break;
3105
3106 case WAITING_ASMFUNC_NAME:
3107 as_bad (_(".endasmfunc without function."));
3108 break;
3109
3110 case WAITING_ENDASMFUNC:
3111 asmfunc_state = OUTSIDE_ASMFUNC;
3112 asmfunc_debug (NULL);
3113 break;
3114 }
3115 demand_empty_rest_of_line ();
3116 }
3117 else
3118 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3119}
3120
3121static void
3122s_ccs_def (int name)
3123{
3124 if (codecomposer_syntax)
3125 s_globl (name);
3126 else
3127 as_bad (_(".def pseudo-op only available with -mccs flag."));
3128}
3129
c19d1205 3130/* Directives: Literal pools. */
a737bd4d 3131
c19d1205
ZW
3132static literal_pool *
3133find_literal_pool (void)
a737bd4d 3134{
c19d1205 3135 literal_pool * pool;
a737bd4d 3136
c19d1205 3137 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3138 {
c19d1205
ZW
3139 if (pool->section == now_seg
3140 && pool->sub_section == now_subseg)
3141 break;
a737bd4d
NC
3142 }
3143
c19d1205 3144 return pool;
a737bd4d
NC
3145}
3146
c19d1205
ZW
3147static literal_pool *
3148find_or_make_literal_pool (void)
a737bd4d 3149{
c19d1205
ZW
3150 /* Next literal pool ID number. */
3151 static unsigned int latest_pool_num = 1;
3152 literal_pool * pool;
a737bd4d 3153
c19d1205 3154 pool = find_literal_pool ();
a737bd4d 3155
c19d1205 3156 if (pool == NULL)
a737bd4d 3157 {
c19d1205 3158 /* Create a new pool. */
325801bd 3159 pool = XNEW (literal_pool);
c19d1205
ZW
3160 if (! pool)
3161 return NULL;
a737bd4d 3162
c19d1205
ZW
3163 pool->next_free_entry = 0;
3164 pool->section = now_seg;
3165 pool->sub_section = now_subseg;
3166 pool->next = list_of_pools;
3167 pool->symbol = NULL;
8335d6aa 3168 pool->alignment = 2;
c19d1205
ZW
3169
3170 /* Add it to the list. */
3171 list_of_pools = pool;
a737bd4d 3172 }
a737bd4d 3173
c19d1205
ZW
3174 /* New pools, and emptied pools, will have a NULL symbol. */
3175 if (pool->symbol == NULL)
a737bd4d 3176 {
c19d1205
ZW
3177 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3178 (valueT) 0, &zero_address_frag);
3179 pool->id = latest_pool_num ++;
a737bd4d
NC
3180 }
3181
c19d1205
ZW
3182 /* Done. */
3183 return pool;
a737bd4d
NC
3184}
3185
c19d1205 3186/* Add the literal in the global 'inst'
5f4273c7 3187 structure to the relevant literal pool. */
b99bd4ef
NC
3188
3189static int
8335d6aa 3190add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3191{
8335d6aa
JW
3192#define PADDING_SLOT 0x1
3193#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3194 literal_pool * pool;
8335d6aa
JW
3195 unsigned int entry, pool_size = 0;
3196 bfd_boolean padding_slot_p = FALSE;
e56c722b 3197 unsigned imm1 = 0;
8335d6aa
JW
3198 unsigned imm2 = 0;
3199
3200 if (nbytes == 8)
3201 {
3202 imm1 = inst.operands[1].imm;
3203 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3204 : inst.reloc.exp.X_unsigned ? 0
2569ceb0 3205 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3206 if (target_big_endian)
3207 {
3208 imm1 = imm2;
3209 imm2 = inst.operands[1].imm;
3210 }
3211 }
b99bd4ef 3212
c19d1205
ZW
3213 pool = find_or_make_literal_pool ();
3214
3215 /* Check if this literal value is already in the pool. */
3216 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3217 {
8335d6aa
JW
3218 if (nbytes == 4)
3219 {
3220 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3221 && (inst.reloc.exp.X_op == O_constant)
3222 && (pool->literals[entry].X_add_number
3223 == inst.reloc.exp.X_add_number)
3224 && (pool->literals[entry].X_md == nbytes)
3225 && (pool->literals[entry].X_unsigned
3226 == inst.reloc.exp.X_unsigned))
3227 break;
3228
3229 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3230 && (inst.reloc.exp.X_op == O_symbol)
3231 && (pool->literals[entry].X_add_number
3232 == inst.reloc.exp.X_add_number)
3233 && (pool->literals[entry].X_add_symbol
3234 == inst.reloc.exp.X_add_symbol)
3235 && (pool->literals[entry].X_op_symbol
3236 == inst.reloc.exp.X_op_symbol)
3237 && (pool->literals[entry].X_md == nbytes))
3238 break;
3239 }
3240 else if ((nbytes == 8)
3241 && !(pool_size & 0x7)
3242 && ((entry + 1) != pool->next_free_entry)
3243 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3244 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa
JW
3245 && (pool->literals[entry].X_unsigned
3246 == inst.reloc.exp.X_unsigned)
3247 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3248 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa
JW
3249 && (pool->literals[entry + 1].X_unsigned
3250 == inst.reloc.exp.X_unsigned))
c19d1205
ZW
3251 break;
3252
8335d6aa
JW
3253 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3254 if (padding_slot_p && (nbytes == 4))
c19d1205 3255 break;
8335d6aa
JW
3256
3257 pool_size += 4;
b99bd4ef
NC
3258 }
3259
c19d1205
ZW
3260 /* Do we need to create a new entry? */
3261 if (entry == pool->next_free_entry)
3262 {
3263 if (entry >= MAX_LITERAL_POOL_SIZE)
3264 {
3265 inst.error = _("literal pool overflow");
3266 return FAIL;
3267 }
3268
8335d6aa
JW
3269 if (nbytes == 8)
3270 {
3271 /* For 8-byte entries, we align to an 8-byte boundary,
3272 and split it into two 4-byte entries, because on 32-bit
3273 host, 8-byte constants are treated as big num, thus
3274 saved in "generic_bignum" which will be overwritten
3275 by later assignments.
3276
3277 We also need to make sure there is enough space for
3278 the split.
3279
3280 We also check to make sure the literal operand is a
3281 constant number. */
19f2f6a9
JW
3282 if (!(inst.reloc.exp.X_op == O_constant
3283 || inst.reloc.exp.X_op == O_big))
8335d6aa
JW
3284 {
3285 inst.error = _("invalid type for literal pool");
3286 return FAIL;
3287 }
3288 else if (pool_size & 0x7)
3289 {
3290 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3291 {
3292 inst.error = _("literal pool overflow");
3293 return FAIL;
3294 }
3295
3296 pool->literals[entry] = inst.reloc.exp;
a6684f0d 3297 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3298 pool->literals[entry].X_add_number = 0;
3299 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3300 pool->next_free_entry += 1;
3301 pool_size += 4;
3302 }
3303 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3304 {
3305 inst.error = _("literal pool overflow");
3306 return FAIL;
3307 }
3308
3309 pool->literals[entry] = inst.reloc.exp;
3310 pool->literals[entry].X_op = O_constant;
3311 pool->literals[entry].X_add_number = imm1;
3312 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3313 pool->literals[entry++].X_md = 4;
3314 pool->literals[entry] = inst.reloc.exp;
3315 pool->literals[entry].X_op = O_constant;
3316 pool->literals[entry].X_add_number = imm2;
3317 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3318 pool->literals[entry].X_md = 4;
3319 pool->alignment = 3;
3320 pool->next_free_entry += 1;
3321 }
3322 else
3323 {
3324 pool->literals[entry] = inst.reloc.exp;
3325 pool->literals[entry].X_md = 4;
3326 }
3327
a8040cf2
NC
3328#ifdef OBJ_ELF
3329 /* PR ld/12974: Record the location of the first source line to reference
3330 this entry in the literal pool. If it turns out during linking that the
3331 symbol does not exist we will be able to give an accurate line number for
3332 the (first use of the) missing reference. */
3333 if (debug_type == DEBUG_DWARF2)
3334 dwarf2_where (pool->locs + entry);
3335#endif
c19d1205
ZW
3336 pool->next_free_entry += 1;
3337 }
8335d6aa
JW
3338 else if (padding_slot_p)
3339 {
3340 pool->literals[entry] = inst.reloc.exp;
3341 pool->literals[entry].X_md = nbytes;
3342 }
b99bd4ef 3343
c19d1205 3344 inst.reloc.exp.X_op = O_symbol;
8335d6aa 3345 inst.reloc.exp.X_add_number = pool_size;
c19d1205 3346 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3347
c19d1205 3348 return SUCCESS;
b99bd4ef
NC
3349}
3350
2e6976a8 3351bfd_boolean
2e57ce7b 3352tc_start_label_without_colon (void)
2e6976a8
DG
3353{
3354 bfd_boolean ret = TRUE;
3355
3356 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3357 {
2e57ce7b 3358 const char *label = input_line_pointer;
2e6976a8
DG
3359
3360 while (!is_end_of_line[(int) label[-1]])
3361 --label;
3362
3363 if (*label == '.')
3364 {
3365 as_bad (_("Invalid label '%s'"), label);
3366 ret = FALSE;
3367 }
3368
3369 asmfunc_debug (label);
3370
3371 asmfunc_state = WAITING_ENDASMFUNC;
3372 }
3373
3374 return ret;
3375}
3376
c19d1205
ZW
3377/* Can't use symbol_new here, so have to create a symbol and then at
3378 a later date assign it a value. Thats what these functions do. */
e16bb312 3379
c19d1205
ZW
3380static void
3381symbol_locate (symbolS * symbolP,
3382 const char * name, /* It is copied, the caller can modify. */
3383 segT segment, /* Segment identifier (SEG_<something>). */
3384 valueT valu, /* Symbol value. */
3385 fragS * frag) /* Associated fragment. */
3386{
e57e6ddc 3387 size_t name_length;
c19d1205 3388 char * preserved_copy_of_name;
e16bb312 3389
c19d1205
ZW
3390 name_length = strlen (name) + 1; /* +1 for \0. */
3391 obstack_grow (&notes, name, name_length);
21d799b5 3392 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3393
c19d1205
ZW
3394#ifdef tc_canonicalize_symbol_name
3395 preserved_copy_of_name =
3396 tc_canonicalize_symbol_name (preserved_copy_of_name);
3397#endif
b99bd4ef 3398
c19d1205 3399 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3400
c19d1205
ZW
3401 S_SET_SEGMENT (symbolP, segment);
3402 S_SET_VALUE (symbolP, valu);
3403 symbol_clear_list_pointers (symbolP);
b99bd4ef 3404
c19d1205 3405 symbol_set_frag (symbolP, frag);
b99bd4ef 3406
c19d1205
ZW
3407 /* Link to end of symbol chain. */
3408 {
3409 extern int symbol_table_frozen;
b99bd4ef 3410
c19d1205
ZW
3411 if (symbol_table_frozen)
3412 abort ();
3413 }
b99bd4ef 3414
c19d1205 3415 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3416
c19d1205 3417 obj_symbol_new_hook (symbolP);
b99bd4ef 3418
c19d1205
ZW
3419#ifdef tc_symbol_new_hook
3420 tc_symbol_new_hook (symbolP);
3421#endif
3422
3423#ifdef DEBUG_SYMS
3424 verify_symbol_chain (symbol_rootP, symbol_lastP);
3425#endif /* DEBUG_SYMS */
b99bd4ef
NC
3426}
3427
c19d1205
ZW
3428static void
3429s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3430{
c19d1205
ZW
3431 unsigned int entry;
3432 literal_pool * pool;
3433 char sym_name[20];
b99bd4ef 3434
c19d1205
ZW
3435 pool = find_literal_pool ();
3436 if (pool == NULL
3437 || pool->symbol == NULL
3438 || pool->next_free_entry == 0)
3439 return;
b99bd4ef 3440
c19d1205
ZW
3441 /* Align pool as you have word accesses.
3442 Only make a frag if we have to. */
3443 if (!need_pass_2)
8335d6aa 3444 frag_align (pool->alignment, 0, 0);
b99bd4ef 3445
c19d1205 3446 record_alignment (now_seg, 2);
b99bd4ef 3447
aaca88ef 3448#ifdef OBJ_ELF
47fc6e36
WN
3449 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3450 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3451#endif
c19d1205 3452 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3453
c19d1205
ZW
3454 symbol_locate (pool->symbol, sym_name, now_seg,
3455 (valueT) frag_now_fix (), frag_now);
3456 symbol_table_insert (pool->symbol);
b99bd4ef 3457
c19d1205 3458 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3459
c19d1205
ZW
3460#if defined OBJ_COFF || defined OBJ_ELF
3461 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3462#endif
6c43fab6 3463
c19d1205 3464 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3465 {
3466#ifdef OBJ_ELF
3467 if (debug_type == DEBUG_DWARF2)
3468 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3469#endif
3470 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3471 emit_expr (&(pool->literals[entry]),
3472 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3473 }
b99bd4ef 3474
c19d1205
ZW
3475 /* Mark the pool as empty. */
3476 pool->next_free_entry = 0;
3477 pool->symbol = NULL;
b99bd4ef
NC
3478}
3479
c19d1205
ZW
3480#ifdef OBJ_ELF
3481/* Forward declarations for functions below, in the MD interface
3482 section. */
3483static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3484static valueT create_unwind_entry (int);
3485static void start_unwind_section (const segT, int);
3486static void add_unwind_opcode (valueT, int);
3487static void flush_pending_unwind (void);
b99bd4ef 3488
c19d1205 3489/* Directives: Data. */
b99bd4ef 3490
c19d1205
ZW
3491static void
3492s_arm_elf_cons (int nbytes)
3493{
3494 expressionS exp;
b99bd4ef 3495
c19d1205
ZW
3496#ifdef md_flush_pending_output
3497 md_flush_pending_output ();
3498#endif
b99bd4ef 3499
c19d1205 3500 if (is_it_end_of_statement ())
b99bd4ef 3501 {
c19d1205
ZW
3502 demand_empty_rest_of_line ();
3503 return;
b99bd4ef
NC
3504 }
3505
c19d1205
ZW
3506#ifdef md_cons_align
3507 md_cons_align (nbytes);
3508#endif
b99bd4ef 3509
c19d1205
ZW
3510 mapping_state (MAP_DATA);
3511 do
b99bd4ef 3512 {
c19d1205
ZW
3513 int reloc;
3514 char *base = input_line_pointer;
b99bd4ef 3515
c19d1205 3516 expression (& exp);
b99bd4ef 3517
c19d1205
ZW
3518 if (exp.X_op != O_symbol)
3519 emit_expr (&exp, (unsigned int) nbytes);
3520 else
3521 {
3522 char *before_reloc = input_line_pointer;
3523 reloc = parse_reloc (&input_line_pointer);
3524 if (reloc == -1)
3525 {
3526 as_bad (_("unrecognized relocation suffix"));
3527 ignore_rest_of_line ();
3528 return;
3529 }
3530 else if (reloc == BFD_RELOC_UNUSED)
3531 emit_expr (&exp, (unsigned int) nbytes);
3532 else
3533 {
21d799b5 3534 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3535 bfd_reloc_type_lookup (stdoutput,
3536 (bfd_reloc_code_real_type) reloc);
c19d1205 3537 int size = bfd_get_reloc_size (howto);
b99bd4ef 3538
2fc8bdac
ZW
3539 if (reloc == BFD_RELOC_ARM_PLT32)
3540 {
3541 as_bad (_("(plt) is only valid on branch targets"));
3542 reloc = BFD_RELOC_UNUSED;
3543 size = 0;
3544 }
3545
c19d1205 3546 if (size > nbytes)
2fc8bdac 3547 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3548 howto->name, nbytes);
3549 else
3550 {
3551 /* We've parsed an expression stopping at O_symbol.
3552 But there may be more expression left now that we
3553 have parsed the relocation marker. Parse it again.
3554 XXX Surely there is a cleaner way to do this. */
3555 char *p = input_line_pointer;
3556 int offset;
325801bd 3557 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3558
c19d1205
ZW
3559 memcpy (save_buf, base, input_line_pointer - base);
3560 memmove (base + (input_line_pointer - before_reloc),
3561 base, before_reloc - base);
3562
3563 input_line_pointer = base + (input_line_pointer-before_reloc);
3564 expression (&exp);
3565 memcpy (base, save_buf, p - base);
3566
3567 offset = nbytes - size;
4b1a927e
AM
3568 p = frag_more (nbytes);
3569 memset (p, 0, nbytes);
c19d1205 3570 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3571 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3572 free (save_buf);
c19d1205
ZW
3573 }
3574 }
3575 }
b99bd4ef 3576 }
c19d1205 3577 while (*input_line_pointer++ == ',');
b99bd4ef 3578
c19d1205
ZW
3579 /* Put terminator back into stream. */
3580 input_line_pointer --;
3581 demand_empty_rest_of_line ();
b99bd4ef
NC
3582}
3583
c921be7d
NC
3584/* Emit an expression containing a 32-bit thumb instruction.
3585 Implementation based on put_thumb32_insn. */
3586
3587static void
3588emit_thumb32_expr (expressionS * exp)
3589{
3590 expressionS exp_high = *exp;
3591
3592 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3593 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3594 exp->X_add_number &= 0xffff;
3595 emit_expr (exp, (unsigned int) THUMB_SIZE);
3596}
3597
3598/* Guess the instruction size based on the opcode. */
3599
3600static int
3601thumb_insn_size (int opcode)
3602{
3603 if ((unsigned int) opcode < 0xe800u)
3604 return 2;
3605 else if ((unsigned int) opcode >= 0xe8000000u)
3606 return 4;
3607 else
3608 return 0;
3609}
3610
3611static bfd_boolean
3612emit_insn (expressionS *exp, int nbytes)
3613{
3614 int size = 0;
3615
3616 if (exp->X_op == O_constant)
3617 {
3618 size = nbytes;
3619
3620 if (size == 0)
3621 size = thumb_insn_size (exp->X_add_number);
3622
3623 if (size != 0)
3624 {
3625 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3626 {
3627 as_bad (_(".inst.n operand too big. "\
3628 "Use .inst.w instead"));
3629 size = 0;
3630 }
3631 else
3632 {
3633 if (now_it.state == AUTOMATIC_IT_BLOCK)
3634 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3635 else
3636 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3637
3638 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3639 emit_thumb32_expr (exp);
3640 else
3641 emit_expr (exp, (unsigned int) size);
3642
3643 it_fsm_post_encode ();
3644 }
3645 }
3646 else
3647 as_bad (_("cannot determine Thumb instruction size. " \
3648 "Use .inst.n/.inst.w instead"));
3649 }
3650 else
3651 as_bad (_("constant expression required"));
3652
3653 return (size != 0);
3654}
3655
3656/* Like s_arm_elf_cons but do not use md_cons_align and
3657 set the mapping state to MAP_ARM/MAP_THUMB. */
3658
3659static void
3660s_arm_elf_inst (int nbytes)
3661{
3662 if (is_it_end_of_statement ())
3663 {
3664 demand_empty_rest_of_line ();
3665 return;
3666 }
3667
3668 /* Calling mapping_state () here will not change ARM/THUMB,
3669 but will ensure not to be in DATA state. */
3670
3671 if (thumb_mode)
3672 mapping_state (MAP_THUMB);
3673 else
3674 {
3675 if (nbytes != 0)
3676 {
3677 as_bad (_("width suffixes are invalid in ARM mode"));
3678 ignore_rest_of_line ();
3679 return;
3680 }
3681
3682 nbytes = 4;
3683
3684 mapping_state (MAP_ARM);
3685 }
3686
3687 do
3688 {
3689 expressionS exp;
3690
3691 expression (& exp);
3692
3693 if (! emit_insn (& exp, nbytes))
3694 {
3695 ignore_rest_of_line ();
3696 return;
3697 }
3698 }
3699 while (*input_line_pointer++ == ',');
3700
3701 /* Put terminator back into stream. */
3702 input_line_pointer --;
3703 demand_empty_rest_of_line ();
3704}
b99bd4ef 3705
c19d1205 3706/* Parse a .rel31 directive. */
b99bd4ef 3707
c19d1205
ZW
3708static void
3709s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3710{
3711 expressionS exp;
3712 char *p;
3713 valueT highbit;
b99bd4ef 3714
c19d1205
ZW
3715 highbit = 0;
3716 if (*input_line_pointer == '1')
3717 highbit = 0x80000000;
3718 else if (*input_line_pointer != '0')
3719 as_bad (_("expected 0 or 1"));
b99bd4ef 3720
c19d1205
ZW
3721 input_line_pointer++;
3722 if (*input_line_pointer != ',')
3723 as_bad (_("missing comma"));
3724 input_line_pointer++;
b99bd4ef 3725
c19d1205
ZW
3726#ifdef md_flush_pending_output
3727 md_flush_pending_output ();
3728#endif
b99bd4ef 3729
c19d1205
ZW
3730#ifdef md_cons_align
3731 md_cons_align (4);
3732#endif
b99bd4ef 3733
c19d1205 3734 mapping_state (MAP_DATA);
b99bd4ef 3735
c19d1205 3736 expression (&exp);
b99bd4ef 3737
c19d1205
ZW
3738 p = frag_more (4);
3739 md_number_to_chars (p, highbit, 4);
3740 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3741 BFD_RELOC_ARM_PREL31);
b99bd4ef 3742
c19d1205 3743 demand_empty_rest_of_line ();
b99bd4ef
NC
3744}
3745
c19d1205 3746/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3747
c19d1205 3748/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3749
c19d1205
ZW
3750static void
3751s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3752{
3753 demand_empty_rest_of_line ();
921e5f0a
PB
3754 if (unwind.proc_start)
3755 {
c921be7d 3756 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3757 return;
3758 }
3759
c19d1205
ZW
3760 /* Mark the start of the function. */
3761 unwind.proc_start = expr_build_dot ();
b99bd4ef 3762
c19d1205
ZW
3763 /* Reset the rest of the unwind info. */
3764 unwind.opcode_count = 0;
3765 unwind.table_entry = NULL;
3766 unwind.personality_routine = NULL;
3767 unwind.personality_index = -1;
3768 unwind.frame_size = 0;
3769 unwind.fp_offset = 0;
fdfde340 3770 unwind.fp_reg = REG_SP;
c19d1205
ZW
3771 unwind.fp_used = 0;
3772 unwind.sp_restored = 0;
3773}
b99bd4ef 3774
b99bd4ef 3775
c19d1205
ZW
3776/* Parse a handlerdata directive. Creates the exception handling table entry
3777 for the function. */
b99bd4ef 3778
c19d1205
ZW
3779static void
3780s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3781{
3782 demand_empty_rest_of_line ();
921e5f0a 3783 if (!unwind.proc_start)
c921be7d 3784 as_bad (MISSING_FNSTART);
921e5f0a 3785
c19d1205 3786 if (unwind.table_entry)
6decc662 3787 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3788
c19d1205
ZW
3789 create_unwind_entry (1);
3790}
a737bd4d 3791
c19d1205 3792/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3793
c19d1205
ZW
3794static void
3795s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3796{
3797 long where;
3798 char *ptr;
3799 valueT val;
940b5ce0 3800 unsigned int marked_pr_dependency;
f02232aa 3801
c19d1205 3802 demand_empty_rest_of_line ();
f02232aa 3803
921e5f0a
PB
3804 if (!unwind.proc_start)
3805 {
c921be7d 3806 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3807 return;
3808 }
3809
c19d1205
ZW
3810 /* Add eh table entry. */
3811 if (unwind.table_entry == NULL)
3812 val = create_unwind_entry (0);
3813 else
3814 val = 0;
f02232aa 3815
c19d1205
ZW
3816 /* Add index table entry. This is two words. */
3817 start_unwind_section (unwind.saved_seg, 1);
3818 frag_align (2, 0, 0);
3819 record_alignment (now_seg, 2);
b99bd4ef 3820
c19d1205 3821 ptr = frag_more (8);
5011093d 3822 memset (ptr, 0, 8);
c19d1205 3823 where = frag_now_fix () - 8;
f02232aa 3824
c19d1205
ZW
3825 /* Self relative offset of the function start. */
3826 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3827 BFD_RELOC_ARM_PREL31);
f02232aa 3828
c19d1205
ZW
3829 /* Indicate dependency on EHABI-defined personality routines to the
3830 linker, if it hasn't been done already. */
940b5ce0
DJ
3831 marked_pr_dependency
3832 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3833 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3834 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3835 {
5f4273c7
NC
3836 static const char *const name[] =
3837 {
3838 "__aeabi_unwind_cpp_pr0",
3839 "__aeabi_unwind_cpp_pr1",
3840 "__aeabi_unwind_cpp_pr2"
3841 };
c19d1205
ZW
3842 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3843 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3844 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3845 |= 1 << unwind.personality_index;
c19d1205 3846 }
f02232aa 3847
c19d1205
ZW
3848 if (val)
3849 /* Inline exception table entry. */
3850 md_number_to_chars (ptr + 4, val, 4);
3851 else
3852 /* Self relative offset of the table entry. */
3853 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3854 BFD_RELOC_ARM_PREL31);
f02232aa 3855
c19d1205
ZW
3856 /* Restore the original section. */
3857 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3858
3859 unwind.proc_start = NULL;
c19d1205 3860}
f02232aa 3861
f02232aa 3862
c19d1205 3863/* Parse an unwind_cantunwind directive. */
b99bd4ef 3864
c19d1205
ZW
3865static void
3866s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3867{
3868 demand_empty_rest_of_line ();
921e5f0a 3869 if (!unwind.proc_start)
c921be7d 3870 as_bad (MISSING_FNSTART);
921e5f0a 3871
c19d1205
ZW
3872 if (unwind.personality_routine || unwind.personality_index != -1)
3873 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3874
c19d1205
ZW
3875 unwind.personality_index = -2;
3876}
b99bd4ef 3877
b99bd4ef 3878
c19d1205 3879/* Parse a personalityindex directive. */
b99bd4ef 3880
c19d1205
ZW
3881static void
3882s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3883{
3884 expressionS exp;
b99bd4ef 3885
921e5f0a 3886 if (!unwind.proc_start)
c921be7d 3887 as_bad (MISSING_FNSTART);
921e5f0a 3888
c19d1205
ZW
3889 if (unwind.personality_routine || unwind.personality_index != -1)
3890 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3891
c19d1205 3892 expression (&exp);
b99bd4ef 3893
c19d1205
ZW
3894 if (exp.X_op != O_constant
3895 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3896 {
c19d1205
ZW
3897 as_bad (_("bad personality routine number"));
3898 ignore_rest_of_line ();
3899 return;
b99bd4ef
NC
3900 }
3901
c19d1205 3902 unwind.personality_index = exp.X_add_number;
b99bd4ef 3903
c19d1205
ZW
3904 demand_empty_rest_of_line ();
3905}
e16bb312 3906
e16bb312 3907
c19d1205 3908/* Parse a personality directive. */
e16bb312 3909
c19d1205
ZW
3910static void
3911s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3912{
3913 char *name, *p, c;
a737bd4d 3914
921e5f0a 3915 if (!unwind.proc_start)
c921be7d 3916 as_bad (MISSING_FNSTART);
921e5f0a 3917
c19d1205
ZW
3918 if (unwind.personality_routine || unwind.personality_index != -1)
3919 as_bad (_("duplicate .personality directive"));
a737bd4d 3920
d02603dc 3921 c = get_symbol_name (& name);
c19d1205 3922 p = input_line_pointer;
d02603dc
NC
3923 if (c == '"')
3924 ++ input_line_pointer;
c19d1205
ZW
3925 unwind.personality_routine = symbol_find_or_make (name);
3926 *p = c;
3927 demand_empty_rest_of_line ();
3928}
e16bb312 3929
e16bb312 3930
c19d1205 3931/* Parse a directive saving core registers. */
e16bb312 3932
c19d1205
ZW
3933static void
3934s_arm_unwind_save_core (void)
e16bb312 3935{
c19d1205
ZW
3936 valueT op;
3937 long range;
3938 int n;
e16bb312 3939
c19d1205
ZW
3940 range = parse_reg_list (&input_line_pointer);
3941 if (range == FAIL)
e16bb312 3942 {
c19d1205
ZW
3943 as_bad (_("expected register list"));
3944 ignore_rest_of_line ();
3945 return;
3946 }
e16bb312 3947
c19d1205 3948 demand_empty_rest_of_line ();
e16bb312 3949
c19d1205
ZW
3950 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3951 into .unwind_save {..., sp...}. We aren't bothered about the value of
3952 ip because it is clobbered by calls. */
3953 if (unwind.sp_restored && unwind.fp_reg == 12
3954 && (range & 0x3000) == 0x1000)
3955 {
3956 unwind.opcode_count--;
3957 unwind.sp_restored = 0;
3958 range = (range | 0x2000) & ~0x1000;
3959 unwind.pending_offset = 0;
3960 }
e16bb312 3961
01ae4198
DJ
3962 /* Pop r4-r15. */
3963 if (range & 0xfff0)
c19d1205 3964 {
01ae4198
DJ
3965 /* See if we can use the short opcodes. These pop a block of up to 8
3966 registers starting with r4, plus maybe r14. */
3967 for (n = 0; n < 8; n++)
3968 {
3969 /* Break at the first non-saved register. */
3970 if ((range & (1 << (n + 4))) == 0)
3971 break;
3972 }
3973 /* See if there are any other bits set. */
3974 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3975 {
3976 /* Use the long form. */
3977 op = 0x8000 | ((range >> 4) & 0xfff);
3978 add_unwind_opcode (op, 2);
3979 }
0dd132b6 3980 else
01ae4198
DJ
3981 {
3982 /* Use the short form. */
3983 if (range & 0x4000)
3984 op = 0xa8; /* Pop r14. */
3985 else
3986 op = 0xa0; /* Do not pop r14. */
3987 op |= (n - 1);
3988 add_unwind_opcode (op, 1);
3989 }
c19d1205 3990 }
0dd132b6 3991
c19d1205
ZW
3992 /* Pop r0-r3. */
3993 if (range & 0xf)
3994 {
3995 op = 0xb100 | (range & 0xf);
3996 add_unwind_opcode (op, 2);
0dd132b6
NC
3997 }
3998
c19d1205
ZW
3999 /* Record the number of bytes pushed. */
4000 for (n = 0; n < 16; n++)
4001 {
4002 if (range & (1 << n))
4003 unwind.frame_size += 4;
4004 }
0dd132b6
NC
4005}
4006
c19d1205
ZW
4007
4008/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4009
4010static void
c19d1205 4011s_arm_unwind_save_fpa (int reg)
b99bd4ef 4012{
c19d1205
ZW
4013 expressionS exp;
4014 int num_regs;
4015 valueT op;
b99bd4ef 4016
c19d1205
ZW
4017 /* Get Number of registers to transfer. */
4018 if (skip_past_comma (&input_line_pointer) != FAIL)
4019 expression (&exp);
4020 else
4021 exp.X_op = O_illegal;
b99bd4ef 4022
c19d1205 4023 if (exp.X_op != O_constant)
b99bd4ef 4024 {
c19d1205
ZW
4025 as_bad (_("expected , <constant>"));
4026 ignore_rest_of_line ();
b99bd4ef
NC
4027 return;
4028 }
4029
c19d1205
ZW
4030 num_regs = exp.X_add_number;
4031
4032 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4033 {
c19d1205
ZW
4034 as_bad (_("number of registers must be in the range [1:4]"));
4035 ignore_rest_of_line ();
b99bd4ef
NC
4036 return;
4037 }
4038
c19d1205 4039 demand_empty_rest_of_line ();
b99bd4ef 4040
c19d1205
ZW
4041 if (reg == 4)
4042 {
4043 /* Short form. */
4044 op = 0xb4 | (num_regs - 1);
4045 add_unwind_opcode (op, 1);
4046 }
b99bd4ef
NC
4047 else
4048 {
c19d1205
ZW
4049 /* Long form. */
4050 op = 0xc800 | (reg << 4) | (num_regs - 1);
4051 add_unwind_opcode (op, 2);
b99bd4ef 4052 }
c19d1205 4053 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4054}
4055
c19d1205 4056
fa073d69
MS
4057/* Parse a directive saving VFP registers for ARMv6 and above. */
4058
4059static void
4060s_arm_unwind_save_vfp_armv6 (void)
4061{
4062 int count;
4063 unsigned int start;
4064 valueT op;
4065 int num_vfpv3_regs = 0;
4066 int num_regs_below_16;
4067
4068 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4069 if (count == FAIL)
4070 {
4071 as_bad (_("expected register list"));
4072 ignore_rest_of_line ();
4073 return;
4074 }
4075
4076 demand_empty_rest_of_line ();
4077
4078 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4079 than FSTMX/FLDMX-style ones). */
4080
4081 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4082 if (start >= 16)
4083 num_vfpv3_regs = count;
4084 else if (start + count > 16)
4085 num_vfpv3_regs = start + count - 16;
4086
4087 if (num_vfpv3_regs > 0)
4088 {
4089 int start_offset = start > 16 ? start - 16 : 0;
4090 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4091 add_unwind_opcode (op, 2);
4092 }
4093
4094 /* Generate opcode for registers numbered in the range 0 .. 15. */
4095 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4096 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4097 if (num_regs_below_16 > 0)
4098 {
4099 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4100 add_unwind_opcode (op, 2);
4101 }
4102
4103 unwind.frame_size += count * 8;
4104}
4105
4106
4107/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4108
4109static void
c19d1205 4110s_arm_unwind_save_vfp (void)
b99bd4ef 4111{
c19d1205 4112 int count;
ca3f61f7 4113 unsigned int reg;
c19d1205 4114 valueT op;
b99bd4ef 4115
5287ad62 4116 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4117 if (count == FAIL)
b99bd4ef 4118 {
c19d1205
ZW
4119 as_bad (_("expected register list"));
4120 ignore_rest_of_line ();
b99bd4ef
NC
4121 return;
4122 }
4123
c19d1205 4124 demand_empty_rest_of_line ();
b99bd4ef 4125
c19d1205 4126 if (reg == 8)
b99bd4ef 4127 {
c19d1205
ZW
4128 /* Short form. */
4129 op = 0xb8 | (count - 1);
4130 add_unwind_opcode (op, 1);
b99bd4ef 4131 }
c19d1205 4132 else
b99bd4ef 4133 {
c19d1205
ZW
4134 /* Long form. */
4135 op = 0xb300 | (reg << 4) | (count - 1);
4136 add_unwind_opcode (op, 2);
b99bd4ef 4137 }
c19d1205
ZW
4138 unwind.frame_size += count * 8 + 4;
4139}
b99bd4ef 4140
b99bd4ef 4141
c19d1205
ZW
4142/* Parse a directive saving iWMMXt data registers. */
4143
4144static void
4145s_arm_unwind_save_mmxwr (void)
4146{
4147 int reg;
4148 int hi_reg;
4149 int i;
4150 unsigned mask = 0;
4151 valueT op;
b99bd4ef 4152
c19d1205
ZW
4153 if (*input_line_pointer == '{')
4154 input_line_pointer++;
b99bd4ef 4155
c19d1205 4156 do
b99bd4ef 4157 {
dcbf9037 4158 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4159
c19d1205 4160 if (reg == FAIL)
b99bd4ef 4161 {
9b7132d3 4162 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4163 goto error;
b99bd4ef
NC
4164 }
4165
c19d1205
ZW
4166 if (mask >> reg)
4167 as_tsktsk (_("register list not in ascending order"));
4168 mask |= 1 << reg;
b99bd4ef 4169
c19d1205
ZW
4170 if (*input_line_pointer == '-')
4171 {
4172 input_line_pointer++;
dcbf9037 4173 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4174 if (hi_reg == FAIL)
4175 {
9b7132d3 4176 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4177 goto error;
4178 }
4179 else if (reg >= hi_reg)
4180 {
4181 as_bad (_("bad register range"));
4182 goto error;
4183 }
4184 for (; reg < hi_reg; reg++)
4185 mask |= 1 << reg;
4186 }
4187 }
4188 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4189
d996d970 4190 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4191
c19d1205 4192 demand_empty_rest_of_line ();
b99bd4ef 4193
708587a4 4194 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4195 the list. */
4196 flush_pending_unwind ();
b99bd4ef 4197
c19d1205 4198 for (i = 0; i < 16; i++)
b99bd4ef 4199 {
c19d1205
ZW
4200 if (mask & (1 << i))
4201 unwind.frame_size += 8;
b99bd4ef
NC
4202 }
4203
c19d1205
ZW
4204 /* Attempt to combine with a previous opcode. We do this because gcc
4205 likes to output separate unwind directives for a single block of
4206 registers. */
4207 if (unwind.opcode_count > 0)
b99bd4ef 4208 {
c19d1205
ZW
4209 i = unwind.opcodes[unwind.opcode_count - 1];
4210 if ((i & 0xf8) == 0xc0)
4211 {
4212 i &= 7;
4213 /* Only merge if the blocks are contiguous. */
4214 if (i < 6)
4215 {
4216 if ((mask & 0xfe00) == (1 << 9))
4217 {
4218 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4219 unwind.opcode_count--;
4220 }
4221 }
4222 else if (i == 6 && unwind.opcode_count >= 2)
4223 {
4224 i = unwind.opcodes[unwind.opcode_count - 2];
4225 reg = i >> 4;
4226 i &= 0xf;
b99bd4ef 4227
c19d1205
ZW
4228 op = 0xffff << (reg - 1);
4229 if (reg > 0
87a1fd79 4230 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4231 {
4232 op = (1 << (reg + i + 1)) - 1;
4233 op &= ~((1 << reg) - 1);
4234 mask |= op;
4235 unwind.opcode_count -= 2;
4236 }
4237 }
4238 }
b99bd4ef
NC
4239 }
4240
c19d1205
ZW
4241 hi_reg = 15;
4242 /* We want to generate opcodes in the order the registers have been
4243 saved, ie. descending order. */
4244 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4245 {
c19d1205
ZW
4246 /* Save registers in blocks. */
4247 if (reg < 0
4248 || !(mask & (1 << reg)))
4249 {
4250 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4251 preceding block. */
c19d1205
ZW
4252 if (reg != hi_reg)
4253 {
4254 if (reg == 9)
4255 {
4256 /* Short form. */
4257 op = 0xc0 | (hi_reg - 10);
4258 add_unwind_opcode (op, 1);
4259 }
4260 else
4261 {
4262 /* Long form. */
4263 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4264 add_unwind_opcode (op, 2);
4265 }
4266 }
4267 hi_reg = reg - 1;
4268 }
b99bd4ef
NC
4269 }
4270
c19d1205
ZW
4271 return;
4272error:
4273 ignore_rest_of_line ();
b99bd4ef
NC
4274}
4275
4276static void
c19d1205 4277s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4278{
c19d1205
ZW
4279 int reg;
4280 int hi_reg;
4281 unsigned mask = 0;
4282 valueT op;
b99bd4ef 4283
c19d1205
ZW
4284 if (*input_line_pointer == '{')
4285 input_line_pointer++;
b99bd4ef 4286
477330fc
RM
4287 skip_whitespace (input_line_pointer);
4288
c19d1205 4289 do
b99bd4ef 4290 {
dcbf9037 4291 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4292
c19d1205
ZW
4293 if (reg == FAIL)
4294 {
9b7132d3 4295 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4296 goto error;
4297 }
b99bd4ef 4298
c19d1205
ZW
4299 reg -= 8;
4300 if (mask >> reg)
4301 as_tsktsk (_("register list not in ascending order"));
4302 mask |= 1 << reg;
b99bd4ef 4303
c19d1205
ZW
4304 if (*input_line_pointer == '-')
4305 {
4306 input_line_pointer++;
dcbf9037 4307 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4308 if (hi_reg == FAIL)
4309 {
9b7132d3 4310 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4311 goto error;
4312 }
4313 else if (reg >= hi_reg)
4314 {
4315 as_bad (_("bad register range"));
4316 goto error;
4317 }
4318 for (; reg < hi_reg; reg++)
4319 mask |= 1 << reg;
4320 }
b99bd4ef 4321 }
c19d1205 4322 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4323
d996d970 4324 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4325
c19d1205
ZW
4326 demand_empty_rest_of_line ();
4327
708587a4 4328 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4329 the list. */
4330 flush_pending_unwind ();
b99bd4ef 4331
c19d1205 4332 for (reg = 0; reg < 16; reg++)
b99bd4ef 4333 {
c19d1205
ZW
4334 if (mask & (1 << reg))
4335 unwind.frame_size += 4;
b99bd4ef 4336 }
c19d1205
ZW
4337 op = 0xc700 | mask;
4338 add_unwind_opcode (op, 2);
4339 return;
4340error:
4341 ignore_rest_of_line ();
b99bd4ef
NC
4342}
4343
c19d1205 4344
fa073d69
MS
4345/* Parse an unwind_save directive.
4346 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4347
b99bd4ef 4348static void
fa073d69 4349s_arm_unwind_save (int arch_v6)
b99bd4ef 4350{
c19d1205
ZW
4351 char *peek;
4352 struct reg_entry *reg;
4353 bfd_boolean had_brace = FALSE;
b99bd4ef 4354
921e5f0a 4355 if (!unwind.proc_start)
c921be7d 4356 as_bad (MISSING_FNSTART);
921e5f0a 4357
c19d1205
ZW
4358 /* Figure out what sort of save we have. */
4359 peek = input_line_pointer;
b99bd4ef 4360
c19d1205 4361 if (*peek == '{')
b99bd4ef 4362 {
c19d1205
ZW
4363 had_brace = TRUE;
4364 peek++;
b99bd4ef
NC
4365 }
4366
c19d1205 4367 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4368
c19d1205 4369 if (!reg)
b99bd4ef 4370 {
c19d1205
ZW
4371 as_bad (_("register expected"));
4372 ignore_rest_of_line ();
b99bd4ef
NC
4373 return;
4374 }
4375
c19d1205 4376 switch (reg->type)
b99bd4ef 4377 {
c19d1205
ZW
4378 case REG_TYPE_FN:
4379 if (had_brace)
4380 {
4381 as_bad (_("FPA .unwind_save does not take a register list"));
4382 ignore_rest_of_line ();
4383 return;
4384 }
93ac2687 4385 input_line_pointer = peek;
c19d1205 4386 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4387 return;
c19d1205 4388
1f5afe1c
NC
4389 case REG_TYPE_RN:
4390 s_arm_unwind_save_core ();
4391 return;
4392
fa073d69
MS
4393 case REG_TYPE_VFD:
4394 if (arch_v6)
477330fc 4395 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4396 else
477330fc 4397 s_arm_unwind_save_vfp ();
fa073d69 4398 return;
1f5afe1c
NC
4399
4400 case REG_TYPE_MMXWR:
4401 s_arm_unwind_save_mmxwr ();
4402 return;
4403
4404 case REG_TYPE_MMXWCG:
4405 s_arm_unwind_save_mmxwcg ();
4406 return;
c19d1205
ZW
4407
4408 default:
4409 as_bad (_(".unwind_save does not support this kind of register"));
4410 ignore_rest_of_line ();
b99bd4ef 4411 }
c19d1205 4412}
b99bd4ef 4413
b99bd4ef 4414
c19d1205
ZW
4415/* Parse an unwind_movsp directive. */
4416
4417static void
4418s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4419{
4420 int reg;
4421 valueT op;
4fa3602b 4422 int offset;
c19d1205 4423
921e5f0a 4424 if (!unwind.proc_start)
c921be7d 4425 as_bad (MISSING_FNSTART);
921e5f0a 4426
dcbf9037 4427 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4428 if (reg == FAIL)
b99bd4ef 4429 {
9b7132d3 4430 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4431 ignore_rest_of_line ();
b99bd4ef
NC
4432 return;
4433 }
4fa3602b
PB
4434
4435 /* Optional constant. */
4436 if (skip_past_comma (&input_line_pointer) != FAIL)
4437 {
4438 if (immediate_for_directive (&offset) == FAIL)
4439 return;
4440 }
4441 else
4442 offset = 0;
4443
c19d1205 4444 demand_empty_rest_of_line ();
b99bd4ef 4445
c19d1205 4446 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4447 {
c19d1205 4448 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4449 return;
4450 }
4451
c19d1205
ZW
4452 if (unwind.fp_reg != REG_SP)
4453 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4454
c19d1205
ZW
4455 /* Generate opcode to restore the value. */
4456 op = 0x90 | reg;
4457 add_unwind_opcode (op, 1);
4458
4459 /* Record the information for later. */
4460 unwind.fp_reg = reg;
4fa3602b 4461 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4462 unwind.sp_restored = 1;
b05fe5cf
ZW
4463}
4464
c19d1205
ZW
4465/* Parse an unwind_pad directive. */
4466
b05fe5cf 4467static void
c19d1205 4468s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4469{
c19d1205 4470 int offset;
b05fe5cf 4471
921e5f0a 4472 if (!unwind.proc_start)
c921be7d 4473 as_bad (MISSING_FNSTART);
921e5f0a 4474
c19d1205
ZW
4475 if (immediate_for_directive (&offset) == FAIL)
4476 return;
b99bd4ef 4477
c19d1205
ZW
4478 if (offset & 3)
4479 {
4480 as_bad (_("stack increment must be multiple of 4"));
4481 ignore_rest_of_line ();
4482 return;
4483 }
b99bd4ef 4484
c19d1205
ZW
4485 /* Don't generate any opcodes, just record the details for later. */
4486 unwind.frame_size += offset;
4487 unwind.pending_offset += offset;
4488
4489 demand_empty_rest_of_line ();
4490}
4491
4492/* Parse an unwind_setfp directive. */
4493
4494static void
4495s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4496{
c19d1205
ZW
4497 int sp_reg;
4498 int fp_reg;
4499 int offset;
4500
921e5f0a 4501 if (!unwind.proc_start)
c921be7d 4502 as_bad (MISSING_FNSTART);
921e5f0a 4503
dcbf9037 4504 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4505 if (skip_past_comma (&input_line_pointer) == FAIL)
4506 sp_reg = FAIL;
4507 else
dcbf9037 4508 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4509
c19d1205
ZW
4510 if (fp_reg == FAIL || sp_reg == FAIL)
4511 {
4512 as_bad (_("expected <reg>, <reg>"));
4513 ignore_rest_of_line ();
4514 return;
4515 }
b99bd4ef 4516
c19d1205
ZW
4517 /* Optional constant. */
4518 if (skip_past_comma (&input_line_pointer) != FAIL)
4519 {
4520 if (immediate_for_directive (&offset) == FAIL)
4521 return;
4522 }
4523 else
4524 offset = 0;
a737bd4d 4525
c19d1205 4526 demand_empty_rest_of_line ();
a737bd4d 4527
fdfde340 4528 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4529 {
c19d1205
ZW
4530 as_bad (_("register must be either sp or set by a previous"
4531 "unwind_movsp directive"));
4532 return;
a737bd4d
NC
4533 }
4534
c19d1205
ZW
4535 /* Don't generate any opcodes, just record the information for later. */
4536 unwind.fp_reg = fp_reg;
4537 unwind.fp_used = 1;
fdfde340 4538 if (sp_reg == REG_SP)
c19d1205
ZW
4539 unwind.fp_offset = unwind.frame_size - offset;
4540 else
4541 unwind.fp_offset -= offset;
a737bd4d
NC
4542}
4543
c19d1205
ZW
4544/* Parse an unwind_raw directive. */
4545
4546static void
4547s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4548{
c19d1205 4549 expressionS exp;
708587a4 4550 /* This is an arbitrary limit. */
c19d1205
ZW
4551 unsigned char op[16];
4552 int count;
a737bd4d 4553
921e5f0a 4554 if (!unwind.proc_start)
c921be7d 4555 as_bad (MISSING_FNSTART);
921e5f0a 4556
c19d1205
ZW
4557 expression (&exp);
4558 if (exp.X_op == O_constant
4559 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4560 {
c19d1205
ZW
4561 unwind.frame_size += exp.X_add_number;
4562 expression (&exp);
4563 }
4564 else
4565 exp.X_op = O_illegal;
a737bd4d 4566
c19d1205
ZW
4567 if (exp.X_op != O_constant)
4568 {
4569 as_bad (_("expected <offset>, <opcode>"));
4570 ignore_rest_of_line ();
4571 return;
4572 }
a737bd4d 4573
c19d1205 4574 count = 0;
a737bd4d 4575
c19d1205
ZW
4576 /* Parse the opcode. */
4577 for (;;)
4578 {
4579 if (count >= 16)
4580 {
4581 as_bad (_("unwind opcode too long"));
4582 ignore_rest_of_line ();
a737bd4d 4583 }
c19d1205 4584 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4585 {
c19d1205
ZW
4586 as_bad (_("invalid unwind opcode"));
4587 ignore_rest_of_line ();
4588 return;
a737bd4d 4589 }
c19d1205 4590 op[count++] = exp.X_add_number;
a737bd4d 4591
c19d1205
ZW
4592 /* Parse the next byte. */
4593 if (skip_past_comma (&input_line_pointer) == FAIL)
4594 break;
a737bd4d 4595
c19d1205
ZW
4596 expression (&exp);
4597 }
b99bd4ef 4598
c19d1205
ZW
4599 /* Add the opcode bytes in reverse order. */
4600 while (count--)
4601 add_unwind_opcode (op[count], 1);
b99bd4ef 4602
c19d1205 4603 demand_empty_rest_of_line ();
b99bd4ef 4604}
ee065d83
PB
4605
4606
4607/* Parse a .eabi_attribute directive. */
4608
4609static void
4610s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4611{
0420f52b 4612 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4613
4614 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4615 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4616}
4617
0855e32b
NS
4618/* Emit a tls fix for the symbol. */
4619
4620static void
4621s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4622{
4623 char *p;
4624 expressionS exp;
4625#ifdef md_flush_pending_output
4626 md_flush_pending_output ();
4627#endif
4628
4629#ifdef md_cons_align
4630 md_cons_align (4);
4631#endif
4632
4633 /* Since we're just labelling the code, there's no need to define a
4634 mapping symbol. */
4635 expression (&exp);
4636 p = obstack_next_free (&frchain_now->frch_obstack);
4637 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4638 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4639 : BFD_RELOC_ARM_TLS_DESCSEQ);
4640}
cdf9ccec 4641#endif /* OBJ_ELF */
0855e32b 4642
ee065d83 4643static void s_arm_arch (int);
7a1d4c38 4644static void s_arm_object_arch (int);
ee065d83
PB
4645static void s_arm_cpu (int);
4646static void s_arm_fpu (int);
69133863 4647static void s_arm_arch_extension (int);
b99bd4ef 4648
f0927246
NC
4649#ifdef TE_PE
4650
4651static void
5f4273c7 4652pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4653{
4654 expressionS exp;
4655
4656 do
4657 {
4658 expression (&exp);
4659 if (exp.X_op == O_symbol)
4660 exp.X_op = O_secrel;
4661
4662 emit_expr (&exp, 4);
4663 }
4664 while (*input_line_pointer++ == ',');
4665
4666 input_line_pointer--;
4667 demand_empty_rest_of_line ();
4668}
4669#endif /* TE_PE */
4670
c19d1205
ZW
4671/* This table describes all the machine specific pseudo-ops the assembler
4672 has to support. The fields are:
4673 pseudo-op name without dot
4674 function to call to execute this pseudo-op
4675 Integer arg to pass to the function. */
b99bd4ef 4676
c19d1205 4677const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4678{
c19d1205
ZW
4679 /* Never called because '.req' does not start a line. */
4680 { "req", s_req, 0 },
dcbf9037
JB
4681 /* Following two are likewise never called. */
4682 { "dn", s_dn, 0 },
4683 { "qn", s_qn, 0 },
c19d1205
ZW
4684 { "unreq", s_unreq, 0 },
4685 { "bss", s_bss, 0 },
db2ed2e0 4686 { "align", s_align_ptwo, 2 },
c19d1205
ZW
4687 { "arm", s_arm, 0 },
4688 { "thumb", s_thumb, 0 },
4689 { "code", s_code, 0 },
4690 { "force_thumb", s_force_thumb, 0 },
4691 { "thumb_func", s_thumb_func, 0 },
4692 { "thumb_set", s_thumb_set, 0 },
4693 { "even", s_even, 0 },
4694 { "ltorg", s_ltorg, 0 },
4695 { "pool", s_ltorg, 0 },
4696 { "syntax", s_syntax, 0 },
8463be01
PB
4697 { "cpu", s_arm_cpu, 0 },
4698 { "arch", s_arm_arch, 0 },
7a1d4c38 4699 { "object_arch", s_arm_object_arch, 0 },
8463be01 4700 { "fpu", s_arm_fpu, 0 },
69133863 4701 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4702#ifdef OBJ_ELF
c921be7d
NC
4703 { "word", s_arm_elf_cons, 4 },
4704 { "long", s_arm_elf_cons, 4 },
4705 { "inst.n", s_arm_elf_inst, 2 },
4706 { "inst.w", s_arm_elf_inst, 4 },
4707 { "inst", s_arm_elf_inst, 0 },
4708 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4709 { "fnstart", s_arm_unwind_fnstart, 0 },
4710 { "fnend", s_arm_unwind_fnend, 0 },
4711 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4712 { "personality", s_arm_unwind_personality, 0 },
4713 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4714 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4715 { "save", s_arm_unwind_save, 0 },
fa073d69 4716 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4717 { "movsp", s_arm_unwind_movsp, 0 },
4718 { "pad", s_arm_unwind_pad, 0 },
4719 { "setfp", s_arm_unwind_setfp, 0 },
4720 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4721 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4722 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4723#else
4724 { "word", cons, 4},
f0927246
NC
4725
4726 /* These are used for dwarf. */
4727 {"2byte", cons, 2},
4728 {"4byte", cons, 4},
4729 {"8byte", cons, 8},
4730 /* These are used for dwarf2. */
4731 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4732 { "loc", dwarf2_directive_loc, 0 },
4733 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4734#endif
4735 { "extend", float_cons, 'x' },
4736 { "ldouble", float_cons, 'x' },
4737 { "packed", float_cons, 'p' },
f0927246
NC
4738#ifdef TE_PE
4739 {"secrel32", pe_directive_secrel, 0},
4740#endif
2e6976a8
DG
4741
4742 /* These are for compatibility with CodeComposer Studio. */
4743 {"ref", s_ccs_ref, 0},
4744 {"def", s_ccs_def, 0},
4745 {"asmfunc", s_ccs_asmfunc, 0},
4746 {"endasmfunc", s_ccs_endasmfunc, 0},
4747
c19d1205
ZW
4748 { 0, 0, 0 }
4749};
4750\f
4751/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4752
c19d1205
ZW
4753/* Generic immediate-value read function for use in insn parsing.
4754 STR points to the beginning of the immediate (the leading #);
4755 VAL receives the value; if the value is outside [MIN, MAX]
4756 issue an error. PREFIX_OPT is true if the immediate prefix is
4757 optional. */
b99bd4ef 4758
c19d1205
ZW
4759static int
4760parse_immediate (char **str, int *val, int min, int max,
4761 bfd_boolean prefix_opt)
4762{
4763 expressionS exp;
4764 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4765 if (exp.X_op != O_constant)
b99bd4ef 4766 {
c19d1205
ZW
4767 inst.error = _("constant expression required");
4768 return FAIL;
4769 }
b99bd4ef 4770
c19d1205
ZW
4771 if (exp.X_add_number < min || exp.X_add_number > max)
4772 {
4773 inst.error = _("immediate value out of range");
4774 return FAIL;
4775 }
b99bd4ef 4776
c19d1205
ZW
4777 *val = exp.X_add_number;
4778 return SUCCESS;
4779}
b99bd4ef 4780
5287ad62 4781/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4782 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4783 instructions. Puts the result directly in inst.operands[i]. */
4784
4785static int
8335d6aa
JW
4786parse_big_immediate (char **str, int i, expressionS *in_exp,
4787 bfd_boolean allow_symbol_p)
5287ad62
JB
4788{
4789 expressionS exp;
8335d6aa 4790 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4791 char *ptr = *str;
4792
8335d6aa 4793 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 4794
8335d6aa 4795 if (exp_p->X_op == O_constant)
036dc3f7 4796 {
8335d6aa 4797 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
4798 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4799 O_constant. We have to be careful not to break compilation for
4800 32-bit X_add_number, though. */
8335d6aa 4801 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4802 {
8335d6aa
JW
4803 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4804 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4805 & 0xffffffff);
036dc3f7
PB
4806 inst.operands[i].regisimm = 1;
4807 }
4808 }
8335d6aa
JW
4809 else if (exp_p->X_op == O_big
4810 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
4811 {
4812 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4813
5287ad62 4814 /* Bignums have their least significant bits in
477330fc
RM
4815 generic_bignum[0]. Make sure we put 32 bits in imm and
4816 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4817 gas_assert (parts != 0);
95b75c01
NC
4818
4819 /* Make sure that the number is not too big.
4820 PR 11972: Bignums can now be sign-extended to the
4821 size of a .octa so check that the out of range bits
4822 are all zero or all one. */
8335d6aa 4823 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
4824 {
4825 LITTLENUM_TYPE m = -1;
4826
4827 if (generic_bignum[parts * 2] != 0
4828 && generic_bignum[parts * 2] != m)
4829 return FAIL;
4830
8335d6aa 4831 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
4832 if (generic_bignum[j] != generic_bignum[j-1])
4833 return FAIL;
4834 }
4835
5287ad62
JB
4836 inst.operands[i].imm = 0;
4837 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4838 inst.operands[i].imm |= generic_bignum[idx]
4839 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4840 inst.operands[i].reg = 0;
4841 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4842 inst.operands[i].reg |= generic_bignum[idx]
4843 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4844 inst.operands[i].regisimm = 1;
4845 }
8335d6aa 4846 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 4847 return FAIL;
5f4273c7 4848
5287ad62
JB
4849 *str = ptr;
4850
4851 return SUCCESS;
4852}
4853
c19d1205
ZW
4854/* Returns the pseudo-register number of an FPA immediate constant,
4855 or FAIL if there isn't a valid constant here. */
b99bd4ef 4856
c19d1205
ZW
4857static int
4858parse_fpa_immediate (char ** str)
4859{
4860 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4861 char * save_in;
4862 expressionS exp;
4863 int i;
4864 int j;
b99bd4ef 4865
c19d1205
ZW
4866 /* First try and match exact strings, this is to guarantee
4867 that some formats will work even for cross assembly. */
b99bd4ef 4868
c19d1205
ZW
4869 for (i = 0; fp_const[i]; i++)
4870 {
4871 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4872 {
c19d1205 4873 char *start = *str;
b99bd4ef 4874
c19d1205
ZW
4875 *str += strlen (fp_const[i]);
4876 if (is_end_of_line[(unsigned char) **str])
4877 return i + 8;
4878 *str = start;
4879 }
4880 }
b99bd4ef 4881
c19d1205
ZW
4882 /* Just because we didn't get a match doesn't mean that the constant
4883 isn't valid, just that it is in a format that we don't
4884 automatically recognize. Try parsing it with the standard
4885 expression routines. */
b99bd4ef 4886
c19d1205 4887 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4888
c19d1205
ZW
4889 /* Look for a raw floating point number. */
4890 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4891 && is_end_of_line[(unsigned char) *save_in])
4892 {
4893 for (i = 0; i < NUM_FLOAT_VALS; i++)
4894 {
4895 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4896 {
c19d1205
ZW
4897 if (words[j] != fp_values[i][j])
4898 break;
b99bd4ef
NC
4899 }
4900
c19d1205 4901 if (j == MAX_LITTLENUMS)
b99bd4ef 4902 {
c19d1205
ZW
4903 *str = save_in;
4904 return i + 8;
b99bd4ef
NC
4905 }
4906 }
4907 }
b99bd4ef 4908
c19d1205
ZW
4909 /* Try and parse a more complex expression, this will probably fail
4910 unless the code uses a floating point prefix (eg "0f"). */
4911 save_in = input_line_pointer;
4912 input_line_pointer = *str;
4913 if (expression (&exp) == absolute_section
4914 && exp.X_op == O_big
4915 && exp.X_add_number < 0)
4916 {
4917 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4918 Ditto for 15. */
ba592044
AM
4919#define X_PRECISION 5
4920#define E_PRECISION 15L
4921 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
4922 {
4923 for (i = 0; i < NUM_FLOAT_VALS; i++)
4924 {
4925 for (j = 0; j < MAX_LITTLENUMS; j++)
4926 {
4927 if (words[j] != fp_values[i][j])
4928 break;
4929 }
b99bd4ef 4930
c19d1205
ZW
4931 if (j == MAX_LITTLENUMS)
4932 {
4933 *str = input_line_pointer;
4934 input_line_pointer = save_in;
4935 return i + 8;
4936 }
4937 }
4938 }
b99bd4ef
NC
4939 }
4940
c19d1205
ZW
4941 *str = input_line_pointer;
4942 input_line_pointer = save_in;
4943 inst.error = _("invalid FPA immediate expression");
4944 return FAIL;
b99bd4ef
NC
4945}
4946
136da414
JB
4947/* Returns 1 if a number has "quarter-precision" float format
4948 0baBbbbbbc defgh000 00000000 00000000. */
4949
4950static int
4951is_quarter_float (unsigned imm)
4952{
4953 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4954 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4955}
4956
aacf0b33
KT
4957
4958/* Detect the presence of a floating point or integer zero constant,
4959 i.e. #0.0 or #0. */
4960
4961static bfd_boolean
4962parse_ifimm_zero (char **in)
4963{
4964 int error_code;
4965
4966 if (!is_immediate_prefix (**in))
4967 return FALSE;
4968
4969 ++*in;
0900a05b
JW
4970
4971 /* Accept #0x0 as a synonym for #0. */
4972 if (strncmp (*in, "0x", 2) == 0)
4973 {
4974 int val;
4975 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
4976 return FALSE;
4977 return TRUE;
4978 }
4979
aacf0b33
KT
4980 error_code = atof_generic (in, ".", EXP_CHARS,
4981 &generic_floating_point_number);
4982
4983 if (!error_code
4984 && generic_floating_point_number.sign == '+'
4985 && (generic_floating_point_number.low
4986 > generic_floating_point_number.leader))
4987 return TRUE;
4988
4989 return FALSE;
4990}
4991
136da414
JB
4992/* Parse an 8-bit "quarter-precision" floating point number of the form:
4993 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4994 The zero and minus-zero cases need special handling, since they can't be
4995 encoded in the "quarter-precision" float format, but can nonetheless be
4996 loaded as integer constants. */
136da414
JB
4997
4998static unsigned
4999parse_qfloat_immediate (char **ccp, int *immed)
5000{
5001 char *str = *ccp;
c96612cc 5002 char *fpnum;
136da414 5003 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5004 int found_fpchar = 0;
5f4273c7 5005
136da414 5006 skip_past_char (&str, '#');
5f4273c7 5007
c96612cc
JB
5008 /* We must not accidentally parse an integer as a floating-point number. Make
5009 sure that the value we parse is not an integer by checking for special
5010 characters '.' or 'e'.
5011 FIXME: This is a horrible hack, but doing better is tricky because type
5012 information isn't in a very usable state at parse time. */
5013 fpnum = str;
5014 skip_whitespace (fpnum);
5015
5016 if (strncmp (fpnum, "0x", 2) == 0)
5017 return FAIL;
5018 else
5019 {
5020 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5021 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5022 {
5023 found_fpchar = 1;
5024 break;
5025 }
c96612cc
JB
5026
5027 if (!found_fpchar)
477330fc 5028 return FAIL;
c96612cc 5029 }
5f4273c7 5030
136da414
JB
5031 if ((str = atof_ieee (str, 's', words)) != NULL)
5032 {
5033 unsigned fpword = 0;
5034 int i;
5f4273c7 5035
136da414
JB
5036 /* Our FP word must be 32 bits (single-precision FP). */
5037 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5038 {
5039 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5040 fpword |= words[i];
5041 }
5f4273c7 5042
c96612cc 5043 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5044 *immed = fpword;
136da414 5045 else
477330fc 5046 return FAIL;
136da414
JB
5047
5048 *ccp = str;
5f4273c7 5049
136da414
JB
5050 return SUCCESS;
5051 }
5f4273c7 5052
136da414
JB
5053 return FAIL;
5054}
5055
c19d1205
ZW
5056/* Shift operands. */
5057enum shift_kind
b99bd4ef 5058{
c19d1205
ZW
5059 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5060};
b99bd4ef 5061
c19d1205
ZW
5062struct asm_shift_name
5063{
5064 const char *name;
5065 enum shift_kind kind;
5066};
b99bd4ef 5067
c19d1205
ZW
5068/* Third argument to parse_shift. */
5069enum parse_shift_mode
5070{
5071 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5072 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5073 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5074 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5075 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5076};
b99bd4ef 5077
c19d1205
ZW
5078/* Parse a <shift> specifier on an ARM data processing instruction.
5079 This has three forms:
b99bd4ef 5080
c19d1205
ZW
5081 (LSL|LSR|ASL|ASR|ROR) Rs
5082 (LSL|LSR|ASL|ASR|ROR) #imm
5083 RRX
b99bd4ef 5084
c19d1205
ZW
5085 Note that ASL is assimilated to LSL in the instruction encoding, and
5086 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5087
c19d1205
ZW
5088static int
5089parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5090{
c19d1205
ZW
5091 const struct asm_shift_name *shift_name;
5092 enum shift_kind shift;
5093 char *s = *str;
5094 char *p = s;
5095 int reg;
b99bd4ef 5096
c19d1205
ZW
5097 for (p = *str; ISALPHA (*p); p++)
5098 ;
b99bd4ef 5099
c19d1205 5100 if (p == *str)
b99bd4ef 5101 {
c19d1205
ZW
5102 inst.error = _("shift expression expected");
5103 return FAIL;
b99bd4ef
NC
5104 }
5105
21d799b5 5106 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5107 p - *str);
c19d1205
ZW
5108
5109 if (shift_name == NULL)
b99bd4ef 5110 {
c19d1205
ZW
5111 inst.error = _("shift expression expected");
5112 return FAIL;
b99bd4ef
NC
5113 }
5114
c19d1205 5115 shift = shift_name->kind;
b99bd4ef 5116
c19d1205
ZW
5117 switch (mode)
5118 {
5119 case NO_SHIFT_RESTRICT:
5120 case SHIFT_IMMEDIATE: break;
b99bd4ef 5121
c19d1205
ZW
5122 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5123 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5124 {
5125 inst.error = _("'LSL' or 'ASR' required");
5126 return FAIL;
5127 }
5128 break;
b99bd4ef 5129
c19d1205
ZW
5130 case SHIFT_LSL_IMMEDIATE:
5131 if (shift != SHIFT_LSL)
5132 {
5133 inst.error = _("'LSL' required");
5134 return FAIL;
5135 }
5136 break;
b99bd4ef 5137
c19d1205
ZW
5138 case SHIFT_ASR_IMMEDIATE:
5139 if (shift != SHIFT_ASR)
5140 {
5141 inst.error = _("'ASR' required");
5142 return FAIL;
5143 }
5144 break;
b99bd4ef 5145
c19d1205
ZW
5146 default: abort ();
5147 }
b99bd4ef 5148
c19d1205
ZW
5149 if (shift != SHIFT_RRX)
5150 {
5151 /* Whitespace can appear here if the next thing is a bare digit. */
5152 skip_whitespace (p);
b99bd4ef 5153
c19d1205 5154 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5155 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5156 {
5157 inst.operands[i].imm = reg;
5158 inst.operands[i].immisreg = 1;
5159 }
5160 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5161 return FAIL;
5162 }
5163 inst.operands[i].shift_kind = shift;
5164 inst.operands[i].shifted = 1;
5165 *str = p;
5166 return SUCCESS;
b99bd4ef
NC
5167}
5168
c19d1205 5169/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5170
c19d1205
ZW
5171 #<immediate>
5172 #<immediate>, <rotate>
5173 <Rm>
5174 <Rm>, <shift>
b99bd4ef 5175
c19d1205
ZW
5176 where <shift> is defined by parse_shift above, and <rotate> is a
5177 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5178 is deferred to md_apply_fix. */
b99bd4ef 5179
c19d1205
ZW
5180static int
5181parse_shifter_operand (char **str, int i)
5182{
5183 int value;
91d6fa6a 5184 expressionS exp;
b99bd4ef 5185
dcbf9037 5186 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5187 {
5188 inst.operands[i].reg = value;
5189 inst.operands[i].isreg = 1;
b99bd4ef 5190
c19d1205
ZW
5191 /* parse_shift will override this if appropriate */
5192 inst.reloc.exp.X_op = O_constant;
5193 inst.reloc.exp.X_add_number = 0;
b99bd4ef 5194
c19d1205
ZW
5195 if (skip_past_comma (str) == FAIL)
5196 return SUCCESS;
b99bd4ef 5197
c19d1205
ZW
5198 /* Shift operation on register. */
5199 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5200 }
5201
c19d1205
ZW
5202 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5203 return FAIL;
b99bd4ef 5204
c19d1205 5205 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5206 {
c19d1205 5207 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5208 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5209 return FAIL;
b99bd4ef 5210
91d6fa6a 5211 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
5212 {
5213 inst.error = _("constant expression expected");
5214 return FAIL;
5215 }
b99bd4ef 5216
91d6fa6a 5217 value = exp.X_add_number;
c19d1205
ZW
5218 if (value < 0 || value > 30 || value % 2 != 0)
5219 {
5220 inst.error = _("invalid rotation");
5221 return FAIL;
5222 }
5223 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5224 {
5225 inst.error = _("invalid constant");
5226 return FAIL;
5227 }
09d92015 5228
a415b1cd
JB
5229 /* Encode as specified. */
5230 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5231 return SUCCESS;
09d92015
MM
5232 }
5233
c19d1205
ZW
5234 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5235 inst.reloc.pc_rel = 0;
5236 return SUCCESS;
09d92015
MM
5237}
5238
4962c51a
MS
5239/* Group relocation information. Each entry in the table contains the
5240 textual name of the relocation as may appear in assembler source
5241 and must end with a colon.
5242 Along with this textual name are the relocation codes to be used if
5243 the corresponding instruction is an ALU instruction (ADD or SUB only),
5244 an LDR, an LDRS, or an LDC. */
5245
5246struct group_reloc_table_entry
5247{
5248 const char *name;
5249 int alu_code;
5250 int ldr_code;
5251 int ldrs_code;
5252 int ldc_code;
5253};
5254
5255typedef enum
5256{
5257 /* Varieties of non-ALU group relocation. */
5258
5259 GROUP_LDR,
5260 GROUP_LDRS,
5261 GROUP_LDC
5262} group_reloc_type;
5263
5264static struct group_reloc_table_entry group_reloc_table[] =
5265 { /* Program counter relative: */
5266 { "pc_g0_nc",
5267 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5268 0, /* LDR */
5269 0, /* LDRS */
5270 0 }, /* LDC */
5271 { "pc_g0",
5272 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5273 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5274 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5275 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5276 { "pc_g1_nc",
5277 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5278 0, /* LDR */
5279 0, /* LDRS */
5280 0 }, /* LDC */
5281 { "pc_g1",
5282 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5283 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5284 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5285 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5286 { "pc_g2",
5287 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5288 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5289 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5290 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5291 /* Section base relative */
5292 { "sb_g0_nc",
5293 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5294 0, /* LDR */
5295 0, /* LDRS */
5296 0 }, /* LDC */
5297 { "sb_g0",
5298 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5299 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5300 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5301 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5302 { "sb_g1_nc",
5303 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5304 0, /* LDR */
5305 0, /* LDRS */
5306 0 }, /* LDC */
5307 { "sb_g1",
5308 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5309 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5310 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5311 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5312 { "sb_g2",
5313 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5314 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5315 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5316 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5317 /* Absolute thumb alu relocations. */
5318 { "lower0_7",
5319 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5320 0, /* LDR. */
5321 0, /* LDRS. */
5322 0 }, /* LDC. */
5323 { "lower8_15",
5324 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5325 0, /* LDR. */
5326 0, /* LDRS. */
5327 0 }, /* LDC. */
5328 { "upper0_7",
5329 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5330 0, /* LDR. */
5331 0, /* LDRS. */
5332 0 }, /* LDC. */
5333 { "upper8_15",
5334 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5335 0, /* LDR. */
5336 0, /* LDRS. */
5337 0 } }; /* LDC. */
4962c51a
MS
5338
5339/* Given the address of a pointer pointing to the textual name of a group
5340 relocation as may appear in assembler source, attempt to find its details
5341 in group_reloc_table. The pointer will be updated to the character after
5342 the trailing colon. On failure, FAIL will be returned; SUCCESS
5343 otherwise. On success, *entry will be updated to point at the relevant
5344 group_reloc_table entry. */
5345
5346static int
5347find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5348{
5349 unsigned int i;
5350 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5351 {
5352 int length = strlen (group_reloc_table[i].name);
5353
5f4273c7
NC
5354 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5355 && (*str)[length] == ':')
477330fc
RM
5356 {
5357 *out = &group_reloc_table[i];
5358 *str += (length + 1);
5359 return SUCCESS;
5360 }
4962c51a
MS
5361 }
5362
5363 return FAIL;
5364}
5365
5366/* Parse a <shifter_operand> for an ARM data processing instruction
5367 (as for parse_shifter_operand) where group relocations are allowed:
5368
5369 #<immediate>
5370 #<immediate>, <rotate>
5371 #:<group_reloc>:<expression>
5372 <Rm>
5373 <Rm>, <shift>
5374
5375 where <group_reloc> is one of the strings defined in group_reloc_table.
5376 The hashes are optional.
5377
5378 Everything else is as for parse_shifter_operand. */
5379
5380static parse_operand_result
5381parse_shifter_operand_group_reloc (char **str, int i)
5382{
5383 /* Determine if we have the sequence of characters #: or just :
5384 coming next. If we do, then we check for a group relocation.
5385 If we don't, punt the whole lot to parse_shifter_operand. */
5386
5387 if (((*str)[0] == '#' && (*str)[1] == ':')
5388 || (*str)[0] == ':')
5389 {
5390 struct group_reloc_table_entry *entry;
5391
5392 if ((*str)[0] == '#')
477330fc 5393 (*str) += 2;
4962c51a 5394 else
477330fc 5395 (*str)++;
4962c51a
MS
5396
5397 /* Try to parse a group relocation. Anything else is an error. */
5398 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5399 {
5400 inst.error = _("unknown group relocation");
5401 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5402 }
4962c51a
MS
5403
5404 /* We now have the group relocation table entry corresponding to
477330fc 5405 the name in the assembler source. Next, we parse the expression. */
4962c51a 5406 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
477330fc 5407 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5408
5409 /* Record the relocation type (always the ALU variant here). */
21d799b5 5410 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5411 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5412
5413 return PARSE_OPERAND_SUCCESS;
5414 }
5415 else
5416 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5417 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5418
5419 /* Never reached. */
5420}
5421
8e560766
MGD
5422/* Parse a Neon alignment expression. Information is written to
5423 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5424
8e560766
MGD
5425 align .imm = align << 8, .immisalign=1, .preind=0 */
5426static parse_operand_result
5427parse_neon_alignment (char **str, int i)
5428{
5429 char *p = *str;
5430 expressionS exp;
5431
5432 my_get_expression (&exp, &p, GE_NO_PREFIX);
5433
5434 if (exp.X_op != O_constant)
5435 {
5436 inst.error = _("alignment must be constant");
5437 return PARSE_OPERAND_FAIL;
5438 }
5439
5440 inst.operands[i].imm = exp.X_add_number << 8;
5441 inst.operands[i].immisalign = 1;
5442 /* Alignments are not pre-indexes. */
5443 inst.operands[i].preind = 0;
5444
5445 *str = p;
5446 return PARSE_OPERAND_SUCCESS;
5447}
5448
c19d1205
ZW
5449/* Parse all forms of an ARM address expression. Information is written
5450 to inst.operands[i] and/or inst.reloc.
09d92015 5451
c19d1205 5452 Preindexed addressing (.preind=1):
09d92015 5453
c19d1205
ZW
5454 [Rn, #offset] .reg=Rn .reloc.exp=offset
5455 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5456 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5457 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5458
c19d1205 5459 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5460
c19d1205 5461 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5462
c19d1205
ZW
5463 [Rn], #offset .reg=Rn .reloc.exp=offset
5464 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5465 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5466 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5467
c19d1205 5468 Unindexed addressing (.preind=0, .postind=0):
09d92015 5469
c19d1205 5470 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5471
c19d1205 5472 Other:
09d92015 5473
c19d1205
ZW
5474 [Rn]{!} shorthand for [Rn,#0]{!}
5475 =immediate .isreg=0 .reloc.exp=immediate
5476 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5477
c19d1205
ZW
5478 It is the caller's responsibility to check for addressing modes not
5479 supported by the instruction, and to set inst.reloc.type. */
5480
4962c51a
MS
5481static parse_operand_result
5482parse_address_main (char **str, int i, int group_relocations,
477330fc 5483 group_reloc_type group_type)
09d92015 5484{
c19d1205
ZW
5485 char *p = *str;
5486 int reg;
09d92015 5487
c19d1205 5488 if (skip_past_char (&p, '[') == FAIL)
09d92015 5489 {
c19d1205
ZW
5490 if (skip_past_char (&p, '=') == FAIL)
5491 {
974da60d 5492 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5493 inst.reloc.pc_rel = 1;
5494 inst.operands[i].reg = REG_PC;
5495 inst.operands[i].isreg = 1;
5496 inst.operands[i].preind = 1;
09d92015 5497
8335d6aa
JW
5498 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5499 return PARSE_OPERAND_FAIL;
5500 }
5501 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5502 /*allow_symbol_p=*/TRUE))
4962c51a 5503 return PARSE_OPERAND_FAIL;
09d92015 5504
c19d1205 5505 *str = p;
4962c51a 5506 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5507 }
5508
8ab8155f
NC
5509 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5510 skip_whitespace (p);
5511
dcbf9037 5512 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5513 {
c19d1205 5514 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5515 return PARSE_OPERAND_FAIL;
09d92015 5516 }
c19d1205
ZW
5517 inst.operands[i].reg = reg;
5518 inst.operands[i].isreg = 1;
09d92015 5519
c19d1205 5520 if (skip_past_comma (&p) == SUCCESS)
09d92015 5521 {
c19d1205 5522 inst.operands[i].preind = 1;
09d92015 5523
c19d1205
ZW
5524 if (*p == '+') p++;
5525 else if (*p == '-') p++, inst.operands[i].negative = 1;
5526
dcbf9037 5527 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5528 {
c19d1205
ZW
5529 inst.operands[i].imm = reg;
5530 inst.operands[i].immisreg = 1;
5531
5532 if (skip_past_comma (&p) == SUCCESS)
5533 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5534 return PARSE_OPERAND_FAIL;
c19d1205 5535 }
5287ad62 5536 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5537 {
5538 /* FIXME: '@' should be used here, but it's filtered out by generic
5539 code before we get to see it here. This may be subject to
5540 change. */
5541 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5542
8e560766
MGD
5543 if (result != PARSE_OPERAND_SUCCESS)
5544 return result;
5545 }
c19d1205
ZW
5546 else
5547 {
5548 if (inst.operands[i].negative)
5549 {
5550 inst.operands[i].negative = 0;
5551 p--;
5552 }
4962c51a 5553
5f4273c7
NC
5554 if (group_relocations
5555 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5556 {
5557 struct group_reloc_table_entry *entry;
5558
477330fc
RM
5559 /* Skip over the #: or : sequence. */
5560 if (*p == '#')
5561 p += 2;
5562 else
5563 p++;
4962c51a
MS
5564
5565 /* Try to parse a group relocation. Anything else is an
477330fc 5566 error. */
4962c51a
MS
5567 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5568 {
5569 inst.error = _("unknown group relocation");
5570 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5571 }
5572
5573 /* We now have the group relocation table entry corresponding to
5574 the name in the assembler source. Next, we parse the
477330fc 5575 expression. */
4962c51a
MS
5576 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5577 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5578
5579 /* Record the relocation type. */
477330fc
RM
5580 switch (group_type)
5581 {
5582 case GROUP_LDR:
5583 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5584 break;
4962c51a 5585
477330fc
RM
5586 case GROUP_LDRS:
5587 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5588 break;
4962c51a 5589
477330fc
RM
5590 case GROUP_LDC:
5591 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5592 break;
4962c51a 5593
477330fc
RM
5594 default:
5595 gas_assert (0);
5596 }
4962c51a 5597
477330fc 5598 if (inst.reloc.type == 0)
4962c51a
MS
5599 {
5600 inst.error = _("this group relocation is not allowed on this instruction");
5601 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5602 }
477330fc
RM
5603 }
5604 else
26d97720
NS
5605 {
5606 char *q = p;
5607 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5608 return PARSE_OPERAND_FAIL;
5609 /* If the offset is 0, find out if it's a +0 or -0. */
5610 if (inst.reloc.exp.X_op == O_constant
5611 && inst.reloc.exp.X_add_number == 0)
5612 {
5613 skip_whitespace (q);
5614 if (*q == '#')
5615 {
5616 q++;
5617 skip_whitespace (q);
5618 }
5619 if (*q == '-')
5620 inst.operands[i].negative = 1;
5621 }
5622 }
09d92015
MM
5623 }
5624 }
8e560766
MGD
5625 else if (skip_past_char (&p, ':') == SUCCESS)
5626 {
5627 /* FIXME: '@' should be used here, but it's filtered out by generic code
5628 before we get to see it here. This may be subject to change. */
5629 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5630
8e560766
MGD
5631 if (result != PARSE_OPERAND_SUCCESS)
5632 return result;
5633 }
09d92015 5634
c19d1205 5635 if (skip_past_char (&p, ']') == FAIL)
09d92015 5636 {
c19d1205 5637 inst.error = _("']' expected");
4962c51a 5638 return PARSE_OPERAND_FAIL;
09d92015
MM
5639 }
5640
c19d1205
ZW
5641 if (skip_past_char (&p, '!') == SUCCESS)
5642 inst.operands[i].writeback = 1;
09d92015 5643
c19d1205 5644 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5645 {
c19d1205
ZW
5646 if (skip_past_char (&p, '{') == SUCCESS)
5647 {
5648 /* [Rn], {expr} - unindexed, with option */
5649 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5650 0, 255, TRUE) == FAIL)
4962c51a 5651 return PARSE_OPERAND_FAIL;
09d92015 5652
c19d1205
ZW
5653 if (skip_past_char (&p, '}') == FAIL)
5654 {
5655 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5656 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5657 }
5658 if (inst.operands[i].preind)
5659 {
5660 inst.error = _("cannot combine index with option");
4962c51a 5661 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5662 }
5663 *str = p;
4962c51a 5664 return PARSE_OPERAND_SUCCESS;
09d92015 5665 }
c19d1205
ZW
5666 else
5667 {
5668 inst.operands[i].postind = 1;
5669 inst.operands[i].writeback = 1;
09d92015 5670
c19d1205
ZW
5671 if (inst.operands[i].preind)
5672 {
5673 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5674 return PARSE_OPERAND_FAIL;
c19d1205 5675 }
09d92015 5676
c19d1205
ZW
5677 if (*p == '+') p++;
5678 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5679
dcbf9037 5680 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5681 {
477330fc
RM
5682 /* We might be using the immediate for alignment already. If we
5683 are, OR the register number into the low-order bits. */
5684 if (inst.operands[i].immisalign)
5685 inst.operands[i].imm |= reg;
5686 else
5687 inst.operands[i].imm = reg;
c19d1205 5688 inst.operands[i].immisreg = 1;
a737bd4d 5689
c19d1205
ZW
5690 if (skip_past_comma (&p) == SUCCESS)
5691 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5692 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5693 }
5694 else
5695 {
26d97720 5696 char *q = p;
c19d1205
ZW
5697 if (inst.operands[i].negative)
5698 {
5699 inst.operands[i].negative = 0;
5700 p--;
5701 }
5702 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5703 return PARSE_OPERAND_FAIL;
26d97720
NS
5704 /* If the offset is 0, find out if it's a +0 or -0. */
5705 if (inst.reloc.exp.X_op == O_constant
5706 && inst.reloc.exp.X_add_number == 0)
5707 {
5708 skip_whitespace (q);
5709 if (*q == '#')
5710 {
5711 q++;
5712 skip_whitespace (q);
5713 }
5714 if (*q == '-')
5715 inst.operands[i].negative = 1;
5716 }
c19d1205
ZW
5717 }
5718 }
a737bd4d
NC
5719 }
5720
c19d1205
ZW
5721 /* If at this point neither .preind nor .postind is set, we have a
5722 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5723 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5724 {
5725 inst.operands[i].preind = 1;
5726 inst.reloc.exp.X_op = O_constant;
5727 inst.reloc.exp.X_add_number = 0;
5728 }
5729 *str = p;
4962c51a
MS
5730 return PARSE_OPERAND_SUCCESS;
5731}
5732
5733static int
5734parse_address (char **str, int i)
5735{
21d799b5 5736 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5737 ? SUCCESS : FAIL;
4962c51a
MS
5738}
5739
5740static parse_operand_result
5741parse_address_group_reloc (char **str, int i, group_reloc_type type)
5742{
5743 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5744}
5745
b6895b4f
PB
5746/* Parse an operand for a MOVW or MOVT instruction. */
5747static int
5748parse_half (char **str)
5749{
5750 char * p;
5f4273c7 5751
b6895b4f
PB
5752 p = *str;
5753 skip_past_char (&p, '#');
5f4273c7 5754 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5755 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5756 else if (strncasecmp (p, ":upper16:", 9) == 0)
5757 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5758
5759 if (inst.reloc.type != BFD_RELOC_UNUSED)
5760 {
5761 p += 9;
5f4273c7 5762 skip_whitespace (p);
b6895b4f
PB
5763 }
5764
5765 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5766 return FAIL;
5767
5768 if (inst.reloc.type == BFD_RELOC_UNUSED)
5769 {
5770 if (inst.reloc.exp.X_op != O_constant)
5771 {
5772 inst.error = _("constant expression expected");
5773 return FAIL;
5774 }
5775 if (inst.reloc.exp.X_add_number < 0
5776 || inst.reloc.exp.X_add_number > 0xffff)
5777 {
5778 inst.error = _("immediate value out of range");
5779 return FAIL;
5780 }
5781 }
5782 *str = p;
5783 return SUCCESS;
5784}
5785
c19d1205 5786/* Miscellaneous. */
a737bd4d 5787
c19d1205
ZW
5788/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5789 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5790static int
d2cd1205 5791parse_psr (char **str, bfd_boolean lhs)
09d92015 5792{
c19d1205
ZW
5793 char *p;
5794 unsigned long psr_field;
62b3e311
PB
5795 const struct asm_psr *psr;
5796 char *start;
d2cd1205 5797 bfd_boolean is_apsr = FALSE;
ac7f631b 5798 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5799
a4482bb6
NC
5800 /* PR gas/12698: If the user has specified -march=all then m_profile will
5801 be TRUE, but we want to ignore it in this case as we are building for any
5802 CPU type, including non-m variants. */
823d2571 5803 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
5804 m_profile = FALSE;
5805
c19d1205
ZW
5806 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5807 feature for ease of use and backwards compatibility. */
5808 p = *str;
62b3e311 5809 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5810 {
5811 if (m_profile)
5812 goto unsupported_psr;
fa94de6b 5813
d2cd1205
JB
5814 psr_field = SPSR_BIT;
5815 }
5816 else if (strncasecmp (p, "CPSR", 4) == 0)
5817 {
5818 if (m_profile)
5819 goto unsupported_psr;
5820
5821 psr_field = 0;
5822 }
5823 else if (strncasecmp (p, "APSR", 4) == 0)
5824 {
5825 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5826 and ARMv7-R architecture CPUs. */
5827 is_apsr = TRUE;
5828 psr_field = 0;
5829 }
5830 else if (m_profile)
62b3e311
PB
5831 {
5832 start = p;
5833 do
5834 p++;
5835 while (ISALNUM (*p) || *p == '_');
5836
d2cd1205
JB
5837 if (strncasecmp (start, "iapsr", 5) == 0
5838 || strncasecmp (start, "eapsr", 5) == 0
5839 || strncasecmp (start, "xpsr", 4) == 0
5840 || strncasecmp (start, "psr", 3) == 0)
5841 p = start + strcspn (start, "rR") + 1;
5842
21d799b5 5843 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5844 p - start);
d2cd1205 5845
62b3e311
PB
5846 if (!psr)
5847 return FAIL;
09d92015 5848
d2cd1205
JB
5849 /* If APSR is being written, a bitfield may be specified. Note that
5850 APSR itself is handled above. */
5851 if (psr->field <= 3)
5852 {
5853 psr_field = psr->field;
5854 is_apsr = TRUE;
5855 goto check_suffix;
5856 }
5857
62b3e311 5858 *str = p;
d2cd1205
JB
5859 /* M-profile MSR instructions have the mask field set to "10", except
5860 *PSR variants which modify APSR, which may use a different mask (and
5861 have been handled already). Do that by setting the PSR_f field
5862 here. */
5863 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5864 }
d2cd1205
JB
5865 else
5866 goto unsupported_psr;
09d92015 5867
62b3e311 5868 p += 4;
d2cd1205 5869check_suffix:
c19d1205
ZW
5870 if (*p == '_')
5871 {
5872 /* A suffix follows. */
c19d1205
ZW
5873 p++;
5874 start = p;
a737bd4d 5875
c19d1205
ZW
5876 do
5877 p++;
5878 while (ISALNUM (*p) || *p == '_');
a737bd4d 5879
d2cd1205
JB
5880 if (is_apsr)
5881 {
5882 /* APSR uses a notation for bits, rather than fields. */
5883 unsigned int nzcvq_bits = 0;
5884 unsigned int g_bit = 0;
5885 char *bit;
fa94de6b 5886
d2cd1205
JB
5887 for (bit = start; bit != p; bit++)
5888 {
5889 switch (TOLOWER (*bit))
477330fc 5890 {
d2cd1205
JB
5891 case 'n':
5892 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5893 break;
5894
5895 case 'z':
5896 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5897 break;
5898
5899 case 'c':
5900 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5901 break;
5902
5903 case 'v':
5904 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5905 break;
fa94de6b 5906
d2cd1205
JB
5907 case 'q':
5908 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5909 break;
fa94de6b 5910
d2cd1205
JB
5911 case 'g':
5912 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5913 break;
fa94de6b 5914
d2cd1205
JB
5915 default:
5916 inst.error = _("unexpected bit specified after APSR");
5917 return FAIL;
5918 }
5919 }
fa94de6b 5920
d2cd1205
JB
5921 if (nzcvq_bits == 0x1f)
5922 psr_field |= PSR_f;
fa94de6b 5923
d2cd1205
JB
5924 if (g_bit == 0x1)
5925 {
5926 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5927 {
d2cd1205
JB
5928 inst.error = _("selected processor does not "
5929 "support DSP extension");
5930 return FAIL;
5931 }
5932
5933 psr_field |= PSR_s;
5934 }
fa94de6b 5935
d2cd1205
JB
5936 if ((nzcvq_bits & 0x20) != 0
5937 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5938 || (g_bit & 0x2) != 0)
5939 {
5940 inst.error = _("bad bitmask specified after APSR");
5941 return FAIL;
5942 }
5943 }
5944 else
477330fc 5945 {
d2cd1205 5946 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 5947 p - start);
d2cd1205 5948 if (!psr)
477330fc 5949 goto error;
a737bd4d 5950
d2cd1205
JB
5951 psr_field |= psr->field;
5952 }
a737bd4d 5953 }
c19d1205 5954 else
a737bd4d 5955 {
c19d1205
ZW
5956 if (ISALNUM (*p))
5957 goto error; /* Garbage after "[CS]PSR". */
5958
d2cd1205 5959 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 5960 is deprecated, but allow it anyway. */
d2cd1205
JB
5961 if (is_apsr && lhs)
5962 {
5963 psr_field |= PSR_f;
5964 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5965 "deprecated"));
5966 }
5967 else if (!m_profile)
5968 /* These bits are never right for M-profile devices: don't set them
5969 (only code paths which read/write APSR reach here). */
5970 psr_field |= (PSR_c | PSR_f);
a737bd4d 5971 }
c19d1205
ZW
5972 *str = p;
5973 return psr_field;
a737bd4d 5974
d2cd1205
JB
5975 unsupported_psr:
5976 inst.error = _("selected processor does not support requested special "
5977 "purpose register");
5978 return FAIL;
5979
c19d1205
ZW
5980 error:
5981 inst.error = _("flag for {c}psr instruction expected");
5982 return FAIL;
a737bd4d
NC
5983}
5984
c19d1205
ZW
5985/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5986 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5987
c19d1205
ZW
5988static int
5989parse_cps_flags (char **str)
a737bd4d 5990{
c19d1205
ZW
5991 int val = 0;
5992 int saw_a_flag = 0;
5993 char *s = *str;
a737bd4d 5994
c19d1205
ZW
5995 for (;;)
5996 switch (*s++)
5997 {
5998 case '\0': case ',':
5999 goto done;
a737bd4d 6000
c19d1205
ZW
6001 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6002 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6003 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6004
c19d1205
ZW
6005 default:
6006 inst.error = _("unrecognized CPS flag");
6007 return FAIL;
6008 }
a737bd4d 6009
c19d1205
ZW
6010 done:
6011 if (saw_a_flag == 0)
a737bd4d 6012 {
c19d1205
ZW
6013 inst.error = _("missing CPS flags");
6014 return FAIL;
a737bd4d 6015 }
a737bd4d 6016
c19d1205
ZW
6017 *str = s - 1;
6018 return val;
a737bd4d
NC
6019}
6020
c19d1205
ZW
6021/* Parse an endian specifier ("BE" or "LE", case insensitive);
6022 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6023
6024static int
c19d1205 6025parse_endian_specifier (char **str)
a737bd4d 6026{
c19d1205
ZW
6027 int little_endian;
6028 char *s = *str;
a737bd4d 6029
c19d1205
ZW
6030 if (strncasecmp (s, "BE", 2))
6031 little_endian = 0;
6032 else if (strncasecmp (s, "LE", 2))
6033 little_endian = 1;
6034 else
a737bd4d 6035 {
c19d1205 6036 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6037 return FAIL;
6038 }
6039
c19d1205 6040 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6041 {
c19d1205 6042 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6043 return FAIL;
6044 }
6045
c19d1205
ZW
6046 *str = s + 2;
6047 return little_endian;
6048}
a737bd4d 6049
c19d1205
ZW
6050/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6051 value suitable for poking into the rotate field of an sxt or sxta
6052 instruction, or FAIL on error. */
6053
6054static int
6055parse_ror (char **str)
6056{
6057 int rot;
6058 char *s = *str;
6059
6060 if (strncasecmp (s, "ROR", 3) == 0)
6061 s += 3;
6062 else
a737bd4d 6063 {
c19d1205 6064 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6065 return FAIL;
6066 }
c19d1205
ZW
6067
6068 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6069 return FAIL;
6070
6071 switch (rot)
a737bd4d 6072 {
c19d1205
ZW
6073 case 0: *str = s; return 0x0;
6074 case 8: *str = s; return 0x1;
6075 case 16: *str = s; return 0x2;
6076 case 24: *str = s; return 0x3;
6077
6078 default:
6079 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6080 return FAIL;
6081 }
c19d1205 6082}
a737bd4d 6083
c19d1205
ZW
6084/* Parse a conditional code (from conds[] below). The value returned is in the
6085 range 0 .. 14, or FAIL. */
6086static int
6087parse_cond (char **str)
6088{
c462b453 6089 char *q;
c19d1205 6090 const struct asm_cond *c;
c462b453
PB
6091 int n;
6092 /* Condition codes are always 2 characters, so matching up to
6093 3 characters is sufficient. */
6094 char cond[3];
a737bd4d 6095
c462b453
PB
6096 q = *str;
6097 n = 0;
6098 while (ISALPHA (*q) && n < 3)
6099 {
e07e6e58 6100 cond[n] = TOLOWER (*q);
c462b453
PB
6101 q++;
6102 n++;
6103 }
a737bd4d 6104
21d799b5 6105 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6106 if (!c)
a737bd4d 6107 {
c19d1205 6108 inst.error = _("condition required");
a737bd4d
NC
6109 return FAIL;
6110 }
6111
c19d1205
ZW
6112 *str = q;
6113 return c->value;
6114}
6115
643afb90
MW
6116/* Record a use of the given feature. */
6117static void
6118record_feature_use (const arm_feature_set *feature)
6119{
6120 if (thumb_mode)
6121 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6122 else
6123 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6124}
6125
e797f7e0
MGD
6126/* If the given feature available in the selected CPU, mark it as used.
6127 Returns TRUE iff feature is available. */
6128static bfd_boolean
6129mark_feature_used (const arm_feature_set *feature)
6130{
6131 /* Ensure the option is valid on the current architecture. */
6132 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6133 return FALSE;
6134
6135 /* Add the appropriate architecture feature for the barrier option used.
6136 */
643afb90 6137 record_feature_use (feature);
e797f7e0
MGD
6138
6139 return TRUE;
6140}
6141
62b3e311
PB
6142/* Parse an option for a barrier instruction. Returns the encoding for the
6143 option, or FAIL. */
6144static int
6145parse_barrier (char **str)
6146{
6147 char *p, *q;
6148 const struct asm_barrier_opt *o;
6149
6150 p = q = *str;
6151 while (ISALPHA (*q))
6152 q++;
6153
21d799b5 6154 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6155 q - p);
62b3e311
PB
6156 if (!o)
6157 return FAIL;
6158
e797f7e0
MGD
6159 if (!mark_feature_used (&o->arch))
6160 return FAIL;
6161
62b3e311
PB
6162 *str = q;
6163 return o->value;
6164}
6165
92e90b6e
PB
6166/* Parse the operands of a table branch instruction. Similar to a memory
6167 operand. */
6168static int
6169parse_tb (char **str)
6170{
6171 char * p = *str;
6172 int reg;
6173
6174 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6175 {
6176 inst.error = _("'[' expected");
6177 return FAIL;
6178 }
92e90b6e 6179
dcbf9037 6180 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6181 {
6182 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6183 return FAIL;
6184 }
6185 inst.operands[0].reg = reg;
6186
6187 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6188 {
6189 inst.error = _("',' expected");
6190 return FAIL;
6191 }
5f4273c7 6192
dcbf9037 6193 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6194 {
6195 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6196 return FAIL;
6197 }
6198 inst.operands[0].imm = reg;
6199
6200 if (skip_past_comma (&p) == SUCCESS)
6201 {
6202 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6203 return FAIL;
6204 if (inst.reloc.exp.X_add_number != 1)
6205 {
6206 inst.error = _("invalid shift");
6207 return FAIL;
6208 }
6209 inst.operands[0].shifted = 1;
6210 }
6211
6212 if (skip_past_char (&p, ']') == FAIL)
6213 {
6214 inst.error = _("']' expected");
6215 return FAIL;
6216 }
6217 *str = p;
6218 return SUCCESS;
6219}
6220
5287ad62
JB
6221/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6222 information on the types the operands can take and how they are encoded.
037e8744
JB
6223 Up to four operands may be read; this function handles setting the
6224 ".present" field for each read operand itself.
5287ad62
JB
6225 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6226 else returns FAIL. */
6227
6228static int
6229parse_neon_mov (char **str, int *which_operand)
6230{
6231 int i = *which_operand, val;
6232 enum arm_reg_type rtype;
6233 char *ptr = *str;
dcbf9037 6234 struct neon_type_el optype;
5f4273c7 6235
dcbf9037 6236 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6237 {
6238 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6239 inst.operands[i].reg = val;
6240 inst.operands[i].isscalar = 1;
dcbf9037 6241 inst.operands[i].vectype = optype;
5287ad62
JB
6242 inst.operands[i++].present = 1;
6243
6244 if (skip_past_comma (&ptr) == FAIL)
477330fc 6245 goto wanted_comma;
5f4273c7 6246
dcbf9037 6247 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6248 goto wanted_arm;
5f4273c7 6249
5287ad62
JB
6250 inst.operands[i].reg = val;
6251 inst.operands[i].isreg = 1;
6252 inst.operands[i].present = 1;
6253 }
037e8744 6254 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6255 != FAIL)
5287ad62
JB
6256 {
6257 /* Cases 0, 1, 2, 3, 5 (D only). */
6258 if (skip_past_comma (&ptr) == FAIL)
477330fc 6259 goto wanted_comma;
5f4273c7 6260
5287ad62
JB
6261 inst.operands[i].reg = val;
6262 inst.operands[i].isreg = 1;
6263 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6264 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6265 inst.operands[i].isvec = 1;
dcbf9037 6266 inst.operands[i].vectype = optype;
5287ad62
JB
6267 inst.operands[i++].present = 1;
6268
dcbf9037 6269 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6270 {
6271 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6272 Case 13: VMOV <Sd>, <Rm> */
6273 inst.operands[i].reg = val;
6274 inst.operands[i].isreg = 1;
6275 inst.operands[i].present = 1;
6276
6277 if (rtype == REG_TYPE_NQ)
6278 {
6279 first_error (_("can't use Neon quad register here"));
6280 return FAIL;
6281 }
6282 else if (rtype != REG_TYPE_VFS)
6283 {
6284 i++;
6285 if (skip_past_comma (&ptr) == FAIL)
6286 goto wanted_comma;
6287 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6288 goto wanted_arm;
6289 inst.operands[i].reg = val;
6290 inst.operands[i].isreg = 1;
6291 inst.operands[i].present = 1;
6292 }
6293 }
037e8744 6294 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6295 &optype)) != FAIL)
6296 {
6297 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6298 Case 1: VMOV<c><q> <Dd>, <Dm>
6299 Case 8: VMOV.F32 <Sd>, <Sm>
6300 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6301
6302 inst.operands[i].reg = val;
6303 inst.operands[i].isreg = 1;
6304 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6305 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6306 inst.operands[i].isvec = 1;
6307 inst.operands[i].vectype = optype;
6308 inst.operands[i].present = 1;
6309
6310 if (skip_past_comma (&ptr) == SUCCESS)
6311 {
6312 /* Case 15. */
6313 i++;
6314
6315 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6316 goto wanted_arm;
6317
6318 inst.operands[i].reg = val;
6319 inst.operands[i].isreg = 1;
6320 inst.operands[i++].present = 1;
6321
6322 if (skip_past_comma (&ptr) == FAIL)
6323 goto wanted_comma;
6324
6325 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6326 goto wanted_arm;
6327
6328 inst.operands[i].reg = val;
6329 inst.operands[i].isreg = 1;
6330 inst.operands[i].present = 1;
6331 }
6332 }
4641781c 6333 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6334 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6335 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6336 Case 10: VMOV.F32 <Sd>, #<imm>
6337 Case 11: VMOV.F64 <Dd>, #<imm> */
6338 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6339 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6340 == SUCCESS)
477330fc
RM
6341 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6342 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6343 ;
5287ad62 6344 else
477330fc
RM
6345 {
6346 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6347 return FAIL;
6348 }
5287ad62 6349 }
dcbf9037 6350 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6351 {
6352 /* Cases 6, 7. */
6353 inst.operands[i].reg = val;
6354 inst.operands[i].isreg = 1;
6355 inst.operands[i++].present = 1;
5f4273c7 6356
5287ad62 6357 if (skip_past_comma (&ptr) == FAIL)
477330fc 6358 goto wanted_comma;
5f4273c7 6359
dcbf9037 6360 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6361 {
6362 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6363 inst.operands[i].reg = val;
6364 inst.operands[i].isscalar = 1;
6365 inst.operands[i].present = 1;
6366 inst.operands[i].vectype = optype;
6367 }
dcbf9037 6368 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6369 {
6370 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6371 inst.operands[i].reg = val;
6372 inst.operands[i].isreg = 1;
6373 inst.operands[i++].present = 1;
6374
6375 if (skip_past_comma (&ptr) == FAIL)
6376 goto wanted_comma;
6377
6378 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6379 == FAIL)
6380 {
6381 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6382 return FAIL;
6383 }
6384
6385 inst.operands[i].reg = val;
6386 inst.operands[i].isreg = 1;
6387 inst.operands[i].isvec = 1;
6388 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6389 inst.operands[i].vectype = optype;
6390 inst.operands[i].present = 1;
6391
6392 if (rtype == REG_TYPE_VFS)
6393 {
6394 /* Case 14. */
6395 i++;
6396 if (skip_past_comma (&ptr) == FAIL)
6397 goto wanted_comma;
6398 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6399 &optype)) == FAIL)
6400 {
6401 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6402 return FAIL;
6403 }
6404 inst.operands[i].reg = val;
6405 inst.operands[i].isreg = 1;
6406 inst.operands[i].isvec = 1;
6407 inst.operands[i].issingle = 1;
6408 inst.operands[i].vectype = optype;
6409 inst.operands[i].present = 1;
6410 }
6411 }
037e8744 6412 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6413 != FAIL)
6414 {
6415 /* Case 13. */
6416 inst.operands[i].reg = val;
6417 inst.operands[i].isreg = 1;
6418 inst.operands[i].isvec = 1;
6419 inst.operands[i].issingle = 1;
6420 inst.operands[i].vectype = optype;
6421 inst.operands[i].present = 1;
6422 }
5287ad62
JB
6423 }
6424 else
6425 {
dcbf9037 6426 first_error (_("parse error"));
5287ad62
JB
6427 return FAIL;
6428 }
6429
6430 /* Successfully parsed the operands. Update args. */
6431 *which_operand = i;
6432 *str = ptr;
6433 return SUCCESS;
6434
5f4273c7 6435 wanted_comma:
dcbf9037 6436 first_error (_("expected comma"));
5287ad62 6437 return FAIL;
5f4273c7
NC
6438
6439 wanted_arm:
dcbf9037 6440 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6441 return FAIL;
5287ad62
JB
6442}
6443
5be8be5d
DG
6444/* Use this macro when the operand constraints are different
6445 for ARM and THUMB (e.g. ldrd). */
6446#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6447 ((arm_operand) | ((thumb_operand) << 16))
6448
c19d1205
ZW
6449/* Matcher codes for parse_operands. */
6450enum operand_parse_code
6451{
6452 OP_stop, /* end of line */
6453
6454 OP_RR, /* ARM register */
6455 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6456 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6457 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6458 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6459 optional trailing ! */
c19d1205
ZW
6460 OP_RRw, /* ARM register, not r15, optional trailing ! */
6461 OP_RCP, /* Coprocessor number */
6462 OP_RCN, /* Coprocessor register */
6463 OP_RF, /* FPA register */
6464 OP_RVS, /* VFP single precision register */
5287ad62
JB
6465 OP_RVD, /* VFP double precision register (0..15) */
6466 OP_RND, /* Neon double precision register (0..31) */
6467 OP_RNQ, /* Neon quad precision register */
037e8744 6468 OP_RVSD, /* VFP single or double precision register */
5287ad62 6469 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6470 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6471 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6472 OP_RVC, /* VFP control register */
6473 OP_RMF, /* Maverick F register */
6474 OP_RMD, /* Maverick D register */
6475 OP_RMFX, /* Maverick FX register */
6476 OP_RMDX, /* Maverick DX register */
6477 OP_RMAX, /* Maverick AX register */
6478 OP_RMDS, /* Maverick DSPSC register */
6479 OP_RIWR, /* iWMMXt wR register */
6480 OP_RIWC, /* iWMMXt wC register */
6481 OP_RIWG, /* iWMMXt wCG register */
6482 OP_RXA, /* XScale accumulator register */
6483
6484 OP_REGLST, /* ARM register list */
6485 OP_VRSLST, /* VFP single-precision register list */
6486 OP_VRDLST, /* VFP double-precision register list */
037e8744 6487 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6488 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6489 OP_NSTRLST, /* Neon element/structure list */
6490
5287ad62 6491 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6492 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6493 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6494 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6495 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6496 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6497 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6498 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6499 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6500 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6501 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6502
6503 OP_I0, /* immediate zero */
c19d1205
ZW
6504 OP_I7, /* immediate value 0 .. 7 */
6505 OP_I15, /* 0 .. 15 */
6506 OP_I16, /* 1 .. 16 */
5287ad62 6507 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6508 OP_I31, /* 0 .. 31 */
6509 OP_I31w, /* 0 .. 31, optional trailing ! */
6510 OP_I32, /* 1 .. 32 */
5287ad62
JB
6511 OP_I32z, /* 0 .. 32 */
6512 OP_I63, /* 0 .. 63 */
c19d1205 6513 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6514 OP_I64, /* 1 .. 64 */
6515 OP_I64z, /* 0 .. 64 */
c19d1205 6516 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6517
6518 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6519 OP_I7b, /* 0 .. 7 */
6520 OP_I15b, /* 0 .. 15 */
6521 OP_I31b, /* 0 .. 31 */
6522
6523 OP_SH, /* shifter operand */
4962c51a 6524 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6525 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6526 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6527 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6528 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6529 OP_EXP, /* arbitrary expression */
6530 OP_EXPi, /* same, with optional immediate prefix */
6531 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6532 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
6533
6534 OP_CPSF, /* CPS flags */
6535 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6536 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6537 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6538 OP_COND, /* conditional code */
92e90b6e 6539 OP_TB, /* Table branch. */
c19d1205 6540
037e8744
JB
6541 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6542
c19d1205
ZW
6543 OP_RRnpc_I0, /* ARM register or literal 0 */
6544 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6545 OP_RR_EXi, /* ARM register or expression with imm prefix */
6546 OP_RF_IF, /* FPA register or immediate */
6547 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6548 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6549
6550 /* Optional operands. */
6551 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6552 OP_oI31b, /* 0 .. 31 */
5287ad62 6553 OP_oI32b, /* 1 .. 32 */
5f1af56b 6554 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6555 OP_oIffffb, /* 0 .. 65535 */
6556 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6557
6558 OP_oRR, /* ARM register */
6559 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6560 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6561 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6562 OP_oRND, /* Optional Neon double precision register */
6563 OP_oRNQ, /* Optional Neon quad precision register */
6564 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6565 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6566 OP_oSHll, /* LSL immediate */
6567 OP_oSHar, /* ASR immediate */
6568 OP_oSHllar, /* LSL or ASR immediate */
6569 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6570 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6571
5be8be5d
DG
6572 /* Some pre-defined mixed (ARM/THUMB) operands. */
6573 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6574 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6575 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6576
c19d1205
ZW
6577 OP_FIRST_OPTIONAL = OP_oI7b
6578};
a737bd4d 6579
c19d1205
ZW
6580/* Generic instruction operand parser. This does no encoding and no
6581 semantic validation; it merely squirrels values away in the inst
6582 structure. Returns SUCCESS or FAIL depending on whether the
6583 specified grammar matched. */
6584static int
5be8be5d 6585parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6586{
5be8be5d 6587 unsigned const int *upat = pattern;
c19d1205
ZW
6588 char *backtrack_pos = 0;
6589 const char *backtrack_error = 0;
99aad254 6590 int i, val = 0, backtrack_index = 0;
5287ad62 6591 enum arm_reg_type rtype;
4962c51a 6592 parse_operand_result result;
5be8be5d 6593 unsigned int op_parse_code;
c19d1205 6594
e07e6e58
NC
6595#define po_char_or_fail(chr) \
6596 do \
6597 { \
6598 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6599 goto bad_args; \
e07e6e58
NC
6600 } \
6601 while (0)
c19d1205 6602
e07e6e58
NC
6603#define po_reg_or_fail(regtype) \
6604 do \
dcbf9037 6605 { \
e07e6e58 6606 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6607 & inst.operands[i].vectype); \
e07e6e58 6608 if (val == FAIL) \
477330fc
RM
6609 { \
6610 first_error (_(reg_expected_msgs[regtype])); \
6611 goto failure; \
6612 } \
e07e6e58
NC
6613 inst.operands[i].reg = val; \
6614 inst.operands[i].isreg = 1; \
6615 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6616 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6617 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6618 || rtype == REG_TYPE_VFD \
6619 || rtype == REG_TYPE_NQ); \
dcbf9037 6620 } \
e07e6e58
NC
6621 while (0)
6622
6623#define po_reg_or_goto(regtype, label) \
6624 do \
6625 { \
6626 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6627 & inst.operands[i].vectype); \
6628 if (val == FAIL) \
6629 goto label; \
dcbf9037 6630 \
e07e6e58
NC
6631 inst.operands[i].reg = val; \
6632 inst.operands[i].isreg = 1; \
6633 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6634 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6635 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6636 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6637 || rtype == REG_TYPE_NQ); \
6638 } \
6639 while (0)
6640
6641#define po_imm_or_fail(min, max, popt) \
6642 do \
6643 { \
6644 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6645 goto failure; \
6646 inst.operands[i].imm = val; \
6647 } \
6648 while (0)
6649
6650#define po_scalar_or_goto(elsz, label) \
6651 do \
6652 { \
6653 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6654 if (val == FAIL) \
6655 goto label; \
6656 inst.operands[i].reg = val; \
6657 inst.operands[i].isscalar = 1; \
6658 } \
6659 while (0)
6660
6661#define po_misc_or_fail(expr) \
6662 do \
6663 { \
6664 if (expr) \
6665 goto failure; \
6666 } \
6667 while (0)
6668
6669#define po_misc_or_fail_no_backtrack(expr) \
6670 do \
6671 { \
6672 result = expr; \
6673 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6674 backtrack_pos = 0; \
6675 if (result != PARSE_OPERAND_SUCCESS) \
6676 goto failure; \
6677 } \
6678 while (0)
4962c51a 6679
52e7f43d
RE
6680#define po_barrier_or_imm(str) \
6681 do \
6682 { \
6683 val = parse_barrier (&str); \
ccb84d65
JB
6684 if (val == FAIL && ! ISALPHA (*str)) \
6685 goto immediate; \
6686 if (val == FAIL \
6687 /* ISB can only take SY as an option. */ \
6688 || ((inst.instruction & 0xf0) == 0x60 \
6689 && val != 0xf)) \
52e7f43d 6690 { \
ccb84d65
JB
6691 inst.error = _("invalid barrier type"); \
6692 backtrack_pos = 0; \
6693 goto failure; \
52e7f43d
RE
6694 } \
6695 } \
6696 while (0)
6697
c19d1205
ZW
6698 skip_whitespace (str);
6699
6700 for (i = 0; upat[i] != OP_stop; i++)
6701 {
5be8be5d
DG
6702 op_parse_code = upat[i];
6703 if (op_parse_code >= 1<<16)
6704 op_parse_code = thumb ? (op_parse_code >> 16)
6705 : (op_parse_code & ((1<<16)-1));
6706
6707 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6708 {
6709 /* Remember where we are in case we need to backtrack. */
9c2799c2 6710 gas_assert (!backtrack_pos);
c19d1205
ZW
6711 backtrack_pos = str;
6712 backtrack_error = inst.error;
6713 backtrack_index = i;
6714 }
6715
b6702015 6716 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6717 po_char_or_fail (',');
6718
5be8be5d 6719 switch (op_parse_code)
c19d1205
ZW
6720 {
6721 /* Registers */
6722 case OP_oRRnpc:
5be8be5d 6723 case OP_oRRnpcsp:
c19d1205 6724 case OP_RRnpc:
5be8be5d 6725 case OP_RRnpcsp:
c19d1205
ZW
6726 case OP_oRR:
6727 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6728 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6729 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6730 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6731 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6732 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6733 case OP_oRND:
5287ad62 6734 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6735 case OP_RVC:
6736 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6737 break;
6738 /* Also accept generic coprocessor regs for unknown registers. */
6739 coproc_reg:
6740 po_reg_or_fail (REG_TYPE_CN);
6741 break;
c19d1205
ZW
6742 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6743 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6744 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6745 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6746 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6747 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6748 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6749 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6750 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6751 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6752 case OP_oRNQ:
5287ad62 6753 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
477330fc 6754 case OP_oRNDQ:
5287ad62 6755 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6756 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6757 case OP_oRNSDQ:
6758 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6759
6760 /* Neon scalar. Using an element size of 8 means that some invalid
6761 scalars are accepted here, so deal with those in later code. */
6762 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6763
6764 case OP_RNDQ_I0:
6765 {
6766 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6767 break;
6768 try_imm0:
6769 po_imm_or_fail (0, 0, TRUE);
6770 }
6771 break;
6772
6773 case OP_RVSD_I0:
6774 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6775 break;
6776
aacf0b33
KT
6777 case OP_RSVD_FI0:
6778 {
6779 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6780 break;
6781 try_ifimm0:
6782 if (parse_ifimm_zero (&str))
6783 inst.operands[i].imm = 0;
6784 else
6785 {
6786 inst.error
6787 = _("only floating point zero is allowed as immediate value");
6788 goto failure;
6789 }
6790 }
6791 break;
6792
477330fc
RM
6793 case OP_RR_RNSC:
6794 {
6795 po_scalar_or_goto (8, try_rr);
6796 break;
6797 try_rr:
6798 po_reg_or_fail (REG_TYPE_RN);
6799 }
6800 break;
6801
6802 case OP_RNSDQ_RNSC:
6803 {
6804 po_scalar_or_goto (8, try_nsdq);
6805 break;
6806 try_nsdq:
6807 po_reg_or_fail (REG_TYPE_NSDQ);
6808 }
6809 break;
6810
6811 case OP_RNDQ_RNSC:
6812 {
6813 po_scalar_or_goto (8, try_ndq);
6814 break;
6815 try_ndq:
6816 po_reg_or_fail (REG_TYPE_NDQ);
6817 }
6818 break;
6819
6820 case OP_RND_RNSC:
6821 {
6822 po_scalar_or_goto (8, try_vfd);
6823 break;
6824 try_vfd:
6825 po_reg_or_fail (REG_TYPE_VFD);
6826 }
6827 break;
6828
6829 case OP_VMOV:
6830 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6831 not careful then bad things might happen. */
6832 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6833 break;
6834
6835 case OP_RNDQ_Ibig:
6836 {
6837 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6838 break;
6839 try_immbig:
6840 /* There's a possibility of getting a 64-bit immediate here, so
6841 we need special handling. */
8335d6aa
JW
6842 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6843 == FAIL)
477330fc
RM
6844 {
6845 inst.error = _("immediate value is out of range");
6846 goto failure;
6847 }
6848 }
6849 break;
6850
6851 case OP_RNDQ_I63b:
6852 {
6853 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6854 break;
6855 try_shimm:
6856 po_imm_or_fail (0, 63, TRUE);
6857 }
6858 break;
c19d1205
ZW
6859
6860 case OP_RRnpcb:
6861 po_char_or_fail ('[');
6862 po_reg_or_fail (REG_TYPE_RN);
6863 po_char_or_fail (']');
6864 break;
a737bd4d 6865
55881a11 6866 case OP_RRnpctw:
c19d1205 6867 case OP_RRw:
b6702015 6868 case OP_oRRw:
c19d1205
ZW
6869 po_reg_or_fail (REG_TYPE_RN);
6870 if (skip_past_char (&str, '!') == SUCCESS)
6871 inst.operands[i].writeback = 1;
6872 break;
6873
6874 /* Immediates */
6875 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6876 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6877 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6878 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6879 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6880 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6881 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6882 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6883 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6884 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6885 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6886 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6887
6888 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6889 case OP_oI7b:
6890 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6891 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6892 case OP_oI31b:
6893 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6894 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6895 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6896 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6897
6898 /* Immediate variants */
6899 case OP_oI255c:
6900 po_char_or_fail ('{');
6901 po_imm_or_fail (0, 255, TRUE);
6902 po_char_or_fail ('}');
6903 break;
6904
6905 case OP_I31w:
6906 /* The expression parser chokes on a trailing !, so we have
6907 to find it first and zap it. */
6908 {
6909 char *s = str;
6910 while (*s && *s != ',')
6911 s++;
6912 if (s[-1] == '!')
6913 {
6914 s[-1] = '\0';
6915 inst.operands[i].writeback = 1;
6916 }
6917 po_imm_or_fail (0, 31, TRUE);
6918 if (str == s - 1)
6919 str = s;
6920 }
6921 break;
6922
6923 /* Expressions */
6924 case OP_EXPi: EXPi:
6925 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6926 GE_OPT_PREFIX));
6927 break;
6928
6929 case OP_EXP:
6930 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6931 GE_NO_PREFIX));
6932 break;
6933
6934 case OP_EXPr: EXPr:
6935 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6936 GE_NO_PREFIX));
6937 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6938 {
c19d1205
ZW
6939 val = parse_reloc (&str);
6940 if (val == -1)
6941 {
6942 inst.error = _("unrecognized relocation suffix");
6943 goto failure;
6944 }
6945 else if (val != BFD_RELOC_UNUSED)
6946 {
6947 inst.operands[i].imm = val;
6948 inst.operands[i].hasreloc = 1;
6949 }
a737bd4d 6950 }
c19d1205 6951 break;
a737bd4d 6952
b6895b4f
PB
6953 /* Operand for MOVW or MOVT. */
6954 case OP_HALF:
6955 po_misc_or_fail (parse_half (&str));
6956 break;
6957
e07e6e58 6958 /* Register or expression. */
c19d1205
ZW
6959 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6960 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6961
e07e6e58 6962 /* Register or immediate. */
c19d1205
ZW
6963 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6964 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6965
c19d1205
ZW
6966 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6967 IF:
6968 if (!is_immediate_prefix (*str))
6969 goto bad_args;
6970 str++;
6971 val = parse_fpa_immediate (&str);
6972 if (val == FAIL)
6973 goto failure;
6974 /* FPA immediates are encoded as registers 8-15.
6975 parse_fpa_immediate has already applied the offset. */
6976 inst.operands[i].reg = val;
6977 inst.operands[i].isreg = 1;
6978 break;
09d92015 6979
2d447fca
JM
6980 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6981 I32z: po_imm_or_fail (0, 32, FALSE); break;
6982
e07e6e58 6983 /* Two kinds of register. */
c19d1205
ZW
6984 case OP_RIWR_RIWC:
6985 {
6986 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6987 if (!rege
6988 || (rege->type != REG_TYPE_MMXWR
6989 && rege->type != REG_TYPE_MMXWC
6990 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6991 {
6992 inst.error = _("iWMMXt data or control register expected");
6993 goto failure;
6994 }
6995 inst.operands[i].reg = rege->number;
6996 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6997 }
6998 break;
09d92015 6999
41adaa5c
JM
7000 case OP_RIWC_RIWG:
7001 {
7002 struct reg_entry *rege = arm_reg_parse_multi (&str);
7003 if (!rege
7004 || (rege->type != REG_TYPE_MMXWC
7005 && rege->type != REG_TYPE_MMXWCG))
7006 {
7007 inst.error = _("iWMMXt control register expected");
7008 goto failure;
7009 }
7010 inst.operands[i].reg = rege->number;
7011 inst.operands[i].isreg = 1;
7012 }
7013 break;
7014
c19d1205
ZW
7015 /* Misc */
7016 case OP_CPSF: val = parse_cps_flags (&str); break;
7017 case OP_ENDI: val = parse_endian_specifier (&str); break;
7018 case OP_oROR: val = parse_ror (&str); break;
c19d1205 7019 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7020 case OP_oBARRIER_I15:
7021 po_barrier_or_imm (str); break;
7022 immediate:
7023 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7024 goto failure;
52e7f43d 7025 break;
c19d1205 7026
fa94de6b 7027 case OP_wPSR:
d2cd1205 7028 case OP_rPSR:
90ec0d68
MGD
7029 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7030 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7031 {
7032 inst.error = _("Banked registers are not available with this "
7033 "architecture.");
7034 goto failure;
7035 }
7036 break;
d2cd1205
JB
7037 try_psr:
7038 val = parse_psr (&str, op_parse_code == OP_wPSR);
7039 break;
037e8744 7040
477330fc
RM
7041 case OP_APSR_RR:
7042 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7043 break;
7044 try_apsr:
7045 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7046 instruction). */
7047 if (strncasecmp (str, "APSR_", 5) == 0)
7048 {
7049 unsigned found = 0;
7050 str += 5;
7051 while (found < 15)
7052 switch (*str++)
7053 {
7054 case 'c': found = (found & 1) ? 16 : found | 1; break;
7055 case 'n': found = (found & 2) ? 16 : found | 2; break;
7056 case 'z': found = (found & 4) ? 16 : found | 4; break;
7057 case 'v': found = (found & 8) ? 16 : found | 8; break;
7058 default: found = 16;
7059 }
7060 if (found != 15)
7061 goto failure;
7062 inst.operands[i].isvec = 1;
f7c21dc7
NC
7063 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7064 inst.operands[i].reg = REG_PC;
477330fc
RM
7065 }
7066 else
7067 goto failure;
7068 break;
037e8744 7069
92e90b6e
PB
7070 case OP_TB:
7071 po_misc_or_fail (parse_tb (&str));
7072 break;
7073
e07e6e58 7074 /* Register lists. */
c19d1205
ZW
7075 case OP_REGLST:
7076 val = parse_reg_list (&str);
7077 if (*str == '^')
7078 {
5e0d7f77 7079 inst.operands[i].writeback = 1;
c19d1205
ZW
7080 str++;
7081 }
7082 break;
09d92015 7083
c19d1205 7084 case OP_VRSLST:
5287ad62 7085 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7086 break;
09d92015 7087
c19d1205 7088 case OP_VRDLST:
5287ad62 7089 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7090 break;
a737bd4d 7091
477330fc
RM
7092 case OP_VRSDLST:
7093 /* Allow Q registers too. */
7094 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7095 REGLIST_NEON_D);
7096 if (val == FAIL)
7097 {
7098 inst.error = NULL;
7099 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7100 REGLIST_VFP_S);
7101 inst.operands[i].issingle = 1;
7102 }
7103 break;
7104
7105 case OP_NRDLST:
7106 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7107 REGLIST_NEON_D);
7108 break;
5287ad62
JB
7109
7110 case OP_NSTRLST:
477330fc
RM
7111 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7112 &inst.operands[i].vectype);
7113 break;
5287ad62 7114
c19d1205
ZW
7115 /* Addressing modes */
7116 case OP_ADDR:
7117 po_misc_or_fail (parse_address (&str, i));
7118 break;
09d92015 7119
4962c51a
MS
7120 case OP_ADDRGLDR:
7121 po_misc_or_fail_no_backtrack (
477330fc 7122 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7123 break;
7124
7125 case OP_ADDRGLDRS:
7126 po_misc_or_fail_no_backtrack (
477330fc 7127 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7128 break;
7129
7130 case OP_ADDRGLDC:
7131 po_misc_or_fail_no_backtrack (
477330fc 7132 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7133 break;
7134
c19d1205
ZW
7135 case OP_SH:
7136 po_misc_or_fail (parse_shifter_operand (&str, i));
7137 break;
09d92015 7138
4962c51a
MS
7139 case OP_SHG:
7140 po_misc_or_fail_no_backtrack (
477330fc 7141 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7142 break;
7143
c19d1205
ZW
7144 case OP_oSHll:
7145 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7146 break;
09d92015 7147
c19d1205
ZW
7148 case OP_oSHar:
7149 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7150 break;
09d92015 7151
c19d1205
ZW
7152 case OP_oSHllar:
7153 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7154 break;
09d92015 7155
c19d1205 7156 default:
5be8be5d 7157 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7158 }
09d92015 7159
c19d1205
ZW
7160 /* Various value-based sanity checks and shared operations. We
7161 do not signal immediate failures for the register constraints;
7162 this allows a syntax error to take precedence. */
5be8be5d 7163 switch (op_parse_code)
c19d1205
ZW
7164 {
7165 case OP_oRRnpc:
7166 case OP_RRnpc:
7167 case OP_RRnpcb:
7168 case OP_RRw:
b6702015 7169 case OP_oRRw:
c19d1205
ZW
7170 case OP_RRnpc_I0:
7171 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7172 inst.error = BAD_PC;
7173 break;
09d92015 7174
5be8be5d
DG
7175 case OP_oRRnpcsp:
7176 case OP_RRnpcsp:
7177 if (inst.operands[i].isreg)
7178 {
7179 if (inst.operands[i].reg == REG_PC)
7180 inst.error = BAD_PC;
7181 else if (inst.operands[i].reg == REG_SP)
7182 inst.error = BAD_SP;
7183 }
7184 break;
7185
55881a11 7186 case OP_RRnpctw:
fa94de6b
RM
7187 if (inst.operands[i].isreg
7188 && inst.operands[i].reg == REG_PC
55881a11
MGD
7189 && (inst.operands[i].writeback || thumb))
7190 inst.error = BAD_PC;
7191 break;
7192
c19d1205
ZW
7193 case OP_CPSF:
7194 case OP_ENDI:
7195 case OP_oROR:
d2cd1205
JB
7196 case OP_wPSR:
7197 case OP_rPSR:
c19d1205 7198 case OP_COND:
52e7f43d 7199 case OP_oBARRIER_I15:
c19d1205
ZW
7200 case OP_REGLST:
7201 case OP_VRSLST:
7202 case OP_VRDLST:
477330fc
RM
7203 case OP_VRSDLST:
7204 case OP_NRDLST:
7205 case OP_NSTRLST:
c19d1205
ZW
7206 if (val == FAIL)
7207 goto failure;
7208 inst.operands[i].imm = val;
7209 break;
a737bd4d 7210
c19d1205
ZW
7211 default:
7212 break;
7213 }
09d92015 7214
c19d1205
ZW
7215 /* If we get here, this operand was successfully parsed. */
7216 inst.operands[i].present = 1;
7217 continue;
09d92015 7218
c19d1205 7219 bad_args:
09d92015 7220 inst.error = BAD_ARGS;
c19d1205
ZW
7221
7222 failure:
7223 if (!backtrack_pos)
d252fdde
PB
7224 {
7225 /* The parse routine should already have set inst.error, but set a
5f4273c7 7226 default here just in case. */
d252fdde
PB
7227 if (!inst.error)
7228 inst.error = _("syntax error");
7229 return FAIL;
7230 }
c19d1205
ZW
7231
7232 /* Do not backtrack over a trailing optional argument that
7233 absorbed some text. We will only fail again, with the
7234 'garbage following instruction' error message, which is
7235 probably less helpful than the current one. */
7236 if (backtrack_index == i && backtrack_pos != str
7237 && upat[i+1] == OP_stop)
d252fdde
PB
7238 {
7239 if (!inst.error)
7240 inst.error = _("syntax error");
7241 return FAIL;
7242 }
c19d1205
ZW
7243
7244 /* Try again, skipping the optional argument at backtrack_pos. */
7245 str = backtrack_pos;
7246 inst.error = backtrack_error;
7247 inst.operands[backtrack_index].present = 0;
7248 i = backtrack_index;
7249 backtrack_pos = 0;
09d92015 7250 }
09d92015 7251
c19d1205
ZW
7252 /* Check that we have parsed all the arguments. */
7253 if (*str != '\0' && !inst.error)
7254 inst.error = _("garbage following instruction");
09d92015 7255
c19d1205 7256 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7257}
7258
c19d1205
ZW
7259#undef po_char_or_fail
7260#undef po_reg_or_fail
7261#undef po_reg_or_goto
7262#undef po_imm_or_fail
5287ad62 7263#undef po_scalar_or_fail
52e7f43d 7264#undef po_barrier_or_imm
e07e6e58 7265
c19d1205 7266/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7267#define constraint(expr, err) \
7268 do \
c19d1205 7269 { \
e07e6e58
NC
7270 if (expr) \
7271 { \
7272 inst.error = err; \
7273 return; \
7274 } \
c19d1205 7275 } \
e07e6e58 7276 while (0)
c19d1205 7277
fdfde340
JM
7278/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7279 instructions are unpredictable if these registers are used. This
7280 is the BadReg predicate in ARM's Thumb-2 documentation. */
7281#define reject_bad_reg(reg) \
7282 do \
7283 if (reg == REG_SP || reg == REG_PC) \
7284 { \
7285 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
7286 return; \
7287 } \
7288 while (0)
7289
94206790
MM
7290/* If REG is R13 (the stack pointer), warn that its use is
7291 deprecated. */
7292#define warn_deprecated_sp(reg) \
7293 do \
7294 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7295 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7296 while (0)
7297
c19d1205
ZW
7298/* Functions for operand encoding. ARM, then Thumb. */
7299
d840c081 7300#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 7301
9db2f6b4
RL
7302/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7303
7304 The only binary encoding difference is the Coprocessor number. Coprocessor
7305 9 is used for half-precision calculations or conversions. The format of the
7306 instruction is the same as the equivalent Coprocessor 10 instuction that
7307 exists for Single-Precision operation. */
7308
7309static void
7310do_scalar_fp16_v82_encode (void)
7311{
7312 if (inst.cond != COND_ALWAYS)
7313 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7314 " the behaviour is UNPREDICTABLE"));
7315 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7316 _(BAD_FP16));
7317
7318 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7319 mark_feature_used (&arm_ext_fp16);
7320}
7321
c19d1205
ZW
7322/* If VAL can be encoded in the immediate field of an ARM instruction,
7323 return the encoded form. Otherwise, return FAIL. */
7324
7325static unsigned int
7326encode_arm_immediate (unsigned int val)
09d92015 7327{
c19d1205
ZW
7328 unsigned int a, i;
7329
4f1d6205
L
7330 if (val <= 0xff)
7331 return val;
7332
7333 for (i = 2; i < 32; i += 2)
c19d1205
ZW
7334 if ((a = rotate_left (val, i)) <= 0xff)
7335 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7336
7337 return FAIL;
09d92015
MM
7338}
7339
c19d1205
ZW
7340/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7341 return the encoded form. Otherwise, return FAIL. */
7342static unsigned int
7343encode_thumb32_immediate (unsigned int val)
09d92015 7344{
c19d1205 7345 unsigned int a, i;
09d92015 7346
9c3c69f2 7347 if (val <= 0xff)
c19d1205 7348 return val;
a737bd4d 7349
9c3c69f2 7350 for (i = 1; i <= 24; i++)
09d92015 7351 {
9c3c69f2
PB
7352 a = val >> i;
7353 if ((val & ~(0xff << i)) == 0)
7354 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7355 }
a737bd4d 7356
c19d1205
ZW
7357 a = val & 0xff;
7358 if (val == ((a << 16) | a))
7359 return 0x100 | a;
7360 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7361 return 0x300 | a;
09d92015 7362
c19d1205
ZW
7363 a = val & 0xff00;
7364 if (val == ((a << 16) | a))
7365 return 0x200 | (a >> 8);
a737bd4d 7366
c19d1205 7367 return FAIL;
09d92015 7368}
5287ad62 7369/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7370
7371static void
5287ad62
JB
7372encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7373{
7374 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7375 && reg > 15)
7376 {
b1cc4aeb 7377 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7378 {
7379 if (thumb_mode)
7380 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7381 fpu_vfp_ext_d32);
7382 else
7383 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7384 fpu_vfp_ext_d32);
7385 }
5287ad62 7386 else
477330fc
RM
7387 {
7388 first_error (_("D register out of range for selected VFP version"));
7389 return;
7390 }
5287ad62
JB
7391 }
7392
c19d1205 7393 switch (pos)
09d92015 7394 {
c19d1205
ZW
7395 case VFP_REG_Sd:
7396 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7397 break;
7398
7399 case VFP_REG_Sn:
7400 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7401 break;
7402
7403 case VFP_REG_Sm:
7404 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7405 break;
7406
5287ad62
JB
7407 case VFP_REG_Dd:
7408 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7409 break;
5f4273c7 7410
5287ad62
JB
7411 case VFP_REG_Dn:
7412 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7413 break;
5f4273c7 7414
5287ad62
JB
7415 case VFP_REG_Dm:
7416 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7417 break;
7418
c19d1205
ZW
7419 default:
7420 abort ();
09d92015 7421 }
09d92015
MM
7422}
7423
c19d1205 7424/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7425 if any, is handled by md_apply_fix. */
09d92015 7426static void
c19d1205 7427encode_arm_shift (int i)
09d92015 7428{
c19d1205
ZW
7429 if (inst.operands[i].shift_kind == SHIFT_RRX)
7430 inst.instruction |= SHIFT_ROR << 5;
7431 else
09d92015 7432 {
c19d1205
ZW
7433 inst.instruction |= inst.operands[i].shift_kind << 5;
7434 if (inst.operands[i].immisreg)
7435 {
7436 inst.instruction |= SHIFT_BY_REG;
7437 inst.instruction |= inst.operands[i].imm << 8;
7438 }
7439 else
7440 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7441 }
c19d1205 7442}
09d92015 7443
c19d1205
ZW
7444static void
7445encode_arm_shifter_operand (int i)
7446{
7447 if (inst.operands[i].isreg)
09d92015 7448 {
c19d1205
ZW
7449 inst.instruction |= inst.operands[i].reg;
7450 encode_arm_shift (i);
09d92015 7451 }
c19d1205 7452 else
a415b1cd
JB
7453 {
7454 inst.instruction |= INST_IMMEDIATE;
7455 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7456 inst.instruction |= inst.operands[i].imm;
7457 }
09d92015
MM
7458}
7459
c19d1205 7460/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7461static void
c19d1205 7462encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7463{
2b2f5df9
NC
7464 /* PR 14260:
7465 Generate an error if the operand is not a register. */
7466 constraint (!inst.operands[i].isreg,
7467 _("Instruction does not support =N addresses"));
7468
c19d1205 7469 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7470
c19d1205 7471 if (inst.operands[i].preind)
09d92015 7472 {
c19d1205
ZW
7473 if (is_t)
7474 {
7475 inst.error = _("instruction does not accept preindexed addressing");
7476 return;
7477 }
7478 inst.instruction |= PRE_INDEX;
7479 if (inst.operands[i].writeback)
7480 inst.instruction |= WRITE_BACK;
09d92015 7481
c19d1205
ZW
7482 }
7483 else if (inst.operands[i].postind)
7484 {
9c2799c2 7485 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7486 if (is_t)
7487 inst.instruction |= WRITE_BACK;
7488 }
7489 else /* unindexed - only for coprocessor */
09d92015 7490 {
c19d1205 7491 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7492 return;
7493 }
7494
c19d1205
ZW
7495 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7496 && (((inst.instruction & 0x000f0000) >> 16)
7497 == ((inst.instruction & 0x0000f000) >> 12)))
7498 as_warn ((inst.instruction & LOAD_BIT)
7499 ? _("destination register same as write-back base")
7500 : _("source register same as write-back base"));
09d92015
MM
7501}
7502
c19d1205
ZW
7503/* inst.operands[i] was set up by parse_address. Encode it into an
7504 ARM-format mode 2 load or store instruction. If is_t is true,
7505 reject forms that cannot be used with a T instruction (i.e. not
7506 post-indexed). */
a737bd4d 7507static void
c19d1205 7508encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7509{
5be8be5d
DG
7510 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7511
c19d1205 7512 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7513
c19d1205 7514 if (inst.operands[i].immisreg)
09d92015 7515 {
5be8be5d
DG
7516 constraint ((inst.operands[i].imm == REG_PC
7517 || (is_pc && inst.operands[i].writeback)),
7518 BAD_PC_ADDRESSING);
c19d1205
ZW
7519 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7520 inst.instruction |= inst.operands[i].imm;
7521 if (!inst.operands[i].negative)
7522 inst.instruction |= INDEX_UP;
7523 if (inst.operands[i].shifted)
7524 {
7525 if (inst.operands[i].shift_kind == SHIFT_RRX)
7526 inst.instruction |= SHIFT_ROR << 5;
7527 else
7528 {
7529 inst.instruction |= inst.operands[i].shift_kind << 5;
7530 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7531 }
7532 }
09d92015 7533 }
c19d1205 7534 else /* immediate offset in inst.reloc */
09d92015 7535 {
5be8be5d
DG
7536 if (is_pc && !inst.reloc.pc_rel)
7537 {
7538 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7539
7540 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7541 cannot use PC in addressing.
7542 PC cannot be used in writeback addressing, either. */
7543 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7544 BAD_PC_ADDRESSING);
23a10334 7545
dc5ec521 7546 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7547 if (warn_on_deprecated
7548 && !is_load
7549 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7550 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7551 }
7552
c19d1205 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 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7559 }
09d92015 7560 }
09d92015
MM
7561}
7562
c19d1205
ZW
7563/* inst.operands[i] was set up by parse_address. Encode it into an
7564 ARM-format mode 3 load or store instruction. Reject forms that
7565 cannot be used with such instructions. If is_t is true, reject
7566 forms that cannot be used with a T instruction (i.e. not
7567 post-indexed). */
7568static void
7569encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7570{
c19d1205 7571 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7572 {
c19d1205
ZW
7573 inst.error = _("instruction does not accept scaled register index");
7574 return;
09d92015 7575 }
a737bd4d 7576
c19d1205 7577 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7578
c19d1205
ZW
7579 if (inst.operands[i].immisreg)
7580 {
5be8be5d 7581 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7582 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7583 BAD_PC_ADDRESSING);
eb9f3f00
JB
7584 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7585 BAD_PC_WRITEBACK);
c19d1205
ZW
7586 inst.instruction |= inst.operands[i].imm;
7587 if (!inst.operands[i].negative)
7588 inst.instruction |= INDEX_UP;
7589 }
7590 else /* immediate offset in inst.reloc */
7591 {
5be8be5d
DG
7592 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7593 && inst.operands[i].writeback),
7594 BAD_PC_WRITEBACK);
c19d1205
ZW
7595 inst.instruction |= HWOFFSET_IMM;
7596 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7597 {
7598 /* Prefer + for zero encoded value. */
7599 if (!inst.operands[i].negative)
7600 inst.instruction |= INDEX_UP;
7601
7602 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7603 }
c19d1205 7604 }
a737bd4d
NC
7605}
7606
8335d6aa
JW
7607/* Write immediate bits [7:0] to the following locations:
7608
7609 |28/24|23 19|18 16|15 4|3 0|
7610 | 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|
7611
7612 This function is used by VMOV/VMVN/VORR/VBIC. */
7613
7614static void
7615neon_write_immbits (unsigned immbits)
7616{
7617 inst.instruction |= immbits & 0xf;
7618 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7619 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7620}
7621
7622/* Invert low-order SIZE bits of XHI:XLO. */
7623
7624static void
7625neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7626{
7627 unsigned immlo = xlo ? *xlo : 0;
7628 unsigned immhi = xhi ? *xhi : 0;
7629
7630 switch (size)
7631 {
7632 case 8:
7633 immlo = (~immlo) & 0xff;
7634 break;
7635
7636 case 16:
7637 immlo = (~immlo) & 0xffff;
7638 break;
7639
7640 case 64:
7641 immhi = (~immhi) & 0xffffffff;
7642 /* fall through. */
7643
7644 case 32:
7645 immlo = (~immlo) & 0xffffffff;
7646 break;
7647
7648 default:
7649 abort ();
7650 }
7651
7652 if (xlo)
7653 *xlo = immlo;
7654
7655 if (xhi)
7656 *xhi = immhi;
7657}
7658
7659/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7660 A, B, C, D. */
09d92015 7661
c19d1205 7662static int
8335d6aa 7663neon_bits_same_in_bytes (unsigned imm)
09d92015 7664{
8335d6aa
JW
7665 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7666 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7667 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7668 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7669}
a737bd4d 7670
8335d6aa 7671/* For immediate of above form, return 0bABCD. */
09d92015 7672
8335d6aa
JW
7673static unsigned
7674neon_squash_bits (unsigned imm)
7675{
7676 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7677 | ((imm & 0x01000000) >> 21);
7678}
7679
7680/* Compress quarter-float representation to 0b...000 abcdefgh. */
7681
7682static unsigned
7683neon_qfloat_bits (unsigned imm)
7684{
7685 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7686}
7687
7688/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7689 the instruction. *OP is passed as the initial value of the op field, and
7690 may be set to a different value depending on the constant (i.e.
7691 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7692 MVN). If the immediate looks like a repeated pattern then also
7693 try smaller element sizes. */
7694
7695static int
7696neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7697 unsigned *immbits, int *op, int size,
7698 enum neon_el_type type)
7699{
7700 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7701 float. */
7702 if (type == NT_float && !float_p)
7703 return FAIL;
7704
7705 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7706 {
8335d6aa
JW
7707 if (size != 32 || *op == 1)
7708 return FAIL;
7709 *immbits = neon_qfloat_bits (immlo);
7710 return 0xf;
7711 }
7712
7713 if (size == 64)
7714 {
7715 if (neon_bits_same_in_bytes (immhi)
7716 && neon_bits_same_in_bytes (immlo))
c19d1205 7717 {
8335d6aa
JW
7718 if (*op == 1)
7719 return FAIL;
7720 *immbits = (neon_squash_bits (immhi) << 4)
7721 | neon_squash_bits (immlo);
7722 *op = 1;
7723 return 0xe;
c19d1205 7724 }
a737bd4d 7725
8335d6aa
JW
7726 if (immhi != immlo)
7727 return FAIL;
7728 }
a737bd4d 7729
8335d6aa 7730 if (size >= 32)
09d92015 7731 {
8335d6aa 7732 if (immlo == (immlo & 0x000000ff))
c19d1205 7733 {
8335d6aa
JW
7734 *immbits = immlo;
7735 return 0x0;
c19d1205 7736 }
8335d6aa 7737 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7738 {
8335d6aa
JW
7739 *immbits = immlo >> 8;
7740 return 0x2;
c19d1205 7741 }
8335d6aa
JW
7742 else if (immlo == (immlo & 0x00ff0000))
7743 {
7744 *immbits = immlo >> 16;
7745 return 0x4;
7746 }
7747 else if (immlo == (immlo & 0xff000000))
7748 {
7749 *immbits = immlo >> 24;
7750 return 0x6;
7751 }
7752 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7753 {
7754 *immbits = (immlo >> 8) & 0xff;
7755 return 0xc;
7756 }
7757 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7758 {
7759 *immbits = (immlo >> 16) & 0xff;
7760 return 0xd;
7761 }
7762
7763 if ((immlo & 0xffff) != (immlo >> 16))
7764 return FAIL;
7765 immlo &= 0xffff;
09d92015 7766 }
a737bd4d 7767
8335d6aa 7768 if (size >= 16)
4962c51a 7769 {
8335d6aa
JW
7770 if (immlo == (immlo & 0x000000ff))
7771 {
7772 *immbits = immlo;
7773 return 0x8;
7774 }
7775 else if (immlo == (immlo & 0x0000ff00))
7776 {
7777 *immbits = immlo >> 8;
7778 return 0xa;
7779 }
7780
7781 if ((immlo & 0xff) != (immlo >> 8))
7782 return FAIL;
7783 immlo &= 0xff;
4962c51a
MS
7784 }
7785
8335d6aa
JW
7786 if (immlo == (immlo & 0x000000ff))
7787 {
7788 /* Don't allow MVN with 8-bit immediate. */
7789 if (*op == 1)
7790 return FAIL;
7791 *immbits = immlo;
7792 return 0xe;
7793 }
26d97720 7794
8335d6aa 7795 return FAIL;
c19d1205 7796}
a737bd4d 7797
5fc177c8 7798#if defined BFD_HOST_64_BIT
ba592044
AM
7799/* Returns TRUE if double precision value V may be cast
7800 to single precision without loss of accuracy. */
7801
7802static bfd_boolean
5fc177c8 7803is_double_a_single (bfd_int64_t v)
ba592044 7804{
5fc177c8 7805 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7806 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7807
7808 return (exp == 0 || exp == 0x7FF
7809 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7810 && (mantissa & 0x1FFFFFFFl) == 0;
7811}
7812
3739860c 7813/* Returns a double precision value casted to single precision
ba592044
AM
7814 (ignoring the least significant bits in exponent and mantissa). */
7815
7816static int
5fc177c8 7817double_to_single (bfd_int64_t v)
ba592044
AM
7818{
7819 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7820 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7821 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7822
7823 if (exp == 0x7FF)
7824 exp = 0xFF;
7825 else
7826 {
7827 exp = exp - 1023 + 127;
7828 if (exp >= 0xFF)
7829 {
7830 /* Infinity. */
7831 exp = 0x7F;
7832 mantissa = 0;
7833 }
7834 else if (exp < 0)
7835 {
7836 /* No denormalized numbers. */
7837 exp = 0;
7838 mantissa = 0;
7839 }
7840 }
7841 mantissa >>= 29;
7842 return (sign << 31) | (exp << 23) | mantissa;
7843}
5fc177c8 7844#endif /* BFD_HOST_64_BIT */
ba592044 7845
8335d6aa
JW
7846enum lit_type
7847{
7848 CONST_THUMB,
7849 CONST_ARM,
7850 CONST_VEC
7851};
7852
ba592044
AM
7853static void do_vfp_nsyn_opcode (const char *);
7854
c19d1205
ZW
7855/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7856 Determine whether it can be performed with a move instruction; if
7857 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7858 return TRUE; if it can't, convert inst.instruction to a literal-pool
7859 load and return FALSE. If this is not a valid thing to do in the
7860 current context, set inst.error and return TRUE.
a737bd4d 7861
c19d1205
ZW
7862 inst.operands[i] describes the destination register. */
7863
c921be7d 7864static bfd_boolean
8335d6aa 7865move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7866{
53365c0d 7867 unsigned long tbit;
8335d6aa
JW
7868 bfd_boolean thumb_p = (t == CONST_THUMB);
7869 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7870
7871 if (thumb_p)
7872 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7873 else
7874 tbit = LOAD_BIT;
7875
7876 if ((inst.instruction & tbit) == 0)
09d92015 7877 {
c19d1205 7878 inst.error = _("invalid pseudo operation");
c921be7d 7879 return TRUE;
09d92015 7880 }
ba592044 7881
8335d6aa
JW
7882 if (inst.reloc.exp.X_op != O_constant
7883 && inst.reloc.exp.X_op != O_symbol
7884 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7885 {
7886 inst.error = _("constant expression expected");
c921be7d 7887 return TRUE;
09d92015 7888 }
ba592044
AM
7889
7890 if (inst.reloc.exp.X_op == O_constant
7891 || inst.reloc.exp.X_op == O_big)
8335d6aa 7892 {
5fc177c8
NC
7893#if defined BFD_HOST_64_BIT
7894 bfd_int64_t v;
7895#else
ba592044 7896 offsetT v;
5fc177c8 7897#endif
ba592044 7898 if (inst.reloc.exp.X_op == O_big)
8335d6aa 7899 {
ba592044
AM
7900 LITTLENUM_TYPE w[X_PRECISION];
7901 LITTLENUM_TYPE * l;
7902
7903 if (inst.reloc.exp.X_add_number == -1)
8335d6aa 7904 {
ba592044
AM
7905 gen_to_words (w, X_PRECISION, E_PRECISION);
7906 l = w;
7907 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 7908 }
ba592044
AM
7909 else
7910 l = generic_bignum;
3739860c 7911
5fc177c8
NC
7912#if defined BFD_HOST_64_BIT
7913 v =
7914 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
7915 << LITTLENUM_NUMBER_OF_BITS)
7916 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
7917 << LITTLENUM_NUMBER_OF_BITS)
7918 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
7919 << LITTLENUM_NUMBER_OF_BITS)
7920 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
7921#else
ba592044
AM
7922 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
7923 | (l[0] & LITTLENUM_MASK);
5fc177c8 7924#endif
8335d6aa 7925 }
ba592044
AM
7926 else
7927 v = inst.reloc.exp.X_add_number;
7928
7929 if (!inst.operands[i].issingle)
8335d6aa 7930 {
12569877 7931 if (thumb_p)
8335d6aa 7932 {
2c32be70
CM
7933 /* This can be encoded only for a low register. */
7934 if ((v & ~0xFF) == 0 && (inst.operands[i].reg < 8))
ba592044
AM
7935 {
7936 /* This can be done with a mov(1) instruction. */
7937 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7938 inst.instruction |= v;
7939 return TRUE;
7940 }
12569877 7941
ff8646ee
TP
7942 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
7943 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
12569877 7944 {
fc289b0a
TP
7945 /* Check if on thumb2 it can be done with a mov.w, mvn or
7946 movw instruction. */
12569877
AM
7947 unsigned int newimm;
7948 bfd_boolean isNegated;
7949
7950 newimm = encode_thumb32_immediate (v);
7951 if (newimm != (unsigned int) FAIL)
7952 isNegated = FALSE;
7953 else
7954 {
582cfe03 7955 newimm = encode_thumb32_immediate (~v);
12569877
AM
7956 if (newimm != (unsigned int) FAIL)
7957 isNegated = TRUE;
7958 }
7959
fc289b0a
TP
7960 /* The number can be loaded with a mov.w or mvn
7961 instruction. */
ff8646ee
TP
7962 if (newimm != (unsigned int) FAIL
7963 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 7964 {
fc289b0a 7965 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 7966 | (inst.operands[i].reg << 8));
fc289b0a 7967 /* Change to MOVN. */
582cfe03 7968 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
7969 inst.instruction |= (newimm & 0x800) << 15;
7970 inst.instruction |= (newimm & 0x700) << 4;
7971 inst.instruction |= (newimm & 0x0ff);
7972 return TRUE;
7973 }
fc289b0a 7974 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
7975 else if ((v & ~0xFFFF) == 0
7976 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 7977 {
582cfe03 7978 int imm = v & 0xFFFF;
12569877 7979
582cfe03 7980 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
7981 inst.instruction |= (inst.operands[i].reg << 8);
7982 inst.instruction |= (imm & 0xf000) << 4;
7983 inst.instruction |= (imm & 0x0800) << 15;
7984 inst.instruction |= (imm & 0x0700) << 4;
7985 inst.instruction |= (imm & 0x00ff);
7986 return TRUE;
7987 }
7988 }
8335d6aa 7989 }
12569877 7990 else if (arm_p)
ba592044
AM
7991 {
7992 int value = encode_arm_immediate (v);
12569877 7993
ba592044
AM
7994 if (value != FAIL)
7995 {
7996 /* This can be done with a mov instruction. */
7997 inst.instruction &= LITERAL_MASK;
7998 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7999 inst.instruction |= value & 0xfff;
8000 return TRUE;
8001 }
8335d6aa 8002
ba592044
AM
8003 value = encode_arm_immediate (~ v);
8004 if (value != FAIL)
8005 {
8006 /* This can be done with a mvn instruction. */
8007 inst.instruction &= LITERAL_MASK;
8008 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8009 inst.instruction |= value & 0xfff;
8010 return TRUE;
8011 }
8012 }
934c2632 8013 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8014 {
ba592044
AM
8015 int op = 0;
8016 unsigned immbits = 0;
8017 unsigned immlo = inst.operands[1].imm;
8018 unsigned immhi = inst.operands[1].regisimm
8019 ? inst.operands[1].reg
8020 : inst.reloc.exp.X_unsigned
8021 ? 0
8022 : ((bfd_int64_t)((int) immlo)) >> 32;
8023 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8024 &op, 64, NT_invtype);
8025
8026 if (cmode == FAIL)
8027 {
8028 neon_invert_size (&immlo, &immhi, 64);
8029 op = !op;
8030 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8031 &op, 64, NT_invtype);
8032 }
8033
8034 if (cmode != FAIL)
8035 {
8036 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8037 | (1 << 23)
8038 | (cmode << 8)
8039 | (op << 5)
8040 | (1 << 4);
8041
8042 /* Fill other bits in vmov encoding for both thumb and arm. */
8043 if (thumb_mode)
eff0bc54 8044 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8045 else
eff0bc54 8046 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8047 neon_write_immbits (immbits);
8048 return TRUE;
8049 }
8335d6aa
JW
8050 }
8051 }
8335d6aa 8052
ba592044
AM
8053 if (t == CONST_VEC)
8054 {
8055 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8056 if (inst.operands[i].issingle
8057 && is_quarter_float (inst.operands[1].imm)
8058 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8059 {
ba592044
AM
8060 inst.operands[1].imm =
8061 neon_qfloat_bits (v);
8062 do_vfp_nsyn_opcode ("fconsts");
8063 return TRUE;
8335d6aa 8064 }
5fc177c8
NC
8065
8066 /* If our host does not support a 64-bit type then we cannot perform
8067 the following optimization. This mean that there will be a
8068 discrepancy between the output produced by an assembler built for
8069 a 32-bit-only host and the output produced from a 64-bit host, but
8070 this cannot be helped. */
8071#if defined BFD_HOST_64_BIT
ba592044
AM
8072 else if (!inst.operands[1].issingle
8073 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8074 {
ba592044
AM
8075 if (is_double_a_single (v)
8076 && is_quarter_float (double_to_single (v)))
8077 {
8078 inst.operands[1].imm =
8079 neon_qfloat_bits (double_to_single (v));
8080 do_vfp_nsyn_opcode ("fconstd");
8081 return TRUE;
8082 }
8335d6aa 8083 }
5fc177c8 8084#endif
8335d6aa
JW
8085 }
8086 }
8087
8088 if (add_to_lit_pool ((!inst.operands[i].isvec
8089 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8090 return TRUE;
8091
8092 inst.operands[1].reg = REG_PC;
8093 inst.operands[1].isreg = 1;
8094 inst.operands[1].preind = 1;
8095 inst.reloc.pc_rel = 1;
8096 inst.reloc.type = (thumb_p
8097 ? BFD_RELOC_ARM_THUMB_OFFSET
8098 : (mode_3
8099 ? BFD_RELOC_ARM_HWLITERAL
8100 : BFD_RELOC_ARM_LITERAL));
8101 return FALSE;
8102}
8103
8104/* inst.operands[i] was set up by parse_address. Encode it into an
8105 ARM-format instruction. Reject all forms which cannot be encoded
8106 into a coprocessor load/store instruction. If wb_ok is false,
8107 reject use of writeback; if unind_ok is false, reject use of
8108 unindexed addressing. If reloc_override is not 0, use it instead
8109 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8110 (in which case it is preserved). */
8111
8112static int
8113encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8114{
8115 if (!inst.operands[i].isreg)
8116 {
99b2a2dd
NC
8117 /* PR 18256 */
8118 if (! inst.operands[0].isvec)
8119 {
8120 inst.error = _("invalid co-processor operand");
8121 return FAIL;
8122 }
8335d6aa
JW
8123 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8124 return SUCCESS;
8125 }
8126
8127 inst.instruction |= inst.operands[i].reg << 16;
8128
8129 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8130
8131 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8132 {
8133 gas_assert (!inst.operands[i].writeback);
8134 if (!unind_ok)
8135 {
8136 inst.error = _("instruction does not support unindexed addressing");
8137 return FAIL;
8138 }
8139 inst.instruction |= inst.operands[i].imm;
8140 inst.instruction |= INDEX_UP;
8141 return SUCCESS;
8142 }
8143
8144 if (inst.operands[i].preind)
8145 inst.instruction |= PRE_INDEX;
8146
8147 if (inst.operands[i].writeback)
09d92015 8148 {
8335d6aa 8149 if (inst.operands[i].reg == REG_PC)
c19d1205 8150 {
8335d6aa
JW
8151 inst.error = _("pc may not be used with write-back");
8152 return FAIL;
c19d1205 8153 }
8335d6aa 8154 if (!wb_ok)
c19d1205 8155 {
8335d6aa
JW
8156 inst.error = _("instruction does not support writeback");
8157 return FAIL;
c19d1205 8158 }
8335d6aa 8159 inst.instruction |= WRITE_BACK;
09d92015
MM
8160 }
8161
8335d6aa
JW
8162 if (reloc_override)
8163 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8164 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8165 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8166 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8167 {
8335d6aa
JW
8168 if (thumb_mode)
8169 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8170 else
8171 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8172 }
8335d6aa
JW
8173
8174 /* Prefer + for zero encoded value. */
8175 if (!inst.operands[i].negative)
8176 inst.instruction |= INDEX_UP;
8177
8178 return SUCCESS;
09d92015
MM
8179}
8180
5f4273c7 8181/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8182 First some generics; their names are taken from the conventional
8183 bit positions for register arguments in ARM format instructions. */
09d92015 8184
a737bd4d 8185static void
c19d1205 8186do_noargs (void)
09d92015 8187{
c19d1205 8188}
a737bd4d 8189
c19d1205
ZW
8190static void
8191do_rd (void)
8192{
8193 inst.instruction |= inst.operands[0].reg << 12;
8194}
a737bd4d 8195
16a1fa25
TP
8196static void
8197do_rn (void)
8198{
8199 inst.instruction |= inst.operands[0].reg << 16;
8200}
8201
c19d1205
ZW
8202static void
8203do_rd_rm (void)
8204{
8205 inst.instruction |= inst.operands[0].reg << 12;
8206 inst.instruction |= inst.operands[1].reg;
8207}
09d92015 8208
9eb6c0f1
MGD
8209static void
8210do_rm_rn (void)
8211{
8212 inst.instruction |= inst.operands[0].reg;
8213 inst.instruction |= inst.operands[1].reg << 16;
8214}
8215
c19d1205
ZW
8216static void
8217do_rd_rn (void)
8218{
8219 inst.instruction |= inst.operands[0].reg << 12;
8220 inst.instruction |= inst.operands[1].reg << 16;
8221}
a737bd4d 8222
c19d1205
ZW
8223static void
8224do_rn_rd (void)
8225{
8226 inst.instruction |= inst.operands[0].reg << 16;
8227 inst.instruction |= inst.operands[1].reg << 12;
8228}
09d92015 8229
4ed7ed8d
TP
8230static void
8231do_tt (void)
8232{
8233 inst.instruction |= inst.operands[0].reg << 8;
8234 inst.instruction |= inst.operands[1].reg << 16;
8235}
8236
59d09be6
MGD
8237static bfd_boolean
8238check_obsolete (const arm_feature_set *feature, const char *msg)
8239{
8240 if (ARM_CPU_IS_ANY (cpu_variant))
8241 {
5c3696f8 8242 as_tsktsk ("%s", msg);
59d09be6
MGD
8243 return TRUE;
8244 }
8245 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8246 {
8247 as_bad ("%s", msg);
8248 return TRUE;
8249 }
8250
8251 return FALSE;
8252}
8253
c19d1205
ZW
8254static void
8255do_rd_rm_rn (void)
8256{
9a64e435 8257 unsigned Rn = inst.operands[2].reg;
708587a4 8258 /* Enforce restrictions on SWP instruction. */
9a64e435 8259 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8260 {
8261 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8262 _("Rn must not overlap other operands"));
8263
59d09be6
MGD
8264 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8265 */
8266 if (!check_obsolete (&arm_ext_v8,
8267 _("swp{b} use is obsoleted for ARMv8 and later"))
8268 && warn_on_deprecated
8269 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8270 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8271 }
59d09be6 8272
c19d1205
ZW
8273 inst.instruction |= inst.operands[0].reg << 12;
8274 inst.instruction |= inst.operands[1].reg;
9a64e435 8275 inst.instruction |= Rn << 16;
c19d1205 8276}
09d92015 8277
c19d1205
ZW
8278static void
8279do_rd_rn_rm (void)
8280{
8281 inst.instruction |= inst.operands[0].reg << 12;
8282 inst.instruction |= inst.operands[1].reg << 16;
8283 inst.instruction |= inst.operands[2].reg;
8284}
a737bd4d 8285
c19d1205
ZW
8286static void
8287do_rm_rd_rn (void)
8288{
5be8be5d
DG
8289 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8290 constraint (((inst.reloc.exp.X_op != O_constant
8291 && inst.reloc.exp.X_op != O_illegal)
8292 || inst.reloc.exp.X_add_number != 0),
8293 BAD_ADDR_MODE);
c19d1205
ZW
8294 inst.instruction |= inst.operands[0].reg;
8295 inst.instruction |= inst.operands[1].reg << 12;
8296 inst.instruction |= inst.operands[2].reg << 16;
8297}
09d92015 8298
c19d1205
ZW
8299static void
8300do_imm0 (void)
8301{
8302 inst.instruction |= inst.operands[0].imm;
8303}
09d92015 8304
c19d1205
ZW
8305static void
8306do_rd_cpaddr (void)
8307{
8308 inst.instruction |= inst.operands[0].reg << 12;
8309 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8310}
a737bd4d 8311
c19d1205
ZW
8312/* ARM instructions, in alphabetical order by function name (except
8313 that wrapper functions appear immediately after the function they
8314 wrap). */
09d92015 8315
c19d1205
ZW
8316/* This is a pseudo-op of the form "adr rd, label" to be converted
8317 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8318
8319static void
c19d1205 8320do_adr (void)
09d92015 8321{
c19d1205 8322 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8323
c19d1205
ZW
8324 /* Frag hacking will turn this into a sub instruction if the offset turns
8325 out to be negative. */
8326 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8327 inst.reloc.pc_rel = 1;
2fc8bdac 8328 inst.reloc.exp.X_add_number -= 8;
c19d1205 8329}
b99bd4ef 8330
c19d1205
ZW
8331/* This is a pseudo-op of the form "adrl rd, label" to be converted
8332 into a relative address of the form:
8333 add rd, pc, #low(label-.-8)"
8334 add rd, rd, #high(label-.-8)" */
b99bd4ef 8335
c19d1205
ZW
8336static void
8337do_adrl (void)
8338{
8339 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8340
c19d1205
ZW
8341 /* Frag hacking will turn this into a sub instruction if the offset turns
8342 out to be negative. */
8343 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8344 inst.reloc.pc_rel = 1;
8345 inst.size = INSN_SIZE * 2;
2fc8bdac 8346 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
8347}
8348
b99bd4ef 8349static void
c19d1205 8350do_arit (void)
b99bd4ef 8351{
a9f02af8
MG
8352 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8353 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
8354 THUMB1_RELOC_ONLY);
c19d1205
ZW
8355 if (!inst.operands[1].present)
8356 inst.operands[1].reg = inst.operands[0].reg;
8357 inst.instruction |= inst.operands[0].reg << 12;
8358 inst.instruction |= inst.operands[1].reg << 16;
8359 encode_arm_shifter_operand (2);
8360}
b99bd4ef 8361
62b3e311
PB
8362static void
8363do_barrier (void)
8364{
8365 if (inst.operands[0].present)
ccb84d65 8366 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8367 else
8368 inst.instruction |= 0xf;
8369}
8370
c19d1205
ZW
8371static void
8372do_bfc (void)
8373{
8374 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8375 constraint (msb > 32, _("bit-field extends past end of register"));
8376 /* The instruction encoding stores the LSB and MSB,
8377 not the LSB and width. */
8378 inst.instruction |= inst.operands[0].reg << 12;
8379 inst.instruction |= inst.operands[1].imm << 7;
8380 inst.instruction |= (msb - 1) << 16;
8381}
b99bd4ef 8382
c19d1205
ZW
8383static void
8384do_bfi (void)
8385{
8386 unsigned int msb;
b99bd4ef 8387
c19d1205
ZW
8388 /* #0 in second position is alternative syntax for bfc, which is
8389 the same instruction but with REG_PC in the Rm field. */
8390 if (!inst.operands[1].isreg)
8391 inst.operands[1].reg = REG_PC;
b99bd4ef 8392
c19d1205
ZW
8393 msb = inst.operands[2].imm + inst.operands[3].imm;
8394 constraint (msb > 32, _("bit-field extends past end of register"));
8395 /* The instruction encoding stores the LSB and MSB,
8396 not the LSB and width. */
8397 inst.instruction |= inst.operands[0].reg << 12;
8398 inst.instruction |= inst.operands[1].reg;
8399 inst.instruction |= inst.operands[2].imm << 7;
8400 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8401}
8402
b99bd4ef 8403static void
c19d1205 8404do_bfx (void)
b99bd4ef 8405{
c19d1205
ZW
8406 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8407 _("bit-field extends past end of register"));
8408 inst.instruction |= inst.operands[0].reg << 12;
8409 inst.instruction |= inst.operands[1].reg;
8410 inst.instruction |= inst.operands[2].imm << 7;
8411 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8412}
09d92015 8413
c19d1205
ZW
8414/* ARM V5 breakpoint instruction (argument parse)
8415 BKPT <16 bit unsigned immediate>
8416 Instruction is not conditional.
8417 The bit pattern given in insns[] has the COND_ALWAYS condition,
8418 and it is an error if the caller tried to override that. */
b99bd4ef 8419
c19d1205
ZW
8420static void
8421do_bkpt (void)
8422{
8423 /* Top 12 of 16 bits to bits 19:8. */
8424 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8425
c19d1205
ZW
8426 /* Bottom 4 of 16 bits to bits 3:0. */
8427 inst.instruction |= inst.operands[0].imm & 0xf;
8428}
09d92015 8429
c19d1205
ZW
8430static void
8431encode_branch (int default_reloc)
8432{
8433 if (inst.operands[0].hasreloc)
8434 {
0855e32b
NS
8435 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8436 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8437 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8438 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8439 ? BFD_RELOC_ARM_PLT32
8440 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8441 }
b99bd4ef 8442 else
9ae92b05 8443 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8444 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8445}
8446
b99bd4ef 8447static void
c19d1205 8448do_branch (void)
b99bd4ef 8449{
39b41c9c
PB
8450#ifdef OBJ_ELF
8451 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8452 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8453 else
8454#endif
8455 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8456}
8457
8458static void
8459do_bl (void)
8460{
8461#ifdef OBJ_ELF
8462 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8463 {
8464 if (inst.cond == COND_ALWAYS)
8465 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8466 else
8467 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8468 }
8469 else
8470#endif
8471 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8472}
b99bd4ef 8473
c19d1205
ZW
8474/* ARM V5 branch-link-exchange instruction (argument parse)
8475 BLX <target_addr> ie BLX(1)
8476 BLX{<condition>} <Rm> ie BLX(2)
8477 Unfortunately, there are two different opcodes for this mnemonic.
8478 So, the insns[].value is not used, and the code here zaps values
8479 into inst.instruction.
8480 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8481
c19d1205
ZW
8482static void
8483do_blx (void)
8484{
8485 if (inst.operands[0].isreg)
b99bd4ef 8486 {
c19d1205
ZW
8487 /* Arg is a register; the opcode provided by insns[] is correct.
8488 It is not illegal to do "blx pc", just useless. */
8489 if (inst.operands[0].reg == REG_PC)
8490 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8491
c19d1205
ZW
8492 inst.instruction |= inst.operands[0].reg;
8493 }
8494 else
b99bd4ef 8495 {
c19d1205 8496 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8497 conditionally, and the opcode must be adjusted.
8498 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8499 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8500 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8501 inst.instruction = 0xfa000000;
267bf995 8502 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8503 }
c19d1205
ZW
8504}
8505
8506static void
8507do_bx (void)
8508{
845b51d6
PB
8509 bfd_boolean want_reloc;
8510
c19d1205
ZW
8511 if (inst.operands[0].reg == REG_PC)
8512 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8513
c19d1205 8514 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8515 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8516 it is for ARMv4t or earlier. */
8517 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8518 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
8519 want_reloc = TRUE;
8520
5ad34203 8521#ifdef OBJ_ELF
845b51d6 8522 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8523#endif
584206db 8524 want_reloc = FALSE;
845b51d6
PB
8525
8526 if (want_reloc)
8527 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8528}
8529
c19d1205
ZW
8530
8531/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8532
8533static void
c19d1205 8534do_bxj (void)
a737bd4d 8535{
c19d1205
ZW
8536 if (inst.operands[0].reg == REG_PC)
8537 as_tsktsk (_("use of r15 in bxj is not really useful"));
8538
8539 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8540}
8541
c19d1205
ZW
8542/* Co-processor data operation:
8543 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8544 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8545static void
8546do_cdp (void)
8547{
8548 inst.instruction |= inst.operands[0].reg << 8;
8549 inst.instruction |= inst.operands[1].imm << 20;
8550 inst.instruction |= inst.operands[2].reg << 12;
8551 inst.instruction |= inst.operands[3].reg << 16;
8552 inst.instruction |= inst.operands[4].reg;
8553 inst.instruction |= inst.operands[5].imm << 5;
8554}
a737bd4d
NC
8555
8556static void
c19d1205 8557do_cmp (void)
a737bd4d 8558{
c19d1205
ZW
8559 inst.instruction |= inst.operands[0].reg << 16;
8560 encode_arm_shifter_operand (1);
a737bd4d
NC
8561}
8562
c19d1205
ZW
8563/* Transfer between coprocessor and ARM registers.
8564 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8565 MRC2
8566 MCR{cond}
8567 MCR2
8568
8569 No special properties. */
09d92015 8570
dcbd0d71
MGD
8571struct deprecated_coproc_regs_s
8572{
8573 unsigned cp;
8574 int opc1;
8575 unsigned crn;
8576 unsigned crm;
8577 int opc2;
8578 arm_feature_set deprecated;
8579 arm_feature_set obsoleted;
8580 const char *dep_msg;
8581 const char *obs_msg;
8582};
8583
8584#define DEPR_ACCESS_V8 \
8585 N_("This coprocessor register access is deprecated in ARMv8")
8586
8587/* Table of all deprecated coprocessor registers. */
8588static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8589{
8590 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8591 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8592 DEPR_ACCESS_V8, NULL},
8593 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8594 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8595 DEPR_ACCESS_V8, NULL},
8596 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8597 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8598 DEPR_ACCESS_V8, NULL},
8599 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8600 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8601 DEPR_ACCESS_V8, NULL},
8602 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8603 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8604 DEPR_ACCESS_V8, NULL},
8605};
8606
8607#undef DEPR_ACCESS_V8
8608
8609static const size_t deprecated_coproc_reg_count =
8610 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8611
09d92015 8612static void
c19d1205 8613do_co_reg (void)
09d92015 8614{
fdfde340 8615 unsigned Rd;
dcbd0d71 8616 size_t i;
fdfde340
JM
8617
8618 Rd = inst.operands[2].reg;
8619 if (thumb_mode)
8620 {
8621 if (inst.instruction == 0xee000010
8622 || inst.instruction == 0xfe000010)
8623 /* MCR, MCR2 */
8624 reject_bad_reg (Rd);
8625 else
8626 /* MRC, MRC2 */
8627 constraint (Rd == REG_SP, BAD_SP);
8628 }
8629 else
8630 {
8631 /* MCR */
8632 if (inst.instruction == 0xe000010)
8633 constraint (Rd == REG_PC, BAD_PC);
8634 }
8635
dcbd0d71
MGD
8636 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8637 {
8638 const struct deprecated_coproc_regs_s *r =
8639 deprecated_coproc_regs + i;
8640
8641 if (inst.operands[0].reg == r->cp
8642 && inst.operands[1].imm == r->opc1
8643 && inst.operands[3].reg == r->crn
8644 && inst.operands[4].reg == r->crm
8645 && inst.operands[5].imm == r->opc2)
8646 {
b10bf8c5 8647 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8648 && warn_on_deprecated
dcbd0d71 8649 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8650 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8651 }
8652 }
fdfde340 8653
c19d1205
ZW
8654 inst.instruction |= inst.operands[0].reg << 8;
8655 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8656 inst.instruction |= Rd << 12;
c19d1205
ZW
8657 inst.instruction |= inst.operands[3].reg << 16;
8658 inst.instruction |= inst.operands[4].reg;
8659 inst.instruction |= inst.operands[5].imm << 5;
8660}
09d92015 8661
c19d1205
ZW
8662/* Transfer between coprocessor register and pair of ARM registers.
8663 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8664 MCRR2
8665 MRRC{cond}
8666 MRRC2
b99bd4ef 8667
c19d1205 8668 Two XScale instructions are special cases of these:
09d92015 8669
c19d1205
ZW
8670 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8671 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8672
5f4273c7 8673 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8674
c19d1205
ZW
8675static void
8676do_co_reg2c (void)
8677{
fdfde340
JM
8678 unsigned Rd, Rn;
8679
8680 Rd = inst.operands[2].reg;
8681 Rn = inst.operands[3].reg;
8682
8683 if (thumb_mode)
8684 {
8685 reject_bad_reg (Rd);
8686 reject_bad_reg (Rn);
8687 }
8688 else
8689 {
8690 constraint (Rd == REG_PC, BAD_PC);
8691 constraint (Rn == REG_PC, BAD_PC);
8692 }
8693
c19d1205
ZW
8694 inst.instruction |= inst.operands[0].reg << 8;
8695 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8696 inst.instruction |= Rd << 12;
8697 inst.instruction |= Rn << 16;
c19d1205 8698 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8699}
8700
c19d1205
ZW
8701static void
8702do_cpsi (void)
8703{
8704 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8705 if (inst.operands[1].present)
8706 {
8707 inst.instruction |= CPSI_MMOD;
8708 inst.instruction |= inst.operands[1].imm;
8709 }
c19d1205 8710}
b99bd4ef 8711
62b3e311
PB
8712static void
8713do_dbg (void)
8714{
8715 inst.instruction |= inst.operands[0].imm;
8716}
8717
eea54501
MGD
8718static void
8719do_div (void)
8720{
8721 unsigned Rd, Rn, Rm;
8722
8723 Rd = inst.operands[0].reg;
8724 Rn = (inst.operands[1].present
8725 ? inst.operands[1].reg : Rd);
8726 Rm = inst.operands[2].reg;
8727
8728 constraint ((Rd == REG_PC), BAD_PC);
8729 constraint ((Rn == REG_PC), BAD_PC);
8730 constraint ((Rm == REG_PC), BAD_PC);
8731
8732 inst.instruction |= Rd << 16;
8733 inst.instruction |= Rn << 0;
8734 inst.instruction |= Rm << 8;
8735}
8736
b99bd4ef 8737static void
c19d1205 8738do_it (void)
b99bd4ef 8739{
c19d1205 8740 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8741 process it to do the validation as if in
8742 thumb mode, just in case the code gets
8743 assembled for thumb using the unified syntax. */
8744
c19d1205 8745 inst.size = 0;
e07e6e58
NC
8746 if (unified_syntax)
8747 {
8748 set_it_insn_type (IT_INSN);
8749 now_it.mask = (inst.instruction & 0xf) | 0x10;
8750 now_it.cc = inst.operands[0].imm;
8751 }
09d92015 8752}
b99bd4ef 8753
6530b175
NC
8754/* If there is only one register in the register list,
8755 then return its register number. Otherwise return -1. */
8756static int
8757only_one_reg_in_list (int range)
8758{
8759 int i = ffs (range) - 1;
8760 return (i > 15 || range != (1 << i)) ? -1 : i;
8761}
8762
09d92015 8763static void
6530b175 8764encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8765{
c19d1205
ZW
8766 int base_reg = inst.operands[0].reg;
8767 int range = inst.operands[1].imm;
6530b175 8768 int one_reg;
ea6ef066 8769
c19d1205
ZW
8770 inst.instruction |= base_reg << 16;
8771 inst.instruction |= range;
ea6ef066 8772
c19d1205
ZW
8773 if (inst.operands[1].writeback)
8774 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8775
c19d1205 8776 if (inst.operands[0].writeback)
ea6ef066 8777 {
c19d1205
ZW
8778 inst.instruction |= WRITE_BACK;
8779 /* Check for unpredictable uses of writeback. */
8780 if (inst.instruction & LOAD_BIT)
09d92015 8781 {
c19d1205
ZW
8782 /* Not allowed in LDM type 2. */
8783 if ((inst.instruction & LDM_TYPE_2_OR_3)
8784 && ((range & (1 << REG_PC)) == 0))
8785 as_warn (_("writeback of base register is UNPREDICTABLE"));
8786 /* Only allowed if base reg not in list for other types. */
8787 else if (range & (1 << base_reg))
8788 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8789 }
8790 else /* STM. */
8791 {
8792 /* Not allowed for type 2. */
8793 if (inst.instruction & LDM_TYPE_2_OR_3)
8794 as_warn (_("writeback of base register is UNPREDICTABLE"));
8795 /* Only allowed if base reg not in list, or first in list. */
8796 else if ((range & (1 << base_reg))
8797 && (range & ((1 << base_reg) - 1)))
8798 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8799 }
ea6ef066 8800 }
6530b175
NC
8801
8802 /* If PUSH/POP has only one register, then use the A2 encoding. */
8803 one_reg = only_one_reg_in_list (range);
8804 if (from_push_pop_mnem && one_reg >= 0)
8805 {
8806 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8807
8808 inst.instruction &= A_COND_MASK;
8809 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8810 inst.instruction |= one_reg << 12;
8811 }
8812}
8813
8814static void
8815do_ldmstm (void)
8816{
8817 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8818}
8819
c19d1205
ZW
8820/* ARMv5TE load-consecutive (argument parse)
8821 Mode is like LDRH.
8822
8823 LDRccD R, mode
8824 STRccD R, mode. */
8825
a737bd4d 8826static void
c19d1205 8827do_ldrd (void)
a737bd4d 8828{
c19d1205 8829 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8830 _("first transfer register must be even"));
c19d1205
ZW
8831 constraint (inst.operands[1].present
8832 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8833 _("can only transfer two consecutive registers"));
c19d1205
ZW
8834 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8835 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8836
c19d1205
ZW
8837 if (!inst.operands[1].present)
8838 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8839
c56791bb
RE
8840 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8841 register and the first register written; we have to diagnose
8842 overlap between the base and the second register written here. */
ea6ef066 8843
c56791bb
RE
8844 if (inst.operands[2].reg == inst.operands[1].reg
8845 && (inst.operands[2].writeback || inst.operands[2].postind))
8846 as_warn (_("base register written back, and overlaps "
8847 "second transfer register"));
b05fe5cf 8848
c56791bb
RE
8849 if (!(inst.instruction & V4_STR_BIT))
8850 {
c19d1205 8851 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8852 destination (even if not write-back). */
8853 if (inst.operands[2].immisreg
8854 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8855 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8856 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8857 }
c19d1205
ZW
8858 inst.instruction |= inst.operands[0].reg << 12;
8859 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8860}
8861
8862static void
c19d1205 8863do_ldrex (void)
b05fe5cf 8864{
c19d1205
ZW
8865 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8866 || inst.operands[1].postind || inst.operands[1].writeback
8867 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8868 || inst.operands[1].negative
8869 /* This can arise if the programmer has written
8870 strex rN, rM, foo
8871 or if they have mistakenly used a register name as the last
8872 operand, eg:
8873 strex rN, rM, rX
8874 It is very difficult to distinguish between these two cases
8875 because "rX" might actually be a label. ie the register
8876 name has been occluded by a symbol of the same name. So we
8877 just generate a general 'bad addressing mode' type error
8878 message and leave it up to the programmer to discover the
8879 true cause and fix their mistake. */
8880 || (inst.operands[1].reg == REG_PC),
8881 BAD_ADDR_MODE);
b05fe5cf 8882
c19d1205
ZW
8883 constraint (inst.reloc.exp.X_op != O_constant
8884 || inst.reloc.exp.X_add_number != 0,
8885 _("offset must be zero in ARM encoding"));
b05fe5cf 8886
5be8be5d
DG
8887 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8888
c19d1205
ZW
8889 inst.instruction |= inst.operands[0].reg << 12;
8890 inst.instruction |= inst.operands[1].reg << 16;
8891 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
8892}
8893
8894static void
c19d1205 8895do_ldrexd (void)
b05fe5cf 8896{
c19d1205
ZW
8897 constraint (inst.operands[0].reg % 2 != 0,
8898 _("even register required"));
8899 constraint (inst.operands[1].present
8900 && inst.operands[1].reg != inst.operands[0].reg + 1,
8901 _("can only load two consecutive registers"));
8902 /* If op 1 were present and equal to PC, this function wouldn't
8903 have been called in the first place. */
8904 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 8905
c19d1205
ZW
8906 inst.instruction |= inst.operands[0].reg << 12;
8907 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
8908}
8909
1be5fd2e
NC
8910/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8911 which is not a multiple of four is UNPREDICTABLE. */
8912static void
8913check_ldr_r15_aligned (void)
8914{
8915 constraint (!(inst.operands[1].immisreg)
8916 && (inst.operands[0].reg == REG_PC
8917 && inst.operands[1].reg == REG_PC
8918 && (inst.reloc.exp.X_add_number & 0x3)),
8919 _("ldr to register 15 must be 4-byte alligned"));
8920}
8921
b05fe5cf 8922static void
c19d1205 8923do_ldst (void)
b05fe5cf 8924{
c19d1205
ZW
8925 inst.instruction |= inst.operands[0].reg << 12;
8926 if (!inst.operands[1].isreg)
8335d6aa 8927 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 8928 return;
c19d1205 8929 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 8930 check_ldr_r15_aligned ();
b05fe5cf
ZW
8931}
8932
8933static void
c19d1205 8934do_ldstt (void)
b05fe5cf 8935{
c19d1205
ZW
8936 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8937 reject [Rn,...]. */
8938 if (inst.operands[1].preind)
b05fe5cf 8939 {
bd3ba5d1
NC
8940 constraint (inst.reloc.exp.X_op != O_constant
8941 || inst.reloc.exp.X_add_number != 0,
c19d1205 8942 _("this instruction requires a post-indexed address"));
b05fe5cf 8943
c19d1205
ZW
8944 inst.operands[1].preind = 0;
8945 inst.operands[1].postind = 1;
8946 inst.operands[1].writeback = 1;
b05fe5cf 8947 }
c19d1205
ZW
8948 inst.instruction |= inst.operands[0].reg << 12;
8949 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
8950}
b05fe5cf 8951
c19d1205 8952/* Halfword and signed-byte load/store operations. */
b05fe5cf 8953
c19d1205
ZW
8954static void
8955do_ldstv4 (void)
8956{
ff4a8d2b 8957 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
8958 inst.instruction |= inst.operands[0].reg << 12;
8959 if (!inst.operands[1].isreg)
8335d6aa 8960 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 8961 return;
c19d1205 8962 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
8963}
8964
8965static void
c19d1205 8966do_ldsttv4 (void)
b05fe5cf 8967{
c19d1205
ZW
8968 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8969 reject [Rn,...]. */
8970 if (inst.operands[1].preind)
b05fe5cf 8971 {
bd3ba5d1
NC
8972 constraint (inst.reloc.exp.X_op != O_constant
8973 || inst.reloc.exp.X_add_number != 0,
c19d1205 8974 _("this instruction requires a post-indexed address"));
b05fe5cf 8975
c19d1205
ZW
8976 inst.operands[1].preind = 0;
8977 inst.operands[1].postind = 1;
8978 inst.operands[1].writeback = 1;
b05fe5cf 8979 }
c19d1205
ZW
8980 inst.instruction |= inst.operands[0].reg << 12;
8981 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
8982}
b05fe5cf 8983
c19d1205
ZW
8984/* Co-processor register load/store.
8985 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
8986static void
8987do_lstc (void)
8988{
8989 inst.instruction |= inst.operands[0].reg << 8;
8990 inst.instruction |= inst.operands[1].reg << 12;
8991 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
8992}
8993
b05fe5cf 8994static void
c19d1205 8995do_mlas (void)
b05fe5cf 8996{
8fb9d7b9 8997 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 8998 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 8999 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9000 && !(inst.instruction & 0x00400000))
8fb9d7b9 9001 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9002
c19d1205
ZW
9003 inst.instruction |= inst.operands[0].reg << 16;
9004 inst.instruction |= inst.operands[1].reg;
9005 inst.instruction |= inst.operands[2].reg << 8;
9006 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9007}
b05fe5cf 9008
c19d1205
ZW
9009static void
9010do_mov (void)
9011{
a9f02af8
MG
9012 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9013 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9014 THUMB1_RELOC_ONLY);
c19d1205
ZW
9015 inst.instruction |= inst.operands[0].reg << 12;
9016 encode_arm_shifter_operand (1);
9017}
b05fe5cf 9018
c19d1205
ZW
9019/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9020static void
9021do_mov16 (void)
9022{
b6895b4f
PB
9023 bfd_vma imm;
9024 bfd_boolean top;
9025
9026 top = (inst.instruction & 0x00400000) != 0;
9027 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
9028 _(":lower16: not allowed this instruction"));
9029 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
9030 _(":upper16: not allowed instruction"));
c19d1205 9031 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
9032 if (inst.reloc.type == BFD_RELOC_UNUSED)
9033 {
9034 imm = inst.reloc.exp.X_add_number;
9035 /* The value is in two pieces: 0:11, 16:19. */
9036 inst.instruction |= (imm & 0x00000fff);
9037 inst.instruction |= (imm & 0x0000f000) << 4;
9038 }
b05fe5cf 9039}
b99bd4ef 9040
037e8744
JB
9041static int
9042do_vfp_nsyn_mrs (void)
9043{
9044 if (inst.operands[0].isvec)
9045 {
9046 if (inst.operands[1].reg != 1)
477330fc 9047 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9048 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9049 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9050 do_vfp_nsyn_opcode ("fmstat");
9051 }
9052 else if (inst.operands[1].isvec)
9053 do_vfp_nsyn_opcode ("fmrx");
9054 else
9055 return FAIL;
5f4273c7 9056
037e8744
JB
9057 return SUCCESS;
9058}
9059
9060static int
9061do_vfp_nsyn_msr (void)
9062{
9063 if (inst.operands[0].isvec)
9064 do_vfp_nsyn_opcode ("fmxr");
9065 else
9066 return FAIL;
9067
9068 return SUCCESS;
9069}
9070
f7c21dc7
NC
9071static void
9072do_vmrs (void)
9073{
9074 unsigned Rt = inst.operands[0].reg;
fa94de6b 9075
16d02dc9 9076 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9077 {
9078 inst.error = BAD_SP;
9079 return;
9080 }
9081
9082 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9083 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9084 {
9085 inst.error = BAD_PC;
9086 return;
9087 }
9088
16d02dc9
JB
9089 /* If we get through parsing the register name, we just insert the number
9090 generated into the instruction without further validation. */
9091 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9092 inst.instruction |= (Rt << 12);
9093}
9094
9095static void
9096do_vmsr (void)
9097{
9098 unsigned Rt = inst.operands[1].reg;
fa94de6b 9099
f7c21dc7
NC
9100 if (thumb_mode)
9101 reject_bad_reg (Rt);
9102 else if (Rt == REG_PC)
9103 {
9104 inst.error = BAD_PC;
9105 return;
9106 }
9107
16d02dc9
JB
9108 /* If we get through parsing the register name, we just insert the number
9109 generated into the instruction without further validation. */
9110 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9111 inst.instruction |= (Rt << 12);
9112}
9113
b99bd4ef 9114static void
c19d1205 9115do_mrs (void)
b99bd4ef 9116{
90ec0d68
MGD
9117 unsigned br;
9118
037e8744
JB
9119 if (do_vfp_nsyn_mrs () == SUCCESS)
9120 return;
9121
ff4a8d2b 9122 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9123 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9124
9125 if (inst.operands[1].isreg)
9126 {
9127 br = inst.operands[1].reg;
9128 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
9129 as_bad (_("bad register for mrs"));
9130 }
9131 else
9132 {
9133 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9134 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9135 != (PSR_c|PSR_f),
d2cd1205 9136 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9137 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9138 }
9139
9140 inst.instruction |= br;
c19d1205 9141}
b99bd4ef 9142
c19d1205
ZW
9143/* Two possible forms:
9144 "{C|S}PSR_<field>, Rm",
9145 "{C|S}PSR_f, #expression". */
b99bd4ef 9146
c19d1205
ZW
9147static void
9148do_msr (void)
9149{
037e8744
JB
9150 if (do_vfp_nsyn_msr () == SUCCESS)
9151 return;
9152
c19d1205
ZW
9153 inst.instruction |= inst.operands[0].imm;
9154 if (inst.operands[1].isreg)
9155 inst.instruction |= inst.operands[1].reg;
9156 else
b99bd4ef 9157 {
c19d1205
ZW
9158 inst.instruction |= INST_IMMEDIATE;
9159 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9160 inst.reloc.pc_rel = 0;
b99bd4ef 9161 }
b99bd4ef
NC
9162}
9163
c19d1205
ZW
9164static void
9165do_mul (void)
a737bd4d 9166{
ff4a8d2b
NC
9167 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9168
c19d1205
ZW
9169 if (!inst.operands[2].present)
9170 inst.operands[2].reg = inst.operands[0].reg;
9171 inst.instruction |= inst.operands[0].reg << 16;
9172 inst.instruction |= inst.operands[1].reg;
9173 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9174
8fb9d7b9
MS
9175 if (inst.operands[0].reg == inst.operands[1].reg
9176 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9177 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9178}
9179
c19d1205
ZW
9180/* Long Multiply Parser
9181 UMULL RdLo, RdHi, Rm, Rs
9182 SMULL RdLo, RdHi, Rm, Rs
9183 UMLAL RdLo, RdHi, Rm, Rs
9184 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9185
9186static void
c19d1205 9187do_mull (void)
b99bd4ef 9188{
c19d1205
ZW
9189 inst.instruction |= inst.operands[0].reg << 12;
9190 inst.instruction |= inst.operands[1].reg << 16;
9191 inst.instruction |= inst.operands[2].reg;
9192 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9193
682b27ad
PB
9194 /* rdhi and rdlo must be different. */
9195 if (inst.operands[0].reg == inst.operands[1].reg)
9196 as_tsktsk (_("rdhi and rdlo must be different"));
9197
9198 /* rdhi, rdlo and rm must all be different before armv6. */
9199 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9200 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9201 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9202 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9203}
b99bd4ef 9204
c19d1205
ZW
9205static void
9206do_nop (void)
9207{
e7495e45
NS
9208 if (inst.operands[0].present
9209 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9210 {
9211 /* Architectural NOP hints are CPSR sets with no bits selected. */
9212 inst.instruction &= 0xf0000000;
e7495e45
NS
9213 inst.instruction |= 0x0320f000;
9214 if (inst.operands[0].present)
9215 inst.instruction |= inst.operands[0].imm;
c19d1205 9216 }
b99bd4ef
NC
9217}
9218
c19d1205
ZW
9219/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9220 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9221 Condition defaults to COND_ALWAYS.
9222 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9223
9224static void
c19d1205 9225do_pkhbt (void)
b99bd4ef 9226{
c19d1205
ZW
9227 inst.instruction |= inst.operands[0].reg << 12;
9228 inst.instruction |= inst.operands[1].reg << 16;
9229 inst.instruction |= inst.operands[2].reg;
9230 if (inst.operands[3].present)
9231 encode_arm_shift (3);
9232}
b99bd4ef 9233
c19d1205 9234/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9235
c19d1205
ZW
9236static void
9237do_pkhtb (void)
9238{
9239 if (!inst.operands[3].present)
b99bd4ef 9240 {
c19d1205
ZW
9241 /* If the shift specifier is omitted, turn the instruction
9242 into pkhbt rd, rm, rn. */
9243 inst.instruction &= 0xfff00010;
9244 inst.instruction |= inst.operands[0].reg << 12;
9245 inst.instruction |= inst.operands[1].reg;
9246 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9247 }
9248 else
9249 {
c19d1205
ZW
9250 inst.instruction |= inst.operands[0].reg << 12;
9251 inst.instruction |= inst.operands[1].reg << 16;
9252 inst.instruction |= inst.operands[2].reg;
9253 encode_arm_shift (3);
b99bd4ef
NC
9254 }
9255}
9256
c19d1205 9257/* ARMv5TE: Preload-Cache
60e5ef9f 9258 MP Extensions: Preload for write
c19d1205 9259
60e5ef9f 9260 PLD(W) <addr_mode>
c19d1205
ZW
9261
9262 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9263
9264static void
c19d1205 9265do_pld (void)
b99bd4ef 9266{
c19d1205
ZW
9267 constraint (!inst.operands[0].isreg,
9268 _("'[' expected after PLD mnemonic"));
9269 constraint (inst.operands[0].postind,
9270 _("post-indexed expression used in preload instruction"));
9271 constraint (inst.operands[0].writeback,
9272 _("writeback used in preload instruction"));
9273 constraint (!inst.operands[0].preind,
9274 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9275 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9276}
b99bd4ef 9277
62b3e311
PB
9278/* ARMv7: PLI <addr_mode> */
9279static void
9280do_pli (void)
9281{
9282 constraint (!inst.operands[0].isreg,
9283 _("'[' expected after PLI mnemonic"));
9284 constraint (inst.operands[0].postind,
9285 _("post-indexed expression used in preload instruction"));
9286 constraint (inst.operands[0].writeback,
9287 _("writeback used in preload instruction"));
9288 constraint (!inst.operands[0].preind,
9289 _("unindexed addressing used in preload instruction"));
9290 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9291 inst.instruction &= ~PRE_INDEX;
9292}
9293
c19d1205
ZW
9294static void
9295do_push_pop (void)
9296{
5e0d7f77
MP
9297 constraint (inst.operands[0].writeback,
9298 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9299 inst.operands[1] = inst.operands[0];
9300 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9301 inst.operands[0].isreg = 1;
9302 inst.operands[0].writeback = 1;
9303 inst.operands[0].reg = REG_SP;
6530b175 9304 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9305}
b99bd4ef 9306
c19d1205
ZW
9307/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9308 word at the specified address and the following word
9309 respectively.
9310 Unconditionally executed.
9311 Error if Rn is R15. */
b99bd4ef 9312
c19d1205
ZW
9313static void
9314do_rfe (void)
9315{
9316 inst.instruction |= inst.operands[0].reg << 16;
9317 if (inst.operands[0].writeback)
9318 inst.instruction |= WRITE_BACK;
9319}
b99bd4ef 9320
c19d1205 9321/* ARM V6 ssat (argument parse). */
b99bd4ef 9322
c19d1205
ZW
9323static void
9324do_ssat (void)
9325{
9326 inst.instruction |= inst.operands[0].reg << 12;
9327 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9328 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9329
c19d1205
ZW
9330 if (inst.operands[3].present)
9331 encode_arm_shift (3);
b99bd4ef
NC
9332}
9333
c19d1205 9334/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9335
9336static void
c19d1205 9337do_usat (void)
b99bd4ef 9338{
c19d1205
ZW
9339 inst.instruction |= inst.operands[0].reg << 12;
9340 inst.instruction |= inst.operands[1].imm << 16;
9341 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9342
c19d1205
ZW
9343 if (inst.operands[3].present)
9344 encode_arm_shift (3);
b99bd4ef
NC
9345}
9346
c19d1205 9347/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9348
9349static void
c19d1205 9350do_ssat16 (void)
09d92015 9351{
c19d1205
ZW
9352 inst.instruction |= inst.operands[0].reg << 12;
9353 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9354 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9355}
9356
c19d1205
ZW
9357static void
9358do_usat16 (void)
a737bd4d 9359{
c19d1205
ZW
9360 inst.instruction |= inst.operands[0].reg << 12;
9361 inst.instruction |= inst.operands[1].imm << 16;
9362 inst.instruction |= inst.operands[2].reg;
9363}
a737bd4d 9364
c19d1205
ZW
9365/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9366 preserving the other bits.
a737bd4d 9367
c19d1205
ZW
9368 setend <endian_specifier>, where <endian_specifier> is either
9369 BE or LE. */
a737bd4d 9370
c19d1205
ZW
9371static void
9372do_setend (void)
9373{
12e37cbc
MGD
9374 if (warn_on_deprecated
9375 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9376 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9377
c19d1205
ZW
9378 if (inst.operands[0].imm)
9379 inst.instruction |= 0x200;
a737bd4d
NC
9380}
9381
9382static void
c19d1205 9383do_shift (void)
a737bd4d 9384{
c19d1205
ZW
9385 unsigned int Rm = (inst.operands[1].present
9386 ? inst.operands[1].reg
9387 : inst.operands[0].reg);
a737bd4d 9388
c19d1205
ZW
9389 inst.instruction |= inst.operands[0].reg << 12;
9390 inst.instruction |= Rm;
9391 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9392 {
c19d1205
ZW
9393 inst.instruction |= inst.operands[2].reg << 8;
9394 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9395 /* PR 12854: Error on extraneous shifts. */
9396 constraint (inst.operands[2].shifted,
9397 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9398 }
9399 else
c19d1205 9400 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9401}
9402
09d92015 9403static void
3eb17e6b 9404do_smc (void)
09d92015 9405{
3eb17e6b 9406 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9407 inst.reloc.pc_rel = 0;
09d92015
MM
9408}
9409
90ec0d68
MGD
9410static void
9411do_hvc (void)
9412{
9413 inst.reloc.type = BFD_RELOC_ARM_HVC;
9414 inst.reloc.pc_rel = 0;
9415}
9416
09d92015 9417static void
c19d1205 9418do_swi (void)
09d92015 9419{
c19d1205
ZW
9420 inst.reloc.type = BFD_RELOC_ARM_SWI;
9421 inst.reloc.pc_rel = 0;
09d92015
MM
9422}
9423
ddfded2f
MW
9424static void
9425do_setpan (void)
9426{
9427 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9428 _("selected processor does not support SETPAN instruction"));
9429
9430 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9431}
9432
9433static void
9434do_t_setpan (void)
9435{
9436 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9437 _("selected processor does not support SETPAN instruction"));
9438
9439 inst.instruction |= (inst.operands[0].imm << 3);
9440}
9441
c19d1205
ZW
9442/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9443 SMLAxy{cond} Rd,Rm,Rs,Rn
9444 SMLAWy{cond} Rd,Rm,Rs,Rn
9445 Error if any register is R15. */
e16bb312 9446
c19d1205
ZW
9447static void
9448do_smla (void)
e16bb312 9449{
c19d1205
ZW
9450 inst.instruction |= inst.operands[0].reg << 16;
9451 inst.instruction |= inst.operands[1].reg;
9452 inst.instruction |= inst.operands[2].reg << 8;
9453 inst.instruction |= inst.operands[3].reg << 12;
9454}
a737bd4d 9455
c19d1205
ZW
9456/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9457 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9458 Error if any register is R15.
9459 Warning if Rdlo == Rdhi. */
a737bd4d 9460
c19d1205
ZW
9461static void
9462do_smlal (void)
9463{
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].reg << 8;
a737bd4d 9468
c19d1205
ZW
9469 if (inst.operands[0].reg == inst.operands[1].reg)
9470 as_tsktsk (_("rdhi and rdlo must be different"));
9471}
a737bd4d 9472
c19d1205
ZW
9473/* ARM V5E (El Segundo) signed-multiply (argument parse)
9474 SMULxy{cond} Rd,Rm,Rs
9475 Error if any register is R15. */
a737bd4d 9476
c19d1205
ZW
9477static void
9478do_smul (void)
9479{
9480 inst.instruction |= inst.operands[0].reg << 16;
9481 inst.instruction |= inst.operands[1].reg;
9482 inst.instruction |= inst.operands[2].reg << 8;
9483}
a737bd4d 9484
b6702015
PB
9485/* ARM V6 srs (argument parse). The variable fields in the encoding are
9486 the same for both ARM and Thumb-2. */
a737bd4d 9487
c19d1205
ZW
9488static void
9489do_srs (void)
9490{
b6702015
PB
9491 int reg;
9492
9493 if (inst.operands[0].present)
9494 {
9495 reg = inst.operands[0].reg;
fdfde340 9496 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9497 }
9498 else
fdfde340 9499 reg = REG_SP;
b6702015
PB
9500
9501 inst.instruction |= reg << 16;
9502 inst.instruction |= inst.operands[1].imm;
9503 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9504 inst.instruction |= WRITE_BACK;
9505}
a737bd4d 9506
c19d1205 9507/* ARM V6 strex (argument parse). */
a737bd4d 9508
c19d1205
ZW
9509static void
9510do_strex (void)
9511{
9512 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9513 || inst.operands[2].postind || inst.operands[2].writeback
9514 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9515 || inst.operands[2].negative
9516 /* See comment in do_ldrex(). */
9517 || (inst.operands[2].reg == REG_PC),
9518 BAD_ADDR_MODE);
a737bd4d 9519
c19d1205
ZW
9520 constraint (inst.operands[0].reg == inst.operands[1].reg
9521 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9522
c19d1205
ZW
9523 constraint (inst.reloc.exp.X_op != O_constant
9524 || inst.reloc.exp.X_add_number != 0,
9525 _("offset must be zero in ARM encoding"));
a737bd4d 9526
c19d1205
ZW
9527 inst.instruction |= inst.operands[0].reg << 12;
9528 inst.instruction |= inst.operands[1].reg;
9529 inst.instruction |= inst.operands[2].reg << 16;
9530 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9531}
9532
877807f8
NC
9533static void
9534do_t_strexbh (void)
9535{
9536 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9537 || inst.operands[2].postind || inst.operands[2].writeback
9538 || inst.operands[2].immisreg || inst.operands[2].shifted
9539 || inst.operands[2].negative,
9540 BAD_ADDR_MODE);
9541
9542 constraint (inst.operands[0].reg == inst.operands[1].reg
9543 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9544
9545 do_rm_rd_rn ();
9546}
9547
e16bb312 9548static void
c19d1205 9549do_strexd (void)
e16bb312 9550{
c19d1205
ZW
9551 constraint (inst.operands[1].reg % 2 != 0,
9552 _("even register required"));
9553 constraint (inst.operands[2].present
9554 && inst.operands[2].reg != inst.operands[1].reg + 1,
9555 _("can only store two consecutive registers"));
9556 /* If op 2 were present and equal to PC, this function wouldn't
9557 have been called in the first place. */
9558 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9559
c19d1205
ZW
9560 constraint (inst.operands[0].reg == inst.operands[1].reg
9561 || inst.operands[0].reg == inst.operands[1].reg + 1
9562 || inst.operands[0].reg == inst.operands[3].reg,
9563 BAD_OVERLAP);
e16bb312 9564
c19d1205
ZW
9565 inst.instruction |= inst.operands[0].reg << 12;
9566 inst.instruction |= inst.operands[1].reg;
9567 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9568}
9569
9eb6c0f1
MGD
9570/* ARM V8 STRL. */
9571static void
4b8c8c02 9572do_stlex (void)
9eb6c0f1
MGD
9573{
9574 constraint (inst.operands[0].reg == inst.operands[1].reg
9575 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9576
9577 do_rd_rm_rn ();
9578}
9579
9580static void
4b8c8c02 9581do_t_stlex (void)
9eb6c0f1
MGD
9582{
9583 constraint (inst.operands[0].reg == inst.operands[1].reg
9584 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9585
9586 do_rm_rd_rn ();
9587}
9588
c19d1205
ZW
9589/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9590 extends it to 32-bits, and adds the result to a value in another
9591 register. You can specify a rotation by 0, 8, 16, or 24 bits
9592 before extracting the 16-bit value.
9593 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9594 Condition defaults to COND_ALWAYS.
9595 Error if any register uses R15. */
9596
e16bb312 9597static void
c19d1205 9598do_sxtah (void)
e16bb312 9599{
c19d1205
ZW
9600 inst.instruction |= inst.operands[0].reg << 12;
9601 inst.instruction |= inst.operands[1].reg << 16;
9602 inst.instruction |= inst.operands[2].reg;
9603 inst.instruction |= inst.operands[3].imm << 10;
9604}
e16bb312 9605
c19d1205 9606/* ARM V6 SXTH.
e16bb312 9607
c19d1205
ZW
9608 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9609 Condition defaults to COND_ALWAYS.
9610 Error if any register uses R15. */
e16bb312
NC
9611
9612static void
c19d1205 9613do_sxth (void)
e16bb312 9614{
c19d1205
ZW
9615 inst.instruction |= inst.operands[0].reg << 12;
9616 inst.instruction |= inst.operands[1].reg;
9617 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9618}
c19d1205
ZW
9619\f
9620/* VFP instructions. In a logical order: SP variant first, monad
9621 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9622
9623static void
c19d1205 9624do_vfp_sp_monadic (void)
e16bb312 9625{
5287ad62
JB
9626 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9627 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9628}
9629
9630static void
c19d1205 9631do_vfp_sp_dyadic (void)
e16bb312 9632{
5287ad62
JB
9633 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9634 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9635 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9636}
9637
9638static void
c19d1205 9639do_vfp_sp_compare_z (void)
e16bb312 9640{
5287ad62 9641 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9642}
9643
9644static void
c19d1205 9645do_vfp_dp_sp_cvt (void)
e16bb312 9646{
5287ad62
JB
9647 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9648 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9649}
9650
9651static void
c19d1205 9652do_vfp_sp_dp_cvt (void)
e16bb312 9653{
5287ad62
JB
9654 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9655 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9656}
9657
9658static void
c19d1205 9659do_vfp_reg_from_sp (void)
e16bb312 9660{
c19d1205 9661 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9662 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9663}
9664
9665static void
c19d1205 9666do_vfp_reg2_from_sp2 (void)
e16bb312 9667{
c19d1205
ZW
9668 constraint (inst.operands[2].imm != 2,
9669 _("only two consecutive VFP SP registers allowed here"));
9670 inst.instruction |= inst.operands[0].reg << 12;
9671 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9672 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9673}
9674
9675static void
c19d1205 9676do_vfp_sp_from_reg (void)
e16bb312 9677{
5287ad62 9678 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9679 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9680}
9681
9682static void
c19d1205 9683do_vfp_sp2_from_reg2 (void)
e16bb312 9684{
c19d1205
ZW
9685 constraint (inst.operands[0].imm != 2,
9686 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9687 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9688 inst.instruction |= inst.operands[1].reg << 12;
9689 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9690}
9691
9692static void
c19d1205 9693do_vfp_sp_ldst (void)
e16bb312 9694{
5287ad62 9695 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9696 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9697}
9698
9699static void
c19d1205 9700do_vfp_dp_ldst (void)
e16bb312 9701{
5287ad62 9702 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9703 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9704}
9705
c19d1205 9706
e16bb312 9707static void
c19d1205 9708vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9709{
c19d1205
ZW
9710 if (inst.operands[0].writeback)
9711 inst.instruction |= WRITE_BACK;
9712 else
9713 constraint (ldstm_type != VFP_LDSTMIA,
9714 _("this addressing mode requires base-register writeback"));
9715 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9716 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9717 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9718}
9719
9720static void
c19d1205 9721vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9722{
c19d1205 9723 int count;
e16bb312 9724
c19d1205
ZW
9725 if (inst.operands[0].writeback)
9726 inst.instruction |= WRITE_BACK;
9727 else
9728 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9729 _("this addressing mode requires base-register writeback"));
e16bb312 9730
c19d1205 9731 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9732 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9733
c19d1205
ZW
9734 count = inst.operands[1].imm << 1;
9735 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9736 count += 1;
e16bb312 9737
c19d1205 9738 inst.instruction |= count;
e16bb312
NC
9739}
9740
9741static void
c19d1205 9742do_vfp_sp_ldstmia (void)
e16bb312 9743{
c19d1205 9744 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9745}
9746
9747static void
c19d1205 9748do_vfp_sp_ldstmdb (void)
e16bb312 9749{
c19d1205 9750 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9751}
9752
9753static void
c19d1205 9754do_vfp_dp_ldstmia (void)
e16bb312 9755{
c19d1205 9756 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9757}
9758
9759static void
c19d1205 9760do_vfp_dp_ldstmdb (void)
e16bb312 9761{
c19d1205 9762 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9763}
9764
9765static void
c19d1205 9766do_vfp_xp_ldstmia (void)
e16bb312 9767{
c19d1205
ZW
9768 vfp_dp_ldstm (VFP_LDSTMIAX);
9769}
e16bb312 9770
c19d1205
ZW
9771static void
9772do_vfp_xp_ldstmdb (void)
9773{
9774 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9775}
5287ad62
JB
9776
9777static void
9778do_vfp_dp_rd_rm (void)
9779{
9780 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9781 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9782}
9783
9784static void
9785do_vfp_dp_rn_rd (void)
9786{
9787 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9788 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9789}
9790
9791static void
9792do_vfp_dp_rd_rn (void)
9793{
9794 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9795 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9796}
9797
9798static void
9799do_vfp_dp_rd_rn_rm (void)
9800{
9801 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9802 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9803 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9804}
9805
9806static void
9807do_vfp_dp_rd (void)
9808{
9809 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9810}
9811
9812static void
9813do_vfp_dp_rm_rd_rn (void)
9814{
9815 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9816 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9817 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9818}
9819
9820/* VFPv3 instructions. */
9821static void
9822do_vfp_sp_const (void)
9823{
9824 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9825 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9826 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9827}
9828
9829static void
9830do_vfp_dp_const (void)
9831{
9832 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9833 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9834 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9835}
9836
9837static void
9838vfp_conv (int srcsize)
9839{
5f1af56b
MGD
9840 int immbits = srcsize - inst.operands[1].imm;
9841
fa94de6b
RM
9842 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9843 {
5f1af56b 9844 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9845 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9846 inst.error = _("immediate value out of range, expected range [0, 16]");
9847 return;
9848 }
fa94de6b 9849 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9850 {
9851 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9852 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9853 inst.error = _("immediate value out of range, expected range [1, 32]");
9854 return;
9855 }
9856
5287ad62
JB
9857 inst.instruction |= (immbits & 1) << 5;
9858 inst.instruction |= (immbits >> 1);
9859}
9860
9861static void
9862do_vfp_sp_conv_16 (void)
9863{
9864 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9865 vfp_conv (16);
9866}
9867
9868static void
9869do_vfp_dp_conv_16 (void)
9870{
9871 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9872 vfp_conv (16);
9873}
9874
9875static void
9876do_vfp_sp_conv_32 (void)
9877{
9878 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9879 vfp_conv (32);
9880}
9881
9882static void
9883do_vfp_dp_conv_32 (void)
9884{
9885 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9886 vfp_conv (32);
9887}
c19d1205
ZW
9888\f
9889/* FPA instructions. Also in a logical order. */
e16bb312 9890
c19d1205
ZW
9891static void
9892do_fpa_cmp (void)
9893{
9894 inst.instruction |= inst.operands[0].reg << 16;
9895 inst.instruction |= inst.operands[1].reg;
9896}
b99bd4ef
NC
9897
9898static void
c19d1205 9899do_fpa_ldmstm (void)
b99bd4ef 9900{
c19d1205
ZW
9901 inst.instruction |= inst.operands[0].reg << 12;
9902 switch (inst.operands[1].imm)
9903 {
9904 case 1: inst.instruction |= CP_T_X; break;
9905 case 2: inst.instruction |= CP_T_Y; break;
9906 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9907 case 4: break;
9908 default: abort ();
9909 }
b99bd4ef 9910
c19d1205
ZW
9911 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9912 {
9913 /* The instruction specified "ea" or "fd", so we can only accept
9914 [Rn]{!}. The instruction does not really support stacking or
9915 unstacking, so we have to emulate these by setting appropriate
9916 bits and offsets. */
9917 constraint (inst.reloc.exp.X_op != O_constant
9918 || inst.reloc.exp.X_add_number != 0,
9919 _("this instruction does not support indexing"));
b99bd4ef 9920
c19d1205
ZW
9921 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9922 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 9923
c19d1205
ZW
9924 if (!(inst.instruction & INDEX_UP))
9925 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 9926
c19d1205
ZW
9927 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
9928 {
9929 inst.operands[2].preind = 0;
9930 inst.operands[2].postind = 1;
9931 }
9932 }
b99bd4ef 9933
c19d1205 9934 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 9935}
c19d1205
ZW
9936\f
9937/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 9938
c19d1205
ZW
9939static void
9940do_iwmmxt_tandorc (void)
9941{
9942 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
9943}
b99bd4ef 9944
c19d1205
ZW
9945static void
9946do_iwmmxt_textrc (void)
9947{
9948 inst.instruction |= inst.operands[0].reg << 12;
9949 inst.instruction |= inst.operands[1].imm;
9950}
b99bd4ef
NC
9951
9952static void
c19d1205 9953do_iwmmxt_textrm (void)
b99bd4ef 9954{
c19d1205
ZW
9955 inst.instruction |= inst.operands[0].reg << 12;
9956 inst.instruction |= inst.operands[1].reg << 16;
9957 inst.instruction |= inst.operands[2].imm;
9958}
b99bd4ef 9959
c19d1205
ZW
9960static void
9961do_iwmmxt_tinsr (void)
9962{
9963 inst.instruction |= inst.operands[0].reg << 16;
9964 inst.instruction |= inst.operands[1].reg << 12;
9965 inst.instruction |= inst.operands[2].imm;
9966}
b99bd4ef 9967
c19d1205
ZW
9968static void
9969do_iwmmxt_tmia (void)
9970{
9971 inst.instruction |= inst.operands[0].reg << 5;
9972 inst.instruction |= inst.operands[1].reg;
9973 inst.instruction |= inst.operands[2].reg << 12;
9974}
b99bd4ef 9975
c19d1205
ZW
9976static void
9977do_iwmmxt_waligni (void)
9978{
9979 inst.instruction |= inst.operands[0].reg << 12;
9980 inst.instruction |= inst.operands[1].reg << 16;
9981 inst.instruction |= inst.operands[2].reg;
9982 inst.instruction |= inst.operands[3].imm << 20;
9983}
b99bd4ef 9984
2d447fca
JM
9985static void
9986do_iwmmxt_wmerge (void)
9987{
9988 inst.instruction |= inst.operands[0].reg << 12;
9989 inst.instruction |= inst.operands[1].reg << 16;
9990 inst.instruction |= inst.operands[2].reg;
9991 inst.instruction |= inst.operands[3].imm << 21;
9992}
9993
c19d1205
ZW
9994static void
9995do_iwmmxt_wmov (void)
9996{
9997 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
9998 inst.instruction |= inst.operands[0].reg << 12;
9999 inst.instruction |= inst.operands[1].reg << 16;
10000 inst.instruction |= inst.operands[1].reg;
10001}
b99bd4ef 10002
c19d1205
ZW
10003static void
10004do_iwmmxt_wldstbh (void)
10005{
8f06b2d8 10006 int reloc;
c19d1205 10007 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
10008 if (thumb_mode)
10009 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10010 else
10011 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10012 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
10013}
10014
c19d1205
ZW
10015static void
10016do_iwmmxt_wldstw (void)
10017{
10018 /* RIWR_RIWC clears .isreg for a control register. */
10019 if (!inst.operands[0].isreg)
10020 {
10021 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10022 inst.instruction |= 0xf0000000;
10023 }
b99bd4ef 10024
c19d1205
ZW
10025 inst.instruction |= inst.operands[0].reg << 12;
10026 encode_arm_cp_address (1, TRUE, TRUE, 0);
10027}
b99bd4ef
NC
10028
10029static void
c19d1205 10030do_iwmmxt_wldstd (void)
b99bd4ef 10031{
c19d1205 10032 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
10033 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10034 && inst.operands[1].immisreg)
10035 {
10036 inst.instruction &= ~0x1a000ff;
eff0bc54 10037 inst.instruction |= (0xfU << 28);
2d447fca
JM
10038 if (inst.operands[1].preind)
10039 inst.instruction |= PRE_INDEX;
10040 if (!inst.operands[1].negative)
10041 inst.instruction |= INDEX_UP;
10042 if (inst.operands[1].writeback)
10043 inst.instruction |= WRITE_BACK;
10044 inst.instruction |= inst.operands[1].reg << 16;
10045 inst.instruction |= inst.reloc.exp.X_add_number << 4;
10046 inst.instruction |= inst.operands[1].imm;
10047 }
10048 else
10049 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10050}
b99bd4ef 10051
c19d1205
ZW
10052static void
10053do_iwmmxt_wshufh (void)
10054{
10055 inst.instruction |= inst.operands[0].reg << 12;
10056 inst.instruction |= inst.operands[1].reg << 16;
10057 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10058 inst.instruction |= (inst.operands[2].imm & 0x0f);
10059}
b99bd4ef 10060
c19d1205
ZW
10061static void
10062do_iwmmxt_wzero (void)
10063{
10064 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10065 inst.instruction |= inst.operands[0].reg;
10066 inst.instruction |= inst.operands[0].reg << 12;
10067 inst.instruction |= inst.operands[0].reg << 16;
10068}
2d447fca
JM
10069
10070static void
10071do_iwmmxt_wrwrwr_or_imm5 (void)
10072{
10073 if (inst.operands[2].isreg)
10074 do_rd_rn_rm ();
10075 else {
10076 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10077 _("immediate operand requires iWMMXt2"));
10078 do_rd_rn ();
10079 if (inst.operands[2].imm == 0)
10080 {
10081 switch ((inst.instruction >> 20) & 0xf)
10082 {
10083 case 4:
10084 case 5:
10085 case 6:
5f4273c7 10086 case 7:
2d447fca
JM
10087 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10088 inst.operands[2].imm = 16;
10089 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10090 break;
10091 case 8:
10092 case 9:
10093 case 10:
10094 case 11:
10095 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10096 inst.operands[2].imm = 32;
10097 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10098 break;
10099 case 12:
10100 case 13:
10101 case 14:
10102 case 15:
10103 {
10104 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10105 unsigned long wrn;
10106 wrn = (inst.instruction >> 16) & 0xf;
10107 inst.instruction &= 0xff0fff0f;
10108 inst.instruction |= wrn;
10109 /* Bail out here; the instruction is now assembled. */
10110 return;
10111 }
10112 }
10113 }
10114 /* Map 32 -> 0, etc. */
10115 inst.operands[2].imm &= 0x1f;
eff0bc54 10116 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10117 }
10118}
c19d1205
ZW
10119\f
10120/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10121 operations first, then control, shift, and load/store. */
b99bd4ef 10122
c19d1205 10123/* Insns like "foo X,Y,Z". */
b99bd4ef 10124
c19d1205
ZW
10125static void
10126do_mav_triple (void)
10127{
10128 inst.instruction |= inst.operands[0].reg << 16;
10129 inst.instruction |= inst.operands[1].reg;
10130 inst.instruction |= inst.operands[2].reg << 12;
10131}
b99bd4ef 10132
c19d1205
ZW
10133/* Insns like "foo W,X,Y,Z".
10134 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10135
c19d1205
ZW
10136static void
10137do_mav_quad (void)
10138{
10139 inst.instruction |= inst.operands[0].reg << 5;
10140 inst.instruction |= inst.operands[1].reg << 12;
10141 inst.instruction |= inst.operands[2].reg << 16;
10142 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10143}
10144
c19d1205
ZW
10145/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10146static void
10147do_mav_dspsc (void)
a737bd4d 10148{
c19d1205
ZW
10149 inst.instruction |= inst.operands[1].reg << 12;
10150}
a737bd4d 10151
c19d1205
ZW
10152/* Maverick shift immediate instructions.
10153 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10154 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10155
c19d1205
ZW
10156static void
10157do_mav_shift (void)
10158{
10159 int imm = inst.operands[2].imm;
a737bd4d 10160
c19d1205
ZW
10161 inst.instruction |= inst.operands[0].reg << 12;
10162 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10163
c19d1205
ZW
10164 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10165 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10166 Bit 4 should be 0. */
10167 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10168
c19d1205
ZW
10169 inst.instruction |= imm;
10170}
10171\f
10172/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10173
c19d1205
ZW
10174/* Xscale multiply-accumulate (argument parse)
10175 MIAcc acc0,Rm,Rs
10176 MIAPHcc acc0,Rm,Rs
10177 MIAxycc acc0,Rm,Rs. */
a737bd4d 10178
c19d1205
ZW
10179static void
10180do_xsc_mia (void)
10181{
10182 inst.instruction |= inst.operands[1].reg;
10183 inst.instruction |= inst.operands[2].reg << 12;
10184}
a737bd4d 10185
c19d1205 10186/* Xscale move-accumulator-register (argument parse)
a737bd4d 10187
c19d1205 10188 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10189
c19d1205
ZW
10190static void
10191do_xsc_mar (void)
10192{
10193 inst.instruction |= inst.operands[1].reg << 12;
10194 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10195}
10196
c19d1205 10197/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10198
c19d1205 10199 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10200
10201static void
c19d1205 10202do_xsc_mra (void)
b99bd4ef 10203{
c19d1205
ZW
10204 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10205 inst.instruction |= inst.operands[0].reg << 12;
10206 inst.instruction |= inst.operands[1].reg << 16;
10207}
10208\f
10209/* Encoding functions relevant only to Thumb. */
b99bd4ef 10210
c19d1205
ZW
10211/* inst.operands[i] is a shifted-register operand; encode
10212 it into inst.instruction in the format used by Thumb32. */
10213
10214static void
10215encode_thumb32_shifted_operand (int i)
10216{
10217 unsigned int value = inst.reloc.exp.X_add_number;
10218 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10219
9c3c69f2
PB
10220 constraint (inst.operands[i].immisreg,
10221 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10222 inst.instruction |= inst.operands[i].reg;
10223 if (shift == SHIFT_RRX)
10224 inst.instruction |= SHIFT_ROR << 4;
10225 else
b99bd4ef 10226 {
c19d1205
ZW
10227 constraint (inst.reloc.exp.X_op != O_constant,
10228 _("expression too complex"));
10229
10230 constraint (value > 32
10231 || (value == 32 && (shift == SHIFT_LSL
10232 || shift == SHIFT_ROR)),
10233 _("shift expression is too large"));
10234
10235 if (value == 0)
10236 shift = SHIFT_LSL;
10237 else if (value == 32)
10238 value = 0;
10239
10240 inst.instruction |= shift << 4;
10241 inst.instruction |= (value & 0x1c) << 10;
10242 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10243 }
c19d1205 10244}
b99bd4ef 10245
b99bd4ef 10246
c19d1205
ZW
10247/* inst.operands[i] was set up by parse_address. Encode it into a
10248 Thumb32 format load or store instruction. Reject forms that cannot
10249 be used with such instructions. If is_t is true, reject forms that
10250 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10251 that cannot be used with a D instruction. If it is a store insn,
10252 reject PC in Rn. */
b99bd4ef 10253
c19d1205
ZW
10254static void
10255encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10256{
5be8be5d 10257 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10258
10259 constraint (!inst.operands[i].isreg,
53365c0d 10260 _("Instruction does not support =N addresses"));
b99bd4ef 10261
c19d1205
ZW
10262 inst.instruction |= inst.operands[i].reg << 16;
10263 if (inst.operands[i].immisreg)
b99bd4ef 10264 {
5be8be5d 10265 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10266 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10267 constraint (inst.operands[i].negative,
10268 _("Thumb does not support negative register indexing"));
10269 constraint (inst.operands[i].postind,
10270 _("Thumb does not support register post-indexing"));
10271 constraint (inst.operands[i].writeback,
10272 _("Thumb does not support register indexing with writeback"));
10273 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10274 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10275
f40d1643 10276 inst.instruction |= inst.operands[i].imm;
c19d1205 10277 if (inst.operands[i].shifted)
b99bd4ef 10278 {
c19d1205
ZW
10279 constraint (inst.reloc.exp.X_op != O_constant,
10280 _("expression too complex"));
9c3c69f2
PB
10281 constraint (inst.reloc.exp.X_add_number < 0
10282 || inst.reloc.exp.X_add_number > 3,
c19d1205 10283 _("shift out of range"));
9c3c69f2 10284 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10285 }
10286 inst.reloc.type = BFD_RELOC_UNUSED;
10287 }
10288 else if (inst.operands[i].preind)
10289 {
5be8be5d 10290 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10291 constraint (is_t && inst.operands[i].writeback,
c19d1205 10292 _("cannot use writeback with this instruction"));
4755303e
WN
10293 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10294 BAD_PC_ADDRESSING);
c19d1205
ZW
10295
10296 if (is_d)
10297 {
10298 inst.instruction |= 0x01000000;
10299 if (inst.operands[i].writeback)
10300 inst.instruction |= 0x00200000;
b99bd4ef 10301 }
c19d1205 10302 else
b99bd4ef 10303 {
c19d1205
ZW
10304 inst.instruction |= 0x00000c00;
10305 if (inst.operands[i].writeback)
10306 inst.instruction |= 0x00000100;
b99bd4ef 10307 }
c19d1205 10308 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10309 }
c19d1205 10310 else if (inst.operands[i].postind)
b99bd4ef 10311 {
9c2799c2 10312 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10313 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10314 constraint (is_t, _("cannot use post-indexing with this instruction"));
10315
10316 if (is_d)
10317 inst.instruction |= 0x00200000;
10318 else
10319 inst.instruction |= 0x00000900;
10320 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10321 }
10322 else /* unindexed - only for coprocessor */
10323 inst.error = _("instruction does not accept unindexed addressing");
10324}
10325
10326/* Table of Thumb instructions which exist in both 16- and 32-bit
10327 encodings (the latter only in post-V6T2 cores). The index is the
10328 value used in the insns table below. When there is more than one
10329 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10330 holds variant (1).
10331 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10332#define T16_32_TAB \
21d799b5
NC
10333 X(_adc, 4140, eb400000), \
10334 X(_adcs, 4140, eb500000), \
10335 X(_add, 1c00, eb000000), \
10336 X(_adds, 1c00, eb100000), \
10337 X(_addi, 0000, f1000000), \
10338 X(_addis, 0000, f1100000), \
10339 X(_add_pc,000f, f20f0000), \
10340 X(_add_sp,000d, f10d0000), \
10341 X(_adr, 000f, f20f0000), \
10342 X(_and, 4000, ea000000), \
10343 X(_ands, 4000, ea100000), \
10344 X(_asr, 1000, fa40f000), \
10345 X(_asrs, 1000, fa50f000), \
10346 X(_b, e000, f000b000), \
10347 X(_bcond, d000, f0008000), \
10348 X(_bic, 4380, ea200000), \
10349 X(_bics, 4380, ea300000), \
10350 X(_cmn, 42c0, eb100f00), \
10351 X(_cmp, 2800, ebb00f00), \
10352 X(_cpsie, b660, f3af8400), \
10353 X(_cpsid, b670, f3af8600), \
10354 X(_cpy, 4600, ea4f0000), \
10355 X(_dec_sp,80dd, f1ad0d00), \
10356 X(_eor, 4040, ea800000), \
10357 X(_eors, 4040, ea900000), \
10358 X(_inc_sp,00dd, f10d0d00), \
10359 X(_ldmia, c800, e8900000), \
10360 X(_ldr, 6800, f8500000), \
10361 X(_ldrb, 7800, f8100000), \
10362 X(_ldrh, 8800, f8300000), \
10363 X(_ldrsb, 5600, f9100000), \
10364 X(_ldrsh, 5e00, f9300000), \
10365 X(_ldr_pc,4800, f85f0000), \
10366 X(_ldr_pc2,4800, f85f0000), \
10367 X(_ldr_sp,9800, f85d0000), \
10368 X(_lsl, 0000, fa00f000), \
10369 X(_lsls, 0000, fa10f000), \
10370 X(_lsr, 0800, fa20f000), \
10371 X(_lsrs, 0800, fa30f000), \
10372 X(_mov, 2000, ea4f0000), \
10373 X(_movs, 2000, ea5f0000), \
10374 X(_mul, 4340, fb00f000), \
10375 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10376 X(_mvn, 43c0, ea6f0000), \
10377 X(_mvns, 43c0, ea7f0000), \
10378 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10379 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10380 X(_orr, 4300, ea400000), \
10381 X(_orrs, 4300, ea500000), \
10382 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10383 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10384 X(_rev, ba00, fa90f080), \
10385 X(_rev16, ba40, fa90f090), \
10386 X(_revsh, bac0, fa90f0b0), \
10387 X(_ror, 41c0, fa60f000), \
10388 X(_rors, 41c0, fa70f000), \
10389 X(_sbc, 4180, eb600000), \
10390 X(_sbcs, 4180, eb700000), \
10391 X(_stmia, c000, e8800000), \
10392 X(_str, 6000, f8400000), \
10393 X(_strb, 7000, f8000000), \
10394 X(_strh, 8000, f8200000), \
10395 X(_str_sp,9000, f84d0000), \
10396 X(_sub, 1e00, eba00000), \
10397 X(_subs, 1e00, ebb00000), \
10398 X(_subi, 8000, f1a00000), \
10399 X(_subis, 8000, f1b00000), \
10400 X(_sxtb, b240, fa4ff080), \
10401 X(_sxth, b200, fa0ff080), \
10402 X(_tst, 4200, ea100f00), \
10403 X(_uxtb, b2c0, fa5ff080), \
10404 X(_uxth, b280, fa1ff080), \
10405 X(_nop, bf00, f3af8000), \
10406 X(_yield, bf10, f3af8001), \
10407 X(_wfe, bf20, f3af8002), \
10408 X(_wfi, bf30, f3af8003), \
53c4b28b 10409 X(_sev, bf40, f3af8004), \
74db7efb
NC
10410 X(_sevl, bf50, f3af8005), \
10411 X(_udf, de00, f7f0a000)
c19d1205
ZW
10412
10413/* To catch errors in encoding functions, the codes are all offset by
10414 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10415 as 16-bit instructions. */
21d799b5 10416#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10417enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10418#undef X
10419
10420#define X(a,b,c) 0x##b
10421static const unsigned short thumb_op16[] = { T16_32_TAB };
10422#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10423#undef X
10424
10425#define X(a,b,c) 0x##c
10426static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10427#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10428#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10429#undef X
10430#undef T16_32_TAB
10431
10432/* Thumb instruction encoders, in alphabetical order. */
10433
92e90b6e 10434/* ADDW or SUBW. */
c921be7d 10435
92e90b6e
PB
10436static void
10437do_t_add_sub_w (void)
10438{
10439 int Rd, Rn;
10440
10441 Rd = inst.operands[0].reg;
10442 Rn = inst.operands[1].reg;
10443
539d4391
NC
10444 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10445 is the SP-{plus,minus}-immediate form of the instruction. */
10446 if (Rn == REG_SP)
10447 constraint (Rd == REG_PC, BAD_PC);
10448 else
10449 reject_bad_reg (Rd);
fdfde340 10450
92e90b6e
PB
10451 inst.instruction |= (Rn << 16) | (Rd << 8);
10452 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10453}
10454
c19d1205
ZW
10455/* Parse an add or subtract instruction. We get here with inst.instruction
10456 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
10457
10458static void
10459do_t_add_sub (void)
10460{
10461 int Rd, Rs, Rn;
10462
10463 Rd = inst.operands[0].reg;
10464 Rs = (inst.operands[1].present
10465 ? inst.operands[1].reg /* Rd, Rs, foo */
10466 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10467
e07e6e58
NC
10468 if (Rd == REG_PC)
10469 set_it_insn_type_last ();
10470
c19d1205
ZW
10471 if (unified_syntax)
10472 {
0110f2b8
PB
10473 bfd_boolean flags;
10474 bfd_boolean narrow;
10475 int opcode;
10476
10477 flags = (inst.instruction == T_MNEM_adds
10478 || inst.instruction == T_MNEM_subs);
10479 if (flags)
e07e6e58 10480 narrow = !in_it_block ();
0110f2b8 10481 else
e07e6e58 10482 narrow = in_it_block ();
c19d1205 10483 if (!inst.operands[2].isreg)
b99bd4ef 10484 {
16805f35
PB
10485 int add;
10486
fdfde340
JM
10487 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10488
16805f35
PB
10489 add = (inst.instruction == T_MNEM_add
10490 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10491 opcode = 0;
10492 if (inst.size_req != 4)
10493 {
0110f2b8 10494 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10495 appropriate. */
0110f2b8
PB
10496 if (Rd == REG_SP && Rs == REG_SP && !flags)
10497 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10498 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10499 opcode = T_MNEM_add_sp;
10500 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10501 opcode = T_MNEM_add_pc;
10502 else if (Rd <= 7 && Rs <= 7 && narrow)
10503 {
10504 if (flags)
10505 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10506 else
10507 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10508 }
10509 if (opcode)
10510 {
10511 inst.instruction = THUMB_OP16(opcode);
10512 inst.instruction |= (Rd << 4) | Rs;
72d98d16
MG
10513 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10514 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
a9f02af8
MG
10515 {
10516 if (inst.size_req == 2)
10517 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10518 else
10519 inst.relax = opcode;
10520 }
0110f2b8
PB
10521 }
10522 else
10523 constraint (inst.size_req == 2, BAD_HIREG);
10524 }
10525 if (inst.size_req == 4
10526 || (inst.size_req != 2 && !opcode))
10527 {
a9f02af8
MG
10528 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10529 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
10530 THUMB1_RELOC_ONLY);
efd81785
PB
10531 if (Rd == REG_PC)
10532 {
fdfde340 10533 constraint (add, BAD_PC);
efd81785
PB
10534 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10535 _("only SUBS PC, LR, #const allowed"));
10536 constraint (inst.reloc.exp.X_op != O_constant,
10537 _("expression too complex"));
10538 constraint (inst.reloc.exp.X_add_number < 0
10539 || inst.reloc.exp.X_add_number > 0xff,
10540 _("immediate value out of range"));
10541 inst.instruction = T2_SUBS_PC_LR
10542 | inst.reloc.exp.X_add_number;
10543 inst.reloc.type = BFD_RELOC_UNUSED;
10544 return;
10545 }
10546 else if (Rs == REG_PC)
16805f35
PB
10547 {
10548 /* Always use addw/subw. */
10549 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10550 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10551 }
10552 else
10553 {
10554 inst.instruction = THUMB_OP32 (inst.instruction);
10555 inst.instruction = (inst.instruction & 0xe1ffffff)
10556 | 0x10000000;
10557 if (flags)
10558 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10559 else
10560 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10561 }
dc4503c6
PB
10562 inst.instruction |= Rd << 8;
10563 inst.instruction |= Rs << 16;
0110f2b8 10564 }
b99bd4ef 10565 }
c19d1205
ZW
10566 else
10567 {
5f4cb198
NC
10568 unsigned int value = inst.reloc.exp.X_add_number;
10569 unsigned int shift = inst.operands[2].shift_kind;
10570
c19d1205
ZW
10571 Rn = inst.operands[2].reg;
10572 /* See if we can do this with a 16-bit instruction. */
10573 if (!inst.operands[2].shifted && inst.size_req != 4)
10574 {
e27ec89e
PB
10575 if (Rd > 7 || Rs > 7 || Rn > 7)
10576 narrow = FALSE;
10577
10578 if (narrow)
c19d1205 10579 {
e27ec89e
PB
10580 inst.instruction = ((inst.instruction == T_MNEM_adds
10581 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10582 ? T_OPCODE_ADD_R3
10583 : T_OPCODE_SUB_R3);
10584 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10585 return;
10586 }
b99bd4ef 10587
7e806470 10588 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10589 {
7e806470
PB
10590 /* Thumb-1 cores (except v6-M) require at least one high
10591 register in a narrow non flag setting add. */
10592 if (Rd > 7 || Rn > 7
10593 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10594 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10595 {
7e806470
PB
10596 if (Rd == Rn)
10597 {
10598 Rn = Rs;
10599 Rs = Rd;
10600 }
c19d1205
ZW
10601 inst.instruction = T_OPCODE_ADD_HI;
10602 inst.instruction |= (Rd & 8) << 4;
10603 inst.instruction |= (Rd & 7);
10604 inst.instruction |= Rn << 3;
10605 return;
10606 }
c19d1205
ZW
10607 }
10608 }
c921be7d 10609
fdfde340
JM
10610 constraint (Rd == REG_PC, BAD_PC);
10611 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10612 constraint (Rs == REG_PC, BAD_PC);
10613 reject_bad_reg (Rn);
10614
c19d1205
ZW
10615 /* If we get here, it can't be done in 16 bits. */
10616 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10617 _("shift must be constant"));
10618 inst.instruction = THUMB_OP32 (inst.instruction);
10619 inst.instruction |= Rd << 8;
10620 inst.instruction |= Rs << 16;
5f4cb198
NC
10621 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10622 _("shift value over 3 not allowed in thumb mode"));
10623 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10624 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10625 encode_thumb32_shifted_operand (2);
10626 }
10627 }
10628 else
10629 {
10630 constraint (inst.instruction == T_MNEM_adds
10631 || inst.instruction == T_MNEM_subs,
10632 BAD_THUMB32);
b99bd4ef 10633
c19d1205 10634 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10635 {
c19d1205
ZW
10636 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10637 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10638 BAD_HIREG);
10639
10640 inst.instruction = (inst.instruction == T_MNEM_add
10641 ? 0x0000 : 0x8000);
10642 inst.instruction |= (Rd << 4) | Rs;
10643 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10644 return;
10645 }
10646
c19d1205
ZW
10647 Rn = inst.operands[2].reg;
10648 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10649
c19d1205
ZW
10650 /* We now have Rd, Rs, and Rn set to registers. */
10651 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10652 {
c19d1205
ZW
10653 /* Can't do this for SUB. */
10654 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10655 inst.instruction = T_OPCODE_ADD_HI;
10656 inst.instruction |= (Rd & 8) << 4;
10657 inst.instruction |= (Rd & 7);
10658 if (Rs == Rd)
10659 inst.instruction |= Rn << 3;
10660 else if (Rn == Rd)
10661 inst.instruction |= Rs << 3;
10662 else
10663 constraint (1, _("dest must overlap one source register"));
10664 }
10665 else
10666 {
10667 inst.instruction = (inst.instruction == T_MNEM_add
10668 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10669 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10670 }
b99bd4ef 10671 }
b99bd4ef
NC
10672}
10673
c19d1205
ZW
10674static void
10675do_t_adr (void)
10676{
fdfde340
JM
10677 unsigned Rd;
10678
10679 Rd = inst.operands[0].reg;
10680 reject_bad_reg (Rd);
10681
10682 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10683 {
10684 /* Defer to section relaxation. */
10685 inst.relax = inst.instruction;
10686 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10687 inst.instruction |= Rd << 4;
0110f2b8
PB
10688 }
10689 else if (unified_syntax && inst.size_req != 2)
e9f89963 10690 {
0110f2b8 10691 /* Generate a 32-bit opcode. */
e9f89963 10692 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10693 inst.instruction |= Rd << 8;
e9f89963
PB
10694 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10695 inst.reloc.pc_rel = 1;
10696 }
10697 else
10698 {
0110f2b8 10699 /* Generate a 16-bit opcode. */
e9f89963
PB
10700 inst.instruction = THUMB_OP16 (inst.instruction);
10701 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10702 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10703 inst.reloc.pc_rel = 1;
b99bd4ef 10704
fdfde340 10705 inst.instruction |= Rd << 4;
e9f89963 10706 }
c19d1205 10707}
b99bd4ef 10708
c19d1205
ZW
10709/* Arithmetic instructions for which there is just one 16-bit
10710 instruction encoding, and it allows only two low registers.
10711 For maximal compatibility with ARM syntax, we allow three register
10712 operands even when Thumb-32 instructions are not available, as long
10713 as the first two are identical. For instance, both "sbc r0,r1" and
10714 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10715static void
c19d1205 10716do_t_arit3 (void)
b99bd4ef 10717{
c19d1205 10718 int Rd, Rs, Rn;
b99bd4ef 10719
c19d1205
ZW
10720 Rd = inst.operands[0].reg;
10721 Rs = (inst.operands[1].present
10722 ? inst.operands[1].reg /* Rd, Rs, foo */
10723 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10724 Rn = inst.operands[2].reg;
b99bd4ef 10725
fdfde340
JM
10726 reject_bad_reg (Rd);
10727 reject_bad_reg (Rs);
10728 if (inst.operands[2].isreg)
10729 reject_bad_reg (Rn);
10730
c19d1205 10731 if (unified_syntax)
b99bd4ef 10732 {
c19d1205
ZW
10733 if (!inst.operands[2].isreg)
10734 {
10735 /* For an immediate, we always generate a 32-bit opcode;
10736 section relaxation will shrink it later if possible. */
10737 inst.instruction = THUMB_OP32 (inst.instruction);
10738 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10739 inst.instruction |= Rd << 8;
10740 inst.instruction |= Rs << 16;
10741 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10742 }
10743 else
10744 {
e27ec89e
PB
10745 bfd_boolean narrow;
10746
c19d1205 10747 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10748 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10749 narrow = !in_it_block ();
e27ec89e 10750 else
e07e6e58 10751 narrow = in_it_block ();
e27ec89e
PB
10752
10753 if (Rd > 7 || Rn > 7 || Rs > 7)
10754 narrow = FALSE;
10755 if (inst.operands[2].shifted)
10756 narrow = FALSE;
10757 if (inst.size_req == 4)
10758 narrow = FALSE;
10759
10760 if (narrow
c19d1205
ZW
10761 && Rd == Rs)
10762 {
10763 inst.instruction = THUMB_OP16 (inst.instruction);
10764 inst.instruction |= Rd;
10765 inst.instruction |= Rn << 3;
10766 return;
10767 }
b99bd4ef 10768
c19d1205
ZW
10769 /* If we get here, it can't be done in 16 bits. */
10770 constraint (inst.operands[2].shifted
10771 && inst.operands[2].immisreg,
10772 _("shift must be constant"));
10773 inst.instruction = THUMB_OP32 (inst.instruction);
10774 inst.instruction |= Rd << 8;
10775 inst.instruction |= Rs << 16;
10776 encode_thumb32_shifted_operand (2);
10777 }
a737bd4d 10778 }
c19d1205 10779 else
b99bd4ef 10780 {
c19d1205
ZW
10781 /* On its face this is a lie - the instruction does set the
10782 flags. However, the only supported mnemonic in this mode
10783 says it doesn't. */
10784 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10785
c19d1205
ZW
10786 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10787 _("unshifted register required"));
10788 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10789 constraint (Rd != Rs,
10790 _("dest and source1 must be the same register"));
a737bd4d 10791
c19d1205
ZW
10792 inst.instruction = THUMB_OP16 (inst.instruction);
10793 inst.instruction |= Rd;
10794 inst.instruction |= Rn << 3;
b99bd4ef 10795 }
a737bd4d 10796}
b99bd4ef 10797
c19d1205
ZW
10798/* Similarly, but for instructions where the arithmetic operation is
10799 commutative, so we can allow either of them to be different from
10800 the destination operand in a 16-bit instruction. For instance, all
10801 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10802 accepted. */
10803static void
10804do_t_arit3c (void)
a737bd4d 10805{
c19d1205 10806 int Rd, Rs, Rn;
b99bd4ef 10807
c19d1205
ZW
10808 Rd = inst.operands[0].reg;
10809 Rs = (inst.operands[1].present
10810 ? inst.operands[1].reg /* Rd, Rs, foo */
10811 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10812 Rn = inst.operands[2].reg;
c921be7d 10813
fdfde340
JM
10814 reject_bad_reg (Rd);
10815 reject_bad_reg (Rs);
10816 if (inst.operands[2].isreg)
10817 reject_bad_reg (Rn);
a737bd4d 10818
c19d1205 10819 if (unified_syntax)
a737bd4d 10820 {
c19d1205 10821 if (!inst.operands[2].isreg)
b99bd4ef 10822 {
c19d1205
ZW
10823 /* For an immediate, we always generate a 32-bit opcode;
10824 section relaxation will shrink it later if possible. */
10825 inst.instruction = THUMB_OP32 (inst.instruction);
10826 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10827 inst.instruction |= Rd << 8;
10828 inst.instruction |= Rs << 16;
10829 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10830 }
c19d1205 10831 else
a737bd4d 10832 {
e27ec89e
PB
10833 bfd_boolean narrow;
10834
c19d1205 10835 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10836 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10837 narrow = !in_it_block ();
e27ec89e 10838 else
e07e6e58 10839 narrow = in_it_block ();
e27ec89e
PB
10840
10841 if (Rd > 7 || Rn > 7 || Rs > 7)
10842 narrow = FALSE;
10843 if (inst.operands[2].shifted)
10844 narrow = FALSE;
10845 if (inst.size_req == 4)
10846 narrow = FALSE;
10847
10848 if (narrow)
a737bd4d 10849 {
c19d1205 10850 if (Rd == Rs)
a737bd4d 10851 {
c19d1205
ZW
10852 inst.instruction = THUMB_OP16 (inst.instruction);
10853 inst.instruction |= Rd;
10854 inst.instruction |= Rn << 3;
10855 return;
a737bd4d 10856 }
c19d1205 10857 if (Rd == Rn)
a737bd4d 10858 {
c19d1205
ZW
10859 inst.instruction = THUMB_OP16 (inst.instruction);
10860 inst.instruction |= Rd;
10861 inst.instruction |= Rs << 3;
10862 return;
a737bd4d
NC
10863 }
10864 }
c19d1205
ZW
10865
10866 /* If we get here, it can't be done in 16 bits. */
10867 constraint (inst.operands[2].shifted
10868 && inst.operands[2].immisreg,
10869 _("shift must be constant"));
10870 inst.instruction = THUMB_OP32 (inst.instruction);
10871 inst.instruction |= Rd << 8;
10872 inst.instruction |= Rs << 16;
10873 encode_thumb32_shifted_operand (2);
a737bd4d 10874 }
b99bd4ef 10875 }
c19d1205
ZW
10876 else
10877 {
10878 /* On its face this is a lie - the instruction does set the
10879 flags. However, the only supported mnemonic in this mode
10880 says it doesn't. */
10881 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10882
c19d1205
ZW
10883 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10884 _("unshifted register required"));
10885 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10886
10887 inst.instruction = THUMB_OP16 (inst.instruction);
10888 inst.instruction |= Rd;
10889
10890 if (Rd == Rs)
10891 inst.instruction |= Rn << 3;
10892 else if (Rd == Rn)
10893 inst.instruction |= Rs << 3;
10894 else
10895 constraint (1, _("dest must overlap one source register"));
10896 }
a737bd4d
NC
10897}
10898
c19d1205
ZW
10899static void
10900do_t_bfc (void)
a737bd4d 10901{
fdfde340 10902 unsigned Rd;
c19d1205
ZW
10903 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10904 constraint (msb > 32, _("bit-field extends past end of register"));
10905 /* The instruction encoding stores the LSB and MSB,
10906 not the LSB and width. */
fdfde340
JM
10907 Rd = inst.operands[0].reg;
10908 reject_bad_reg (Rd);
10909 inst.instruction |= Rd << 8;
c19d1205
ZW
10910 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10911 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10912 inst.instruction |= msb - 1;
b99bd4ef
NC
10913}
10914
c19d1205
ZW
10915static void
10916do_t_bfi (void)
b99bd4ef 10917{
fdfde340 10918 int Rd, Rn;
c19d1205 10919 unsigned int msb;
b99bd4ef 10920
fdfde340
JM
10921 Rd = inst.operands[0].reg;
10922 reject_bad_reg (Rd);
10923
c19d1205
ZW
10924 /* #0 in second position is alternative syntax for bfc, which is
10925 the same instruction but with REG_PC in the Rm field. */
10926 if (!inst.operands[1].isreg)
fdfde340
JM
10927 Rn = REG_PC;
10928 else
10929 {
10930 Rn = inst.operands[1].reg;
10931 reject_bad_reg (Rn);
10932 }
b99bd4ef 10933
c19d1205
ZW
10934 msb = inst.operands[2].imm + inst.operands[3].imm;
10935 constraint (msb > 32, _("bit-field extends past end of register"));
10936 /* The instruction encoding stores the LSB and MSB,
10937 not the LSB and width. */
fdfde340
JM
10938 inst.instruction |= Rd << 8;
10939 inst.instruction |= Rn << 16;
c19d1205
ZW
10940 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10941 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10942 inst.instruction |= msb - 1;
b99bd4ef
NC
10943}
10944
c19d1205
ZW
10945static void
10946do_t_bfx (void)
b99bd4ef 10947{
fdfde340
JM
10948 unsigned Rd, Rn;
10949
10950 Rd = inst.operands[0].reg;
10951 Rn = inst.operands[1].reg;
10952
10953 reject_bad_reg (Rd);
10954 reject_bad_reg (Rn);
10955
c19d1205
ZW
10956 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
10957 _("bit-field extends past end of register"));
fdfde340
JM
10958 inst.instruction |= Rd << 8;
10959 inst.instruction |= Rn << 16;
c19d1205
ZW
10960 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10961 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10962 inst.instruction |= inst.operands[3].imm - 1;
10963}
b99bd4ef 10964
c19d1205
ZW
10965/* ARM V5 Thumb BLX (argument parse)
10966 BLX <target_addr> which is BLX(1)
10967 BLX <Rm> which is BLX(2)
10968 Unfortunately, there are two different opcodes for this mnemonic.
10969 So, the insns[].value is not used, and the code here zaps values
10970 into inst.instruction.
b99bd4ef 10971
c19d1205
ZW
10972 ??? How to take advantage of the additional two bits of displacement
10973 available in Thumb32 mode? Need new relocation? */
b99bd4ef 10974
c19d1205
ZW
10975static void
10976do_t_blx (void)
10977{
e07e6e58
NC
10978 set_it_insn_type_last ();
10979
c19d1205 10980 if (inst.operands[0].isreg)
fdfde340
JM
10981 {
10982 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10983 /* We have a register, so this is BLX(2). */
10984 inst.instruction |= inst.operands[0].reg << 3;
10985 }
b99bd4ef
NC
10986 else
10987 {
c19d1205 10988 /* No register. This must be BLX(1). */
2fc8bdac 10989 inst.instruction = 0xf000e800;
0855e32b 10990 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
10991 }
10992}
10993
c19d1205
ZW
10994static void
10995do_t_branch (void)
b99bd4ef 10996{
0110f2b8 10997 int opcode;
dfa9f0d5 10998 int cond;
2fe88214 10999 bfd_reloc_code_real_type reloc;
dfa9f0d5 11000
e07e6e58
NC
11001 cond = inst.cond;
11002 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
11003
11004 if (in_it_block ())
dfa9f0d5
PB
11005 {
11006 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 11007 branches. */
dfa9f0d5 11008 cond = COND_ALWAYS;
dfa9f0d5
PB
11009 }
11010 else
11011 cond = inst.cond;
11012
11013 if (cond != COND_ALWAYS)
0110f2b8
PB
11014 opcode = T_MNEM_bcond;
11015 else
11016 opcode = inst.instruction;
11017
12d6b0b7
RS
11018 if (unified_syntax
11019 && (inst.size_req == 4
10960bfb
PB
11020 || (inst.size_req != 2
11021 && (inst.operands[0].hasreloc
11022 || inst.reloc.exp.X_op == O_constant))))
c19d1205 11023 {
0110f2b8 11024 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 11025 if (cond == COND_ALWAYS)
9ae92b05 11026 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
11027 else
11028 {
ff8646ee
TP
11029 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11030 _("selected architecture does not support "
11031 "wide conditional branch instruction"));
11032
9c2799c2 11033 gas_assert (cond != 0xF);
dfa9f0d5 11034 inst.instruction |= cond << 22;
9ae92b05 11035 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
11036 }
11037 }
b99bd4ef
NC
11038 else
11039 {
0110f2b8 11040 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 11041 if (cond == COND_ALWAYS)
9ae92b05 11042 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 11043 else
b99bd4ef 11044 {
dfa9f0d5 11045 inst.instruction |= cond << 8;
9ae92b05 11046 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 11047 }
0110f2b8
PB
11048 /* Allow section relaxation. */
11049 if (unified_syntax && inst.size_req != 2)
11050 inst.relax = opcode;
b99bd4ef 11051 }
9ae92b05 11052 inst.reloc.type = reloc;
c19d1205 11053 inst.reloc.pc_rel = 1;
b99bd4ef
NC
11054}
11055
8884b720 11056/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11057 between the two is the maximum immediate allowed - which is passed in
8884b720 11058 RANGE. */
b99bd4ef 11059static void
8884b720 11060do_t_bkpt_hlt1 (int range)
b99bd4ef 11061{
dfa9f0d5
PB
11062 constraint (inst.cond != COND_ALWAYS,
11063 _("instruction is always unconditional"));
c19d1205 11064 if (inst.operands[0].present)
b99bd4ef 11065 {
8884b720 11066 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11067 _("immediate value out of range"));
11068 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11069 }
8884b720
MGD
11070
11071 set_it_insn_type (NEUTRAL_IT_INSN);
11072}
11073
11074static void
11075do_t_hlt (void)
11076{
11077 do_t_bkpt_hlt1 (63);
11078}
11079
11080static void
11081do_t_bkpt (void)
11082{
11083 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11084}
11085
11086static void
c19d1205 11087do_t_branch23 (void)
b99bd4ef 11088{
e07e6e58 11089 set_it_insn_type_last ();
0855e32b 11090 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11091
0855e32b
NS
11092 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11093 this file. We used to simply ignore the PLT reloc type here --
11094 the branch encoding is now needed to deal with TLSCALL relocs.
11095 So if we see a PLT reloc now, put it back to how it used to be to
11096 keep the preexisting behaviour. */
11097 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
11098 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11099
4343666d 11100#if defined(OBJ_COFF)
c19d1205
ZW
11101 /* If the destination of the branch is a defined symbol which does not have
11102 the THUMB_FUNC attribute, then we must be calling a function which has
11103 the (interfacearm) attribute. We look for the Thumb entry point to that
11104 function and change the branch to refer to that function instead. */
11105 if ( inst.reloc.exp.X_op == O_symbol
11106 && inst.reloc.exp.X_add_symbol != NULL
11107 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
11108 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
11109 inst.reloc.exp.X_add_symbol =
11110 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 11111#endif
90e4755a
RE
11112}
11113
11114static void
c19d1205 11115do_t_bx (void)
90e4755a 11116{
e07e6e58 11117 set_it_insn_type_last ();
c19d1205
ZW
11118 inst.instruction |= inst.operands[0].reg << 3;
11119 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11120 should cause the alignment to be checked once it is known. This is
11121 because BX PC only works if the instruction is word aligned. */
11122}
90e4755a 11123
c19d1205
ZW
11124static void
11125do_t_bxj (void)
11126{
fdfde340 11127 int Rm;
90e4755a 11128
e07e6e58 11129 set_it_insn_type_last ();
fdfde340
JM
11130 Rm = inst.operands[0].reg;
11131 reject_bad_reg (Rm);
11132 inst.instruction |= Rm << 16;
90e4755a
RE
11133}
11134
11135static void
c19d1205 11136do_t_clz (void)
90e4755a 11137{
fdfde340
JM
11138 unsigned Rd;
11139 unsigned Rm;
11140
11141 Rd = inst.operands[0].reg;
11142 Rm = inst.operands[1].reg;
11143
11144 reject_bad_reg (Rd);
11145 reject_bad_reg (Rm);
11146
11147 inst.instruction |= Rd << 8;
11148 inst.instruction |= Rm << 16;
11149 inst.instruction |= Rm;
c19d1205 11150}
90e4755a 11151
dfa9f0d5
PB
11152static void
11153do_t_cps (void)
11154{
e07e6e58 11155 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11156 inst.instruction |= inst.operands[0].imm;
11157}
11158
c19d1205
ZW
11159static void
11160do_t_cpsi (void)
11161{
e07e6e58 11162 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11163 if (unified_syntax
62b3e311
PB
11164 && (inst.operands[1].present || inst.size_req == 4)
11165 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11166 {
c19d1205
ZW
11167 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11168 inst.instruction = 0xf3af8000;
11169 inst.instruction |= imod << 9;
11170 inst.instruction |= inst.operands[0].imm << 5;
11171 if (inst.operands[1].present)
11172 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11173 }
c19d1205 11174 else
90e4755a 11175 {
62b3e311
PB
11176 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11177 && (inst.operands[0].imm & 4),
11178 _("selected processor does not support 'A' form "
11179 "of this instruction"));
11180 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11181 _("Thumb does not support the 2-argument "
11182 "form of this instruction"));
11183 inst.instruction |= inst.operands[0].imm;
90e4755a 11184 }
90e4755a
RE
11185}
11186
c19d1205
ZW
11187/* THUMB CPY instruction (argument parse). */
11188
90e4755a 11189static void
c19d1205 11190do_t_cpy (void)
90e4755a 11191{
c19d1205 11192 if (inst.size_req == 4)
90e4755a 11193 {
c19d1205
ZW
11194 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11195 inst.instruction |= inst.operands[0].reg << 8;
11196 inst.instruction |= inst.operands[1].reg;
90e4755a 11197 }
c19d1205 11198 else
90e4755a 11199 {
c19d1205
ZW
11200 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11201 inst.instruction |= (inst.operands[0].reg & 0x7);
11202 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11203 }
90e4755a
RE
11204}
11205
90e4755a 11206static void
25fe350b 11207do_t_cbz (void)
90e4755a 11208{
e07e6e58 11209 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11210 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11211 inst.instruction |= inst.operands[0].reg;
11212 inst.reloc.pc_rel = 1;
11213 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11214}
90e4755a 11215
62b3e311
PB
11216static void
11217do_t_dbg (void)
11218{
11219 inst.instruction |= inst.operands[0].imm;
11220}
11221
11222static void
11223do_t_div (void)
11224{
fdfde340
JM
11225 unsigned Rd, Rn, Rm;
11226
11227 Rd = inst.operands[0].reg;
11228 Rn = (inst.operands[1].present
11229 ? inst.operands[1].reg : Rd);
11230 Rm = inst.operands[2].reg;
11231
11232 reject_bad_reg (Rd);
11233 reject_bad_reg (Rn);
11234 reject_bad_reg (Rm);
11235
11236 inst.instruction |= Rd << 8;
11237 inst.instruction |= Rn << 16;
11238 inst.instruction |= Rm;
62b3e311
PB
11239}
11240
c19d1205
ZW
11241static void
11242do_t_hint (void)
11243{
11244 if (unified_syntax && inst.size_req == 4)
11245 inst.instruction = THUMB_OP32 (inst.instruction);
11246 else
11247 inst.instruction = THUMB_OP16 (inst.instruction);
11248}
90e4755a 11249
c19d1205
ZW
11250static void
11251do_t_it (void)
11252{
11253 unsigned int cond = inst.operands[0].imm;
e27ec89e 11254
e07e6e58
NC
11255 set_it_insn_type (IT_INSN);
11256 now_it.mask = (inst.instruction & 0xf) | 0x10;
11257 now_it.cc = cond;
5a01bb1d 11258 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11259
11260 /* If the condition is a negative condition, invert the mask. */
c19d1205 11261 if ((cond & 0x1) == 0x0)
90e4755a 11262 {
c19d1205 11263 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11264
c19d1205 11265 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11266 {
11267 /* No conversion needed. */
11268 now_it.block_length = 1;
11269 }
c19d1205 11270 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11271 {
11272 mask ^= 0x8;
11273 now_it.block_length = 2;
11274 }
e27ec89e 11275 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11276 {
11277 mask ^= 0xC;
11278 now_it.block_length = 3;
11279 }
c19d1205 11280 else
5a01bb1d
MGD
11281 {
11282 mask ^= 0xE;
11283 now_it.block_length = 4;
11284 }
90e4755a 11285
e27ec89e
PB
11286 inst.instruction &= 0xfff0;
11287 inst.instruction |= mask;
c19d1205 11288 }
90e4755a 11289
c19d1205
ZW
11290 inst.instruction |= cond << 4;
11291}
90e4755a 11292
3c707909
PB
11293/* Helper function used for both push/pop and ldm/stm. */
11294static void
11295encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11296{
11297 bfd_boolean load;
11298
11299 load = (inst.instruction & (1 << 20)) != 0;
11300
11301 if (mask & (1 << 13))
11302 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11303
11304 if ((mask & (1 << base)) != 0
11305 && writeback)
11306 inst.error = _("having the base register in the register list when "
11307 "using write back is UNPREDICTABLE");
11308
3c707909
PB
11309 if (load)
11310 {
e07e6e58 11311 if (mask & (1 << 15))
477330fc
RM
11312 {
11313 if (mask & (1 << 14))
11314 inst.error = _("LR and PC should not both be in register list");
11315 else
11316 set_it_insn_type_last ();
11317 }
3c707909
PB
11318 }
11319 else
11320 {
11321 if (mask & (1 << 15))
11322 inst.error = _("PC not allowed in register list");
3c707909
PB
11323 }
11324
11325 if ((mask & (mask - 1)) == 0)
11326 {
11327 /* Single register transfers implemented as str/ldr. */
11328 if (writeback)
11329 {
11330 if (inst.instruction & (1 << 23))
11331 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11332 else
11333 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11334 }
11335 else
11336 {
11337 if (inst.instruction & (1 << 23))
11338 inst.instruction = 0x00800000; /* ia -> [base] */
11339 else
11340 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11341 }
11342
11343 inst.instruction |= 0xf8400000;
11344 if (load)
11345 inst.instruction |= 0x00100000;
11346
5f4273c7 11347 mask = ffs (mask) - 1;
3c707909
PB
11348 mask <<= 12;
11349 }
11350 else if (writeback)
11351 inst.instruction |= WRITE_BACK;
11352
11353 inst.instruction |= mask;
11354 inst.instruction |= base << 16;
11355}
11356
c19d1205
ZW
11357static void
11358do_t_ldmstm (void)
11359{
11360 /* This really doesn't seem worth it. */
11361 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11362 _("expression too complex"));
11363 constraint (inst.operands[1].writeback,
11364 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11365
c19d1205
ZW
11366 if (unified_syntax)
11367 {
3c707909
PB
11368 bfd_boolean narrow;
11369 unsigned mask;
11370
11371 narrow = FALSE;
c19d1205
ZW
11372 /* See if we can use a 16-bit instruction. */
11373 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11374 && inst.size_req != 4
3c707909 11375 && !(inst.operands[1].imm & ~0xff))
90e4755a 11376 {
3c707909 11377 mask = 1 << inst.operands[0].reg;
90e4755a 11378
eab4f823 11379 if (inst.operands[0].reg <= 7)
90e4755a 11380 {
3c707909 11381 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11382 ? inst.operands[0].writeback
11383 : (inst.operands[0].writeback
11384 == !(inst.operands[1].imm & mask)))
477330fc 11385 {
eab4f823
MGD
11386 if (inst.instruction == T_MNEM_stmia
11387 && (inst.operands[1].imm & mask)
11388 && (inst.operands[1].imm & (mask - 1)))
11389 as_warn (_("value stored for r%d is UNKNOWN"),
11390 inst.operands[0].reg);
3c707909 11391
eab4f823
MGD
11392 inst.instruction = THUMB_OP16 (inst.instruction);
11393 inst.instruction |= inst.operands[0].reg << 8;
11394 inst.instruction |= inst.operands[1].imm;
11395 narrow = TRUE;
11396 }
11397 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11398 {
11399 /* This means 1 register in reg list one of 3 situations:
11400 1. Instruction is stmia, but without writeback.
11401 2. lmdia without writeback, but with Rn not in
477330fc 11402 reglist.
eab4f823
MGD
11403 3. ldmia with writeback, but with Rn in reglist.
11404 Case 3 is UNPREDICTABLE behaviour, so we handle
11405 case 1 and 2 which can be converted into a 16-bit
11406 str or ldr. The SP cases are handled below. */
11407 unsigned long opcode;
11408 /* First, record an error for Case 3. */
11409 if (inst.operands[1].imm & mask
11410 && inst.operands[0].writeback)
fa94de6b 11411 inst.error =
eab4f823
MGD
11412 _("having the base register in the register list when "
11413 "using write back is UNPREDICTABLE");
fa94de6b
RM
11414
11415 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11416 : T_MNEM_ldr);
11417 inst.instruction = THUMB_OP16 (opcode);
11418 inst.instruction |= inst.operands[0].reg << 3;
11419 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11420 narrow = TRUE;
11421 }
90e4755a 11422 }
eab4f823 11423 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11424 {
eab4f823
MGD
11425 if (inst.operands[0].writeback)
11426 {
fa94de6b 11427 inst.instruction =
eab4f823 11428 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11429 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11430 inst.instruction |= inst.operands[1].imm;
477330fc 11431 narrow = TRUE;
eab4f823
MGD
11432 }
11433 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11434 {
fa94de6b 11435 inst.instruction =
eab4f823 11436 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11437 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11438 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11439 narrow = TRUE;
eab4f823 11440 }
90e4755a 11441 }
3c707909
PB
11442 }
11443
11444 if (!narrow)
11445 {
c19d1205
ZW
11446 if (inst.instruction < 0xffff)
11447 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11448
5f4273c7
NC
11449 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11450 inst.operands[0].writeback);
90e4755a
RE
11451 }
11452 }
c19d1205 11453 else
90e4755a 11454 {
c19d1205
ZW
11455 constraint (inst.operands[0].reg > 7
11456 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11457 constraint (inst.instruction != T_MNEM_ldmia
11458 && inst.instruction != T_MNEM_stmia,
11459 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11460 if (inst.instruction == T_MNEM_stmia)
f03698e6 11461 {
c19d1205
ZW
11462 if (!inst.operands[0].writeback)
11463 as_warn (_("this instruction will write back the base register"));
11464 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11465 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11466 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11467 inst.operands[0].reg);
f03698e6 11468 }
c19d1205 11469 else
90e4755a 11470 {
c19d1205
ZW
11471 if (!inst.operands[0].writeback
11472 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11473 as_warn (_("this instruction will write back the base register"));
11474 else if (inst.operands[0].writeback
11475 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11476 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11477 }
11478
c19d1205
ZW
11479 inst.instruction = THUMB_OP16 (inst.instruction);
11480 inst.instruction |= inst.operands[0].reg << 8;
11481 inst.instruction |= inst.operands[1].imm;
11482 }
11483}
e28cd48c 11484
c19d1205
ZW
11485static void
11486do_t_ldrex (void)
11487{
11488 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11489 || inst.operands[1].postind || inst.operands[1].writeback
11490 || inst.operands[1].immisreg || inst.operands[1].shifted
11491 || inst.operands[1].negative,
01cfc07f 11492 BAD_ADDR_MODE);
e28cd48c 11493
5be8be5d
DG
11494 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11495
c19d1205
ZW
11496 inst.instruction |= inst.operands[0].reg << 12;
11497 inst.instruction |= inst.operands[1].reg << 16;
11498 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11499}
e28cd48c 11500
c19d1205
ZW
11501static void
11502do_t_ldrexd (void)
11503{
11504 if (!inst.operands[1].present)
1cac9012 11505 {
c19d1205
ZW
11506 constraint (inst.operands[0].reg == REG_LR,
11507 _("r14 not allowed as first register "
11508 "when second register is omitted"));
11509 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11510 }
c19d1205
ZW
11511 constraint (inst.operands[0].reg == inst.operands[1].reg,
11512 BAD_OVERLAP);
b99bd4ef 11513
c19d1205
ZW
11514 inst.instruction |= inst.operands[0].reg << 12;
11515 inst.instruction |= inst.operands[1].reg << 8;
11516 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11517}
11518
11519static void
c19d1205 11520do_t_ldst (void)
b99bd4ef 11521{
0110f2b8
PB
11522 unsigned long opcode;
11523 int Rn;
11524
e07e6e58
NC
11525 if (inst.operands[0].isreg
11526 && !inst.operands[0].preind
11527 && inst.operands[0].reg == REG_PC)
11528 set_it_insn_type_last ();
11529
0110f2b8 11530 opcode = inst.instruction;
c19d1205 11531 if (unified_syntax)
b99bd4ef 11532 {
53365c0d
PB
11533 if (!inst.operands[1].isreg)
11534 {
11535 if (opcode <= 0xffff)
11536 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11537 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11538 return;
11539 }
0110f2b8
PB
11540 if (inst.operands[1].isreg
11541 && !inst.operands[1].writeback
c19d1205
ZW
11542 && !inst.operands[1].shifted && !inst.operands[1].postind
11543 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11544 && opcode <= 0xffff
11545 && inst.size_req != 4)
c19d1205 11546 {
0110f2b8
PB
11547 /* Insn may have a 16-bit form. */
11548 Rn = inst.operands[1].reg;
11549 if (inst.operands[1].immisreg)
11550 {
11551 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11552 /* [Rn, Rik] */
0110f2b8
PB
11553 if (Rn <= 7 && inst.operands[1].imm <= 7)
11554 goto op16;
5be8be5d
DG
11555 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11556 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11557 }
11558 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11559 && opcode != T_MNEM_ldrsb)
11560 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11561 || (Rn == REG_SP && opcode == T_MNEM_str))
11562 {
11563 /* [Rn, #const] */
11564 if (Rn > 7)
11565 {
11566 if (Rn == REG_PC)
11567 {
11568 if (inst.reloc.pc_rel)
11569 opcode = T_MNEM_ldr_pc2;
11570 else
11571 opcode = T_MNEM_ldr_pc;
11572 }
11573 else
11574 {
11575 if (opcode == T_MNEM_ldr)
11576 opcode = T_MNEM_ldr_sp;
11577 else
11578 opcode = T_MNEM_str_sp;
11579 }
11580 inst.instruction = inst.operands[0].reg << 8;
11581 }
11582 else
11583 {
11584 inst.instruction = inst.operands[0].reg;
11585 inst.instruction |= inst.operands[1].reg << 3;
11586 }
11587 inst.instruction |= THUMB_OP16 (opcode);
11588 if (inst.size_req == 2)
11589 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11590 else
11591 inst.relax = opcode;
11592 return;
11593 }
c19d1205 11594 }
0110f2b8 11595 /* Definitely a 32-bit variant. */
5be8be5d 11596
8d67f500
NC
11597 /* Warning for Erratum 752419. */
11598 if (opcode == T_MNEM_ldr
11599 && inst.operands[0].reg == REG_SP
11600 && inst.operands[1].writeback == 1
11601 && !inst.operands[1].immisreg)
11602 {
11603 if (no_cpu_selected ()
11604 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11605 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11606 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11607 as_warn (_("This instruction may be unpredictable "
11608 "if executed on M-profile cores "
11609 "with interrupts enabled."));
11610 }
11611
5be8be5d 11612 /* Do some validations regarding addressing modes. */
1be5fd2e 11613 if (inst.operands[1].immisreg)
5be8be5d
DG
11614 reject_bad_reg (inst.operands[1].imm);
11615
1be5fd2e
NC
11616 constraint (inst.operands[1].writeback == 1
11617 && inst.operands[0].reg == inst.operands[1].reg,
11618 BAD_OVERLAP);
11619
0110f2b8 11620 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11621 inst.instruction |= inst.operands[0].reg << 12;
11622 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11623 check_ldr_r15_aligned ();
b99bd4ef
NC
11624 return;
11625 }
11626
c19d1205
ZW
11627 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11628
11629 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11630 {
c19d1205
ZW
11631 /* Only [Rn,Rm] is acceptable. */
11632 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11633 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11634 || inst.operands[1].postind || inst.operands[1].shifted
11635 || inst.operands[1].negative,
11636 _("Thumb does not support this addressing mode"));
11637 inst.instruction = THUMB_OP16 (inst.instruction);
11638 goto op16;
b99bd4ef 11639 }
5f4273c7 11640
c19d1205
ZW
11641 inst.instruction = THUMB_OP16 (inst.instruction);
11642 if (!inst.operands[1].isreg)
8335d6aa 11643 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11644 return;
b99bd4ef 11645
c19d1205
ZW
11646 constraint (!inst.operands[1].preind
11647 || inst.operands[1].shifted
11648 || inst.operands[1].writeback,
11649 _("Thumb does not support this addressing mode"));
11650 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11651 {
c19d1205
ZW
11652 constraint (inst.instruction & 0x0600,
11653 _("byte or halfword not valid for base register"));
11654 constraint (inst.operands[1].reg == REG_PC
11655 && !(inst.instruction & THUMB_LOAD_BIT),
11656 _("r15 based store not allowed"));
11657 constraint (inst.operands[1].immisreg,
11658 _("invalid base register for register offset"));
b99bd4ef 11659
c19d1205
ZW
11660 if (inst.operands[1].reg == REG_PC)
11661 inst.instruction = T_OPCODE_LDR_PC;
11662 else if (inst.instruction & THUMB_LOAD_BIT)
11663 inst.instruction = T_OPCODE_LDR_SP;
11664 else
11665 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11666
c19d1205
ZW
11667 inst.instruction |= inst.operands[0].reg << 8;
11668 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11669 return;
11670 }
90e4755a 11671
c19d1205
ZW
11672 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11673 if (!inst.operands[1].immisreg)
11674 {
11675 /* Immediate offset. */
11676 inst.instruction |= inst.operands[0].reg;
11677 inst.instruction |= inst.operands[1].reg << 3;
11678 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11679 return;
11680 }
90e4755a 11681
c19d1205
ZW
11682 /* Register offset. */
11683 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11684 constraint (inst.operands[1].negative,
11685 _("Thumb does not support this addressing mode"));
90e4755a 11686
c19d1205
ZW
11687 op16:
11688 switch (inst.instruction)
11689 {
11690 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11691 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11692 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11693 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11694 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11695 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11696 case 0x5600 /* ldrsb */:
11697 case 0x5e00 /* ldrsh */: break;
11698 default: abort ();
11699 }
90e4755a 11700
c19d1205
ZW
11701 inst.instruction |= inst.operands[0].reg;
11702 inst.instruction |= inst.operands[1].reg << 3;
11703 inst.instruction |= inst.operands[1].imm << 6;
11704}
90e4755a 11705
c19d1205
ZW
11706static void
11707do_t_ldstd (void)
11708{
11709 if (!inst.operands[1].present)
b99bd4ef 11710 {
c19d1205
ZW
11711 inst.operands[1].reg = inst.operands[0].reg + 1;
11712 constraint (inst.operands[0].reg == REG_LR,
11713 _("r14 not allowed here"));
bd340a04 11714 constraint (inst.operands[0].reg == REG_R12,
477330fc 11715 _("r12 not allowed here"));
b99bd4ef 11716 }
bd340a04
MGD
11717
11718 if (inst.operands[2].writeback
11719 && (inst.operands[0].reg == inst.operands[2].reg
11720 || inst.operands[1].reg == inst.operands[2].reg))
11721 as_warn (_("base register written back, and overlaps "
477330fc 11722 "one of transfer registers"));
bd340a04 11723
c19d1205
ZW
11724 inst.instruction |= inst.operands[0].reg << 12;
11725 inst.instruction |= inst.operands[1].reg << 8;
11726 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11727}
11728
c19d1205
ZW
11729static void
11730do_t_ldstt (void)
11731{
11732 inst.instruction |= inst.operands[0].reg << 12;
11733 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11734}
a737bd4d 11735
b99bd4ef 11736static void
c19d1205 11737do_t_mla (void)
b99bd4ef 11738{
fdfde340 11739 unsigned Rd, Rn, Rm, Ra;
c921be7d 11740
fdfde340
JM
11741 Rd = inst.operands[0].reg;
11742 Rn = inst.operands[1].reg;
11743 Rm = inst.operands[2].reg;
11744 Ra = inst.operands[3].reg;
11745
11746 reject_bad_reg (Rd);
11747 reject_bad_reg (Rn);
11748 reject_bad_reg (Rm);
11749 reject_bad_reg (Ra);
11750
11751 inst.instruction |= Rd << 8;
11752 inst.instruction |= Rn << 16;
11753 inst.instruction |= Rm;
11754 inst.instruction |= Ra << 12;
c19d1205 11755}
b99bd4ef 11756
c19d1205
ZW
11757static void
11758do_t_mlal (void)
11759{
fdfde340
JM
11760 unsigned RdLo, RdHi, Rn, Rm;
11761
11762 RdLo = inst.operands[0].reg;
11763 RdHi = inst.operands[1].reg;
11764 Rn = inst.operands[2].reg;
11765 Rm = inst.operands[3].reg;
11766
11767 reject_bad_reg (RdLo);
11768 reject_bad_reg (RdHi);
11769 reject_bad_reg (Rn);
11770 reject_bad_reg (Rm);
11771
11772 inst.instruction |= RdLo << 12;
11773 inst.instruction |= RdHi << 8;
11774 inst.instruction |= Rn << 16;
11775 inst.instruction |= Rm;
c19d1205 11776}
b99bd4ef 11777
c19d1205
ZW
11778static void
11779do_t_mov_cmp (void)
11780{
fdfde340
JM
11781 unsigned Rn, Rm;
11782
11783 Rn = inst.operands[0].reg;
11784 Rm = inst.operands[1].reg;
11785
e07e6e58
NC
11786 if (Rn == REG_PC)
11787 set_it_insn_type_last ();
11788
c19d1205 11789 if (unified_syntax)
b99bd4ef 11790 {
c19d1205
ZW
11791 int r0off = (inst.instruction == T_MNEM_mov
11792 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11793 unsigned long opcode;
3d388997
PB
11794 bfd_boolean narrow;
11795 bfd_boolean low_regs;
11796
fdfde340 11797 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11798 opcode = inst.instruction;
e07e6e58 11799 if (in_it_block ())
0110f2b8 11800 narrow = opcode != T_MNEM_movs;
3d388997 11801 else
0110f2b8 11802 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11803 if (inst.size_req == 4
11804 || inst.operands[1].shifted)
11805 narrow = FALSE;
11806
efd81785
PB
11807 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11808 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11809 && !inst.operands[1].shifted
fdfde340
JM
11810 && Rn == REG_PC
11811 && Rm == REG_LR)
efd81785
PB
11812 {
11813 inst.instruction = T2_SUBS_PC_LR;
11814 return;
11815 }
11816
fdfde340
JM
11817 if (opcode == T_MNEM_cmp)
11818 {
11819 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11820 if (narrow)
11821 {
11822 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11823 but valid. */
11824 warn_deprecated_sp (Rm);
11825 /* R15 was documented as a valid choice for Rm in ARMv6,
11826 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11827 tools reject R15, so we do too. */
11828 constraint (Rm == REG_PC, BAD_PC);
11829 }
11830 else
11831 reject_bad_reg (Rm);
fdfde340
JM
11832 }
11833 else if (opcode == T_MNEM_mov
11834 || opcode == T_MNEM_movs)
11835 {
11836 if (inst.operands[1].isreg)
11837 {
11838 if (opcode == T_MNEM_movs)
11839 {
11840 reject_bad_reg (Rn);
11841 reject_bad_reg (Rm);
11842 }
76fa04a4
MGD
11843 else if (narrow)
11844 {
11845 /* This is mov.n. */
11846 if ((Rn == REG_SP || Rn == REG_PC)
11847 && (Rm == REG_SP || Rm == REG_PC))
11848 {
5c3696f8 11849 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
11850 "deprecated when r%u is the destination "
11851 "register."), Rm, Rn);
11852 }
11853 }
11854 else
11855 {
11856 /* This is mov.w. */
11857 constraint (Rn == REG_PC, BAD_PC);
11858 constraint (Rm == REG_PC, BAD_PC);
11859 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
11860 }
fdfde340
JM
11861 }
11862 else
11863 reject_bad_reg (Rn);
11864 }
11865
c19d1205
ZW
11866 if (!inst.operands[1].isreg)
11867 {
0110f2b8 11868 /* Immediate operand. */
e07e6e58 11869 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
11870 narrow = 0;
11871 if (low_regs && narrow)
11872 {
11873 inst.instruction = THUMB_OP16 (opcode);
fdfde340 11874 inst.instruction |= Rn << 8;
a9f02af8
MG
11875 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11876 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 11877 {
a9f02af8 11878 if (inst.size_req == 2)
72d98d16 11879 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
11880 else
11881 inst.relax = opcode;
72d98d16 11882 }
0110f2b8
PB
11883 }
11884 else
11885 {
a9f02af8
MG
11886 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11887 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
11888 THUMB1_RELOC_ONLY);
11889
0110f2b8
PB
11890 inst.instruction = THUMB_OP32 (inst.instruction);
11891 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11892 inst.instruction |= Rn << r0off;
0110f2b8
PB
11893 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11894 }
c19d1205 11895 }
728ca7c9
PB
11896 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11897 && (inst.instruction == T_MNEM_mov
11898 || inst.instruction == T_MNEM_movs))
11899 {
11900 /* Register shifts are encoded as separate shift instructions. */
11901 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11902
e07e6e58 11903 if (in_it_block ())
728ca7c9
PB
11904 narrow = !flags;
11905 else
11906 narrow = flags;
11907
11908 if (inst.size_req == 4)
11909 narrow = FALSE;
11910
11911 if (!low_regs || inst.operands[1].imm > 7)
11912 narrow = FALSE;
11913
fdfde340 11914 if (Rn != Rm)
728ca7c9
PB
11915 narrow = FALSE;
11916
11917 switch (inst.operands[1].shift_kind)
11918 {
11919 case SHIFT_LSL:
11920 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
11921 break;
11922 case SHIFT_ASR:
11923 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
11924 break;
11925 case SHIFT_LSR:
11926 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
11927 break;
11928 case SHIFT_ROR:
11929 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
11930 break;
11931 default:
5f4273c7 11932 abort ();
728ca7c9
PB
11933 }
11934
11935 inst.instruction = opcode;
11936 if (narrow)
11937 {
fdfde340 11938 inst.instruction |= Rn;
728ca7c9
PB
11939 inst.instruction |= inst.operands[1].imm << 3;
11940 }
11941 else
11942 {
11943 if (flags)
11944 inst.instruction |= CONDS_BIT;
11945
fdfde340
JM
11946 inst.instruction |= Rn << 8;
11947 inst.instruction |= Rm << 16;
728ca7c9
PB
11948 inst.instruction |= inst.operands[1].imm;
11949 }
11950 }
3d388997 11951 else if (!narrow)
c19d1205 11952 {
728ca7c9
PB
11953 /* Some mov with immediate shift have narrow variants.
11954 Register shifts are handled above. */
11955 if (low_regs && inst.operands[1].shifted
11956 && (inst.instruction == T_MNEM_mov
11957 || inst.instruction == T_MNEM_movs))
11958 {
e07e6e58 11959 if (in_it_block ())
728ca7c9
PB
11960 narrow = (inst.instruction == T_MNEM_mov);
11961 else
11962 narrow = (inst.instruction == T_MNEM_movs);
11963 }
11964
11965 if (narrow)
11966 {
11967 switch (inst.operands[1].shift_kind)
11968 {
11969 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11970 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11971 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11972 default: narrow = FALSE; break;
11973 }
11974 }
11975
11976 if (narrow)
11977 {
fdfde340
JM
11978 inst.instruction |= Rn;
11979 inst.instruction |= Rm << 3;
728ca7c9
PB
11980 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11981 }
11982 else
11983 {
11984 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 11985 inst.instruction |= Rn << r0off;
728ca7c9
PB
11986 encode_thumb32_shifted_operand (1);
11987 }
c19d1205
ZW
11988 }
11989 else
11990 switch (inst.instruction)
11991 {
11992 case T_MNEM_mov:
837b3435 11993 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
11994 results. Don't allow this. */
11995 if (low_regs)
11996 {
11997 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
11998 "MOV Rd, Rs with two low registers is not "
11999 "permitted on this architecture");
fa94de6b 12000 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
12001 arm_ext_v6);
12002 }
12003
c19d1205 12004 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
12005 inst.instruction |= (Rn & 0x8) << 4;
12006 inst.instruction |= (Rn & 0x7);
12007 inst.instruction |= Rm << 3;
c19d1205 12008 break;
b99bd4ef 12009
c19d1205
ZW
12010 case T_MNEM_movs:
12011 /* We know we have low registers at this point.
941a8a52
MGD
12012 Generate LSLS Rd, Rs, #0. */
12013 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
12014 inst.instruction |= Rn;
12015 inst.instruction |= Rm << 3;
c19d1205
ZW
12016 break;
12017
12018 case T_MNEM_cmp:
3d388997 12019 if (low_regs)
c19d1205
ZW
12020 {
12021 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
12022 inst.instruction |= Rn;
12023 inst.instruction |= Rm << 3;
c19d1205
ZW
12024 }
12025 else
12026 {
12027 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
12028 inst.instruction |= (Rn & 0x8) << 4;
12029 inst.instruction |= (Rn & 0x7);
12030 inst.instruction |= Rm << 3;
c19d1205
ZW
12031 }
12032 break;
12033 }
b99bd4ef
NC
12034 return;
12035 }
12036
c19d1205 12037 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
12038
12039 /* PR 10443: Do not silently ignore shifted operands. */
12040 constraint (inst.operands[1].shifted,
12041 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12042
c19d1205 12043 if (inst.operands[1].isreg)
b99bd4ef 12044 {
fdfde340 12045 if (Rn < 8 && Rm < 8)
b99bd4ef 12046 {
c19d1205
ZW
12047 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12048 since a MOV instruction produces unpredictable results. */
12049 if (inst.instruction == T_OPCODE_MOV_I8)
12050 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 12051 else
c19d1205 12052 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 12053
fdfde340
JM
12054 inst.instruction |= Rn;
12055 inst.instruction |= Rm << 3;
b99bd4ef
NC
12056 }
12057 else
12058 {
c19d1205
ZW
12059 if (inst.instruction == T_OPCODE_MOV_I8)
12060 inst.instruction = T_OPCODE_MOV_HR;
12061 else
12062 inst.instruction = T_OPCODE_CMP_HR;
12063 do_t_cpy ();
b99bd4ef
NC
12064 }
12065 }
c19d1205 12066 else
b99bd4ef 12067 {
fdfde340 12068 constraint (Rn > 7,
c19d1205 12069 _("only lo regs allowed with immediate"));
fdfde340 12070 inst.instruction |= Rn << 8;
c19d1205
ZW
12071 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
12072 }
12073}
b99bd4ef 12074
c19d1205
ZW
12075static void
12076do_t_mov16 (void)
12077{
fdfde340 12078 unsigned Rd;
b6895b4f
PB
12079 bfd_vma imm;
12080 bfd_boolean top;
12081
12082 top = (inst.instruction & 0x00800000) != 0;
12083 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
12084 {
12085 constraint (top, _(":lower16: not allowed this instruction"));
12086 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
12087 }
12088 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
12089 {
12090 constraint (!top, _(":upper16: not allowed this instruction"));
12091 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
12092 }
12093
fdfde340
JM
12094 Rd = inst.operands[0].reg;
12095 reject_bad_reg (Rd);
12096
12097 inst.instruction |= Rd << 8;
b6895b4f
PB
12098 if (inst.reloc.type == BFD_RELOC_UNUSED)
12099 {
12100 imm = inst.reloc.exp.X_add_number;
12101 inst.instruction |= (imm & 0xf000) << 4;
12102 inst.instruction |= (imm & 0x0800) << 15;
12103 inst.instruction |= (imm & 0x0700) << 4;
12104 inst.instruction |= (imm & 0x00ff);
12105 }
c19d1205 12106}
b99bd4ef 12107
c19d1205
ZW
12108static void
12109do_t_mvn_tst (void)
12110{
fdfde340 12111 unsigned Rn, Rm;
c921be7d 12112
fdfde340
JM
12113 Rn = inst.operands[0].reg;
12114 Rm = inst.operands[1].reg;
12115
12116 if (inst.instruction == T_MNEM_cmp
12117 || inst.instruction == T_MNEM_cmn)
12118 constraint (Rn == REG_PC, BAD_PC);
12119 else
12120 reject_bad_reg (Rn);
12121 reject_bad_reg (Rm);
12122
c19d1205
ZW
12123 if (unified_syntax)
12124 {
12125 int r0off = (inst.instruction == T_MNEM_mvn
12126 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12127 bfd_boolean narrow;
12128
12129 if (inst.size_req == 4
12130 || inst.instruction > 0xffff
12131 || inst.operands[1].shifted
fdfde340 12132 || Rn > 7 || Rm > 7)
3d388997 12133 narrow = FALSE;
fe8b4cc3
KT
12134 else if (inst.instruction == T_MNEM_cmn
12135 || inst.instruction == T_MNEM_tst)
3d388997
PB
12136 narrow = TRUE;
12137 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12138 narrow = !in_it_block ();
3d388997 12139 else
e07e6e58 12140 narrow = in_it_block ();
3d388997 12141
c19d1205 12142 if (!inst.operands[1].isreg)
b99bd4ef 12143 {
c19d1205
ZW
12144 /* For an immediate, we always generate a 32-bit opcode;
12145 section relaxation will shrink it later if possible. */
12146 if (inst.instruction < 0xffff)
12147 inst.instruction = THUMB_OP32 (inst.instruction);
12148 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12149 inst.instruction |= Rn << r0off;
c19d1205 12150 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12151 }
c19d1205 12152 else
b99bd4ef 12153 {
c19d1205 12154 /* See if we can do this with a 16-bit instruction. */
3d388997 12155 if (narrow)
b99bd4ef 12156 {
c19d1205 12157 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12158 inst.instruction |= Rn;
12159 inst.instruction |= Rm << 3;
b99bd4ef 12160 }
c19d1205 12161 else
b99bd4ef 12162 {
c19d1205
ZW
12163 constraint (inst.operands[1].shifted
12164 && inst.operands[1].immisreg,
12165 _("shift must be constant"));
12166 if (inst.instruction < 0xffff)
12167 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12168 inst.instruction |= Rn << r0off;
c19d1205 12169 encode_thumb32_shifted_operand (1);
b99bd4ef 12170 }
b99bd4ef
NC
12171 }
12172 }
12173 else
12174 {
c19d1205
ZW
12175 constraint (inst.instruction > 0xffff
12176 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12177 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12178 _("unshifted register required"));
fdfde340 12179 constraint (Rn > 7 || Rm > 7,
c19d1205 12180 BAD_HIREG);
b99bd4ef 12181
c19d1205 12182 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12183 inst.instruction |= Rn;
12184 inst.instruction |= Rm << 3;
b99bd4ef 12185 }
b99bd4ef
NC
12186}
12187
b05fe5cf 12188static void
c19d1205 12189do_t_mrs (void)
b05fe5cf 12190{
fdfde340 12191 unsigned Rd;
037e8744
JB
12192
12193 if (do_vfp_nsyn_mrs () == SUCCESS)
12194 return;
12195
90ec0d68
MGD
12196 Rd = inst.operands[0].reg;
12197 reject_bad_reg (Rd);
12198 inst.instruction |= Rd << 8;
12199
12200 if (inst.operands[1].isreg)
62b3e311 12201 {
90ec0d68
MGD
12202 unsigned br = inst.operands[1].reg;
12203 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12204 as_bad (_("bad register for mrs"));
12205
12206 inst.instruction |= br & (0xf << 16);
12207 inst.instruction |= (br & 0x300) >> 4;
12208 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12209 }
12210 else
12211 {
90ec0d68 12212 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12213
d2cd1205 12214 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12215 {
12216 /* PR gas/12698: The constraint is only applied for m_profile.
12217 If the user has specified -march=all, we want to ignore it as
12218 we are building for any CPU type, including non-m variants. */
823d2571
TG
12219 bfd_boolean m_profile =
12220 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12221 constraint ((flags != 0) && m_profile, _("selected processor does "
12222 "not support requested special purpose register"));
12223 }
90ec0d68 12224 else
d2cd1205
JB
12225 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12226 devices). */
12227 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12228 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12229
90ec0d68
MGD
12230 inst.instruction |= (flags & SPSR_BIT) >> 2;
12231 inst.instruction |= inst.operands[1].imm & 0xff;
12232 inst.instruction |= 0xf0000;
12233 }
c19d1205 12234}
b05fe5cf 12235
c19d1205
ZW
12236static void
12237do_t_msr (void)
12238{
62b3e311 12239 int flags;
fdfde340 12240 unsigned Rn;
62b3e311 12241
037e8744
JB
12242 if (do_vfp_nsyn_msr () == SUCCESS)
12243 return;
12244
c19d1205
ZW
12245 constraint (!inst.operands[1].isreg,
12246 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12247
12248 if (inst.operands[0].isreg)
12249 flags = (int)(inst.operands[0].reg);
12250 else
12251 flags = inst.operands[0].imm;
12252
d2cd1205 12253 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12254 {
d2cd1205
JB
12255 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12256
1a43faaf 12257 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12258 If the user has specified -march=all, we want to ignore it as
12259 we are building for any CPU type, including non-m variants. */
823d2571
TG
12260 bfd_boolean m_profile =
12261 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12262 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12263 && (bits & ~(PSR_s | PSR_f)) != 0)
12264 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12265 && bits != PSR_f)) && m_profile,
12266 _("selected processor does not support requested special "
12267 "purpose register"));
62b3e311
PB
12268 }
12269 else
d2cd1205
JB
12270 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12271 "requested special purpose register"));
c921be7d 12272
fdfde340
JM
12273 Rn = inst.operands[1].reg;
12274 reject_bad_reg (Rn);
12275
62b3e311 12276 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12277 inst.instruction |= (flags & 0xf0000) >> 8;
12278 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12279 inst.instruction |= (flags & 0xff);
fdfde340 12280 inst.instruction |= Rn << 16;
c19d1205 12281}
b05fe5cf 12282
c19d1205
ZW
12283static void
12284do_t_mul (void)
12285{
17828f45 12286 bfd_boolean narrow;
fdfde340 12287 unsigned Rd, Rn, Rm;
17828f45 12288
c19d1205
ZW
12289 if (!inst.operands[2].present)
12290 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12291
fdfde340
JM
12292 Rd = inst.operands[0].reg;
12293 Rn = inst.operands[1].reg;
12294 Rm = inst.operands[2].reg;
12295
17828f45 12296 if (unified_syntax)
b05fe5cf 12297 {
17828f45 12298 if (inst.size_req == 4
fdfde340
JM
12299 || (Rd != Rn
12300 && Rd != Rm)
12301 || Rn > 7
12302 || Rm > 7)
17828f45
JM
12303 narrow = FALSE;
12304 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12305 narrow = !in_it_block ();
17828f45 12306 else
e07e6e58 12307 narrow = in_it_block ();
b05fe5cf 12308 }
c19d1205 12309 else
b05fe5cf 12310 {
17828f45 12311 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12312 constraint (Rn > 7 || Rm > 7,
c19d1205 12313 BAD_HIREG);
17828f45
JM
12314 narrow = TRUE;
12315 }
b05fe5cf 12316
17828f45
JM
12317 if (narrow)
12318 {
12319 /* 16-bit MULS/Conditional MUL. */
c19d1205 12320 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12321 inst.instruction |= Rd;
b05fe5cf 12322
fdfde340
JM
12323 if (Rd == Rn)
12324 inst.instruction |= Rm << 3;
12325 else if (Rd == Rm)
12326 inst.instruction |= Rn << 3;
c19d1205
ZW
12327 else
12328 constraint (1, _("dest must overlap one source register"));
12329 }
17828f45
JM
12330 else
12331 {
e07e6e58
NC
12332 constraint (inst.instruction != T_MNEM_mul,
12333 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12334 /* 32-bit MUL. */
12335 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12336 inst.instruction |= Rd << 8;
12337 inst.instruction |= Rn << 16;
12338 inst.instruction |= Rm << 0;
12339
12340 reject_bad_reg (Rd);
12341 reject_bad_reg (Rn);
12342 reject_bad_reg (Rm);
17828f45 12343 }
c19d1205 12344}
b05fe5cf 12345
c19d1205
ZW
12346static void
12347do_t_mull (void)
12348{
fdfde340 12349 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12350
fdfde340
JM
12351 RdLo = inst.operands[0].reg;
12352 RdHi = inst.operands[1].reg;
12353 Rn = inst.operands[2].reg;
12354 Rm = inst.operands[3].reg;
12355
12356 reject_bad_reg (RdLo);
12357 reject_bad_reg (RdHi);
12358 reject_bad_reg (Rn);
12359 reject_bad_reg (Rm);
12360
12361 inst.instruction |= RdLo << 12;
12362 inst.instruction |= RdHi << 8;
12363 inst.instruction |= Rn << 16;
12364 inst.instruction |= Rm;
12365
12366 if (RdLo == RdHi)
c19d1205
ZW
12367 as_tsktsk (_("rdhi and rdlo must be different"));
12368}
b05fe5cf 12369
c19d1205
ZW
12370static void
12371do_t_nop (void)
12372{
e07e6e58
NC
12373 set_it_insn_type (NEUTRAL_IT_INSN);
12374
c19d1205
ZW
12375 if (unified_syntax)
12376 {
12377 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12378 {
c19d1205
ZW
12379 inst.instruction = THUMB_OP32 (inst.instruction);
12380 inst.instruction |= inst.operands[0].imm;
12381 }
12382 else
12383 {
bc2d1808
NC
12384 /* PR9722: Check for Thumb2 availability before
12385 generating a thumb2 nop instruction. */
afa62d5e 12386 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12387 {
12388 inst.instruction = THUMB_OP16 (inst.instruction);
12389 inst.instruction |= inst.operands[0].imm << 4;
12390 }
12391 else
12392 inst.instruction = 0x46c0;
c19d1205
ZW
12393 }
12394 }
12395 else
12396 {
12397 constraint (inst.operands[0].present,
12398 _("Thumb does not support NOP with hints"));
12399 inst.instruction = 0x46c0;
12400 }
12401}
b05fe5cf 12402
c19d1205
ZW
12403static void
12404do_t_neg (void)
12405{
12406 if (unified_syntax)
12407 {
3d388997
PB
12408 bfd_boolean narrow;
12409
12410 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12411 narrow = !in_it_block ();
3d388997 12412 else
e07e6e58 12413 narrow = in_it_block ();
3d388997
PB
12414 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12415 narrow = FALSE;
12416 if (inst.size_req == 4)
12417 narrow = FALSE;
12418
12419 if (!narrow)
c19d1205
ZW
12420 {
12421 inst.instruction = THUMB_OP32 (inst.instruction);
12422 inst.instruction |= inst.operands[0].reg << 8;
12423 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12424 }
12425 else
12426 {
c19d1205
ZW
12427 inst.instruction = THUMB_OP16 (inst.instruction);
12428 inst.instruction |= inst.operands[0].reg;
12429 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12430 }
12431 }
12432 else
12433 {
c19d1205
ZW
12434 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12435 BAD_HIREG);
12436 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12437
12438 inst.instruction = THUMB_OP16 (inst.instruction);
12439 inst.instruction |= inst.operands[0].reg;
12440 inst.instruction |= inst.operands[1].reg << 3;
12441 }
12442}
12443
1c444d06
JM
12444static void
12445do_t_orn (void)
12446{
12447 unsigned Rd, Rn;
12448
12449 Rd = inst.operands[0].reg;
12450 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12451
fdfde340
JM
12452 reject_bad_reg (Rd);
12453 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12454 reject_bad_reg (Rn);
12455
1c444d06
JM
12456 inst.instruction |= Rd << 8;
12457 inst.instruction |= Rn << 16;
12458
12459 if (!inst.operands[2].isreg)
12460 {
12461 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12462 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12463 }
12464 else
12465 {
12466 unsigned Rm;
12467
12468 Rm = inst.operands[2].reg;
fdfde340 12469 reject_bad_reg (Rm);
1c444d06
JM
12470
12471 constraint (inst.operands[2].shifted
12472 && inst.operands[2].immisreg,
12473 _("shift must be constant"));
12474 encode_thumb32_shifted_operand (2);
12475 }
12476}
12477
c19d1205
ZW
12478static void
12479do_t_pkhbt (void)
12480{
fdfde340
JM
12481 unsigned Rd, Rn, Rm;
12482
12483 Rd = inst.operands[0].reg;
12484 Rn = inst.operands[1].reg;
12485 Rm = inst.operands[2].reg;
12486
12487 reject_bad_reg (Rd);
12488 reject_bad_reg (Rn);
12489 reject_bad_reg (Rm);
12490
12491 inst.instruction |= Rd << 8;
12492 inst.instruction |= Rn << 16;
12493 inst.instruction |= Rm;
c19d1205
ZW
12494 if (inst.operands[3].present)
12495 {
12496 unsigned int val = inst.reloc.exp.X_add_number;
12497 constraint (inst.reloc.exp.X_op != O_constant,
12498 _("expression too complex"));
12499 inst.instruction |= (val & 0x1c) << 10;
12500 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12501 }
c19d1205 12502}
b05fe5cf 12503
c19d1205
ZW
12504static void
12505do_t_pkhtb (void)
12506{
12507 if (!inst.operands[3].present)
1ef52f49
NC
12508 {
12509 unsigned Rtmp;
12510
12511 inst.instruction &= ~0x00000020;
12512
12513 /* PR 10168. Swap the Rm and Rn registers. */
12514 Rtmp = inst.operands[1].reg;
12515 inst.operands[1].reg = inst.operands[2].reg;
12516 inst.operands[2].reg = Rtmp;
12517 }
c19d1205 12518 do_t_pkhbt ();
b05fe5cf
ZW
12519}
12520
c19d1205
ZW
12521static void
12522do_t_pld (void)
12523{
fdfde340
JM
12524 if (inst.operands[0].immisreg)
12525 reject_bad_reg (inst.operands[0].imm);
12526
c19d1205
ZW
12527 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12528}
b05fe5cf 12529
c19d1205
ZW
12530static void
12531do_t_push_pop (void)
b99bd4ef 12532{
e9f89963 12533 unsigned mask;
5f4273c7 12534
c19d1205
ZW
12535 constraint (inst.operands[0].writeback,
12536 _("push/pop do not support {reglist}^"));
12537 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12538 _("expression too complex"));
b99bd4ef 12539
e9f89963 12540 mask = inst.operands[0].imm;
d3bfe16e 12541 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12542 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 12543 else if (inst.size_req != 4
c6025a80 12544 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 12545 ? REG_LR : REG_PC)))
b99bd4ef 12546 {
c19d1205
ZW
12547 inst.instruction = THUMB_OP16 (inst.instruction);
12548 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12549 inst.instruction |= mask & 0xff;
c19d1205
ZW
12550 }
12551 else if (unified_syntax)
12552 {
3c707909 12553 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12554 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12555 }
12556 else
12557 {
12558 inst.error = _("invalid register list to push/pop instruction");
12559 return;
12560 }
c19d1205 12561}
b99bd4ef 12562
c19d1205
ZW
12563static void
12564do_t_rbit (void)
12565{
fdfde340
JM
12566 unsigned Rd, Rm;
12567
12568 Rd = inst.operands[0].reg;
12569 Rm = inst.operands[1].reg;
12570
12571 reject_bad_reg (Rd);
12572 reject_bad_reg (Rm);
12573
12574 inst.instruction |= Rd << 8;
12575 inst.instruction |= Rm << 16;
12576 inst.instruction |= Rm;
c19d1205 12577}
b99bd4ef 12578
c19d1205
ZW
12579static void
12580do_t_rev (void)
12581{
fdfde340
JM
12582 unsigned Rd, Rm;
12583
12584 Rd = inst.operands[0].reg;
12585 Rm = inst.operands[1].reg;
12586
12587 reject_bad_reg (Rd);
12588 reject_bad_reg (Rm);
12589
12590 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12591 && inst.size_req != 4)
12592 {
12593 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12594 inst.instruction |= Rd;
12595 inst.instruction |= Rm << 3;
c19d1205
ZW
12596 }
12597 else if (unified_syntax)
12598 {
12599 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12600 inst.instruction |= Rd << 8;
12601 inst.instruction |= Rm << 16;
12602 inst.instruction |= Rm;
c19d1205
ZW
12603 }
12604 else
12605 inst.error = BAD_HIREG;
12606}
b99bd4ef 12607
1c444d06
JM
12608static void
12609do_t_rrx (void)
12610{
12611 unsigned Rd, Rm;
12612
12613 Rd = inst.operands[0].reg;
12614 Rm = inst.operands[1].reg;
12615
fdfde340
JM
12616 reject_bad_reg (Rd);
12617 reject_bad_reg (Rm);
c921be7d 12618
1c444d06
JM
12619 inst.instruction |= Rd << 8;
12620 inst.instruction |= Rm;
12621}
12622
c19d1205
ZW
12623static void
12624do_t_rsb (void)
12625{
fdfde340 12626 unsigned Rd, Rs;
b99bd4ef 12627
c19d1205
ZW
12628 Rd = inst.operands[0].reg;
12629 Rs = (inst.operands[1].present
12630 ? inst.operands[1].reg /* Rd, Rs, foo */
12631 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12632
fdfde340
JM
12633 reject_bad_reg (Rd);
12634 reject_bad_reg (Rs);
12635 if (inst.operands[2].isreg)
12636 reject_bad_reg (inst.operands[2].reg);
12637
c19d1205
ZW
12638 inst.instruction |= Rd << 8;
12639 inst.instruction |= Rs << 16;
12640 if (!inst.operands[2].isreg)
12641 {
026d3abb
PB
12642 bfd_boolean narrow;
12643
12644 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12645 narrow = !in_it_block ();
026d3abb 12646 else
e07e6e58 12647 narrow = in_it_block ();
026d3abb
PB
12648
12649 if (Rd > 7 || Rs > 7)
12650 narrow = FALSE;
12651
12652 if (inst.size_req == 4 || !unified_syntax)
12653 narrow = FALSE;
12654
12655 if (inst.reloc.exp.X_op != O_constant
12656 || inst.reloc.exp.X_add_number != 0)
12657 narrow = FALSE;
12658
12659 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12660 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12661 if (narrow)
12662 {
12663 inst.reloc.type = BFD_RELOC_UNUSED;
12664 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12665 inst.instruction |= Rs << 3;
12666 inst.instruction |= Rd;
12667 }
12668 else
12669 {
12670 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12671 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12672 }
c19d1205
ZW
12673 }
12674 else
12675 encode_thumb32_shifted_operand (2);
12676}
b99bd4ef 12677
c19d1205
ZW
12678static void
12679do_t_setend (void)
12680{
12e37cbc
MGD
12681 if (warn_on_deprecated
12682 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12683 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12684
e07e6e58 12685 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12686 if (inst.operands[0].imm)
12687 inst.instruction |= 0x8;
12688}
b99bd4ef 12689
c19d1205
ZW
12690static void
12691do_t_shift (void)
12692{
12693 if (!inst.operands[1].present)
12694 inst.operands[1].reg = inst.operands[0].reg;
12695
12696 if (unified_syntax)
12697 {
3d388997
PB
12698 bfd_boolean narrow;
12699 int shift_kind;
12700
12701 switch (inst.instruction)
12702 {
12703 case T_MNEM_asr:
12704 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12705 case T_MNEM_lsl:
12706 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12707 case T_MNEM_lsr:
12708 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12709 case T_MNEM_ror:
12710 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12711 default: abort ();
12712 }
12713
12714 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12715 narrow = !in_it_block ();
3d388997 12716 else
e07e6e58 12717 narrow = in_it_block ();
3d388997
PB
12718 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12719 narrow = FALSE;
12720 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12721 narrow = FALSE;
12722 if (inst.operands[2].isreg
12723 && (inst.operands[1].reg != inst.operands[0].reg
12724 || inst.operands[2].reg > 7))
12725 narrow = FALSE;
12726 if (inst.size_req == 4)
12727 narrow = FALSE;
12728
fdfde340
JM
12729 reject_bad_reg (inst.operands[0].reg);
12730 reject_bad_reg (inst.operands[1].reg);
c921be7d 12731
3d388997 12732 if (!narrow)
c19d1205
ZW
12733 {
12734 if (inst.operands[2].isreg)
b99bd4ef 12735 {
fdfde340 12736 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12737 inst.instruction = THUMB_OP32 (inst.instruction);
12738 inst.instruction |= inst.operands[0].reg << 8;
12739 inst.instruction |= inst.operands[1].reg << 16;
12740 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12741
12742 /* PR 12854: Error on extraneous shifts. */
12743 constraint (inst.operands[2].shifted,
12744 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12745 }
12746 else
12747 {
12748 inst.operands[1].shifted = 1;
3d388997 12749 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12750 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12751 ? T_MNEM_movs : T_MNEM_mov);
12752 inst.instruction |= inst.operands[0].reg << 8;
12753 encode_thumb32_shifted_operand (1);
12754 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12755 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12756 }
12757 }
12758 else
12759 {
c19d1205 12760 if (inst.operands[2].isreg)
b99bd4ef 12761 {
3d388997 12762 switch (shift_kind)
b99bd4ef 12763 {
3d388997
PB
12764 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12765 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12766 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12767 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12768 default: abort ();
b99bd4ef 12769 }
5f4273c7 12770
c19d1205
ZW
12771 inst.instruction |= inst.operands[0].reg;
12772 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12773
12774 /* PR 12854: Error on extraneous shifts. */
12775 constraint (inst.operands[2].shifted,
12776 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12777 }
12778 else
12779 {
3d388997 12780 switch (shift_kind)
b99bd4ef 12781 {
3d388997
PB
12782 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12783 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12784 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12785 default: abort ();
b99bd4ef 12786 }
c19d1205
ZW
12787 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12788 inst.instruction |= inst.operands[0].reg;
12789 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12790 }
12791 }
c19d1205
ZW
12792 }
12793 else
12794 {
12795 constraint (inst.operands[0].reg > 7
12796 || inst.operands[1].reg > 7, BAD_HIREG);
12797 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12798
c19d1205
ZW
12799 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12800 {
12801 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12802 constraint (inst.operands[0].reg != inst.operands[1].reg,
12803 _("source1 and dest must be same register"));
b99bd4ef 12804
c19d1205
ZW
12805 switch (inst.instruction)
12806 {
12807 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12808 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12809 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12810 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12811 default: abort ();
12812 }
5f4273c7 12813
c19d1205
ZW
12814 inst.instruction |= inst.operands[0].reg;
12815 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12816
12817 /* PR 12854: Error on extraneous shifts. */
12818 constraint (inst.operands[2].shifted,
12819 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12820 }
12821 else
b99bd4ef 12822 {
c19d1205
ZW
12823 switch (inst.instruction)
12824 {
12825 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12826 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12827 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12828 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12829 default: abort ();
12830 }
12831 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12832 inst.instruction |= inst.operands[0].reg;
12833 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12834 }
12835 }
b99bd4ef
NC
12836}
12837
12838static void
c19d1205 12839do_t_simd (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 12854}
b99bd4ef 12855
03ee1b7f
NC
12856static void
12857do_t_simd2 (void)
12858{
12859 unsigned Rd, Rn, Rm;
12860
12861 Rd = inst.operands[0].reg;
12862 Rm = inst.operands[1].reg;
12863 Rn = inst.operands[2].reg;
12864
12865 reject_bad_reg (Rd);
12866 reject_bad_reg (Rn);
12867 reject_bad_reg (Rm);
12868
12869 inst.instruction |= Rd << 8;
12870 inst.instruction |= Rn << 16;
12871 inst.instruction |= Rm;
12872}
12873
c19d1205 12874static void
3eb17e6b 12875do_t_smc (void)
c19d1205
ZW
12876{
12877 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
12878 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12879 _("SMC is not permitted on this architecture"));
c19d1205
ZW
12880 constraint (inst.reloc.exp.X_op != O_constant,
12881 _("expression too complex"));
12882 inst.reloc.type = BFD_RELOC_UNUSED;
12883 inst.instruction |= (value & 0xf000) >> 12;
12884 inst.instruction |= (value & 0x0ff0);
12885 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
12886 /* PR gas/15623: SMC instructions must be last in an IT block. */
12887 set_it_insn_type_last ();
c19d1205 12888}
b99bd4ef 12889
90ec0d68
MGD
12890static void
12891do_t_hvc (void)
12892{
12893 unsigned int value = inst.reloc.exp.X_add_number;
12894
12895 inst.reloc.type = BFD_RELOC_UNUSED;
12896 inst.instruction |= (value & 0x0fff);
12897 inst.instruction |= (value & 0xf000) << 4;
12898}
12899
c19d1205 12900static void
3a21c15a 12901do_t_ssat_usat (int bias)
c19d1205 12902{
fdfde340
JM
12903 unsigned Rd, Rn;
12904
12905 Rd = inst.operands[0].reg;
12906 Rn = inst.operands[2].reg;
12907
12908 reject_bad_reg (Rd);
12909 reject_bad_reg (Rn);
12910
12911 inst.instruction |= Rd << 8;
3a21c15a 12912 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 12913 inst.instruction |= Rn << 16;
b99bd4ef 12914
c19d1205 12915 if (inst.operands[3].present)
b99bd4ef 12916 {
3a21c15a
NC
12917 offsetT shift_amount = inst.reloc.exp.X_add_number;
12918
12919 inst.reloc.type = BFD_RELOC_UNUSED;
12920
c19d1205
ZW
12921 constraint (inst.reloc.exp.X_op != O_constant,
12922 _("expression too complex"));
b99bd4ef 12923
3a21c15a 12924 if (shift_amount != 0)
6189168b 12925 {
3a21c15a
NC
12926 constraint (shift_amount > 31,
12927 _("shift expression is too large"));
12928
c19d1205 12929 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
12930 inst.instruction |= 0x00200000; /* sh bit. */
12931
12932 inst.instruction |= (shift_amount & 0x1c) << 10;
12933 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
12934 }
12935 }
b99bd4ef 12936}
c921be7d 12937
3a21c15a
NC
12938static void
12939do_t_ssat (void)
12940{
12941 do_t_ssat_usat (1);
12942}
b99bd4ef 12943
0dd132b6 12944static void
c19d1205 12945do_t_ssat16 (void)
0dd132b6 12946{
fdfde340
JM
12947 unsigned Rd, Rn;
12948
12949 Rd = inst.operands[0].reg;
12950 Rn = inst.operands[2].reg;
12951
12952 reject_bad_reg (Rd);
12953 reject_bad_reg (Rn);
12954
12955 inst.instruction |= Rd << 8;
c19d1205 12956 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 12957 inst.instruction |= Rn << 16;
c19d1205 12958}
0dd132b6 12959
c19d1205
ZW
12960static void
12961do_t_strex (void)
12962{
12963 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
12964 || inst.operands[2].postind || inst.operands[2].writeback
12965 || inst.operands[2].immisreg || inst.operands[2].shifted
12966 || inst.operands[2].negative,
01cfc07f 12967 BAD_ADDR_MODE);
0dd132b6 12968
5be8be5d
DG
12969 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
12970
c19d1205
ZW
12971 inst.instruction |= inst.operands[0].reg << 8;
12972 inst.instruction |= inst.operands[1].reg << 12;
12973 inst.instruction |= inst.operands[2].reg << 16;
12974 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
12975}
12976
b99bd4ef 12977static void
c19d1205 12978do_t_strexd (void)
b99bd4ef 12979{
c19d1205
ZW
12980 if (!inst.operands[2].present)
12981 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 12982
c19d1205
ZW
12983 constraint (inst.operands[0].reg == inst.operands[1].reg
12984 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 12985 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 12986 BAD_OVERLAP);
b99bd4ef 12987
c19d1205
ZW
12988 inst.instruction |= inst.operands[0].reg;
12989 inst.instruction |= inst.operands[1].reg << 12;
12990 inst.instruction |= inst.operands[2].reg << 8;
12991 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
12992}
12993
12994static void
c19d1205 12995do_t_sxtah (void)
b99bd4ef 12996{
fdfde340
JM
12997 unsigned Rd, Rn, Rm;
12998
12999 Rd = inst.operands[0].reg;
13000 Rn = inst.operands[1].reg;
13001 Rm = inst.operands[2].reg;
13002
13003 reject_bad_reg (Rd);
13004 reject_bad_reg (Rn);
13005 reject_bad_reg (Rm);
13006
13007 inst.instruction |= Rd << 8;
13008 inst.instruction |= Rn << 16;
13009 inst.instruction |= Rm;
c19d1205
ZW
13010 inst.instruction |= inst.operands[3].imm << 4;
13011}
b99bd4ef 13012
c19d1205
ZW
13013static void
13014do_t_sxth (void)
13015{
fdfde340
JM
13016 unsigned Rd, Rm;
13017
13018 Rd = inst.operands[0].reg;
13019 Rm = inst.operands[1].reg;
13020
13021 reject_bad_reg (Rd);
13022 reject_bad_reg (Rm);
c921be7d
NC
13023
13024 if (inst.instruction <= 0xffff
13025 && inst.size_req != 4
fdfde340 13026 && Rd <= 7 && Rm <= 7
c19d1205 13027 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 13028 {
c19d1205 13029 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13030 inst.instruction |= Rd;
13031 inst.instruction |= Rm << 3;
b99bd4ef 13032 }
c19d1205 13033 else if (unified_syntax)
b99bd4ef 13034 {
c19d1205
ZW
13035 if (inst.instruction <= 0xffff)
13036 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13037 inst.instruction |= Rd << 8;
13038 inst.instruction |= Rm;
c19d1205 13039 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 13040 }
c19d1205 13041 else
b99bd4ef 13042 {
c19d1205
ZW
13043 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13044 _("Thumb encoding does not support rotation"));
13045 constraint (1, BAD_HIREG);
b99bd4ef 13046 }
c19d1205 13047}
b99bd4ef 13048
c19d1205
ZW
13049static void
13050do_t_swi (void)
13051{
b2a5fbdc
MGD
13052 /* We have to do the following check manually as ARM_EXT_OS only applies
13053 to ARM_EXT_V6M. */
13054 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
13055 {
ac7f631b
NC
13056 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
13057 /* This only applies to the v6m howver, not later architectures. */
13058 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
13059 as_bad (_("SVC is not permitted on this architecture"));
13060 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
13061 }
13062
c19d1205
ZW
13063 inst.reloc.type = BFD_RELOC_ARM_SWI;
13064}
b99bd4ef 13065
92e90b6e
PB
13066static void
13067do_t_tb (void)
13068{
fdfde340 13069 unsigned Rn, Rm;
92e90b6e
PB
13070 int half;
13071
13072 half = (inst.instruction & 0x10) != 0;
e07e6e58 13073 set_it_insn_type_last ();
dfa9f0d5
PB
13074 constraint (inst.operands[0].immisreg,
13075 _("instruction requires register index"));
fdfde340
JM
13076
13077 Rn = inst.operands[0].reg;
13078 Rm = inst.operands[0].imm;
c921be7d 13079
fdfde340
JM
13080 constraint (Rn == REG_SP, BAD_SP);
13081 reject_bad_reg (Rm);
13082
92e90b6e
PB
13083 constraint (!half && inst.operands[0].shifted,
13084 _("instruction does not allow shifted index"));
fdfde340 13085 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
13086}
13087
74db7efb
NC
13088static void
13089do_t_udf (void)
13090{
13091 if (!inst.operands[0].present)
13092 inst.operands[0].imm = 0;
13093
13094 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13095 {
13096 constraint (inst.size_req == 2,
13097 _("immediate value out of range"));
13098 inst.instruction = THUMB_OP32 (inst.instruction);
13099 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13100 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13101 }
13102 else
13103 {
13104 inst.instruction = THUMB_OP16 (inst.instruction);
13105 inst.instruction |= inst.operands[0].imm;
13106 }
13107
13108 set_it_insn_type (NEUTRAL_IT_INSN);
13109}
13110
13111
c19d1205
ZW
13112static void
13113do_t_usat (void)
13114{
3a21c15a 13115 do_t_ssat_usat (0);
b99bd4ef
NC
13116}
13117
13118static void
c19d1205 13119do_t_usat16 (void)
b99bd4ef 13120{
fdfde340
JM
13121 unsigned Rd, Rn;
13122
13123 Rd = inst.operands[0].reg;
13124 Rn = inst.operands[2].reg;
13125
13126 reject_bad_reg (Rd);
13127 reject_bad_reg (Rn);
13128
13129 inst.instruction |= Rd << 8;
c19d1205 13130 inst.instruction |= inst.operands[1].imm;
fdfde340 13131 inst.instruction |= Rn << 16;
b99bd4ef 13132}
c19d1205 13133
5287ad62 13134/* Neon instruction encoder helpers. */
5f4273c7 13135
5287ad62 13136/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13137
5287ad62
JB
13138/* An "invalid" code for the following tables. */
13139#define N_INV -1u
13140
13141struct neon_tab_entry
b99bd4ef 13142{
5287ad62
JB
13143 unsigned integer;
13144 unsigned float_or_poly;
13145 unsigned scalar_or_imm;
13146};
5f4273c7 13147
5287ad62
JB
13148/* Map overloaded Neon opcodes to their respective encodings. */
13149#define NEON_ENC_TAB \
13150 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13151 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13152 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13153 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13154 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13155 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13156 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13157 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13158 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13159 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13160 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13161 /* Register variants of the following two instructions are encoded as
e07e6e58 13162 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13163 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13164 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13165 X(vfma, N_INV, 0x0000c10, N_INV), \
13166 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13167 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13168 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13169 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13170 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13171 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13172 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13173 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13174 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13175 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13176 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13177 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13178 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13179 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13180 X(vshl, 0x0000400, N_INV, 0x0800510), \
13181 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13182 X(vand, 0x0000110, N_INV, 0x0800030), \
13183 X(vbic, 0x0100110, N_INV, 0x0800030), \
13184 X(veor, 0x1000110, N_INV, N_INV), \
13185 X(vorn, 0x0300110, N_INV, 0x0800010), \
13186 X(vorr, 0x0200110, N_INV, 0x0800010), \
13187 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13188 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13189 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13190 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13191 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13192 X(vst1, 0x0000000, 0x0800000, N_INV), \
13193 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13194 X(vst2, 0x0000100, 0x0800100, N_INV), \
13195 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13196 X(vst3, 0x0000200, 0x0800200, N_INV), \
13197 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13198 X(vst4, 0x0000300, 0x0800300, N_INV), \
13199 X(vmovn, 0x1b20200, N_INV, N_INV), \
13200 X(vtrn, 0x1b20080, N_INV, N_INV), \
13201 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13202 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13203 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13204 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13205 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13206 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13207 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13208 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13209 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13210 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13211 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13212 X(vseleq, 0xe000a00, N_INV, N_INV), \
13213 X(vselvs, 0xe100a00, N_INV, N_INV), \
13214 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13215 X(vselgt, 0xe300a00, N_INV, N_INV), \
13216 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13217 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13218 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13219 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13220 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13221 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13222 X(sha3op, 0x2000c00, N_INV, N_INV), \
13223 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13224 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13225
13226enum neon_opc
13227{
13228#define X(OPC,I,F,S) N_MNEM_##OPC
13229NEON_ENC_TAB
13230#undef X
13231};
b99bd4ef 13232
5287ad62
JB
13233static const struct neon_tab_entry neon_enc_tab[] =
13234{
13235#define X(OPC,I,F,S) { (I), (F), (S) }
13236NEON_ENC_TAB
13237#undef X
13238};
b99bd4ef 13239
88714cb8
DG
13240/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13241#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13242#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13243#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13244#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13245#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13246#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13247#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13248#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13249#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13250#define NEON_ENC_SINGLE_(X) \
037e8744 13251 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13252#define NEON_ENC_DOUBLE_(X) \
037e8744 13253 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13254#define NEON_ENC_FPV8_(X) \
13255 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13256
88714cb8
DG
13257#define NEON_ENCODE(type, inst) \
13258 do \
13259 { \
13260 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13261 inst.is_neon = 1; \
13262 } \
13263 while (0)
13264
13265#define check_neon_suffixes \
13266 do \
13267 { \
13268 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13269 { \
13270 as_bad (_("invalid neon suffix for non neon instruction")); \
13271 return; \
13272 } \
13273 } \
13274 while (0)
13275
037e8744
JB
13276/* Define shapes for instruction operands. The following mnemonic characters
13277 are used in this table:
5287ad62 13278
037e8744 13279 F - VFP S<n> register
5287ad62
JB
13280 D - Neon D<n> register
13281 Q - Neon Q<n> register
13282 I - Immediate
13283 S - Scalar
13284 R - ARM register
13285 L - D<n> register list
5f4273c7 13286
037e8744
JB
13287 This table is used to generate various data:
13288 - enumerations of the form NS_DDR to be used as arguments to
13289 neon_select_shape.
13290 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13291 - a table used to drive neon_select_shape. */
b99bd4ef 13292
037e8744
JB
13293#define NEON_SHAPE_DEF \
13294 X(3, (D, D, D), DOUBLE), \
13295 X(3, (Q, Q, Q), QUAD), \
13296 X(3, (D, D, I), DOUBLE), \
13297 X(3, (Q, Q, I), QUAD), \
13298 X(3, (D, D, S), DOUBLE), \
13299 X(3, (Q, Q, S), QUAD), \
13300 X(2, (D, D), DOUBLE), \
13301 X(2, (Q, Q), QUAD), \
13302 X(2, (D, S), DOUBLE), \
13303 X(2, (Q, S), QUAD), \
13304 X(2, (D, R), DOUBLE), \
13305 X(2, (Q, R), QUAD), \
13306 X(2, (D, I), DOUBLE), \
13307 X(2, (Q, I), QUAD), \
13308 X(3, (D, L, D), DOUBLE), \
13309 X(2, (D, Q), MIXED), \
13310 X(2, (Q, D), MIXED), \
13311 X(3, (D, Q, I), MIXED), \
13312 X(3, (Q, D, I), MIXED), \
13313 X(3, (Q, D, D), MIXED), \
13314 X(3, (D, Q, Q), MIXED), \
13315 X(3, (Q, Q, D), MIXED), \
13316 X(3, (Q, D, S), MIXED), \
13317 X(3, (D, Q, S), MIXED), \
13318 X(4, (D, D, D, I), DOUBLE), \
13319 X(4, (Q, Q, Q, I), QUAD), \
13320 X(2, (F, F), SINGLE), \
13321 X(3, (F, F, F), SINGLE), \
13322 X(2, (F, I), SINGLE), \
13323 X(2, (F, D), MIXED), \
13324 X(2, (D, F), MIXED), \
13325 X(3, (F, F, I), MIXED), \
13326 X(4, (R, R, F, F), SINGLE), \
13327 X(4, (F, F, R, R), SINGLE), \
13328 X(3, (D, R, R), DOUBLE), \
13329 X(3, (R, R, D), DOUBLE), \
13330 X(2, (S, R), SINGLE), \
13331 X(2, (R, S), SINGLE), \
13332 X(2, (F, R), SINGLE), \
d54af2d0
RL
13333 X(2, (R, F), SINGLE), \
13334/* Half float shape supported so far. */\
13335 X (2, (H, D), MIXED), \
13336 X (2, (D, H), MIXED), \
13337 X (2, (H, F), MIXED), \
13338 X (2, (F, H), MIXED), \
13339 X (2, (H, H), HALF), \
13340 X (2, (H, R), HALF), \
13341 X (2, (R, H), HALF), \
13342 X (2, (H, I), HALF), \
13343 X (3, (H, H, H), HALF), \
13344 X (3, (H, F, I), MIXED), \
13345 X (3, (F, H, I), MIXED)
037e8744
JB
13346
13347#define S2(A,B) NS_##A##B
13348#define S3(A,B,C) NS_##A##B##C
13349#define S4(A,B,C,D) NS_##A##B##C##D
13350
13351#define X(N, L, C) S##N L
13352
5287ad62
JB
13353enum neon_shape
13354{
037e8744
JB
13355 NEON_SHAPE_DEF,
13356 NS_NULL
5287ad62 13357};
b99bd4ef 13358
037e8744
JB
13359#undef X
13360#undef S2
13361#undef S3
13362#undef S4
13363
13364enum neon_shape_class
13365{
d54af2d0 13366 SC_HALF,
037e8744
JB
13367 SC_SINGLE,
13368 SC_DOUBLE,
13369 SC_QUAD,
13370 SC_MIXED
13371};
13372
13373#define X(N, L, C) SC_##C
13374
13375static enum neon_shape_class neon_shape_class[] =
13376{
13377 NEON_SHAPE_DEF
13378};
13379
13380#undef X
13381
13382enum neon_shape_el
13383{
d54af2d0 13384 SE_H,
037e8744
JB
13385 SE_F,
13386 SE_D,
13387 SE_Q,
13388 SE_I,
13389 SE_S,
13390 SE_R,
13391 SE_L
13392};
13393
13394/* Register widths of above. */
13395static unsigned neon_shape_el_size[] =
13396{
d54af2d0 13397 16,
037e8744
JB
13398 32,
13399 64,
13400 128,
13401 0,
13402 32,
13403 32,
13404 0
13405};
13406
13407struct neon_shape_info
13408{
13409 unsigned els;
13410 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13411};
13412
13413#define S2(A,B) { SE_##A, SE_##B }
13414#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13415#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13416
13417#define X(N, L, C) { N, S##N L }
13418
13419static struct neon_shape_info neon_shape_tab[] =
13420{
13421 NEON_SHAPE_DEF
13422};
13423
13424#undef X
13425#undef S2
13426#undef S3
13427#undef S4
13428
5287ad62
JB
13429/* Bit masks used in type checking given instructions.
13430 'N_EQK' means the type must be the same as (or based on in some way) the key
13431 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13432 set, various other bits can be set as well in order to modify the meaning of
13433 the type constraint. */
13434
13435enum neon_type_mask
13436{
8e79c3df
CM
13437 N_S8 = 0x0000001,
13438 N_S16 = 0x0000002,
13439 N_S32 = 0x0000004,
13440 N_S64 = 0x0000008,
13441 N_U8 = 0x0000010,
13442 N_U16 = 0x0000020,
13443 N_U32 = 0x0000040,
13444 N_U64 = 0x0000080,
13445 N_I8 = 0x0000100,
13446 N_I16 = 0x0000200,
13447 N_I32 = 0x0000400,
13448 N_I64 = 0x0000800,
13449 N_8 = 0x0001000,
13450 N_16 = 0x0002000,
13451 N_32 = 0x0004000,
13452 N_64 = 0x0008000,
13453 N_P8 = 0x0010000,
13454 N_P16 = 0x0020000,
13455 N_F16 = 0x0040000,
13456 N_F32 = 0x0080000,
13457 N_F64 = 0x0100000,
4f51b4bd 13458 N_P64 = 0x0200000,
c921be7d
NC
13459 N_KEY = 0x1000000, /* Key element (main type specifier). */
13460 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13461 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13462 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13463 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13464 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13465 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13466 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13467 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13468 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13469 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13470 N_UTYP = 0,
4f51b4bd 13471 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13472};
13473
dcbf9037
JB
13474#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13475
5287ad62
JB
13476#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13477#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13478#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
13479#define N_S_32 (N_S8 | N_S16 | N_S32)
13480#define N_F_16_32 (N_F16 | N_F32)
13481#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 13482#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 13483#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 13484#define N_F_ALL (N_F16 | N_F32 | N_F64)
5287ad62
JB
13485
13486/* Pass this as the first type argument to neon_check_type to ignore types
13487 altogether. */
13488#define N_IGNORE_TYPE (N_KEY | N_EQK)
13489
037e8744
JB
13490/* Select a "shape" for the current instruction (describing register types or
13491 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13492 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13493 function of operand parsing, so this function doesn't need to be called.
13494 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13495
13496static enum neon_shape
037e8744 13497neon_select_shape (enum neon_shape shape, ...)
5287ad62 13498{
037e8744
JB
13499 va_list ap;
13500 enum neon_shape first_shape = shape;
5287ad62
JB
13501
13502 /* Fix missing optional operands. FIXME: we don't know at this point how
13503 many arguments we should have, so this makes the assumption that we have
13504 > 1. This is true of all current Neon opcodes, I think, but may not be
13505 true in the future. */
13506 if (!inst.operands[1].present)
13507 inst.operands[1] = inst.operands[0];
13508
037e8744 13509 va_start (ap, shape);
5f4273c7 13510
21d799b5 13511 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13512 {
13513 unsigned j;
13514 int matches = 1;
13515
13516 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13517 {
13518 if (!inst.operands[j].present)
13519 {
13520 matches = 0;
13521 break;
13522 }
13523
13524 switch (neon_shape_tab[shape].el[j])
13525 {
d54af2d0
RL
13526 /* If a .f16, .16, .u16, .s16 type specifier is given over
13527 a VFP single precision register operand, it's essentially
13528 means only half of the register is used.
13529
13530 If the type specifier is given after the mnemonics, the
13531 information is stored in inst.vectype. If the type specifier
13532 is given after register operand, the information is stored
13533 in inst.operands[].vectype.
13534
13535 When there is only one type specifier, and all the register
13536 operands are the same type of hardware register, the type
13537 specifier applies to all register operands.
13538
13539 If no type specifier is given, the shape is inferred from
13540 operand information.
13541
13542 for example:
13543 vadd.f16 s0, s1, s2: NS_HHH
13544 vabs.f16 s0, s1: NS_HH
13545 vmov.f16 s0, r1: NS_HR
13546 vmov.f16 r0, s1: NS_RH
13547 vcvt.f16 r0, s1: NS_RH
13548 vcvt.f16.s32 s2, s2, #29: NS_HFI
13549 vcvt.f16.s32 s2, s2: NS_HF
13550 */
13551 case SE_H:
13552 if (!(inst.operands[j].isreg
13553 && inst.operands[j].isvec
13554 && inst.operands[j].issingle
13555 && !inst.operands[j].isquad
13556 && ((inst.vectype.elems == 1
13557 && inst.vectype.el[0].size == 16)
13558 || (inst.vectype.elems > 1
13559 && inst.vectype.el[j].size == 16)
13560 || (inst.vectype.elems == 0
13561 && inst.operands[j].vectype.type != NT_invtype
13562 && inst.operands[j].vectype.size == 16))))
13563 matches = 0;
13564 break;
13565
477330fc
RM
13566 case SE_F:
13567 if (!(inst.operands[j].isreg
13568 && inst.operands[j].isvec
13569 && inst.operands[j].issingle
d54af2d0
RL
13570 && !inst.operands[j].isquad
13571 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13572 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13573 || (inst.vectype.elems == 0
13574 && (inst.operands[j].vectype.size == 32
13575 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
13576 matches = 0;
13577 break;
13578
13579 case SE_D:
13580 if (!(inst.operands[j].isreg
13581 && inst.operands[j].isvec
13582 && !inst.operands[j].isquad
13583 && !inst.operands[j].issingle))
13584 matches = 0;
13585 break;
13586
13587 case SE_R:
13588 if (!(inst.operands[j].isreg
13589 && !inst.operands[j].isvec))
13590 matches = 0;
13591 break;
13592
13593 case SE_Q:
13594 if (!(inst.operands[j].isreg
13595 && inst.operands[j].isvec
13596 && inst.operands[j].isquad
13597 && !inst.operands[j].issingle))
13598 matches = 0;
13599 break;
13600
13601 case SE_I:
13602 if (!(!inst.operands[j].isreg
13603 && !inst.operands[j].isscalar))
13604 matches = 0;
13605 break;
13606
13607 case SE_S:
13608 if (!(!inst.operands[j].isreg
13609 && inst.operands[j].isscalar))
13610 matches = 0;
13611 break;
13612
13613 case SE_L:
13614 break;
13615 }
3fde54a2
JZ
13616 if (!matches)
13617 break;
477330fc 13618 }
ad6cec43
MGD
13619 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13620 /* We've matched all the entries in the shape table, and we don't
13621 have any left over operands which have not been matched. */
477330fc 13622 break;
037e8744 13623 }
5f4273c7 13624
037e8744 13625 va_end (ap);
5287ad62 13626
037e8744
JB
13627 if (shape == NS_NULL && first_shape != NS_NULL)
13628 first_error (_("invalid instruction shape"));
5287ad62 13629
037e8744
JB
13630 return shape;
13631}
5287ad62 13632
037e8744
JB
13633/* True if SHAPE is predominantly a quadword operation (most of the time, this
13634 means the Q bit should be set). */
13635
13636static int
13637neon_quad (enum neon_shape shape)
13638{
13639 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13640}
037e8744 13641
5287ad62
JB
13642static void
13643neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13644 unsigned *g_size)
5287ad62
JB
13645{
13646 /* Allow modification to be made to types which are constrained to be
13647 based on the key element, based on bits set alongside N_EQK. */
13648 if ((typebits & N_EQK) != 0)
13649 {
13650 if ((typebits & N_HLF) != 0)
13651 *g_size /= 2;
13652 else if ((typebits & N_DBL) != 0)
13653 *g_size *= 2;
13654 if ((typebits & N_SGN) != 0)
13655 *g_type = NT_signed;
13656 else if ((typebits & N_UNS) != 0)
477330fc 13657 *g_type = NT_unsigned;
5287ad62 13658 else if ((typebits & N_INT) != 0)
477330fc 13659 *g_type = NT_integer;
5287ad62 13660 else if ((typebits & N_FLT) != 0)
477330fc 13661 *g_type = NT_float;
dcbf9037 13662 else if ((typebits & N_SIZ) != 0)
477330fc 13663 *g_type = NT_untyped;
5287ad62
JB
13664 }
13665}
5f4273c7 13666
5287ad62
JB
13667/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13668 operand type, i.e. the single type specified in a Neon instruction when it
13669 is the only one given. */
13670
13671static struct neon_type_el
13672neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13673{
13674 struct neon_type_el dest = *key;
5f4273c7 13675
9c2799c2 13676 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13677
5287ad62
JB
13678 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13679
13680 return dest;
13681}
13682
13683/* Convert Neon type and size into compact bitmask representation. */
13684
13685static enum neon_type_mask
13686type_chk_of_el_type (enum neon_el_type type, unsigned size)
13687{
13688 switch (type)
13689 {
13690 case NT_untyped:
13691 switch (size)
477330fc
RM
13692 {
13693 case 8: return N_8;
13694 case 16: return N_16;
13695 case 32: return N_32;
13696 case 64: return N_64;
13697 default: ;
13698 }
5287ad62
JB
13699 break;
13700
13701 case NT_integer:
13702 switch (size)
477330fc
RM
13703 {
13704 case 8: return N_I8;
13705 case 16: return N_I16;
13706 case 32: return N_I32;
13707 case 64: return N_I64;
13708 default: ;
13709 }
5287ad62
JB
13710 break;
13711
13712 case NT_float:
037e8744 13713 switch (size)
477330fc 13714 {
8e79c3df 13715 case 16: return N_F16;
477330fc
RM
13716 case 32: return N_F32;
13717 case 64: return N_F64;
13718 default: ;
13719 }
5287ad62
JB
13720 break;
13721
13722 case NT_poly:
13723 switch (size)
477330fc
RM
13724 {
13725 case 8: return N_P8;
13726 case 16: return N_P16;
4f51b4bd 13727 case 64: return N_P64;
477330fc
RM
13728 default: ;
13729 }
5287ad62
JB
13730 break;
13731
13732 case NT_signed:
13733 switch (size)
477330fc
RM
13734 {
13735 case 8: return N_S8;
13736 case 16: return N_S16;
13737 case 32: return N_S32;
13738 case 64: return N_S64;
13739 default: ;
13740 }
5287ad62
JB
13741 break;
13742
13743 case NT_unsigned:
13744 switch (size)
477330fc
RM
13745 {
13746 case 8: return N_U8;
13747 case 16: return N_U16;
13748 case 32: return N_U32;
13749 case 64: return N_U64;
13750 default: ;
13751 }
5287ad62
JB
13752 break;
13753
13754 default: ;
13755 }
5f4273c7 13756
5287ad62
JB
13757 return N_UTYP;
13758}
13759
13760/* Convert compact Neon bitmask type representation to a type and size. Only
13761 handles the case where a single bit is set in the mask. */
13762
dcbf9037 13763static int
5287ad62 13764el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13765 enum neon_type_mask mask)
5287ad62 13766{
dcbf9037
JB
13767 if ((mask & N_EQK) != 0)
13768 return FAIL;
13769
5287ad62
JB
13770 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13771 *size = 8;
c70a8987 13772 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13773 *size = 16;
dcbf9037 13774 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13775 *size = 32;
4f51b4bd 13776 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13777 *size = 64;
dcbf9037
JB
13778 else
13779 return FAIL;
13780
5287ad62
JB
13781 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13782 *type = NT_signed;
dcbf9037 13783 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13784 *type = NT_unsigned;
dcbf9037 13785 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13786 *type = NT_integer;
dcbf9037 13787 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13788 *type = NT_untyped;
4f51b4bd 13789 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13790 *type = NT_poly;
d54af2d0 13791 else if ((mask & (N_F_ALL)) != 0)
5287ad62 13792 *type = NT_float;
dcbf9037
JB
13793 else
13794 return FAIL;
5f4273c7 13795
dcbf9037 13796 return SUCCESS;
5287ad62
JB
13797}
13798
13799/* Modify a bitmask of allowed types. This is only needed for type
13800 relaxation. */
13801
13802static unsigned
13803modify_types_allowed (unsigned allowed, unsigned mods)
13804{
13805 unsigned size;
13806 enum neon_el_type type;
13807 unsigned destmask;
13808 int i;
5f4273c7 13809
5287ad62 13810 destmask = 0;
5f4273c7 13811
5287ad62
JB
13812 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13813 {
21d799b5 13814 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13815 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13816 {
13817 neon_modify_type_size (mods, &type, &size);
13818 destmask |= type_chk_of_el_type (type, size);
13819 }
5287ad62 13820 }
5f4273c7 13821
5287ad62
JB
13822 return destmask;
13823}
13824
13825/* Check type and return type classification.
13826 The manual states (paraphrase): If one datatype is given, it indicates the
13827 type given in:
13828 - the second operand, if there is one
13829 - the operand, if there is no second operand
13830 - the result, if there are no operands.
13831 This isn't quite good enough though, so we use a concept of a "key" datatype
13832 which is set on a per-instruction basis, which is the one which matters when
13833 only one data type is written.
13834 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13835 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13836
13837static struct neon_type_el
13838neon_check_type (unsigned els, enum neon_shape ns, ...)
13839{
13840 va_list ap;
13841 unsigned i, pass, key_el = 0;
13842 unsigned types[NEON_MAX_TYPE_ELS];
13843 enum neon_el_type k_type = NT_invtype;
13844 unsigned k_size = -1u;
13845 struct neon_type_el badtype = {NT_invtype, -1};
13846 unsigned key_allowed = 0;
13847
13848 /* Optional registers in Neon instructions are always (not) in operand 1.
13849 Fill in the missing operand here, if it was omitted. */
13850 if (els > 1 && !inst.operands[1].present)
13851 inst.operands[1] = inst.operands[0];
13852
13853 /* Suck up all the varargs. */
13854 va_start (ap, ns);
13855 for (i = 0; i < els; i++)
13856 {
13857 unsigned thisarg = va_arg (ap, unsigned);
13858 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
13859 {
13860 va_end (ap);
13861 return badtype;
13862 }
5287ad62
JB
13863 types[i] = thisarg;
13864 if ((thisarg & N_KEY) != 0)
477330fc 13865 key_el = i;
5287ad62
JB
13866 }
13867 va_end (ap);
13868
dcbf9037
JB
13869 if (inst.vectype.elems > 0)
13870 for (i = 0; i < els; i++)
13871 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
13872 {
13873 first_error (_("types specified in both the mnemonic and operands"));
13874 return badtype;
13875 }
dcbf9037 13876
5287ad62
JB
13877 /* Duplicate inst.vectype elements here as necessary.
13878 FIXME: No idea if this is exactly the same as the ARM assembler,
13879 particularly when an insn takes one register and one non-register
13880 operand. */
13881 if (inst.vectype.elems == 1 && els > 1)
13882 {
13883 unsigned j;
13884 inst.vectype.elems = els;
13885 inst.vectype.el[key_el] = inst.vectype.el[0];
13886 for (j = 0; j < els; j++)
477330fc
RM
13887 if (j != key_el)
13888 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13889 types[j]);
dcbf9037
JB
13890 }
13891 else if (inst.vectype.elems == 0 && els > 0)
13892 {
13893 unsigned j;
13894 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
13895 after each operand. We allow some flexibility here; as long as the
13896 "key" operand has a type, we can infer the others. */
dcbf9037 13897 for (j = 0; j < els; j++)
477330fc
RM
13898 if (inst.operands[j].vectype.type != NT_invtype)
13899 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
13900
13901 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
13902 {
13903 for (j = 0; j < els; j++)
13904 if (inst.operands[j].vectype.type == NT_invtype)
13905 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13906 types[j]);
13907 }
dcbf9037 13908 else
477330fc
RM
13909 {
13910 first_error (_("operand types can't be inferred"));
13911 return badtype;
13912 }
5287ad62
JB
13913 }
13914 else if (inst.vectype.elems != els)
13915 {
dcbf9037 13916 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
13917 return badtype;
13918 }
13919
13920 for (pass = 0; pass < 2; pass++)
13921 {
13922 for (i = 0; i < els; i++)
477330fc
RM
13923 {
13924 unsigned thisarg = types[i];
13925 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
13926 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
13927 enum neon_el_type g_type = inst.vectype.el[i].type;
13928 unsigned g_size = inst.vectype.el[i].size;
13929
13930 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 13931 integer types if sign-specific variants are unavailable. */
477330fc 13932 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
13933 && (types_allowed & N_SU_ALL) == 0)
13934 g_type = NT_integer;
13935
477330fc 13936 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
13937 them. Some instructions only care about signs for some element
13938 sizes, so handle that properly. */
477330fc 13939 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
13940 && ((g_size == 8 && (types_allowed & N_8) != 0)
13941 || (g_size == 16 && (types_allowed & N_16) != 0)
13942 || (g_size == 32 && (types_allowed & N_32) != 0)
13943 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
13944 g_type = NT_untyped;
13945
477330fc
RM
13946 if (pass == 0)
13947 {
13948 if ((thisarg & N_KEY) != 0)
13949 {
13950 k_type = g_type;
13951 k_size = g_size;
13952 key_allowed = thisarg & ~N_KEY;
cc933301
JW
13953
13954 /* Check architecture constraint on FP16 extension. */
13955 if (k_size == 16
13956 && k_type == NT_float
13957 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
13958 {
13959 inst.error = _(BAD_FP16);
13960 return badtype;
13961 }
477330fc
RM
13962 }
13963 }
13964 else
13965 {
13966 if ((thisarg & N_VFP) != 0)
13967 {
13968 enum neon_shape_el regshape;
13969 unsigned regwidth, match;
99b253c5
NC
13970
13971 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
13972 if (ns == NS_NULL)
13973 {
13974 first_error (_("invalid instruction shape"));
13975 return badtype;
13976 }
477330fc
RM
13977 regshape = neon_shape_tab[ns].el[i];
13978 regwidth = neon_shape_el_size[regshape];
13979
13980 /* In VFP mode, operands must match register widths. If we
13981 have a key operand, use its width, else use the width of
13982 the current operand. */
13983 if (k_size != -1u)
13984 match = k_size;
13985 else
13986 match = g_size;
13987
9db2f6b4
RL
13988 /* FP16 will use a single precision register. */
13989 if (regwidth == 32 && match == 16)
13990 {
13991 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
13992 match = regwidth;
13993 else
13994 {
13995 inst.error = _(BAD_FP16);
13996 return badtype;
13997 }
13998 }
13999
477330fc
RM
14000 if (regwidth != match)
14001 {
14002 first_error (_("operand size must match register width"));
14003 return badtype;
14004 }
14005 }
14006
14007 if ((thisarg & N_EQK) == 0)
14008 {
14009 unsigned given_type = type_chk_of_el_type (g_type, g_size);
14010
14011 if ((given_type & types_allowed) == 0)
14012 {
14013 first_error (_("bad type in Neon instruction"));
14014 return badtype;
14015 }
14016 }
14017 else
14018 {
14019 enum neon_el_type mod_k_type = k_type;
14020 unsigned mod_k_size = k_size;
14021 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
14022 if (g_type != mod_k_type || g_size != mod_k_size)
14023 {
14024 first_error (_("inconsistent types in Neon instruction"));
14025 return badtype;
14026 }
14027 }
14028 }
14029 }
5287ad62
JB
14030 }
14031
14032 return inst.vectype.el[key_el];
14033}
14034
037e8744 14035/* Neon-style VFP instruction forwarding. */
5287ad62 14036
037e8744
JB
14037/* Thumb VFP instructions have 0xE in the condition field. */
14038
14039static void
14040do_vfp_cond_or_thumb (void)
5287ad62 14041{
88714cb8
DG
14042 inst.is_neon = 1;
14043
5287ad62 14044 if (thumb_mode)
037e8744 14045 inst.instruction |= 0xe0000000;
5287ad62 14046 else
037e8744 14047 inst.instruction |= inst.cond << 28;
5287ad62
JB
14048}
14049
037e8744
JB
14050/* Look up and encode a simple mnemonic, for use as a helper function for the
14051 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14052 etc. It is assumed that operand parsing has already been done, and that the
14053 operands are in the form expected by the given opcode (this isn't necessarily
14054 the same as the form in which they were parsed, hence some massaging must
14055 take place before this function is called).
14056 Checks current arch version against that in the looked-up opcode. */
5287ad62 14057
037e8744
JB
14058static void
14059do_vfp_nsyn_opcode (const char *opname)
5287ad62 14060{
037e8744 14061 const struct asm_opcode *opcode;
5f4273c7 14062
21d799b5 14063 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 14064
037e8744
JB
14065 if (!opcode)
14066 abort ();
5287ad62 14067
037e8744 14068 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
14069 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14070 _(BAD_FPU));
5287ad62 14071
88714cb8
DG
14072 inst.is_neon = 1;
14073
037e8744
JB
14074 if (thumb_mode)
14075 {
14076 inst.instruction = opcode->tvalue;
14077 opcode->tencode ();
14078 }
14079 else
14080 {
14081 inst.instruction = (inst.cond << 28) | opcode->avalue;
14082 opcode->aencode ();
14083 }
14084}
5287ad62
JB
14085
14086static void
037e8744 14087do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 14088{
037e8744
JB
14089 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14090
9db2f6b4 14091 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14092 {
14093 if (is_add)
477330fc 14094 do_vfp_nsyn_opcode ("fadds");
037e8744 14095 else
477330fc 14096 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
14097
14098 /* ARMv8.2 fp16 instruction. */
14099 if (rs == NS_HHH)
14100 do_scalar_fp16_v82_encode ();
037e8744
JB
14101 }
14102 else
14103 {
14104 if (is_add)
477330fc 14105 do_vfp_nsyn_opcode ("faddd");
037e8744 14106 else
477330fc 14107 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
14108 }
14109}
14110
14111/* Check operand types to see if this is a VFP instruction, and if so call
14112 PFN (). */
14113
14114static int
14115try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14116{
14117 enum neon_shape rs;
14118 struct neon_type_el et;
14119
14120 switch (args)
14121 {
14122 case 2:
9db2f6b4
RL
14123 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14124 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 14125 break;
5f4273c7 14126
037e8744 14127 case 3:
9db2f6b4
RL
14128 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14129 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14130 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
14131 break;
14132
14133 default:
14134 abort ();
14135 }
14136
14137 if (et.type != NT_invtype)
14138 {
14139 pfn (rs);
14140 return SUCCESS;
14141 }
037e8744 14142
99b253c5 14143 inst.error = NULL;
037e8744
JB
14144 return FAIL;
14145}
14146
14147static void
14148do_vfp_nsyn_mla_mls (enum neon_shape rs)
14149{
14150 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 14151
9db2f6b4 14152 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14153 {
14154 if (is_mla)
477330fc 14155 do_vfp_nsyn_opcode ("fmacs");
037e8744 14156 else
477330fc 14157 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
14158
14159 /* ARMv8.2 fp16 instruction. */
14160 if (rs == NS_HHH)
14161 do_scalar_fp16_v82_encode ();
037e8744
JB
14162 }
14163 else
14164 {
14165 if (is_mla)
477330fc 14166 do_vfp_nsyn_opcode ("fmacd");
037e8744 14167 else
477330fc 14168 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
14169 }
14170}
14171
62f3b8c8
PB
14172static void
14173do_vfp_nsyn_fma_fms (enum neon_shape rs)
14174{
14175 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14176
9db2f6b4 14177 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
14178 {
14179 if (is_fma)
477330fc 14180 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 14181 else
477330fc 14182 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
14183
14184 /* ARMv8.2 fp16 instruction. */
14185 if (rs == NS_HHH)
14186 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
14187 }
14188 else
14189 {
14190 if (is_fma)
477330fc 14191 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14192 else
477330fc 14193 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14194 }
14195}
14196
037e8744
JB
14197static void
14198do_vfp_nsyn_mul (enum neon_shape rs)
14199{
9db2f6b4
RL
14200 if (rs == NS_FFF || rs == NS_HHH)
14201 {
14202 do_vfp_nsyn_opcode ("fmuls");
14203
14204 /* ARMv8.2 fp16 instruction. */
14205 if (rs == NS_HHH)
14206 do_scalar_fp16_v82_encode ();
14207 }
037e8744
JB
14208 else
14209 do_vfp_nsyn_opcode ("fmuld");
14210}
14211
14212static void
14213do_vfp_nsyn_abs_neg (enum neon_shape rs)
14214{
14215 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 14216 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 14217
9db2f6b4 14218 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
14219 {
14220 if (is_neg)
477330fc 14221 do_vfp_nsyn_opcode ("fnegs");
037e8744 14222 else
477330fc 14223 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
14224
14225 /* ARMv8.2 fp16 instruction. */
14226 if (rs == NS_HH)
14227 do_scalar_fp16_v82_encode ();
037e8744
JB
14228 }
14229 else
14230 {
14231 if (is_neg)
477330fc 14232 do_vfp_nsyn_opcode ("fnegd");
037e8744 14233 else
477330fc 14234 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14235 }
14236}
14237
14238/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14239 insns belong to Neon, and are handled elsewhere. */
14240
14241static void
14242do_vfp_nsyn_ldm_stm (int is_dbmode)
14243{
14244 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14245 if (is_ldm)
14246 {
14247 if (is_dbmode)
477330fc 14248 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14249 else
477330fc 14250 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14251 }
14252 else
14253 {
14254 if (is_dbmode)
477330fc 14255 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14256 else
477330fc 14257 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14258 }
14259}
14260
037e8744
JB
14261static void
14262do_vfp_nsyn_sqrt (void)
14263{
9db2f6b4
RL
14264 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14265 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14266
9db2f6b4
RL
14267 if (rs == NS_FF || rs == NS_HH)
14268 {
14269 do_vfp_nsyn_opcode ("fsqrts");
14270
14271 /* ARMv8.2 fp16 instruction. */
14272 if (rs == NS_HH)
14273 do_scalar_fp16_v82_encode ();
14274 }
037e8744
JB
14275 else
14276 do_vfp_nsyn_opcode ("fsqrtd");
14277}
14278
14279static void
14280do_vfp_nsyn_div (void)
14281{
9db2f6b4 14282 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14283 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14284 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14285
9db2f6b4
RL
14286 if (rs == NS_FFF || rs == NS_HHH)
14287 {
14288 do_vfp_nsyn_opcode ("fdivs");
14289
14290 /* ARMv8.2 fp16 instruction. */
14291 if (rs == NS_HHH)
14292 do_scalar_fp16_v82_encode ();
14293 }
037e8744
JB
14294 else
14295 do_vfp_nsyn_opcode ("fdivd");
14296}
14297
14298static void
14299do_vfp_nsyn_nmul (void)
14300{
9db2f6b4 14301 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14302 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14303 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14304
9db2f6b4 14305 if (rs == NS_FFF || rs == NS_HHH)
037e8744 14306 {
88714cb8 14307 NEON_ENCODE (SINGLE, inst);
037e8744 14308 do_vfp_sp_dyadic ();
9db2f6b4
RL
14309
14310 /* ARMv8.2 fp16 instruction. */
14311 if (rs == NS_HHH)
14312 do_scalar_fp16_v82_encode ();
037e8744
JB
14313 }
14314 else
14315 {
88714cb8 14316 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14317 do_vfp_dp_rd_rn_rm ();
14318 }
14319 do_vfp_cond_or_thumb ();
9db2f6b4 14320
037e8744
JB
14321}
14322
14323static void
14324do_vfp_nsyn_cmp (void)
14325{
9db2f6b4 14326 enum neon_shape rs;
037e8744
JB
14327 if (inst.operands[1].isreg)
14328 {
9db2f6b4
RL
14329 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14330 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14331
9db2f6b4 14332 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
14333 {
14334 NEON_ENCODE (SINGLE, inst);
14335 do_vfp_sp_monadic ();
14336 }
037e8744 14337 else
477330fc
RM
14338 {
14339 NEON_ENCODE (DOUBLE, inst);
14340 do_vfp_dp_rd_rm ();
14341 }
037e8744
JB
14342 }
14343 else
14344 {
9db2f6b4
RL
14345 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14346 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
14347
14348 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14349 {
14350 case N_MNEM_vcmp:
14351 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14352 break;
14353 case N_MNEM_vcmpe:
14354 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14355 break;
14356 default:
14357 abort ();
14358 }
5f4273c7 14359
9db2f6b4 14360 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
14361 {
14362 NEON_ENCODE (SINGLE, inst);
14363 do_vfp_sp_compare_z ();
14364 }
037e8744 14365 else
477330fc
RM
14366 {
14367 NEON_ENCODE (DOUBLE, inst);
14368 do_vfp_dp_rd ();
14369 }
037e8744
JB
14370 }
14371 do_vfp_cond_or_thumb ();
9db2f6b4
RL
14372
14373 /* ARMv8.2 fp16 instruction. */
14374 if (rs == NS_HI || rs == NS_HH)
14375 do_scalar_fp16_v82_encode ();
037e8744
JB
14376}
14377
14378static void
14379nsyn_insert_sp (void)
14380{
14381 inst.operands[1] = inst.operands[0];
14382 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14383 inst.operands[0].reg = REG_SP;
037e8744
JB
14384 inst.operands[0].isreg = 1;
14385 inst.operands[0].writeback = 1;
14386 inst.operands[0].present = 1;
14387}
14388
14389static void
14390do_vfp_nsyn_push (void)
14391{
14392 nsyn_insert_sp ();
b126985e
NC
14393
14394 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14395 _("register list must contain at least 1 and at most 16 "
14396 "registers"));
14397
037e8744
JB
14398 if (inst.operands[1].issingle)
14399 do_vfp_nsyn_opcode ("fstmdbs");
14400 else
14401 do_vfp_nsyn_opcode ("fstmdbd");
14402}
14403
14404static void
14405do_vfp_nsyn_pop (void)
14406{
14407 nsyn_insert_sp ();
b126985e
NC
14408
14409 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14410 _("register list must contain at least 1 and at most 16 "
14411 "registers"));
14412
037e8744 14413 if (inst.operands[1].issingle)
22b5b651 14414 do_vfp_nsyn_opcode ("fldmias");
037e8744 14415 else
22b5b651 14416 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14417}
14418
14419/* Fix up Neon data-processing instructions, ORing in the correct bits for
14420 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14421
88714cb8
DG
14422static void
14423neon_dp_fixup (struct arm_it* insn)
037e8744 14424{
88714cb8
DG
14425 unsigned int i = insn->instruction;
14426 insn->is_neon = 1;
14427
037e8744
JB
14428 if (thumb_mode)
14429 {
14430 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14431 if (i & (1 << 24))
477330fc 14432 i |= 1 << 28;
5f4273c7 14433
037e8744 14434 i &= ~(1 << 24);
5f4273c7 14435
037e8744
JB
14436 i |= 0xef000000;
14437 }
14438 else
14439 i |= 0xf2000000;
5f4273c7 14440
88714cb8 14441 insn->instruction = i;
037e8744
JB
14442}
14443
14444/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14445 (0, 1, 2, 3). */
14446
14447static unsigned
14448neon_logbits (unsigned x)
14449{
14450 return ffs (x) - 4;
14451}
14452
14453#define LOW4(R) ((R) & 0xf)
14454#define HI1(R) (((R) >> 4) & 1)
14455
14456/* Encode insns with bit pattern:
14457
14458 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14459 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14460
037e8744
JB
14461 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14462 different meaning for some instruction. */
14463
14464static void
14465neon_three_same (int isquad, int ubit, int size)
14466{
14467 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14468 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14469 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14470 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14471 inst.instruction |= LOW4 (inst.operands[2].reg);
14472 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14473 inst.instruction |= (isquad != 0) << 6;
14474 inst.instruction |= (ubit != 0) << 24;
14475 if (size != -1)
14476 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14477
88714cb8 14478 neon_dp_fixup (&inst);
037e8744
JB
14479}
14480
14481/* Encode instructions of the form:
14482
14483 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14484 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14485
14486 Don't write size if SIZE == -1. */
14487
14488static void
14489neon_two_same (int qbit, int ubit, int size)
14490{
14491 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14492 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14493 inst.instruction |= LOW4 (inst.operands[1].reg);
14494 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14495 inst.instruction |= (qbit != 0) << 6;
14496 inst.instruction |= (ubit != 0) << 24;
14497
14498 if (size != -1)
14499 inst.instruction |= neon_logbits (size) << 18;
14500
88714cb8 14501 neon_dp_fixup (&inst);
5287ad62
JB
14502}
14503
14504/* Neon instruction encoders, in approximate order of appearance. */
14505
14506static void
14507do_neon_dyadic_i_su (void)
14508{
037e8744 14509 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14510 struct neon_type_el et = neon_check_type (3, rs,
14511 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14512 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14513}
14514
14515static void
14516do_neon_dyadic_i64_su (void)
14517{
037e8744 14518 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14519 struct neon_type_el et = neon_check_type (3, rs,
14520 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14521 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14522}
14523
14524static void
14525neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14526 unsigned immbits)
5287ad62
JB
14527{
14528 unsigned size = et.size >> 3;
14529 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14530 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14531 inst.instruction |= LOW4 (inst.operands[1].reg);
14532 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14533 inst.instruction |= (isquad != 0) << 6;
14534 inst.instruction |= immbits << 16;
14535 inst.instruction |= (size >> 3) << 7;
14536 inst.instruction |= (size & 0x7) << 19;
14537 if (write_ubit)
14538 inst.instruction |= (uval != 0) << 24;
14539
88714cb8 14540 neon_dp_fixup (&inst);
5287ad62
JB
14541}
14542
14543static void
14544do_neon_shl_imm (void)
14545{
14546 if (!inst.operands[2].isreg)
14547 {
037e8744 14548 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14549 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14550 int imm = inst.operands[2].imm;
14551
14552 constraint (imm < 0 || (unsigned)imm >= et.size,
14553 _("immediate out of range for shift"));
88714cb8 14554 NEON_ENCODE (IMMED, inst);
cb3b1e65 14555 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14556 }
14557 else
14558 {
037e8744 14559 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14560 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14561 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14562 unsigned int tmp;
14563
14564 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14565 vshl.xx Dd, Dm, Dn
14566 whereas other 3-register operations encoded by neon_three_same have
14567 syntax like:
14568 vadd.xx Dd, Dn, Dm
14569 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14570 here. */
627907b7
JB
14571 tmp = inst.operands[2].reg;
14572 inst.operands[2].reg = inst.operands[1].reg;
14573 inst.operands[1].reg = tmp;
88714cb8 14574 NEON_ENCODE (INTEGER, inst);
037e8744 14575 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14576 }
14577}
14578
14579static void
14580do_neon_qshl_imm (void)
14581{
14582 if (!inst.operands[2].isreg)
14583 {
037e8744 14584 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14585 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14586 int imm = inst.operands[2].imm;
627907b7 14587
cb3b1e65
JB
14588 constraint (imm < 0 || (unsigned)imm >= et.size,
14589 _("immediate out of range for shift"));
88714cb8 14590 NEON_ENCODE (IMMED, inst);
cb3b1e65 14591 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14592 }
14593 else
14594 {
037e8744 14595 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14596 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14597 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14598 unsigned int tmp;
14599
14600 /* See note in do_neon_shl_imm. */
14601 tmp = inst.operands[2].reg;
14602 inst.operands[2].reg = inst.operands[1].reg;
14603 inst.operands[1].reg = tmp;
88714cb8 14604 NEON_ENCODE (INTEGER, inst);
037e8744 14605 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14606 }
14607}
14608
627907b7
JB
14609static void
14610do_neon_rshl (void)
14611{
14612 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14613 struct neon_type_el et = neon_check_type (3, rs,
14614 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14615 unsigned int tmp;
14616
14617 tmp = inst.operands[2].reg;
14618 inst.operands[2].reg = inst.operands[1].reg;
14619 inst.operands[1].reg = tmp;
14620 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14621}
14622
5287ad62
JB
14623static int
14624neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14625{
036dc3f7
PB
14626 /* Handle .I8 pseudo-instructions. */
14627 if (size == 8)
5287ad62 14628 {
5287ad62 14629 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14630 FIXME is this the intended semantics? There doesn't seem much point in
14631 accepting .I8 if so. */
5287ad62
JB
14632 immediate |= immediate << 8;
14633 size = 16;
036dc3f7
PB
14634 }
14635
14636 if (size >= 32)
14637 {
14638 if (immediate == (immediate & 0x000000ff))
14639 {
14640 *immbits = immediate;
14641 return 0x1;
14642 }
14643 else if (immediate == (immediate & 0x0000ff00))
14644 {
14645 *immbits = immediate >> 8;
14646 return 0x3;
14647 }
14648 else if (immediate == (immediate & 0x00ff0000))
14649 {
14650 *immbits = immediate >> 16;
14651 return 0x5;
14652 }
14653 else if (immediate == (immediate & 0xff000000))
14654 {
14655 *immbits = immediate >> 24;
14656 return 0x7;
14657 }
14658 if ((immediate & 0xffff) != (immediate >> 16))
14659 goto bad_immediate;
14660 immediate &= 0xffff;
5287ad62
JB
14661 }
14662
14663 if (immediate == (immediate & 0x000000ff))
14664 {
14665 *immbits = immediate;
036dc3f7 14666 return 0x9;
5287ad62
JB
14667 }
14668 else if (immediate == (immediate & 0x0000ff00))
14669 {
14670 *immbits = immediate >> 8;
036dc3f7 14671 return 0xb;
5287ad62
JB
14672 }
14673
14674 bad_immediate:
dcbf9037 14675 first_error (_("immediate value out of range"));
5287ad62
JB
14676 return FAIL;
14677}
14678
5287ad62
JB
14679static void
14680do_neon_logic (void)
14681{
14682 if (inst.operands[2].present && inst.operands[2].isreg)
14683 {
037e8744 14684 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14685 neon_check_type (3, rs, N_IGNORE_TYPE);
14686 /* U bit and size field were set as part of the bitmask. */
88714cb8 14687 NEON_ENCODE (INTEGER, inst);
037e8744 14688 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14689 }
14690 else
14691 {
4316f0d2
DG
14692 const int three_ops_form = (inst.operands[2].present
14693 && !inst.operands[2].isreg);
14694 const int immoperand = (three_ops_form ? 2 : 1);
14695 enum neon_shape rs = (three_ops_form
14696 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14697 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14698 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14699 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14700 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14701 unsigned immbits;
14702 int cmode;
5f4273c7 14703
5287ad62 14704 if (et.type == NT_invtype)
477330fc 14705 return;
5f4273c7 14706
4316f0d2
DG
14707 if (three_ops_form)
14708 constraint (inst.operands[0].reg != inst.operands[1].reg,
14709 _("first and second operands shall be the same register"));
14710
88714cb8 14711 NEON_ENCODE (IMMED, inst);
5287ad62 14712
4316f0d2 14713 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14714 if (et.size == 64)
14715 {
14716 /* .i64 is a pseudo-op, so the immediate must be a repeating
14717 pattern. */
4316f0d2
DG
14718 if (immbits != (inst.operands[immoperand].regisimm ?
14719 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14720 {
14721 /* Set immbits to an invalid constant. */
14722 immbits = 0xdeadbeef;
14723 }
14724 }
14725
5287ad62 14726 switch (opcode)
477330fc
RM
14727 {
14728 case N_MNEM_vbic:
14729 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14730 break;
14731
14732 case N_MNEM_vorr:
14733 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14734 break;
14735
14736 case N_MNEM_vand:
14737 /* Pseudo-instruction for VBIC. */
14738 neon_invert_size (&immbits, 0, et.size);
14739 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14740 break;
14741
14742 case N_MNEM_vorn:
14743 /* Pseudo-instruction for VORR. */
14744 neon_invert_size (&immbits, 0, et.size);
14745 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14746 break;
14747
14748 default:
14749 abort ();
14750 }
5287ad62
JB
14751
14752 if (cmode == FAIL)
477330fc 14753 return;
5287ad62 14754
037e8744 14755 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14756 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14757 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14758 inst.instruction |= cmode << 8;
14759 neon_write_immbits (immbits);
5f4273c7 14760
88714cb8 14761 neon_dp_fixup (&inst);
5287ad62
JB
14762 }
14763}
14764
14765static void
14766do_neon_bitfield (void)
14767{
037e8744 14768 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14769 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14770 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14771}
14772
14773static void
dcbf9037 14774neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14775 unsigned destbits)
5287ad62 14776{
037e8744 14777 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14778 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14779 types | N_KEY);
5287ad62
JB
14780 if (et.type == NT_float)
14781 {
88714cb8 14782 NEON_ENCODE (FLOAT, inst);
cc933301 14783 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
14784 }
14785 else
14786 {
88714cb8 14787 NEON_ENCODE (INTEGER, inst);
037e8744 14788 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14789 }
14790}
14791
14792static void
14793do_neon_dyadic_if_su (void)
14794{
dcbf9037 14795 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14796}
14797
14798static void
14799do_neon_dyadic_if_su_d (void)
14800{
14801 /* This version only allow D registers, but that constraint is enforced during
14802 operand parsing so we don't need to do anything extra here. */
dcbf9037 14803 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14804}
14805
5287ad62
JB
14806static void
14807do_neon_dyadic_if_i_d (void)
14808{
428e3f1f
PB
14809 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14810 affected if we specify unsigned args. */
14811 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14812}
14813
037e8744
JB
14814enum vfp_or_neon_is_neon_bits
14815{
14816 NEON_CHECK_CC = 1,
73924fbc
MGD
14817 NEON_CHECK_ARCH = 2,
14818 NEON_CHECK_ARCH8 = 4
037e8744
JB
14819};
14820
14821/* Call this function if an instruction which may have belonged to the VFP or
14822 Neon instruction sets, but turned out to be a Neon instruction (due to the
14823 operand types involved, etc.). We have to check and/or fix-up a couple of
14824 things:
14825
14826 - Make sure the user hasn't attempted to make a Neon instruction
14827 conditional.
14828 - Alter the value in the condition code field if necessary.
14829 - Make sure that the arch supports Neon instructions.
14830
14831 Which of these operations take place depends on bits from enum
14832 vfp_or_neon_is_neon_bits.
14833
14834 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14835 current instruction's condition is COND_ALWAYS, the condition field is
14836 changed to inst.uncond_value. This is necessary because instructions shared
14837 between VFP and Neon may be conditional for the VFP variants only, and the
14838 unconditional Neon version must have, e.g., 0xF in the condition field. */
14839
14840static int
14841vfp_or_neon_is_neon (unsigned check)
14842{
14843 /* Conditions are always legal in Thumb mode (IT blocks). */
14844 if (!thumb_mode && (check & NEON_CHECK_CC))
14845 {
14846 if (inst.cond != COND_ALWAYS)
477330fc
RM
14847 {
14848 first_error (_(BAD_COND));
14849 return FAIL;
14850 }
037e8744 14851 if (inst.uncond_value != -1)
477330fc 14852 inst.instruction |= inst.uncond_value << 28;
037e8744 14853 }
5f4273c7 14854
037e8744 14855 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14856 && !mark_feature_used (&fpu_neon_ext_v1))
14857 {
14858 first_error (_(BAD_FPU));
14859 return FAIL;
14860 }
14861
14862 if ((check & NEON_CHECK_ARCH8)
14863 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
14864 {
14865 first_error (_(BAD_FPU));
14866 return FAIL;
14867 }
5f4273c7 14868
037e8744
JB
14869 return SUCCESS;
14870}
14871
5287ad62
JB
14872static void
14873do_neon_addsub_if_i (void)
14874{
037e8744
JB
14875 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14876 return;
14877
14878 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14879 return;
14880
5287ad62
JB
14881 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14882 affected if we specify unsigned args. */
dcbf9037 14883 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
14884}
14885
14886/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14887 result to be:
14888 V<op> A,B (A is operand 0, B is operand 2)
14889 to mean:
14890 V<op> A,B,A
14891 not:
14892 V<op> A,B,B
14893 so handle that case specially. */
14894
14895static void
14896neon_exchange_operands (void)
14897{
5287ad62
JB
14898 if (inst.operands[1].present)
14899 {
e1fa0163
NC
14900 void *scratch = xmalloc (sizeof (inst.operands[0]));
14901
5287ad62
JB
14902 /* Swap operands[1] and operands[2]. */
14903 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14904 inst.operands[1] = inst.operands[2];
14905 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 14906 free (scratch);
5287ad62
JB
14907 }
14908 else
14909 {
14910 inst.operands[1] = inst.operands[2];
14911 inst.operands[2] = inst.operands[0];
14912 }
14913}
14914
14915static void
14916neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14917{
14918 if (inst.operands[2].isreg)
14919 {
14920 if (invert)
477330fc 14921 neon_exchange_operands ();
dcbf9037 14922 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
14923 }
14924 else
14925 {
037e8744 14926 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 14927 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14928 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 14929
88714cb8 14930 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14931 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14932 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14933 inst.instruction |= LOW4 (inst.operands[1].reg);
14934 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14935 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14936 inst.instruction |= (et.type == NT_float) << 10;
14937 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14938
88714cb8 14939 neon_dp_fixup (&inst);
5287ad62
JB
14940 }
14941}
14942
14943static void
14944do_neon_cmp (void)
14945{
cc933301 14946 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
14947}
14948
14949static void
14950do_neon_cmp_inv (void)
14951{
cc933301 14952 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
14953}
14954
14955static void
14956do_neon_ceq (void)
14957{
14958 neon_compare (N_IF_32, N_IF_32, FALSE);
14959}
14960
14961/* For multiply instructions, we have the possibility of 16-bit or 32-bit
14962 scalars, which are encoded in 5 bits, M : Rm.
14963 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
14964 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
14965 index in M. */
14966
14967static unsigned
14968neon_scalar_for_mul (unsigned scalar, unsigned elsize)
14969{
dcbf9037
JB
14970 unsigned regno = NEON_SCALAR_REG (scalar);
14971 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
14972
14973 switch (elsize)
14974 {
14975 case 16:
14976 if (regno > 7 || elno > 3)
477330fc 14977 goto bad_scalar;
5287ad62 14978 return regno | (elno << 3);
5f4273c7 14979
5287ad62
JB
14980 case 32:
14981 if (regno > 15 || elno > 1)
477330fc 14982 goto bad_scalar;
5287ad62
JB
14983 return regno | (elno << 4);
14984
14985 default:
14986 bad_scalar:
dcbf9037 14987 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
14988 }
14989
14990 return 0;
14991}
14992
14993/* Encode multiply / multiply-accumulate scalar instructions. */
14994
14995static void
14996neon_mul_mac (struct neon_type_el et, int ubit)
14997{
dcbf9037
JB
14998 unsigned scalar;
14999
15000 /* Give a more helpful error message if we have an invalid type. */
15001 if (et.type == NT_invtype)
15002 return;
5f4273c7 15003
dcbf9037 15004 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
15005 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15006 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15007 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15008 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15009 inst.instruction |= LOW4 (scalar);
15010 inst.instruction |= HI1 (scalar) << 5;
15011 inst.instruction |= (et.type == NT_float) << 8;
15012 inst.instruction |= neon_logbits (et.size) << 20;
15013 inst.instruction |= (ubit != 0) << 24;
15014
88714cb8 15015 neon_dp_fixup (&inst);
5287ad62
JB
15016}
15017
15018static void
15019do_neon_mac_maybe_scalar (void)
15020{
037e8744
JB
15021 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
15022 return;
15023
15024 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15025 return;
15026
5287ad62
JB
15027 if (inst.operands[2].isscalar)
15028 {
037e8744 15029 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15030 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 15031 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 15032 NEON_ENCODE (SCALAR, inst);
037e8744 15033 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15034 }
15035 else
428e3f1f
PB
15036 {
15037 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15038 affected if we specify unsigned args. */
15039 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15040 }
5287ad62
JB
15041}
15042
62f3b8c8
PB
15043static void
15044do_neon_fmac (void)
15045{
15046 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15047 return;
15048
15049 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15050 return;
15051
15052 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15053}
15054
5287ad62
JB
15055static void
15056do_neon_tst (void)
15057{
037e8744 15058 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15059 struct neon_type_el et = neon_check_type (3, rs,
15060 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 15061 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15062}
15063
15064/* VMUL with 3 registers allows the P8 type. The scalar version supports the
15065 same types as the MAC equivalents. The polynomial type for this instruction
15066 is encoded the same as the integer type. */
15067
15068static void
15069do_neon_mul (void)
15070{
037e8744
JB
15071 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
15072 return;
15073
15074 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15075 return;
15076
5287ad62
JB
15077 if (inst.operands[2].isscalar)
15078 do_neon_mac_maybe_scalar ();
15079 else
cc933301 15080 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
5287ad62
JB
15081}
15082
15083static void
15084do_neon_qdmulh (void)
15085{
15086 if (inst.operands[2].isscalar)
15087 {
037e8744 15088 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15089 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15090 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15091 NEON_ENCODE (SCALAR, inst);
037e8744 15092 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15093 }
15094 else
15095 {
037e8744 15096 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15097 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15098 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15099 NEON_ENCODE (INTEGER, inst);
5287ad62 15100 /* The U bit (rounding) comes from bit mask. */
037e8744 15101 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15102 }
15103}
15104
643afb90
MW
15105static void
15106do_neon_qrdmlah (void)
15107{
15108 /* Check we're on the correct architecture. */
15109 if (!mark_feature_used (&fpu_neon_ext_armv8))
15110 inst.error =
15111 _("instruction form not available on this architecture.");
15112 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15113 {
15114 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15115 record_feature_use (&fpu_neon_ext_v8_1);
15116 }
15117
15118 if (inst.operands[2].isscalar)
15119 {
15120 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15121 struct neon_type_el et = neon_check_type (3, rs,
15122 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15123 NEON_ENCODE (SCALAR, inst);
15124 neon_mul_mac (et, neon_quad (rs));
15125 }
15126 else
15127 {
15128 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15129 struct neon_type_el et = neon_check_type (3, rs,
15130 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15131 NEON_ENCODE (INTEGER, inst);
15132 /* The U bit (rounding) comes from bit mask. */
15133 neon_three_same (neon_quad (rs), 0, et.size);
15134 }
15135}
15136
5287ad62
JB
15137static void
15138do_neon_fcmp_absolute (void)
15139{
037e8744 15140 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15141 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15142 N_F_16_32 | N_KEY);
5287ad62 15143 /* Size field comes from bit mask. */
cc933301 15144 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15145}
15146
15147static void
15148do_neon_fcmp_absolute_inv (void)
15149{
15150 neon_exchange_operands ();
15151 do_neon_fcmp_absolute ();
15152}
15153
15154static void
15155do_neon_step (void)
15156{
037e8744 15157 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15158 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15159 N_F_16_32 | N_KEY);
15160 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15161}
15162
15163static void
15164do_neon_abs_neg (void)
15165{
037e8744
JB
15166 enum neon_shape rs;
15167 struct neon_type_el et;
5f4273c7 15168
037e8744
JB
15169 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15170 return;
15171
15172 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15173 return;
15174
15175 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 15176 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 15177
5287ad62
JB
15178 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15179 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15180 inst.instruction |= LOW4 (inst.operands[1].reg);
15181 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15182 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15183 inst.instruction |= (et.type == NT_float) << 10;
15184 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15185
88714cb8 15186 neon_dp_fixup (&inst);
5287ad62
JB
15187}
15188
15189static void
15190do_neon_sli (void)
15191{
037e8744 15192 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15193 struct neon_type_el et = neon_check_type (2, rs,
15194 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15195 int imm = inst.operands[2].imm;
15196 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15197 _("immediate out of range for insert"));
037e8744 15198 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15199}
15200
15201static void
15202do_neon_sri (void)
15203{
037e8744 15204 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15205 struct neon_type_el et = neon_check_type (2, rs,
15206 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15207 int imm = inst.operands[2].imm;
15208 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15209 _("immediate out of range for insert"));
037e8744 15210 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15211}
15212
15213static void
15214do_neon_qshlu_imm (void)
15215{
037e8744 15216 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15217 struct neon_type_el et = neon_check_type (2, rs,
15218 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15219 int imm = inst.operands[2].imm;
15220 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15221 _("immediate out of range for shift"));
5287ad62
JB
15222 /* Only encodes the 'U present' variant of the instruction.
15223 In this case, signed types have OP (bit 8) set to 0.
15224 Unsigned types have OP set to 1. */
15225 inst.instruction |= (et.type == NT_unsigned) << 8;
15226 /* The rest of the bits are the same as other immediate shifts. */
037e8744 15227 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15228}
15229
15230static void
15231do_neon_qmovn (void)
15232{
15233 struct neon_type_el et = neon_check_type (2, NS_DQ,
15234 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15235 /* Saturating move where operands can be signed or unsigned, and the
15236 destination has the same signedness. */
88714cb8 15237 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15238 if (et.type == NT_unsigned)
15239 inst.instruction |= 0xc0;
15240 else
15241 inst.instruction |= 0x80;
15242 neon_two_same (0, 1, et.size / 2);
15243}
15244
15245static void
15246do_neon_qmovun (void)
15247{
15248 struct neon_type_el et = neon_check_type (2, NS_DQ,
15249 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15250 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 15251 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15252 neon_two_same (0, 1, et.size / 2);
15253}
15254
15255static void
15256do_neon_rshift_sat_narrow (void)
15257{
15258 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15259 or unsigned. If operands are unsigned, results must also be unsigned. */
15260 struct neon_type_el et = neon_check_type (2, NS_DQI,
15261 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15262 int imm = inst.operands[2].imm;
15263 /* This gets the bounds check, size encoding and immediate bits calculation
15264 right. */
15265 et.size /= 2;
5f4273c7 15266
5287ad62
JB
15267 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15268 VQMOVN.I<size> <Dd>, <Qm>. */
15269 if (imm == 0)
15270 {
15271 inst.operands[2].present = 0;
15272 inst.instruction = N_MNEM_vqmovn;
15273 do_neon_qmovn ();
15274 return;
15275 }
5f4273c7 15276
5287ad62 15277 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15278 _("immediate out of range"));
5287ad62
JB
15279 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15280}
15281
15282static void
15283do_neon_rshift_sat_narrow_u (void)
15284{
15285 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15286 or unsigned. If operands are unsigned, results must also be unsigned. */
15287 struct neon_type_el et = neon_check_type (2, NS_DQI,
15288 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15289 int imm = inst.operands[2].imm;
15290 /* This gets the bounds check, size encoding and immediate bits calculation
15291 right. */
15292 et.size /= 2;
15293
15294 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15295 VQMOVUN.I<size> <Dd>, <Qm>. */
15296 if (imm == 0)
15297 {
15298 inst.operands[2].present = 0;
15299 inst.instruction = N_MNEM_vqmovun;
15300 do_neon_qmovun ();
15301 return;
15302 }
15303
15304 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15305 _("immediate out of range"));
5287ad62
JB
15306 /* FIXME: The manual is kind of unclear about what value U should have in
15307 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15308 must be 1. */
15309 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15310}
15311
15312static void
15313do_neon_movn (void)
15314{
15315 struct neon_type_el et = neon_check_type (2, NS_DQ,
15316 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15317 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15318 neon_two_same (0, 1, et.size / 2);
15319}
15320
15321static void
15322do_neon_rshift_narrow (void)
15323{
15324 struct neon_type_el et = neon_check_type (2, NS_DQI,
15325 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15326 int imm = inst.operands[2].imm;
15327 /* This gets the bounds check, size encoding and immediate bits calculation
15328 right. */
15329 et.size /= 2;
5f4273c7 15330
5287ad62
JB
15331 /* If immediate is zero then we are a pseudo-instruction for
15332 VMOVN.I<size> <Dd>, <Qm> */
15333 if (imm == 0)
15334 {
15335 inst.operands[2].present = 0;
15336 inst.instruction = N_MNEM_vmovn;
15337 do_neon_movn ();
15338 return;
15339 }
5f4273c7 15340
5287ad62 15341 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15342 _("immediate out of range for narrowing operation"));
5287ad62
JB
15343 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15344}
15345
15346static void
15347do_neon_shll (void)
15348{
15349 /* FIXME: Type checking when lengthening. */
15350 struct neon_type_el et = neon_check_type (2, NS_QDI,
15351 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15352 unsigned imm = inst.operands[2].imm;
15353
15354 if (imm == et.size)
15355 {
15356 /* Maximum shift variant. */
88714cb8 15357 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15358 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15359 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15360 inst.instruction |= LOW4 (inst.operands[1].reg);
15361 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15362 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15363
88714cb8 15364 neon_dp_fixup (&inst);
5287ad62
JB
15365 }
15366 else
15367 {
15368 /* A more-specific type check for non-max versions. */
15369 et = neon_check_type (2, NS_QDI,
477330fc 15370 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15371 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15372 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15373 }
15374}
15375
037e8744 15376/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15377 the current instruction is. */
15378
6b9a8b67
MGD
15379#define CVT_FLAVOUR_VAR \
15380 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15381 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15382 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15383 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15384 /* Half-precision conversions. */ \
cc933301
JW
15385 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15386 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15387 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
15388 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
15389 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15390 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
15391 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15392 Compared with single/double precision variants, only the co-processor \
15393 field is different, so the encoding flow is reused here. */ \
15394 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15395 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15396 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15397 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
15398 /* VFP instructions. */ \
15399 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15400 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15401 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15402 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15403 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15404 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15405 /* VFP instructions with bitshift. */ \
15406 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15407 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15408 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15409 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15410 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15411 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15412 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15413 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15414
15415#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15416 neon_cvt_flavour_##C,
15417
15418/* The different types of conversions we can do. */
15419enum neon_cvt_flavour
15420{
15421 CVT_FLAVOUR_VAR
15422 neon_cvt_flavour_invalid,
15423 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15424};
15425
15426#undef CVT_VAR
15427
15428static enum neon_cvt_flavour
15429get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15430{
6b9a8b67
MGD
15431#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15432 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15433 if (et.type != NT_invtype) \
15434 { \
15435 inst.error = NULL; \
15436 return (neon_cvt_flavour_##C); \
5287ad62 15437 }
6b9a8b67 15438
5287ad62 15439 struct neon_type_el et;
037e8744 15440 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15441 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15442 /* The instruction versions which take an immediate take one register
15443 argument, which is extended to the width of the full register. Thus the
15444 "source" and "destination" registers must have the same width. Hack that
15445 here by making the size equal to the key (wider, in this case) operand. */
15446 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15447
6b9a8b67
MGD
15448 CVT_FLAVOUR_VAR;
15449
15450 return neon_cvt_flavour_invalid;
5287ad62
JB
15451#undef CVT_VAR
15452}
15453
7e8e6784
MGD
15454enum neon_cvt_mode
15455{
15456 neon_cvt_mode_a,
15457 neon_cvt_mode_n,
15458 neon_cvt_mode_p,
15459 neon_cvt_mode_m,
15460 neon_cvt_mode_z,
30bdf752
MGD
15461 neon_cvt_mode_x,
15462 neon_cvt_mode_r
7e8e6784
MGD
15463};
15464
037e8744
JB
15465/* Neon-syntax VFP conversions. */
15466
5287ad62 15467static void
6b9a8b67 15468do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15469{
037e8744 15470 const char *opname = 0;
5f4273c7 15471
d54af2d0
RL
15472 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15473 || rs == NS_FHI || rs == NS_HFI)
5287ad62 15474 {
037e8744
JB
15475 /* Conversions with immediate bitshift. */
15476 const char *enc[] =
477330fc 15477 {
6b9a8b67
MGD
15478#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15479 CVT_FLAVOUR_VAR
15480 NULL
15481#undef CVT_VAR
477330fc 15482 };
037e8744 15483
6b9a8b67 15484 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15485 {
15486 opname = enc[flavour];
15487 constraint (inst.operands[0].reg != inst.operands[1].reg,
15488 _("operands 0 and 1 must be the same register"));
15489 inst.operands[1] = inst.operands[2];
15490 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15491 }
5287ad62
JB
15492 }
15493 else
15494 {
037e8744
JB
15495 /* Conversions without bitshift. */
15496 const char *enc[] =
477330fc 15497 {
6b9a8b67
MGD
15498#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15499 CVT_FLAVOUR_VAR
15500 NULL
15501#undef CVT_VAR
477330fc 15502 };
037e8744 15503
6b9a8b67 15504 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15505 opname = enc[flavour];
037e8744
JB
15506 }
15507
15508 if (opname)
15509 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
15510
15511 /* ARMv8.2 fp16 VCVT instruction. */
15512 if (flavour == neon_cvt_flavour_s32_f16
15513 || flavour == neon_cvt_flavour_u32_f16
15514 || flavour == neon_cvt_flavour_f16_u32
15515 || flavour == neon_cvt_flavour_f16_s32)
15516 do_scalar_fp16_v82_encode ();
037e8744
JB
15517}
15518
15519static void
15520do_vfp_nsyn_cvtz (void)
15521{
d54af2d0 15522 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 15523 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15524 const char *enc[] =
15525 {
6b9a8b67
MGD
15526#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15527 CVT_FLAVOUR_VAR
15528 NULL
15529#undef CVT_VAR
037e8744
JB
15530 };
15531
6b9a8b67 15532 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15533 do_vfp_nsyn_opcode (enc[flavour]);
15534}
f31fef98 15535
037e8744 15536static void
bacebabc 15537do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15538 enum neon_cvt_mode mode)
15539{
15540 int sz, op;
15541 int rm;
15542
a715796b
TG
15543 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15544 D register operands. */
15545 if (flavour == neon_cvt_flavour_s32_f64
15546 || flavour == neon_cvt_flavour_u32_f64)
15547 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15548 _(BAD_FPU));
15549
9db2f6b4
RL
15550 if (flavour == neon_cvt_flavour_s32_f16
15551 || flavour == neon_cvt_flavour_u32_f16)
15552 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15553 _(BAD_FP16));
15554
7e8e6784
MGD
15555 set_it_insn_type (OUTSIDE_IT_INSN);
15556
15557 switch (flavour)
15558 {
15559 case neon_cvt_flavour_s32_f64:
15560 sz = 1;
827f64ff 15561 op = 1;
7e8e6784
MGD
15562 break;
15563 case neon_cvt_flavour_s32_f32:
15564 sz = 0;
15565 op = 1;
15566 break;
9db2f6b4
RL
15567 case neon_cvt_flavour_s32_f16:
15568 sz = 0;
15569 op = 1;
15570 break;
7e8e6784
MGD
15571 case neon_cvt_flavour_u32_f64:
15572 sz = 1;
15573 op = 0;
15574 break;
15575 case neon_cvt_flavour_u32_f32:
15576 sz = 0;
15577 op = 0;
15578 break;
9db2f6b4
RL
15579 case neon_cvt_flavour_u32_f16:
15580 sz = 0;
15581 op = 0;
15582 break;
7e8e6784
MGD
15583 default:
15584 first_error (_("invalid instruction shape"));
15585 return;
15586 }
15587
15588 switch (mode)
15589 {
15590 case neon_cvt_mode_a: rm = 0; break;
15591 case neon_cvt_mode_n: rm = 1; break;
15592 case neon_cvt_mode_p: rm = 2; break;
15593 case neon_cvt_mode_m: rm = 3; break;
15594 default: first_error (_("invalid rounding mode")); return;
15595 }
15596
15597 NEON_ENCODE (FPV8, inst);
15598 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15599 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15600 inst.instruction |= sz << 8;
9db2f6b4
RL
15601
15602 /* ARMv8.2 fp16 VCVT instruction. */
15603 if (flavour == neon_cvt_flavour_s32_f16
15604 ||flavour == neon_cvt_flavour_u32_f16)
15605 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
15606 inst.instruction |= op << 7;
15607 inst.instruction |= rm << 16;
15608 inst.instruction |= 0xf0000000;
15609 inst.is_neon = TRUE;
15610}
15611
15612static void
15613do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15614{
15615 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
15616 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
15617 NS_FH, NS_HF, NS_FHI, NS_HFI,
15618 NS_NULL);
6b9a8b67 15619 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15620
cc933301
JW
15621 if (flavour == neon_cvt_flavour_invalid)
15622 return;
15623
e3e535bc 15624 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15625 if (mode == neon_cvt_mode_z
e3e535bc 15626 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
15627 && (flavour == neon_cvt_flavour_s16_f16
15628 || flavour == neon_cvt_flavour_u16_f16
15629 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
15630 || flavour == neon_cvt_flavour_u32_f32
15631 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15632 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15633 && (rs == NS_FD || rs == NS_FF))
15634 {
15635 do_vfp_nsyn_cvtz ();
15636 return;
15637 }
15638
9db2f6b4
RL
15639 /* ARMv8.2 fp16 VCVT conversions. */
15640 if (mode == neon_cvt_mode_z
15641 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
15642 && (flavour == neon_cvt_flavour_s32_f16
15643 || flavour == neon_cvt_flavour_u32_f16)
15644 && (rs == NS_FH))
15645 {
15646 do_vfp_nsyn_cvtz ();
15647 do_scalar_fp16_v82_encode ();
15648 return;
15649 }
15650
037e8744 15651 /* VFP rather than Neon conversions. */
6b9a8b67 15652 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15653 {
7e8e6784
MGD
15654 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15655 do_vfp_nsyn_cvt (rs, flavour);
15656 else
15657 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15658
037e8744
JB
15659 return;
15660 }
15661
15662 switch (rs)
15663 {
15664 case NS_DDI:
15665 case NS_QQI:
15666 {
477330fc 15667 unsigned immbits;
cc933301
JW
15668 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
15669 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 15670
477330fc
RM
15671 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15672 return;
037e8744 15673
477330fc
RM
15674 /* Fixed-point conversion with #0 immediate is encoded as an
15675 integer conversion. */
15676 if (inst.operands[2].present && inst.operands[2].imm == 0)
15677 goto int_encode;
477330fc
RM
15678 NEON_ENCODE (IMMED, inst);
15679 if (flavour != neon_cvt_flavour_invalid)
15680 inst.instruction |= enctab[flavour];
15681 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15682 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15683 inst.instruction |= LOW4 (inst.operands[1].reg);
15684 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15685 inst.instruction |= neon_quad (rs) << 6;
15686 inst.instruction |= 1 << 21;
cc933301
JW
15687 if (flavour < neon_cvt_flavour_s16_f16)
15688 {
15689 inst.instruction |= 1 << 21;
15690 immbits = 32 - inst.operands[2].imm;
15691 inst.instruction |= immbits << 16;
15692 }
15693 else
15694 {
15695 inst.instruction |= 3 << 20;
15696 immbits = 16 - inst.operands[2].imm;
15697 inst.instruction |= immbits << 16;
15698 inst.instruction &= ~(1 << 9);
15699 }
477330fc
RM
15700
15701 neon_dp_fixup (&inst);
037e8744
JB
15702 }
15703 break;
15704
15705 case NS_DD:
15706 case NS_QQ:
7e8e6784
MGD
15707 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15708 {
15709 NEON_ENCODE (FLOAT, inst);
15710 set_it_insn_type (OUTSIDE_IT_INSN);
15711
15712 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15713 return;
15714
15715 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15716 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15717 inst.instruction |= LOW4 (inst.operands[1].reg);
15718 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15719 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15720 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
15721 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 15722 inst.instruction |= mode << 8;
cc933301
JW
15723 if (flavour == neon_cvt_flavour_u16_f16
15724 || flavour == neon_cvt_flavour_s16_f16)
15725 /* Mask off the original size bits and reencode them. */
15726 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
15727
7e8e6784
MGD
15728 if (thumb_mode)
15729 inst.instruction |= 0xfc000000;
15730 else
15731 inst.instruction |= 0xf0000000;
15732 }
15733 else
15734 {
037e8744 15735 int_encode:
7e8e6784 15736 {
cc933301
JW
15737 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
15738 0x100, 0x180, 0x0, 0x080};
037e8744 15739
7e8e6784 15740 NEON_ENCODE (INTEGER, inst);
037e8744 15741
7e8e6784
MGD
15742 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15743 return;
037e8744 15744
7e8e6784
MGD
15745 if (flavour != neon_cvt_flavour_invalid)
15746 inst.instruction |= enctab[flavour];
037e8744 15747
7e8e6784
MGD
15748 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15749 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15750 inst.instruction |= LOW4 (inst.operands[1].reg);
15751 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15752 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15753 if (flavour >= neon_cvt_flavour_s16_f16
15754 && flavour <= neon_cvt_flavour_f16_u16)
15755 /* Half precision. */
15756 inst.instruction |= 1 << 18;
15757 else
15758 inst.instruction |= 2 << 18;
037e8744 15759
7e8e6784
MGD
15760 neon_dp_fixup (&inst);
15761 }
15762 }
15763 break;
037e8744 15764
8e79c3df
CM
15765 /* Half-precision conversions for Advanced SIMD -- neon. */
15766 case NS_QD:
15767 case NS_DQ:
15768
15769 if ((rs == NS_DQ)
15770 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15771 {
15772 as_bad (_("operand size must match register width"));
15773 break;
15774 }
15775
15776 if ((rs == NS_QD)
15777 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15778 {
15779 as_bad (_("operand size must match register width"));
15780 break;
15781 }
15782
15783 if (rs == NS_DQ)
477330fc 15784 inst.instruction = 0x3b60600;
8e79c3df
CM
15785 else
15786 inst.instruction = 0x3b60700;
15787
15788 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15789 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15790 inst.instruction |= LOW4 (inst.operands[1].reg);
15791 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15792 neon_dp_fixup (&inst);
8e79c3df
CM
15793 break;
15794
037e8744
JB
15795 default:
15796 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15797 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15798 do_vfp_nsyn_cvt (rs, flavour);
15799 else
15800 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15801 }
5287ad62
JB
15802}
15803
e3e535bc
NC
15804static void
15805do_neon_cvtr (void)
15806{
7e8e6784 15807 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15808}
15809
15810static void
15811do_neon_cvt (void)
15812{
7e8e6784
MGD
15813 do_neon_cvt_1 (neon_cvt_mode_z);
15814}
15815
15816static void
15817do_neon_cvta (void)
15818{
15819 do_neon_cvt_1 (neon_cvt_mode_a);
15820}
15821
15822static void
15823do_neon_cvtn (void)
15824{
15825 do_neon_cvt_1 (neon_cvt_mode_n);
15826}
15827
15828static void
15829do_neon_cvtp (void)
15830{
15831 do_neon_cvt_1 (neon_cvt_mode_p);
15832}
15833
15834static void
15835do_neon_cvtm (void)
15836{
15837 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15838}
15839
8e79c3df 15840static void
c70a8987 15841do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15842{
c70a8987
MGD
15843 if (is_double)
15844 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15845
c70a8987
MGD
15846 encode_arm_vfp_reg (inst.operands[0].reg,
15847 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15848 encode_arm_vfp_reg (inst.operands[1].reg,
15849 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15850 inst.instruction |= to ? 0x10000 : 0;
15851 inst.instruction |= t ? 0x80 : 0;
15852 inst.instruction |= is_double ? 0x100 : 0;
15853 do_vfp_cond_or_thumb ();
15854}
8e79c3df 15855
c70a8987
MGD
15856static void
15857do_neon_cvttb_1 (bfd_boolean t)
15858{
d54af2d0
RL
15859 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
15860 NS_DF, NS_DH, NS_NULL);
8e79c3df 15861
c70a8987
MGD
15862 if (rs == NS_NULL)
15863 return;
15864 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
15865 {
15866 inst.error = NULL;
15867 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
15868 }
15869 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
15870 {
15871 inst.error = NULL;
15872 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
15873 }
15874 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
15875 {
a715796b
TG
15876 /* The VCVTB and VCVTT instructions with D-register operands
15877 don't work for SP only targets. */
15878 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15879 _(BAD_FPU));
15880
c70a8987
MGD
15881 inst.error = NULL;
15882 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
15883 }
15884 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
15885 {
a715796b
TG
15886 /* The VCVTB and VCVTT instructions with D-register operands
15887 don't work for SP only targets. */
15888 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15889 _(BAD_FPU));
15890
c70a8987
MGD
15891 inst.error = NULL;
15892 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
15893 }
15894 else
15895 return;
15896}
15897
15898static void
15899do_neon_cvtb (void)
15900{
15901 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
15902}
15903
15904
15905static void
15906do_neon_cvtt (void)
15907{
c70a8987 15908 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
15909}
15910
5287ad62
JB
15911static void
15912neon_move_immediate (void)
15913{
037e8744
JB
15914 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
15915 struct neon_type_el et = neon_check_type (2, rs,
15916 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 15917 unsigned immlo, immhi = 0, immbits;
c96612cc 15918 int op, cmode, float_p;
5287ad62 15919
037e8744 15920 constraint (et.type == NT_invtype,
477330fc 15921 _("operand size must be specified for immediate VMOV"));
037e8744 15922
5287ad62
JB
15923 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
15924 op = (inst.instruction & (1 << 5)) != 0;
15925
15926 immlo = inst.operands[1].imm;
15927 if (inst.operands[1].regisimm)
15928 immhi = inst.operands[1].reg;
15929
15930 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 15931 _("immediate has bits set outside the operand size"));
5287ad62 15932
c96612cc
JB
15933 float_p = inst.operands[1].immisfloat;
15934
15935 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 15936 et.size, et.type)) == FAIL)
5287ad62
JB
15937 {
15938 /* Invert relevant bits only. */
15939 neon_invert_size (&immlo, &immhi, et.size);
15940 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
15941 with one or the other; those cases are caught by
15942 neon_cmode_for_move_imm. */
5287ad62 15943 op = !op;
c96612cc
JB
15944 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
15945 &op, et.size, et.type)) == FAIL)
477330fc
RM
15946 {
15947 first_error (_("immediate out of range"));
15948 return;
15949 }
5287ad62
JB
15950 }
15951
15952 inst.instruction &= ~(1 << 5);
15953 inst.instruction |= op << 5;
15954
15955 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15956 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 15957 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15958 inst.instruction |= cmode << 8;
15959
15960 neon_write_immbits (immbits);
15961}
15962
15963static void
15964do_neon_mvn (void)
15965{
15966 if (inst.operands[1].isreg)
15967 {
037e8744 15968 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 15969
88714cb8 15970 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15971 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15972 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15973 inst.instruction |= LOW4 (inst.operands[1].reg);
15974 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15975 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15976 }
15977 else
15978 {
88714cb8 15979 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15980 neon_move_immediate ();
15981 }
15982
88714cb8 15983 neon_dp_fixup (&inst);
5287ad62
JB
15984}
15985
15986/* Encode instructions of form:
15987
15988 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 15989 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
15990
15991static void
15992neon_mixed_length (struct neon_type_el et, unsigned size)
15993{
15994 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15995 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15996 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15997 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15998 inst.instruction |= LOW4 (inst.operands[2].reg);
15999 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16000 inst.instruction |= (et.type == NT_unsigned) << 24;
16001 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16002
88714cb8 16003 neon_dp_fixup (&inst);
5287ad62
JB
16004}
16005
16006static void
16007do_neon_dyadic_long (void)
16008{
16009 /* FIXME: Type checking for lengthening op. */
16010 struct neon_type_el et = neon_check_type (3, NS_QDD,
16011 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
16012 neon_mixed_length (et, et.size);
16013}
16014
16015static void
16016do_neon_abal (void)
16017{
16018 struct neon_type_el et = neon_check_type (3, NS_QDD,
16019 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16020 neon_mixed_length (et, et.size);
16021}
16022
16023static void
16024neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16025{
16026 if (inst.operands[2].isscalar)
16027 {
dcbf9037 16028 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 16029 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 16030 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16031 neon_mul_mac (et, et.type == NT_unsigned);
16032 }
16033 else
16034 {
16035 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16036 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 16037 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16038 neon_mixed_length (et, et.size);
16039 }
16040}
16041
16042static void
16043do_neon_mac_maybe_scalar_long (void)
16044{
16045 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16046}
16047
16048static void
16049do_neon_dyadic_wide (void)
16050{
16051 struct neon_type_el et = neon_check_type (3, NS_QQD,
16052 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
16053 neon_mixed_length (et, et.size);
16054}
16055
16056static void
16057do_neon_dyadic_narrow (void)
16058{
16059 struct neon_type_el et = neon_check_type (3, NS_QDD,
16060 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
16061 /* Operand sign is unimportant, and the U bit is part of the opcode,
16062 so force the operand type to integer. */
16063 et.type = NT_integer;
5287ad62
JB
16064 neon_mixed_length (et, et.size / 2);
16065}
16066
16067static void
16068do_neon_mul_sat_scalar_long (void)
16069{
16070 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
16071}
16072
16073static void
16074do_neon_vmull (void)
16075{
16076 if (inst.operands[2].isscalar)
16077 do_neon_mac_maybe_scalar_long ();
16078 else
16079 {
16080 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16081 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 16082
5287ad62 16083 if (et.type == NT_poly)
477330fc 16084 NEON_ENCODE (POLY, inst);
5287ad62 16085 else
477330fc 16086 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
16087
16088 /* For polynomial encoding the U bit must be zero, and the size must
16089 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
16090 obviously, as 0b10). */
16091 if (et.size == 64)
16092 {
16093 /* Check we're on the correct architecture. */
16094 if (!mark_feature_used (&fpu_crypto_ext_armv8))
16095 inst.error =
16096 _("Instruction form not available on this architecture.");
16097
16098 et.size = 32;
16099 }
16100
5287ad62
JB
16101 neon_mixed_length (et, et.size);
16102 }
16103}
16104
16105static void
16106do_neon_ext (void)
16107{
037e8744 16108 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
16109 struct neon_type_el et = neon_check_type (3, rs,
16110 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16111 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
16112
16113 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
16114 _("shift out of range"));
5287ad62
JB
16115 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16116 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16117 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16118 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16119 inst.instruction |= LOW4 (inst.operands[2].reg);
16120 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 16121 inst.instruction |= neon_quad (rs) << 6;
5287ad62 16122 inst.instruction |= imm << 8;
5f4273c7 16123
88714cb8 16124 neon_dp_fixup (&inst);
5287ad62
JB
16125}
16126
16127static void
16128do_neon_rev (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,
16132 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16133 unsigned op = (inst.instruction >> 7) & 3;
16134 /* N (width of reversed regions) is encoded as part of the bitmask. We
16135 extract it here to check the elements to be reversed are smaller.
16136 Otherwise we'd get a reserved instruction. */
16137 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 16138 gas_assert (elsize != 0);
5287ad62 16139 constraint (et.size >= elsize,
477330fc 16140 _("elements must be smaller than reversal region"));
037e8744 16141 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16142}
16143
16144static void
16145do_neon_dup (void)
16146{
16147 if (inst.operands[1].isscalar)
16148 {
037e8744 16149 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 16150 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16151 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 16152 unsigned sizebits = et.size >> 3;
dcbf9037 16153 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 16154 int logsize = neon_logbits (et.size);
dcbf9037 16155 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
16156
16157 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 16158 return;
037e8744 16159
88714cb8 16160 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16161 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16162 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16163 inst.instruction |= LOW4 (dm);
16164 inst.instruction |= HI1 (dm) << 5;
037e8744 16165 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16166 inst.instruction |= x << 17;
16167 inst.instruction |= sizebits << 16;
5f4273c7 16168
88714cb8 16169 neon_dp_fixup (&inst);
5287ad62
JB
16170 }
16171 else
16172 {
037e8744
JB
16173 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16174 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16175 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 16176 /* Duplicate ARM register to lanes of vector. */
88714cb8 16177 NEON_ENCODE (ARMREG, inst);
5287ad62 16178 switch (et.size)
477330fc
RM
16179 {
16180 case 8: inst.instruction |= 0x400000; break;
16181 case 16: inst.instruction |= 0x000020; break;
16182 case 32: inst.instruction |= 0x000000; break;
16183 default: break;
16184 }
5287ad62
JB
16185 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16186 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16187 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 16188 inst.instruction |= neon_quad (rs) << 21;
5287ad62 16189 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 16190 variants, except for the condition field. */
037e8744 16191 do_vfp_cond_or_thumb ();
5287ad62
JB
16192 }
16193}
16194
16195/* VMOV has particularly many variations. It can be one of:
16196 0. VMOV<c><q> <Qd>, <Qm>
16197 1. VMOV<c><q> <Dd>, <Dm>
16198 (Register operations, which are VORR with Rm = Rn.)
16199 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16200 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16201 (Immediate loads.)
16202 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16203 (ARM register to scalar.)
16204 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16205 (Two ARM registers to vector.)
16206 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16207 (Scalar to ARM register.)
16208 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16209 (Vector to two ARM registers.)
037e8744
JB
16210 8. VMOV.F32 <Sd>, <Sm>
16211 9. VMOV.F64 <Dd>, <Dm>
16212 (VFP register moves.)
16213 10. VMOV.F32 <Sd>, #imm
16214 11. VMOV.F64 <Dd>, #imm
16215 (VFP float immediate load.)
16216 12. VMOV <Rd>, <Sm>
16217 (VFP single to ARM reg.)
16218 13. VMOV <Sd>, <Rm>
16219 (ARM reg to VFP single.)
16220 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16221 (Two ARM regs to two VFP singles.)
16222 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16223 (Two VFP singles to two ARM regs.)
5f4273c7 16224
037e8744
JB
16225 These cases can be disambiguated using neon_select_shape, except cases 1/9
16226 and 3/11 which depend on the operand type too.
5f4273c7 16227
5287ad62 16228 All the encoded bits are hardcoded by this function.
5f4273c7 16229
b7fc2769
JB
16230 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16231 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 16232
5287ad62 16233 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 16234 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
16235
16236static void
16237do_neon_mov (void)
16238{
037e8744 16239 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
16240 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16241 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16242 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
16243 struct neon_type_el et;
16244 const char *ldconst = 0;
5287ad62 16245
037e8744 16246 switch (rs)
5287ad62 16247 {
037e8744
JB
16248 case NS_DD: /* case 1/9. */
16249 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16250 /* It is not an error here if no type is given. */
16251 inst.error = NULL;
16252 if (et.type == NT_float && et.size == 64)
477330fc
RM
16253 {
16254 do_vfp_nsyn_opcode ("fcpyd");
16255 break;
16256 }
037e8744 16257 /* fall through. */
5287ad62 16258
037e8744
JB
16259 case NS_QQ: /* case 0/1. */
16260 {
477330fc
RM
16261 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16262 return;
16263 /* The architecture manual I have doesn't explicitly state which
16264 value the U bit should have for register->register moves, but
16265 the equivalent VORR instruction has U = 0, so do that. */
16266 inst.instruction = 0x0200110;
16267 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16268 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16269 inst.instruction |= LOW4 (inst.operands[1].reg);
16270 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16271 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16272 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16273 inst.instruction |= neon_quad (rs) << 6;
16274
16275 neon_dp_fixup (&inst);
037e8744
JB
16276 }
16277 break;
5f4273c7 16278
037e8744
JB
16279 case NS_DI: /* case 3/11. */
16280 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16281 inst.error = NULL;
16282 if (et.type == NT_float && et.size == 64)
477330fc
RM
16283 {
16284 /* case 11 (fconstd). */
16285 ldconst = "fconstd";
16286 goto encode_fconstd;
16287 }
037e8744
JB
16288 /* fall through. */
16289
16290 case NS_QI: /* case 2/3. */
16291 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 16292 return;
037e8744
JB
16293 inst.instruction = 0x0800010;
16294 neon_move_immediate ();
88714cb8 16295 neon_dp_fixup (&inst);
5287ad62 16296 break;
5f4273c7 16297
037e8744
JB
16298 case NS_SR: /* case 4. */
16299 {
477330fc
RM
16300 unsigned bcdebits = 0;
16301 int logsize;
16302 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16303 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 16304
05ac0ffb
JB
16305 /* .<size> is optional here, defaulting to .32. */
16306 if (inst.vectype.elems == 0
16307 && inst.operands[0].vectype.type == NT_invtype
16308 && inst.operands[1].vectype.type == NT_invtype)
16309 {
16310 inst.vectype.el[0].type = NT_untyped;
16311 inst.vectype.el[0].size = 32;
16312 inst.vectype.elems = 1;
16313 }
16314
477330fc
RM
16315 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16316 logsize = neon_logbits (et.size);
16317
16318 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16319 _(BAD_FPU));
16320 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16321 && et.size != 32, _(BAD_FPU));
16322 constraint (et.type == NT_invtype, _("bad type for scalar"));
16323 constraint (x >= 64 / et.size, _("scalar index out of range"));
16324
16325 switch (et.size)
16326 {
16327 case 8: bcdebits = 0x8; break;
16328 case 16: bcdebits = 0x1; break;
16329 case 32: bcdebits = 0x0; break;
16330 default: ;
16331 }
16332
16333 bcdebits |= x << logsize;
16334
16335 inst.instruction = 0xe000b10;
16336 do_vfp_cond_or_thumb ();
16337 inst.instruction |= LOW4 (dn) << 16;
16338 inst.instruction |= HI1 (dn) << 7;
16339 inst.instruction |= inst.operands[1].reg << 12;
16340 inst.instruction |= (bcdebits & 3) << 5;
16341 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
16342 }
16343 break;
5f4273c7 16344
037e8744 16345 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 16346 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16347 _(BAD_FPU));
b7fc2769 16348
037e8744
JB
16349 inst.instruction = 0xc400b10;
16350 do_vfp_cond_or_thumb ();
16351 inst.instruction |= LOW4 (inst.operands[0].reg);
16352 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16353 inst.instruction |= inst.operands[1].reg << 12;
16354 inst.instruction |= inst.operands[2].reg << 16;
16355 break;
5f4273c7 16356
037e8744
JB
16357 case NS_RS: /* case 6. */
16358 {
477330fc
RM
16359 unsigned logsize;
16360 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16361 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16362 unsigned abcdebits = 0;
037e8744 16363
05ac0ffb
JB
16364 /* .<dt> is optional here, defaulting to .32. */
16365 if (inst.vectype.elems == 0
16366 && inst.operands[0].vectype.type == NT_invtype
16367 && inst.operands[1].vectype.type == NT_invtype)
16368 {
16369 inst.vectype.el[0].type = NT_untyped;
16370 inst.vectype.el[0].size = 32;
16371 inst.vectype.elems = 1;
16372 }
16373
91d6fa6a
NC
16374 et = neon_check_type (2, NS_NULL,
16375 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
16376 logsize = neon_logbits (et.size);
16377
16378 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16379 _(BAD_FPU));
16380 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16381 && et.size != 32, _(BAD_FPU));
16382 constraint (et.type == NT_invtype, _("bad type for scalar"));
16383 constraint (x >= 64 / et.size, _("scalar index out of range"));
16384
16385 switch (et.size)
16386 {
16387 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16388 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16389 case 32: abcdebits = 0x00; break;
16390 default: ;
16391 }
16392
16393 abcdebits |= x << logsize;
16394 inst.instruction = 0xe100b10;
16395 do_vfp_cond_or_thumb ();
16396 inst.instruction |= LOW4 (dn) << 16;
16397 inst.instruction |= HI1 (dn) << 7;
16398 inst.instruction |= inst.operands[0].reg << 12;
16399 inst.instruction |= (abcdebits & 3) << 5;
16400 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16401 }
16402 break;
5f4273c7 16403
037e8744
JB
16404 case NS_RRD: /* case 7 (fmrrd). */
16405 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16406 _(BAD_FPU));
037e8744
JB
16407
16408 inst.instruction = 0xc500b10;
16409 do_vfp_cond_or_thumb ();
16410 inst.instruction |= inst.operands[0].reg << 12;
16411 inst.instruction |= inst.operands[1].reg << 16;
16412 inst.instruction |= LOW4 (inst.operands[2].reg);
16413 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16414 break;
5f4273c7 16415
037e8744
JB
16416 case NS_FF: /* case 8 (fcpys). */
16417 do_vfp_nsyn_opcode ("fcpys");
16418 break;
5f4273c7 16419
9db2f6b4 16420 case NS_HI:
037e8744
JB
16421 case NS_FI: /* case 10 (fconsts). */
16422 ldconst = "fconsts";
16423 encode_fconstd:
16424 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16425 {
16426 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16427 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
16428
16429 /* ARMv8.2 fp16 vmov.f16 instruction. */
16430 if (rs == NS_HI)
16431 do_scalar_fp16_v82_encode ();
477330fc 16432 }
5287ad62 16433 else
477330fc 16434 first_error (_("immediate out of range"));
037e8744 16435 break;
5f4273c7 16436
9db2f6b4 16437 case NS_RH:
037e8744
JB
16438 case NS_RF: /* case 12 (fmrs). */
16439 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
16440 /* ARMv8.2 fp16 vmov.f16 instruction. */
16441 if (rs == NS_RH)
16442 do_scalar_fp16_v82_encode ();
037e8744 16443 break;
5f4273c7 16444
9db2f6b4 16445 case NS_HR:
037e8744
JB
16446 case NS_FR: /* case 13 (fmsr). */
16447 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
16448 /* ARMv8.2 fp16 vmov.f16 instruction. */
16449 if (rs == NS_HR)
16450 do_scalar_fp16_v82_encode ();
037e8744 16451 break;
5f4273c7 16452
037e8744
JB
16453 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16454 (one of which is a list), but we have parsed four. Do some fiddling to
16455 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16456 expect. */
16457 case NS_RRFF: /* case 14 (fmrrs). */
16458 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16459 _("VFP registers must be adjacent"));
037e8744
JB
16460 inst.operands[2].imm = 2;
16461 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16462 do_vfp_nsyn_opcode ("fmrrs");
16463 break;
5f4273c7 16464
037e8744
JB
16465 case NS_FFRR: /* case 15 (fmsrr). */
16466 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16467 _("VFP registers must be adjacent"));
037e8744
JB
16468 inst.operands[1] = inst.operands[2];
16469 inst.operands[2] = inst.operands[3];
16470 inst.operands[0].imm = 2;
16471 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16472 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16473 break;
5f4273c7 16474
4c261dff
NC
16475 case NS_NULL:
16476 /* neon_select_shape has determined that the instruction
16477 shape is wrong and has already set the error message. */
16478 break;
16479
5287ad62
JB
16480 default:
16481 abort ();
16482 }
16483}
16484
16485static void
16486do_neon_rshift_round_imm (void)
16487{
037e8744 16488 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16489 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16490 int imm = inst.operands[2].imm;
16491
16492 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16493 if (imm == 0)
16494 {
16495 inst.operands[2].present = 0;
16496 do_neon_mov ();
16497 return;
16498 }
16499
16500 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16501 _("immediate out of range for shift"));
037e8744 16502 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16503 et.size - imm);
5287ad62
JB
16504}
16505
9db2f6b4
RL
16506static void
16507do_neon_movhf (void)
16508{
16509 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
16510 constraint (rs != NS_HH, _("invalid suffix"));
16511
16512 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16513 _(BAD_FPU));
16514
16515 do_vfp_sp_monadic ();
16516
16517 inst.is_neon = 1;
16518 inst.instruction |= 0xf0000000;
16519}
16520
5287ad62
JB
16521static void
16522do_neon_movl (void)
16523{
16524 struct neon_type_el et = neon_check_type (2, NS_QD,
16525 N_EQK | N_DBL, N_SU_32 | N_KEY);
16526 unsigned sizebits = et.size >> 3;
16527 inst.instruction |= sizebits << 19;
16528 neon_two_same (0, et.type == NT_unsigned, -1);
16529}
16530
16531static void
16532do_neon_trn (void)
16533{
037e8744 16534 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16535 struct neon_type_el et = neon_check_type (2, rs,
16536 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16537 NEON_ENCODE (INTEGER, inst);
037e8744 16538 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16539}
16540
16541static void
16542do_neon_zip_uzp (void)
16543{
037e8744 16544 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16545 struct neon_type_el et = neon_check_type (2, rs,
16546 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16547 if (rs == NS_DD && et.size == 32)
16548 {
16549 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16550 inst.instruction = N_MNEM_vtrn;
16551 do_neon_trn ();
16552 return;
16553 }
037e8744 16554 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16555}
16556
16557static void
16558do_neon_sat_abs_neg (void)
16559{
037e8744 16560 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16561 struct neon_type_el et = neon_check_type (2, rs,
16562 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16563 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16564}
16565
16566static void
16567do_neon_pair_long (void)
16568{
037e8744 16569 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16570 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16571 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16572 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16573 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16574}
16575
16576static void
16577do_neon_recip_est (void)
16578{
037e8744 16579 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 16580 struct neon_type_el et = neon_check_type (2, rs,
cc933301 16581 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 16582 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16583 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16584}
16585
16586static void
16587do_neon_cls (void)
16588{
037e8744 16589 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16590 struct neon_type_el et = neon_check_type (2, rs,
16591 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16592 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16593}
16594
16595static void
16596do_neon_clz (void)
16597{
037e8744 16598 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16599 struct neon_type_el et = neon_check_type (2, rs,
16600 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16601 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16602}
16603
16604static void
16605do_neon_cnt (void)
16606{
037e8744 16607 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16608 struct neon_type_el et = neon_check_type (2, rs,
16609 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16610 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16611}
16612
16613static void
16614do_neon_swp (void)
16615{
037e8744
JB
16616 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16617 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16618}
16619
16620static void
16621do_neon_tbl_tbx (void)
16622{
16623 unsigned listlenbits;
dcbf9037 16624 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16625
5287ad62
JB
16626 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16627 {
dcbf9037 16628 first_error (_("bad list length for table lookup"));
5287ad62
JB
16629 return;
16630 }
5f4273c7 16631
5287ad62
JB
16632 listlenbits = inst.operands[1].imm - 1;
16633 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16634 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16635 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16636 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16637 inst.instruction |= LOW4 (inst.operands[2].reg);
16638 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16639 inst.instruction |= listlenbits << 8;
5f4273c7 16640
88714cb8 16641 neon_dp_fixup (&inst);
5287ad62
JB
16642}
16643
16644static void
16645do_neon_ldm_stm (void)
16646{
16647 /* P, U and L bits are part of bitmask. */
16648 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16649 unsigned offsetbits = inst.operands[1].imm * 2;
16650
037e8744
JB
16651 if (inst.operands[1].issingle)
16652 {
16653 do_vfp_nsyn_ldm_stm (is_dbmode);
16654 return;
16655 }
16656
5287ad62 16657 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16658 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16659
16660 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16661 _("register list must contain at least 1 and at most 16 "
16662 "registers"));
5287ad62
JB
16663
16664 inst.instruction |= inst.operands[0].reg << 16;
16665 inst.instruction |= inst.operands[0].writeback << 21;
16666 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16667 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16668
16669 inst.instruction |= offsetbits;
5f4273c7 16670
037e8744 16671 do_vfp_cond_or_thumb ();
5287ad62
JB
16672}
16673
16674static void
16675do_neon_ldr_str (void)
16676{
5287ad62 16677 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16678
6844b2c2
MGD
16679 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16680 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16681 if (!is_ldr
6844b2c2 16682 && inst.operands[1].reg == REG_PC
ba86b375 16683 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16684 {
94dcf8bf 16685 if (thumb_mode)
6844b2c2 16686 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 16687 else if (warn_on_deprecated)
5c3696f8 16688 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
16689 }
16690
037e8744
JB
16691 if (inst.operands[0].issingle)
16692 {
cd2f129f 16693 if (is_ldr)
477330fc 16694 do_vfp_nsyn_opcode ("flds");
cd2f129f 16695 else
477330fc 16696 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
16697
16698 /* ARMv8.2 vldr.16/vstr.16 instruction. */
16699 if (inst.vectype.el[0].size == 16)
16700 do_scalar_fp16_v82_encode ();
5287ad62
JB
16701 }
16702 else
5287ad62 16703 {
cd2f129f 16704 if (is_ldr)
477330fc 16705 do_vfp_nsyn_opcode ("fldd");
5287ad62 16706 else
477330fc 16707 do_vfp_nsyn_opcode ("fstd");
5287ad62 16708 }
5287ad62
JB
16709}
16710
16711/* "interleave" version also handles non-interleaving register VLD1/VST1
16712 instructions. */
16713
16714static void
16715do_neon_ld_st_interleave (void)
16716{
037e8744 16717 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 16718 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
16719 unsigned alignbits = 0;
16720 unsigned idx;
16721 /* The bits in this table go:
16722 0: register stride of one (0) or two (1)
16723 1,2: register list length, minus one (1, 2, 3, 4).
16724 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
16725 We use -1 for invalid entries. */
16726 const int typetable[] =
16727 {
16728 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
16729 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
16730 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
16731 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
16732 };
16733 int typebits;
16734
dcbf9037
JB
16735 if (et.type == NT_invtype)
16736 return;
16737
5287ad62
JB
16738 if (inst.operands[1].immisalign)
16739 switch (inst.operands[1].imm >> 8)
16740 {
16741 case 64: alignbits = 1; break;
16742 case 128:
477330fc 16743 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 16744 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
16745 goto bad_alignment;
16746 alignbits = 2;
16747 break;
5287ad62 16748 case 256:
477330fc
RM
16749 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
16750 goto bad_alignment;
16751 alignbits = 3;
16752 break;
5287ad62
JB
16753 default:
16754 bad_alignment:
477330fc
RM
16755 first_error (_("bad alignment"));
16756 return;
5287ad62
JB
16757 }
16758
16759 inst.instruction |= alignbits << 4;
16760 inst.instruction |= neon_logbits (et.size) << 6;
16761
16762 /* Bits [4:6] of the immediate in a list specifier encode register stride
16763 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
16764 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
16765 up the right value for "type" in a table based on this value and the given
16766 list style, then stick it back. */
16767 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 16768 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
16769
16770 typebits = typetable[idx];
5f4273c7 16771
5287ad62 16772 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
16773 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
16774 _("bad element type for instruction"));
5287ad62
JB
16775
16776 inst.instruction &= ~0xf00;
16777 inst.instruction |= typebits << 8;
16778}
16779
16780/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
16781 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
16782 otherwise. The variable arguments are a list of pairs of legal (size, align)
16783 values, terminated with -1. */
16784
16785static int
aa8a0863 16786neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
16787{
16788 va_list ap;
16789 int result = FAIL, thissize, thisalign;
5f4273c7 16790
5287ad62
JB
16791 if (!inst.operands[1].immisalign)
16792 {
aa8a0863 16793 *do_alignment = 0;
5287ad62
JB
16794 return SUCCESS;
16795 }
5f4273c7 16796
aa8a0863 16797 va_start (ap, do_alignment);
5287ad62
JB
16798
16799 do
16800 {
16801 thissize = va_arg (ap, int);
16802 if (thissize == -1)
477330fc 16803 break;
5287ad62
JB
16804 thisalign = va_arg (ap, int);
16805
16806 if (size == thissize && align == thisalign)
477330fc 16807 result = SUCCESS;
5287ad62
JB
16808 }
16809 while (result != SUCCESS);
16810
16811 va_end (ap);
16812
16813 if (result == SUCCESS)
aa8a0863 16814 *do_alignment = 1;
5287ad62 16815 else
dcbf9037 16816 first_error (_("unsupported alignment for instruction"));
5f4273c7 16817
5287ad62
JB
16818 return result;
16819}
16820
16821static void
16822do_neon_ld_st_lane (void)
16823{
037e8744 16824 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16825 int align_good, do_alignment = 0;
5287ad62
JB
16826 int logsize = neon_logbits (et.size);
16827 int align = inst.operands[1].imm >> 8;
16828 int n = (inst.instruction >> 8) & 3;
16829 int max_el = 64 / et.size;
5f4273c7 16830
dcbf9037
JB
16831 if (et.type == NT_invtype)
16832 return;
5f4273c7 16833
5287ad62 16834 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 16835 _("bad list length"));
5287ad62 16836 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 16837 _("scalar index out of range"));
5287ad62 16838 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
16839 && et.size == 8,
16840 _("stride of 2 unavailable when element size is 8"));
5f4273c7 16841
5287ad62
JB
16842 switch (n)
16843 {
16844 case 0: /* VLD1 / VST1. */
aa8a0863 16845 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 16846 32, 32, -1);
5287ad62 16847 if (align_good == FAIL)
477330fc 16848 return;
aa8a0863 16849 if (do_alignment)
477330fc
RM
16850 {
16851 unsigned alignbits = 0;
16852 switch (et.size)
16853 {
16854 case 16: alignbits = 0x1; break;
16855 case 32: alignbits = 0x3; break;
16856 default: ;
16857 }
16858 inst.instruction |= alignbits << 4;
16859 }
5287ad62
JB
16860 break;
16861
16862 case 1: /* VLD2 / VST2. */
aa8a0863
TS
16863 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
16864 16, 32, 32, 64, -1);
5287ad62 16865 if (align_good == FAIL)
477330fc 16866 return;
aa8a0863 16867 if (do_alignment)
477330fc 16868 inst.instruction |= 1 << 4;
5287ad62
JB
16869 break;
16870
16871 case 2: /* VLD3 / VST3. */
16872 constraint (inst.operands[1].immisalign,
477330fc 16873 _("can't use alignment with this instruction"));
5287ad62
JB
16874 break;
16875
16876 case 3: /* VLD4 / VST4. */
aa8a0863 16877 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 16878 16, 64, 32, 64, 32, 128, -1);
5287ad62 16879 if (align_good == FAIL)
477330fc 16880 return;
aa8a0863 16881 if (do_alignment)
477330fc
RM
16882 {
16883 unsigned alignbits = 0;
16884 switch (et.size)
16885 {
16886 case 8: alignbits = 0x1; break;
16887 case 16: alignbits = 0x1; break;
16888 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
16889 default: ;
16890 }
16891 inst.instruction |= alignbits << 4;
16892 }
5287ad62
JB
16893 break;
16894
16895 default: ;
16896 }
16897
16898 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
16899 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16900 inst.instruction |= 1 << (4 + logsize);
5f4273c7 16901
5287ad62
JB
16902 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
16903 inst.instruction |= logsize << 10;
16904}
16905
16906/* Encode single n-element structure to all lanes VLD<n> instructions. */
16907
16908static void
16909do_neon_ld_dup (void)
16910{
037e8744 16911 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16912 int align_good, do_alignment = 0;
5287ad62 16913
dcbf9037
JB
16914 if (et.type == NT_invtype)
16915 return;
16916
5287ad62
JB
16917 switch ((inst.instruction >> 8) & 3)
16918 {
16919 case 0: /* VLD1. */
9c2799c2 16920 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 16921 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 16922 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 16923 if (align_good == FAIL)
477330fc 16924 return;
5287ad62 16925 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
16926 {
16927 case 1: break;
16928 case 2: inst.instruction |= 1 << 5; break;
16929 default: first_error (_("bad list length")); return;
16930 }
5287ad62
JB
16931 inst.instruction |= neon_logbits (et.size) << 6;
16932 break;
16933
16934 case 1: /* VLD2. */
16935 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
16936 &do_alignment, 8, 16, 16, 32, 32, 64,
16937 -1);
5287ad62 16938 if (align_good == FAIL)
477330fc 16939 return;
5287ad62 16940 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 16941 _("bad list length"));
5287ad62 16942 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16943 inst.instruction |= 1 << 5;
5287ad62
JB
16944 inst.instruction |= neon_logbits (et.size) << 6;
16945 break;
16946
16947 case 2: /* VLD3. */
16948 constraint (inst.operands[1].immisalign,
477330fc 16949 _("can't use alignment with this instruction"));
5287ad62 16950 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 16951 _("bad list length"));
5287ad62 16952 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16953 inst.instruction |= 1 << 5;
5287ad62
JB
16954 inst.instruction |= neon_logbits (et.size) << 6;
16955 break;
16956
16957 case 3: /* VLD4. */
16958 {
477330fc 16959 int align = inst.operands[1].imm >> 8;
aa8a0863 16960 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
16961 16, 64, 32, 64, 32, 128, -1);
16962 if (align_good == FAIL)
16963 return;
16964 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
16965 _("bad list length"));
16966 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16967 inst.instruction |= 1 << 5;
16968 if (et.size == 32 && align == 128)
16969 inst.instruction |= 0x3 << 6;
16970 else
16971 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
16972 }
16973 break;
16974
16975 default: ;
16976 }
16977
aa8a0863 16978 inst.instruction |= do_alignment << 4;
5287ad62
JB
16979}
16980
16981/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
16982 apart from bits [11:4]. */
16983
16984static void
16985do_neon_ldx_stx (void)
16986{
b1a769ed
DG
16987 if (inst.operands[1].isreg)
16988 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16989
5287ad62
JB
16990 switch (NEON_LANE (inst.operands[0].imm))
16991 {
16992 case NEON_INTERLEAVE_LANES:
88714cb8 16993 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
16994 do_neon_ld_st_interleave ();
16995 break;
5f4273c7 16996
5287ad62 16997 case NEON_ALL_LANES:
88714cb8 16998 NEON_ENCODE (DUP, inst);
2d51fb74
JB
16999 if (inst.instruction == N_INV)
17000 {
17001 first_error ("only loads support such operands");
17002 break;
17003 }
5287ad62
JB
17004 do_neon_ld_dup ();
17005 break;
5f4273c7 17006
5287ad62 17007 default:
88714cb8 17008 NEON_ENCODE (LANE, inst);
5287ad62
JB
17009 do_neon_ld_st_lane ();
17010 }
17011
17012 /* L bit comes from bit mask. */
17013 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17014 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17015 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 17016
5287ad62
JB
17017 if (inst.operands[1].postind)
17018 {
17019 int postreg = inst.operands[1].imm & 0xf;
17020 constraint (!inst.operands[1].immisreg,
477330fc 17021 _("post-index must be a register"));
5287ad62 17022 constraint (postreg == 0xd || postreg == 0xf,
477330fc 17023 _("bad register for post-index"));
5287ad62
JB
17024 inst.instruction |= postreg;
17025 }
4f2374c7 17026 else
5287ad62 17027 {
4f2374c7
WN
17028 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17029 constraint (inst.reloc.exp.X_op != O_constant
17030 || inst.reloc.exp.X_add_number != 0,
17031 BAD_ADDR_MODE);
17032
17033 if (inst.operands[1].writeback)
17034 {
17035 inst.instruction |= 0xd;
17036 }
17037 else
17038 inst.instruction |= 0xf;
5287ad62 17039 }
5f4273c7 17040
5287ad62
JB
17041 if (thumb_mode)
17042 inst.instruction |= 0xf9000000;
17043 else
17044 inst.instruction |= 0xf4000000;
17045}
33399f07
MGD
17046
17047/* FP v8. */
17048static void
17049do_vfp_nsyn_fpv8 (enum neon_shape rs)
17050{
a715796b
TG
17051 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17052 D register operands. */
17053 if (neon_shape_class[rs] == SC_DOUBLE)
17054 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17055 _(BAD_FPU));
17056
33399f07
MGD
17057 NEON_ENCODE (FPV8, inst);
17058
9db2f6b4
RL
17059 if (rs == NS_FFF || rs == NS_HHH)
17060 {
17061 do_vfp_sp_dyadic ();
17062
17063 /* ARMv8.2 fp16 instruction. */
17064 if (rs == NS_HHH)
17065 do_scalar_fp16_v82_encode ();
17066 }
33399f07
MGD
17067 else
17068 do_vfp_dp_rd_rn_rm ();
17069
17070 if (rs == NS_DDD)
17071 inst.instruction |= 0x100;
17072
17073 inst.instruction |= 0xf0000000;
17074}
17075
17076static void
17077do_vsel (void)
17078{
17079 set_it_insn_type (OUTSIDE_IT_INSN);
17080
17081 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
17082 first_error (_("invalid instruction shape"));
17083}
17084
73924fbc
MGD
17085static void
17086do_vmaxnm (void)
17087{
17088 set_it_insn_type (OUTSIDE_IT_INSN);
17089
17090 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
17091 return;
17092
17093 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17094 return;
17095
cc933301 17096 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
17097}
17098
30bdf752
MGD
17099static void
17100do_vrint_1 (enum neon_cvt_mode mode)
17101{
9db2f6b4 17102 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
17103 struct neon_type_el et;
17104
17105 if (rs == NS_NULL)
17106 return;
17107
a715796b
TG
17108 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17109 D register operands. */
17110 if (neon_shape_class[rs] == SC_DOUBLE)
17111 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17112 _(BAD_FPU));
17113
9db2f6b4
RL
17114 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
17115 | N_VFP);
30bdf752
MGD
17116 if (et.type != NT_invtype)
17117 {
17118 /* VFP encodings. */
17119 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
17120 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
17121 set_it_insn_type (OUTSIDE_IT_INSN);
17122
17123 NEON_ENCODE (FPV8, inst);
9db2f6b4 17124 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
17125 do_vfp_sp_monadic ();
17126 else
17127 do_vfp_dp_rd_rm ();
17128
17129 switch (mode)
17130 {
17131 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
17132 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
17133 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
17134 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
17135 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
17136 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
17137 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
17138 default: abort ();
17139 }
17140
17141 inst.instruction |= (rs == NS_DD) << 8;
17142 do_vfp_cond_or_thumb ();
9db2f6b4
RL
17143
17144 /* ARMv8.2 fp16 vrint instruction. */
17145 if (rs == NS_HH)
17146 do_scalar_fp16_v82_encode ();
30bdf752
MGD
17147 }
17148 else
17149 {
17150 /* Neon encodings (or something broken...). */
17151 inst.error = NULL;
cc933301 17152 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
17153
17154 if (et.type == NT_invtype)
17155 return;
17156
17157 set_it_insn_type (OUTSIDE_IT_INSN);
17158 NEON_ENCODE (FLOAT, inst);
17159
17160 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17161 return;
17162
17163 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17164 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17165 inst.instruction |= LOW4 (inst.operands[1].reg);
17166 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17167 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
17168 /* Mask off the original size bits and reencode them. */
17169 inst.instruction = ((inst.instruction & 0xfff3ffff)
17170 | neon_logbits (et.size) << 18);
17171
30bdf752
MGD
17172 switch (mode)
17173 {
17174 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17175 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17176 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17177 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17178 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17179 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17180 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17181 default: abort ();
17182 }
17183
17184 if (thumb_mode)
17185 inst.instruction |= 0xfc000000;
17186 else
17187 inst.instruction |= 0xf0000000;
17188 }
17189}
17190
17191static void
17192do_vrintx (void)
17193{
17194 do_vrint_1 (neon_cvt_mode_x);
17195}
17196
17197static void
17198do_vrintz (void)
17199{
17200 do_vrint_1 (neon_cvt_mode_z);
17201}
17202
17203static void
17204do_vrintr (void)
17205{
17206 do_vrint_1 (neon_cvt_mode_r);
17207}
17208
17209static void
17210do_vrinta (void)
17211{
17212 do_vrint_1 (neon_cvt_mode_a);
17213}
17214
17215static void
17216do_vrintn (void)
17217{
17218 do_vrint_1 (neon_cvt_mode_n);
17219}
17220
17221static void
17222do_vrintp (void)
17223{
17224 do_vrint_1 (neon_cvt_mode_p);
17225}
17226
17227static void
17228do_vrintm (void)
17229{
17230 do_vrint_1 (neon_cvt_mode_m);
17231}
17232
91ff7894
MGD
17233/* Crypto v1 instructions. */
17234static void
17235do_crypto_2op_1 (unsigned elttype, int op)
17236{
17237 set_it_insn_type (OUTSIDE_IT_INSN);
17238
17239 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17240 == NT_invtype)
17241 return;
17242
17243 inst.error = NULL;
17244
17245 NEON_ENCODE (INTEGER, inst);
17246 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17247 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17248 inst.instruction |= LOW4 (inst.operands[1].reg);
17249 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17250 if (op != -1)
17251 inst.instruction |= op << 6;
17252
17253 if (thumb_mode)
17254 inst.instruction |= 0xfc000000;
17255 else
17256 inst.instruction |= 0xf0000000;
17257}
17258
48adcd8e
MGD
17259static void
17260do_crypto_3op_1 (int u, int op)
17261{
17262 set_it_insn_type (OUTSIDE_IT_INSN);
17263
17264 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17265 N_32 | N_UNT | N_KEY).type == NT_invtype)
17266 return;
17267
17268 inst.error = NULL;
17269
17270 NEON_ENCODE (INTEGER, inst);
17271 neon_three_same (1, u, 8 << op);
17272}
17273
91ff7894
MGD
17274static void
17275do_aese (void)
17276{
17277 do_crypto_2op_1 (N_8, 0);
17278}
17279
17280static void
17281do_aesd (void)
17282{
17283 do_crypto_2op_1 (N_8, 1);
17284}
17285
17286static void
17287do_aesmc (void)
17288{
17289 do_crypto_2op_1 (N_8, 2);
17290}
17291
17292static void
17293do_aesimc (void)
17294{
17295 do_crypto_2op_1 (N_8, 3);
17296}
17297
48adcd8e
MGD
17298static void
17299do_sha1c (void)
17300{
17301 do_crypto_3op_1 (0, 0);
17302}
17303
17304static void
17305do_sha1p (void)
17306{
17307 do_crypto_3op_1 (0, 1);
17308}
17309
17310static void
17311do_sha1m (void)
17312{
17313 do_crypto_3op_1 (0, 2);
17314}
17315
17316static void
17317do_sha1su0 (void)
17318{
17319 do_crypto_3op_1 (0, 3);
17320}
91ff7894 17321
48adcd8e
MGD
17322static void
17323do_sha256h (void)
17324{
17325 do_crypto_3op_1 (1, 0);
17326}
17327
17328static void
17329do_sha256h2 (void)
17330{
17331 do_crypto_3op_1 (1, 1);
17332}
17333
17334static void
17335do_sha256su1 (void)
17336{
17337 do_crypto_3op_1 (1, 2);
17338}
3c9017d2
MGD
17339
17340static void
17341do_sha1h (void)
17342{
17343 do_crypto_2op_1 (N_32, -1);
17344}
17345
17346static void
17347do_sha1su1 (void)
17348{
17349 do_crypto_2op_1 (N_32, 0);
17350}
17351
17352static void
17353do_sha256su0 (void)
17354{
17355 do_crypto_2op_1 (N_32, 1);
17356}
dd5181d5
KT
17357
17358static void
17359do_crc32_1 (unsigned int poly, unsigned int sz)
17360{
17361 unsigned int Rd = inst.operands[0].reg;
17362 unsigned int Rn = inst.operands[1].reg;
17363 unsigned int Rm = inst.operands[2].reg;
17364
17365 set_it_insn_type (OUTSIDE_IT_INSN);
17366 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
17367 inst.instruction |= LOW4 (Rn) << 16;
17368 inst.instruction |= LOW4 (Rm);
17369 inst.instruction |= sz << (thumb_mode ? 4 : 21);
17370 inst.instruction |= poly << (thumb_mode ? 20 : 9);
17371
17372 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
17373 as_warn (UNPRED_REG ("r15"));
17374 if (thumb_mode && (Rd == REG_SP || Rn == REG_SP || Rm == REG_SP))
17375 as_warn (UNPRED_REG ("r13"));
17376}
17377
17378static void
17379do_crc32b (void)
17380{
17381 do_crc32_1 (0, 0);
17382}
17383
17384static void
17385do_crc32h (void)
17386{
17387 do_crc32_1 (0, 1);
17388}
17389
17390static void
17391do_crc32w (void)
17392{
17393 do_crc32_1 (0, 2);
17394}
17395
17396static void
17397do_crc32cb (void)
17398{
17399 do_crc32_1 (1, 0);
17400}
17401
17402static void
17403do_crc32ch (void)
17404{
17405 do_crc32_1 (1, 1);
17406}
17407
17408static void
17409do_crc32cw (void)
17410{
17411 do_crc32_1 (1, 2);
17412}
17413
5287ad62
JB
17414\f
17415/* Overall per-instruction processing. */
17416
17417/* We need to be able to fix up arbitrary expressions in some statements.
17418 This is so that we can handle symbols that are an arbitrary distance from
17419 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17420 which returns part of an address in a form which will be valid for
17421 a data instruction. We do this by pushing the expression into a symbol
17422 in the expr_section, and creating a fix for that. */
17423
17424static void
17425fix_new_arm (fragS * frag,
17426 int where,
17427 short int size,
17428 expressionS * exp,
17429 int pc_rel,
17430 int reloc)
17431{
17432 fixS * new_fix;
17433
17434 switch (exp->X_op)
17435 {
17436 case O_constant:
6e7ce2cd
PB
17437 if (pc_rel)
17438 {
17439 /* Create an absolute valued symbol, so we have something to
477330fc
RM
17440 refer to in the object file. Unfortunately for us, gas's
17441 generic expression parsing will already have folded out
17442 any use of .set foo/.type foo %function that may have
17443 been used to set type information of the target location,
17444 that's being specified symbolically. We have to presume
17445 the user knows what they are doing. */
6e7ce2cd
PB
17446 char name[16 + 8];
17447 symbolS *symbol;
17448
17449 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17450
17451 symbol = symbol_find_or_make (name);
17452 S_SET_SEGMENT (symbol, absolute_section);
17453 symbol_set_frag (symbol, &zero_address_frag);
17454 S_SET_VALUE (symbol, exp->X_add_number);
17455 exp->X_op = O_symbol;
17456 exp->X_add_symbol = symbol;
17457 exp->X_add_number = 0;
17458 }
17459 /* FALLTHROUGH */
5287ad62
JB
17460 case O_symbol:
17461 case O_add:
17462 case O_subtract:
21d799b5 17463 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 17464 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17465 break;
17466
17467 default:
21d799b5 17468 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 17469 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17470 break;
17471 }
17472
17473 /* Mark whether the fix is to a THUMB instruction, or an ARM
17474 instruction. */
17475 new_fix->tc_fix_data = thumb_mode;
17476}
17477
17478/* Create a frg for an instruction requiring relaxation. */
17479static void
17480output_relax_insn (void)
17481{
17482 char * to;
17483 symbolS *sym;
0110f2b8
PB
17484 int offset;
17485
6e1cb1a6
PB
17486 /* The size of the instruction is unknown, so tie the debug info to the
17487 start of the instruction. */
17488 dwarf2_emit_insn (0);
6e1cb1a6 17489
0110f2b8
PB
17490 switch (inst.reloc.exp.X_op)
17491 {
17492 case O_symbol:
17493 sym = inst.reloc.exp.X_add_symbol;
17494 offset = inst.reloc.exp.X_add_number;
17495 break;
17496 case O_constant:
17497 sym = NULL;
17498 offset = inst.reloc.exp.X_add_number;
17499 break;
17500 default:
17501 sym = make_expr_symbol (&inst.reloc.exp);
17502 offset = 0;
17503 break;
17504 }
17505 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17506 inst.relax, sym, offset, NULL/*offset, opcode*/);
17507 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
17508}
17509
17510/* Write a 32-bit thumb instruction to buf. */
17511static void
17512put_thumb32_insn (char * buf, unsigned long insn)
17513{
17514 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17515 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17516}
17517
b99bd4ef 17518static void
c19d1205 17519output_inst (const char * str)
b99bd4ef 17520{
c19d1205 17521 char * to = NULL;
b99bd4ef 17522
c19d1205 17523 if (inst.error)
b99bd4ef 17524 {
c19d1205 17525 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
17526 return;
17527 }
5f4273c7
NC
17528 if (inst.relax)
17529 {
17530 output_relax_insn ();
0110f2b8 17531 return;
5f4273c7 17532 }
c19d1205
ZW
17533 if (inst.size == 0)
17534 return;
b99bd4ef 17535
c19d1205 17536 to = frag_more (inst.size);
8dc2430f
NC
17537 /* PR 9814: Record the thumb mode into the current frag so that we know
17538 what type of NOP padding to use, if necessary. We override any previous
17539 setting so that if the mode has changed then the NOPS that we use will
17540 match the encoding of the last instruction in the frag. */
cd000bff 17541 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
17542
17543 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 17544 {
9c2799c2 17545 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 17546 put_thumb32_insn (to, inst.instruction);
b99bd4ef 17547 }
c19d1205 17548 else if (inst.size > INSN_SIZE)
b99bd4ef 17549 {
9c2799c2 17550 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
17551 md_number_to_chars (to, inst.instruction, INSN_SIZE);
17552 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 17553 }
c19d1205
ZW
17554 else
17555 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 17556
c19d1205
ZW
17557 if (inst.reloc.type != BFD_RELOC_UNUSED)
17558 fix_new_arm (frag_now, to - frag_now->fr_literal,
17559 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
17560 inst.reloc.type);
b99bd4ef 17561
c19d1205 17562 dwarf2_emit_insn (inst.size);
c19d1205 17563}
b99bd4ef 17564
e07e6e58
NC
17565static char *
17566output_it_inst (int cond, int mask, char * to)
17567{
17568 unsigned long instruction = 0xbf00;
17569
17570 mask &= 0xf;
17571 instruction |= mask;
17572 instruction |= cond << 4;
17573
17574 if (to == NULL)
17575 {
17576 to = frag_more (2);
17577#ifdef OBJ_ELF
17578 dwarf2_emit_insn (2);
17579#endif
17580 }
17581
17582 md_number_to_chars (to, instruction, 2);
17583
17584 return to;
17585}
17586
c19d1205
ZW
17587/* Tag values used in struct asm_opcode's tag field. */
17588enum opcode_tag
17589{
17590 OT_unconditional, /* Instruction cannot be conditionalized.
17591 The ARM condition field is still 0xE. */
17592 OT_unconditionalF, /* Instruction cannot be conditionalized
17593 and carries 0xF in its ARM condition field. */
17594 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 17595 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
17596 suffix, others place 0xF where the condition field
17597 would be. */
c19d1205
ZW
17598 OT_cinfix3, /* Instruction takes a conditional infix,
17599 beginning at character index 3. (In
17600 unified mode, it becomes a suffix.) */
088fa78e
KH
17601 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
17602 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
17603 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
17604 character index 3, even in unified mode. Used for
17605 legacy instructions where suffix and infix forms
17606 may be ambiguous. */
c19d1205 17607 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 17608 suffix or an infix at character index 3. */
c19d1205
ZW
17609 OT_odd_infix_unc, /* This is the unconditional variant of an
17610 instruction that takes a conditional infix
17611 at an unusual position. In unified mode,
17612 this variant will accept a suffix. */
17613 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
17614 are the conditional variants of instructions that
17615 take conditional infixes in unusual positions.
17616 The infix appears at character index
17617 (tag - OT_odd_infix_0). These are not accepted
17618 in unified mode. */
17619};
b99bd4ef 17620
c19d1205
ZW
17621/* Subroutine of md_assemble, responsible for looking up the primary
17622 opcode from the mnemonic the user wrote. STR points to the
17623 beginning of the mnemonic.
17624
17625 This is not simply a hash table lookup, because of conditional
17626 variants. Most instructions have conditional variants, which are
17627 expressed with a _conditional affix_ to the mnemonic. If we were
17628 to encode each conditional variant as a literal string in the opcode
17629 table, it would have approximately 20,000 entries.
17630
17631 Most mnemonics take this affix as a suffix, and in unified syntax,
17632 'most' is upgraded to 'all'. However, in the divided syntax, some
17633 instructions take the affix as an infix, notably the s-variants of
17634 the arithmetic instructions. Of those instructions, all but six
17635 have the infix appear after the third character of the mnemonic.
17636
17637 Accordingly, the algorithm for looking up primary opcodes given
17638 an identifier is:
17639
17640 1. Look up the identifier in the opcode table.
17641 If we find a match, go to step U.
17642
17643 2. Look up the last two characters of the identifier in the
17644 conditions table. If we find a match, look up the first N-2
17645 characters of the identifier in the opcode table. If we
17646 find a match, go to step CE.
17647
17648 3. Look up the fourth and fifth characters of the identifier in
17649 the conditions table. If we find a match, extract those
17650 characters from the identifier, and look up the remaining
17651 characters in the opcode table. If we find a match, go
17652 to step CM.
17653
17654 4. Fail.
17655
17656 U. Examine the tag field of the opcode structure, in case this is
17657 one of the six instructions with its conditional infix in an
17658 unusual place. If it is, the tag tells us where to find the
17659 infix; look it up in the conditions table and set inst.cond
17660 accordingly. Otherwise, this is an unconditional instruction.
17661 Again set inst.cond accordingly. Return the opcode structure.
17662
17663 CE. Examine the tag field to make sure this is an instruction that
17664 should receive a conditional suffix. If it is not, fail.
17665 Otherwise, set inst.cond from the suffix we already looked up,
17666 and return the opcode structure.
17667
17668 CM. Examine the tag field to make sure this is an instruction that
17669 should receive a conditional infix after the third character.
17670 If it is not, fail. Otherwise, undo the edits to the current
17671 line of input and proceed as for case CE. */
17672
17673static const struct asm_opcode *
17674opcode_lookup (char **str)
17675{
17676 char *end, *base;
17677 char *affix;
17678 const struct asm_opcode *opcode;
17679 const struct asm_cond *cond;
e3cb604e 17680 char save[2];
c19d1205
ZW
17681
17682 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 17683 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 17684 for (base = end = *str; *end != '\0'; end++)
721a8186 17685 if (*end == ' ' || *end == '.')
c19d1205 17686 break;
b99bd4ef 17687
c19d1205 17688 if (end == base)
c921be7d 17689 return NULL;
b99bd4ef 17690
5287ad62 17691 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 17692 if (end[0] == '.')
b99bd4ef 17693 {
5287ad62 17694 int offset = 2;
5f4273c7 17695
267d2029 17696 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 17697 use. */
267d2029 17698 if (unified_syntax && end[1] == 'w')
c19d1205 17699 inst.size_req = 4;
267d2029 17700 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
17701 inst.size_req = 2;
17702 else
477330fc 17703 offset = 0;
5287ad62
JB
17704
17705 inst.vectype.elems = 0;
17706
17707 *str = end + offset;
b99bd4ef 17708
5f4273c7 17709 if (end[offset] == '.')
5287ad62 17710 {
267d2029 17711 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
17712 non-unified ARM syntax mode). */
17713 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 17714 return NULL;
477330fc 17715 }
5287ad62 17716 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 17717 return NULL;
b99bd4ef 17718 }
c19d1205
ZW
17719 else
17720 *str = end;
b99bd4ef 17721
c19d1205 17722 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 17723 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17724 end - base);
c19d1205 17725 if (opcode)
b99bd4ef 17726 {
c19d1205
ZW
17727 /* step U */
17728 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 17729 {
c19d1205
ZW
17730 inst.cond = COND_ALWAYS;
17731 return opcode;
b99bd4ef 17732 }
b99bd4ef 17733
278df34e 17734 if (warn_on_deprecated && unified_syntax)
5c3696f8 17735 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 17736 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 17737 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 17738 gas_assert (cond);
b99bd4ef 17739
c19d1205
ZW
17740 inst.cond = cond->value;
17741 return opcode;
17742 }
b99bd4ef 17743
c19d1205
ZW
17744 /* Cannot have a conditional suffix on a mnemonic of less than two
17745 characters. */
17746 if (end - base < 3)
c921be7d 17747 return NULL;
b99bd4ef 17748
c19d1205
ZW
17749 /* Look for suffixed mnemonic. */
17750 affix = end - 2;
21d799b5
NC
17751 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
17752 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17753 affix - base);
c19d1205
ZW
17754 if (opcode && cond)
17755 {
17756 /* step CE */
17757 switch (opcode->tag)
17758 {
e3cb604e
PB
17759 case OT_cinfix3_legacy:
17760 /* Ignore conditional suffixes matched on infix only mnemonics. */
17761 break;
17762
c19d1205 17763 case OT_cinfix3:
088fa78e 17764 case OT_cinfix3_deprecated:
c19d1205
ZW
17765 case OT_odd_infix_unc:
17766 if (!unified_syntax)
e3cb604e 17767 return 0;
c19d1205
ZW
17768 /* else fall through */
17769
17770 case OT_csuffix:
477330fc 17771 case OT_csuffixF:
c19d1205
ZW
17772 case OT_csuf_or_in3:
17773 inst.cond = cond->value;
17774 return opcode;
17775
17776 case OT_unconditional:
17777 case OT_unconditionalF:
dfa9f0d5 17778 if (thumb_mode)
c921be7d 17779 inst.cond = cond->value;
dfa9f0d5
PB
17780 else
17781 {
c921be7d 17782 /* Delayed diagnostic. */
dfa9f0d5
PB
17783 inst.error = BAD_COND;
17784 inst.cond = COND_ALWAYS;
17785 }
c19d1205 17786 return opcode;
b99bd4ef 17787
c19d1205 17788 default:
c921be7d 17789 return NULL;
c19d1205
ZW
17790 }
17791 }
b99bd4ef 17792
c19d1205
ZW
17793 /* Cannot have a usual-position infix on a mnemonic of less than
17794 six characters (five would be a suffix). */
17795 if (end - base < 6)
c921be7d 17796 return NULL;
b99bd4ef 17797
c19d1205
ZW
17798 /* Look for infixed mnemonic in the usual position. */
17799 affix = base + 3;
21d799b5 17800 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 17801 if (!cond)
c921be7d 17802 return NULL;
e3cb604e
PB
17803
17804 memcpy (save, affix, 2);
17805 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 17806 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17807 (end - base) - 2);
e3cb604e
PB
17808 memmove (affix + 2, affix, (end - affix) - 2);
17809 memcpy (affix, save, 2);
17810
088fa78e
KH
17811 if (opcode
17812 && (opcode->tag == OT_cinfix3
17813 || opcode->tag == OT_cinfix3_deprecated
17814 || opcode->tag == OT_csuf_or_in3
17815 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 17816 {
c921be7d 17817 /* Step CM. */
278df34e 17818 if (warn_on_deprecated && unified_syntax
088fa78e
KH
17819 && (opcode->tag == OT_cinfix3
17820 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 17821 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
17822
17823 inst.cond = cond->value;
17824 return opcode;
b99bd4ef
NC
17825 }
17826
c921be7d 17827 return NULL;
b99bd4ef
NC
17828}
17829
e07e6e58
NC
17830/* This function generates an initial IT instruction, leaving its block
17831 virtually open for the new instructions. Eventually,
17832 the mask will be updated by now_it_add_mask () each time
17833 a new instruction needs to be included in the IT block.
17834 Finally, the block is closed with close_automatic_it_block ().
17835 The block closure can be requested either from md_assemble (),
17836 a tencode (), or due to a label hook. */
17837
17838static void
17839new_automatic_it_block (int cond)
17840{
17841 now_it.state = AUTOMATIC_IT_BLOCK;
17842 now_it.mask = 0x18;
17843 now_it.cc = cond;
17844 now_it.block_length = 1;
cd000bff 17845 mapping_state (MAP_THUMB);
e07e6e58 17846 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
17847 now_it.warn_deprecated = FALSE;
17848 now_it.insn_cond = TRUE;
e07e6e58
NC
17849}
17850
17851/* Close an automatic IT block.
17852 See comments in new_automatic_it_block (). */
17853
17854static void
17855close_automatic_it_block (void)
17856{
17857 now_it.mask = 0x10;
17858 now_it.block_length = 0;
17859}
17860
17861/* Update the mask of the current automatically-generated IT
17862 instruction. See comments in new_automatic_it_block (). */
17863
17864static void
17865now_it_add_mask (int cond)
17866{
17867#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
17868#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 17869 | ((bitvalue) << (nbit)))
e07e6e58 17870 const int resulting_bit = (cond & 1);
c921be7d 17871
e07e6e58
NC
17872 now_it.mask &= 0xf;
17873 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17874 resulting_bit,
17875 (5 - now_it.block_length));
e07e6e58 17876 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17877 1,
17878 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
17879 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
17880
17881#undef CLEAR_BIT
17882#undef SET_BIT_VALUE
e07e6e58
NC
17883}
17884
17885/* The IT blocks handling machinery is accessed through the these functions:
17886 it_fsm_pre_encode () from md_assemble ()
17887 set_it_insn_type () optional, from the tencode functions
17888 set_it_insn_type_last () ditto
17889 in_it_block () ditto
17890 it_fsm_post_encode () from md_assemble ()
17891 force_automatic_it_block_close () from label habdling functions
17892
17893 Rationale:
17894 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
17895 initializing the IT insn type with a generic initial value depending
17896 on the inst.condition.
e07e6e58 17897 2) During the tencode function, two things may happen:
477330fc
RM
17898 a) The tencode function overrides the IT insn type by
17899 calling either set_it_insn_type (type) or set_it_insn_type_last ().
17900 b) The tencode function queries the IT block state by
17901 calling in_it_block () (i.e. to determine narrow/not narrow mode).
17902
17903 Both set_it_insn_type and in_it_block run the internal FSM state
17904 handling function (handle_it_state), because: a) setting the IT insn
17905 type may incur in an invalid state (exiting the function),
17906 and b) querying the state requires the FSM to be updated.
17907 Specifically we want to avoid creating an IT block for conditional
17908 branches, so it_fsm_pre_encode is actually a guess and we can't
17909 determine whether an IT block is required until the tencode () routine
17910 has decided what type of instruction this actually it.
17911 Because of this, if set_it_insn_type and in_it_block have to be used,
17912 set_it_insn_type has to be called first.
17913
17914 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
17915 determines the insn IT type depending on the inst.cond code.
17916 When a tencode () routine encodes an instruction that can be
17917 either outside an IT block, or, in the case of being inside, has to be
17918 the last one, set_it_insn_type_last () will determine the proper
17919 IT instruction type based on the inst.cond code. Otherwise,
17920 set_it_insn_type can be called for overriding that logic or
17921 for covering other cases.
17922
17923 Calling handle_it_state () may not transition the IT block state to
17924 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
17925 still queried. Instead, if the FSM determines that the state should
17926 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
17927 after the tencode () function: that's what it_fsm_post_encode () does.
17928
17929 Since in_it_block () calls the state handling function to get an
17930 updated state, an error may occur (due to invalid insns combination).
17931 In that case, inst.error is set.
17932 Therefore, inst.error has to be checked after the execution of
17933 the tencode () routine.
e07e6e58
NC
17934
17935 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
17936 any pending state change (if any) that didn't take place in
17937 handle_it_state () as explained above. */
e07e6e58
NC
17938
17939static void
17940it_fsm_pre_encode (void)
17941{
17942 if (inst.cond != COND_ALWAYS)
17943 inst.it_insn_type = INSIDE_IT_INSN;
17944 else
17945 inst.it_insn_type = OUTSIDE_IT_INSN;
17946
17947 now_it.state_handled = 0;
17948}
17949
17950/* IT state FSM handling function. */
17951
17952static int
17953handle_it_state (void)
17954{
17955 now_it.state_handled = 1;
5a01bb1d 17956 now_it.insn_cond = FALSE;
e07e6e58
NC
17957
17958 switch (now_it.state)
17959 {
17960 case OUTSIDE_IT_BLOCK:
17961 switch (inst.it_insn_type)
17962 {
17963 case OUTSIDE_IT_INSN:
17964 break;
17965
17966 case INSIDE_IT_INSN:
17967 case INSIDE_IT_LAST_INSN:
17968 if (thumb_mode == 0)
17969 {
c921be7d 17970 if (unified_syntax
e07e6e58
NC
17971 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
17972 as_tsktsk (_("Warning: conditional outside an IT block"\
17973 " for Thumb."));
17974 }
17975 else
17976 {
17977 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
fc289b0a 17978 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
e07e6e58
NC
17979 {
17980 /* Automatically generate the IT instruction. */
17981 new_automatic_it_block (inst.cond);
17982 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
17983 close_automatic_it_block ();
17984 }
17985 else
17986 {
17987 inst.error = BAD_OUT_IT;
17988 return FAIL;
17989 }
17990 }
17991 break;
17992
17993 case IF_INSIDE_IT_LAST_INSN:
17994 case NEUTRAL_IT_INSN:
17995 break;
17996
17997 case IT_INSN:
17998 now_it.state = MANUAL_IT_BLOCK;
17999 now_it.block_length = 0;
18000 break;
18001 }
18002 break;
18003
18004 case AUTOMATIC_IT_BLOCK:
18005 /* Three things may happen now:
18006 a) We should increment current it block size;
18007 b) We should close current it block (closing insn or 4 insns);
18008 c) We should close current it block and start a new one (due
18009 to incompatible conditions or
18010 4 insns-length block reached). */
18011
18012 switch (inst.it_insn_type)
18013 {
18014 case OUTSIDE_IT_INSN:
18015 /* The closure of the block shall happen immediatelly,
18016 so any in_it_block () call reports the block as closed. */
18017 force_automatic_it_block_close ();
18018 break;
18019
18020 case INSIDE_IT_INSN:
18021 case INSIDE_IT_LAST_INSN:
18022 case IF_INSIDE_IT_LAST_INSN:
18023 now_it.block_length++;
18024
18025 if (now_it.block_length > 4
18026 || !now_it_compatible (inst.cond))
18027 {
18028 force_automatic_it_block_close ();
18029 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
18030 new_automatic_it_block (inst.cond);
18031 }
18032 else
18033 {
5a01bb1d 18034 now_it.insn_cond = TRUE;
e07e6e58
NC
18035 now_it_add_mask (inst.cond);
18036 }
18037
18038 if (now_it.state == AUTOMATIC_IT_BLOCK
18039 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
18040 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
18041 close_automatic_it_block ();
18042 break;
18043
18044 case NEUTRAL_IT_INSN:
18045 now_it.block_length++;
5a01bb1d 18046 now_it.insn_cond = TRUE;
e07e6e58
NC
18047
18048 if (now_it.block_length > 4)
18049 force_automatic_it_block_close ();
18050 else
18051 now_it_add_mask (now_it.cc & 1);
18052 break;
18053
18054 case IT_INSN:
18055 close_automatic_it_block ();
18056 now_it.state = MANUAL_IT_BLOCK;
18057 break;
18058 }
18059 break;
18060
18061 case MANUAL_IT_BLOCK:
18062 {
18063 /* Check conditional suffixes. */
18064 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
18065 int is_last;
18066 now_it.mask <<= 1;
18067 now_it.mask &= 0x1f;
18068 is_last = (now_it.mask == 0x10);
5a01bb1d 18069 now_it.insn_cond = TRUE;
e07e6e58
NC
18070
18071 switch (inst.it_insn_type)
18072 {
18073 case OUTSIDE_IT_INSN:
18074 inst.error = BAD_NOT_IT;
18075 return FAIL;
18076
18077 case INSIDE_IT_INSN:
18078 if (cond != inst.cond)
18079 {
18080 inst.error = BAD_IT_COND;
18081 return FAIL;
18082 }
18083 break;
18084
18085 case INSIDE_IT_LAST_INSN:
18086 case IF_INSIDE_IT_LAST_INSN:
18087 if (cond != inst.cond)
18088 {
18089 inst.error = BAD_IT_COND;
18090 return FAIL;
18091 }
18092 if (!is_last)
18093 {
18094 inst.error = BAD_BRANCH;
18095 return FAIL;
18096 }
18097 break;
18098
18099 case NEUTRAL_IT_INSN:
18100 /* The BKPT instruction is unconditional even in an IT block. */
18101 break;
18102
18103 case IT_INSN:
18104 inst.error = BAD_IT_IT;
18105 return FAIL;
18106 }
18107 }
18108 break;
18109 }
18110
18111 return SUCCESS;
18112}
18113
5a01bb1d
MGD
18114struct depr_insn_mask
18115{
18116 unsigned long pattern;
18117 unsigned long mask;
18118 const char* description;
18119};
18120
18121/* List of 16-bit instruction patterns deprecated in an IT block in
18122 ARMv8. */
18123static const struct depr_insn_mask depr_it_insns[] = {
18124 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
18125 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
18126 { 0xa000, 0xb800, N_("ADR") },
18127 { 0x4800, 0xf800, N_("Literal loads") },
18128 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
18129 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
18130 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
18131 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
18132 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
18133 { 0, 0, NULL }
18134};
18135
e07e6e58
NC
18136static void
18137it_fsm_post_encode (void)
18138{
18139 int is_last;
18140
18141 if (!now_it.state_handled)
18142 handle_it_state ();
18143
5a01bb1d
MGD
18144 if (now_it.insn_cond
18145 && !now_it.warn_deprecated
18146 && warn_on_deprecated
18147 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
18148 {
18149 if (inst.instruction >= 0x10000)
18150 {
5c3696f8 18151 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
5a01bb1d
MGD
18152 "deprecated in ARMv8"));
18153 now_it.warn_deprecated = TRUE;
18154 }
18155 else
18156 {
18157 const struct depr_insn_mask *p = depr_it_insns;
18158
18159 while (p->mask != 0)
18160 {
18161 if ((inst.instruction & p->mask) == p->pattern)
18162 {
5c3696f8 18163 as_tsktsk (_("IT blocks containing 16-bit Thumb instructions "
5a01bb1d
MGD
18164 "of the following class are deprecated in ARMv8: "
18165 "%s"), p->description);
18166 now_it.warn_deprecated = TRUE;
18167 break;
18168 }
18169
18170 ++p;
18171 }
18172 }
18173
18174 if (now_it.block_length > 1)
18175 {
5c3696f8 18176 as_tsktsk (_("IT blocks containing more than one conditional "
0a8897c7 18177 "instruction are deprecated in ARMv8"));
5a01bb1d
MGD
18178 now_it.warn_deprecated = TRUE;
18179 }
18180 }
18181
e07e6e58
NC
18182 is_last = (now_it.mask == 0x10);
18183 if (is_last)
18184 {
18185 now_it.state = OUTSIDE_IT_BLOCK;
18186 now_it.mask = 0;
18187 }
18188}
18189
18190static void
18191force_automatic_it_block_close (void)
18192{
18193 if (now_it.state == AUTOMATIC_IT_BLOCK)
18194 {
18195 close_automatic_it_block ();
18196 now_it.state = OUTSIDE_IT_BLOCK;
18197 now_it.mask = 0;
18198 }
18199}
18200
18201static int
18202in_it_block (void)
18203{
18204 if (!now_it.state_handled)
18205 handle_it_state ();
18206
18207 return now_it.state != OUTSIDE_IT_BLOCK;
18208}
18209
ff8646ee
TP
18210/* Whether OPCODE only has T32 encoding. Since this function is only used by
18211 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18212 here, hence the "known" in the function name. */
fc289b0a
TP
18213
18214static bfd_boolean
ff8646ee 18215known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
18216{
18217 /* Original Thumb-1 wide instruction. */
18218 if (opcode->tencode == do_t_blx
18219 || opcode->tencode == do_t_branch23
18220 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18221 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18222 return TRUE;
18223
16a1fa25
TP
18224 /* Wide-only instruction added to ARMv8-M Baseline. */
18225 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
18226 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18227 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18228 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18229 return TRUE;
18230
18231 return FALSE;
18232}
18233
18234/* Whether wide instruction variant can be used if available for a valid OPCODE
18235 in ARCH. */
18236
18237static bfd_boolean
18238t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18239{
18240 if (known_t32_only_insn (opcode))
18241 return TRUE;
18242
18243 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18244 of variant T3 of B.W is checked in do_t_branch. */
18245 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18246 && opcode->tencode == do_t_branch)
18247 return TRUE;
18248
18249 /* Wide instruction variants of all instructions with narrow *and* wide
18250 variants become available with ARMv6t2. Other opcodes are either
18251 narrow-only or wide-only and are thus available if OPCODE is valid. */
18252 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18253 return TRUE;
18254
18255 /* OPCODE with narrow only instruction variant or wide variant not
18256 available. */
fc289b0a
TP
18257 return FALSE;
18258}
18259
c19d1205
ZW
18260void
18261md_assemble (char *str)
b99bd4ef 18262{
c19d1205
ZW
18263 char *p = str;
18264 const struct asm_opcode * opcode;
b99bd4ef 18265
c19d1205
ZW
18266 /* Align the previous label if needed. */
18267 if (last_label_seen != NULL)
b99bd4ef 18268 {
c19d1205
ZW
18269 symbol_set_frag (last_label_seen, frag_now);
18270 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18271 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
18272 }
18273
c19d1205
ZW
18274 memset (&inst, '\0', sizeof (inst));
18275 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 18276
c19d1205
ZW
18277 opcode = opcode_lookup (&p);
18278 if (!opcode)
b99bd4ef 18279 {
c19d1205 18280 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 18281 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 18282 if (! create_register_alias (str, p)
477330fc 18283 && ! create_neon_reg_alias (str, p))
c19d1205 18284 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 18285
b99bd4ef
NC
18286 return;
18287 }
18288
278df34e 18289 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 18290 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 18291
037e8744
JB
18292 /* The value which unconditional instructions should have in place of the
18293 condition field. */
18294 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
18295
c19d1205 18296 if (thumb_mode)
b99bd4ef 18297 {
e74cfd16 18298 arm_feature_set variant;
8f06b2d8
PB
18299
18300 variant = cpu_variant;
18301 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
18302 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
18303 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 18304 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
18305 if (!opcode->tvariant
18306 || (thumb_mode == 1
18307 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 18308 {
84b52b66 18309 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
18310 return;
18311 }
c19d1205
ZW
18312 if (inst.cond != COND_ALWAYS && !unified_syntax
18313 && opcode->tencode != do_t_branch)
b99bd4ef 18314 {
c19d1205 18315 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
18316 return;
18317 }
18318
fc289b0a
TP
18319 /* Two things are addressed here:
18320 1) Implicit require narrow instructions on Thumb-1.
18321 This avoids relaxation accidentally introducing Thumb-2
18322 instructions.
18323 2) Reject wide instructions in non Thumb-2 cores.
18324
18325 Only instructions with narrow and wide variants need to be handled
18326 but selecting all non wide-only instructions is easier. */
18327 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 18328 && !t32_insn_ok (variant, opcode))
076d447c 18329 {
fc289b0a
TP
18330 if (inst.size_req == 0)
18331 inst.size_req = 2;
18332 else if (inst.size_req == 4)
752d5da4 18333 {
ff8646ee
TP
18334 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
18335 as_bad (_("selected processor does not support 32bit wide "
18336 "variant of instruction `%s'"), str);
18337 else
18338 as_bad (_("selected processor does not support `%s' in "
18339 "Thumb-2 mode"), str);
fc289b0a 18340 return;
752d5da4 18341 }
076d447c
PB
18342 }
18343
c19d1205
ZW
18344 inst.instruction = opcode->tvalue;
18345
5be8be5d 18346 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
18347 {
18348 /* Prepare the it_insn_type for those encodings that don't set
18349 it. */
18350 it_fsm_pre_encode ();
c19d1205 18351
477330fc 18352 opcode->tencode ();
e07e6e58 18353
477330fc
RM
18354 it_fsm_post_encode ();
18355 }
e27ec89e 18356
0110f2b8 18357 if (!(inst.error || inst.relax))
b99bd4ef 18358 {
9c2799c2 18359 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
18360 inst.size = (inst.instruction > 0xffff ? 4 : 2);
18361 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 18362 {
c19d1205 18363 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
18364 return;
18365 }
18366 }
076d447c
PB
18367
18368 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 18369 instruction. */
9c2799c2 18370 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 18371
e74cfd16
PB
18372 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18373 *opcode->tvariant);
ee065d83 18374 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
18375 set those bits when Thumb-2 32-bit instructions are seen. The impact
18376 of relaxable instructions will be considered later after we finish all
18377 relaxation. */
ff8646ee
TP
18378 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
18379 variant = arm_arch_none;
18380 else
18381 variant = cpu_variant;
18382 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
18383 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18384 arm_ext_v6t2);
cd000bff 18385
88714cb8
DG
18386 check_neon_suffixes;
18387
cd000bff 18388 if (!inst.error)
c877a2f2
NC
18389 {
18390 mapping_state (MAP_THUMB);
18391 }
c19d1205 18392 }
3e9e4fcf 18393 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 18394 {
845b51d6
PB
18395 bfd_boolean is_bx;
18396
18397 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
18398 is_bx = (opcode->aencode == do_bx);
18399
c19d1205 18400 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
18401 if (!(is_bx && fix_v4bx)
18402 && !(opcode->avariant &&
18403 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 18404 {
84b52b66 18405 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 18406 return;
b99bd4ef 18407 }
c19d1205 18408 if (inst.size_req)
b99bd4ef 18409 {
c19d1205
ZW
18410 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
18411 return;
b99bd4ef
NC
18412 }
18413
c19d1205
ZW
18414 inst.instruction = opcode->avalue;
18415 if (opcode->tag == OT_unconditionalF)
eff0bc54 18416 inst.instruction |= 0xFU << 28;
c19d1205
ZW
18417 else
18418 inst.instruction |= inst.cond << 28;
18419 inst.size = INSN_SIZE;
5be8be5d 18420 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
18421 {
18422 it_fsm_pre_encode ();
18423 opcode->aencode ();
18424 it_fsm_post_encode ();
18425 }
ee065d83 18426 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 18427 on a hypothetical non-thumb v5 core. */
845b51d6 18428 if (is_bx)
e74cfd16 18429 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 18430 else
e74cfd16
PB
18431 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
18432 *opcode->avariant);
88714cb8
DG
18433
18434 check_neon_suffixes;
18435
cd000bff 18436 if (!inst.error)
c877a2f2
NC
18437 {
18438 mapping_state (MAP_ARM);
18439 }
b99bd4ef 18440 }
3e9e4fcf
JB
18441 else
18442 {
18443 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
18444 "-- `%s'"), str);
18445 return;
18446 }
c19d1205
ZW
18447 output_inst (str);
18448}
b99bd4ef 18449
e07e6e58
NC
18450static void
18451check_it_blocks_finished (void)
18452{
18453#ifdef OBJ_ELF
18454 asection *sect;
18455
18456 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
18457 if (seg_info (sect)->tc_segment_info_data.current_it.state
18458 == MANUAL_IT_BLOCK)
18459 {
18460 as_warn (_("section '%s' finished with an open IT block."),
18461 sect->name);
18462 }
18463#else
18464 if (now_it.state == MANUAL_IT_BLOCK)
18465 as_warn (_("file finished with an open IT block."));
18466#endif
18467}
18468
c19d1205
ZW
18469/* Various frobbings of labels and their addresses. */
18470
18471void
18472arm_start_line_hook (void)
18473{
18474 last_label_seen = NULL;
b99bd4ef
NC
18475}
18476
c19d1205
ZW
18477void
18478arm_frob_label (symbolS * sym)
b99bd4ef 18479{
c19d1205 18480 last_label_seen = sym;
b99bd4ef 18481
c19d1205 18482 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 18483
c19d1205
ZW
18484#if defined OBJ_COFF || defined OBJ_ELF
18485 ARM_SET_INTERWORK (sym, support_interwork);
18486#endif
b99bd4ef 18487
e07e6e58
NC
18488 force_automatic_it_block_close ();
18489
5f4273c7 18490 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
18491 as Thumb functions. This is because these labels, whilst
18492 they exist inside Thumb code, are not the entry points for
18493 possible ARM->Thumb calls. Also, these labels can be used
18494 as part of a computed goto or switch statement. eg gcc
18495 can generate code that looks like this:
b99bd4ef 18496
c19d1205
ZW
18497 ldr r2, [pc, .Laaa]
18498 lsl r3, r3, #2
18499 ldr r2, [r3, r2]
18500 mov pc, r2
b99bd4ef 18501
c19d1205
ZW
18502 .Lbbb: .word .Lxxx
18503 .Lccc: .word .Lyyy
18504 ..etc...
18505 .Laaa: .word Lbbb
b99bd4ef 18506
c19d1205
ZW
18507 The first instruction loads the address of the jump table.
18508 The second instruction converts a table index into a byte offset.
18509 The third instruction gets the jump address out of the table.
18510 The fourth instruction performs the jump.
b99bd4ef 18511
c19d1205
ZW
18512 If the address stored at .Laaa is that of a symbol which has the
18513 Thumb_Func bit set, then the linker will arrange for this address
18514 to have the bottom bit set, which in turn would mean that the
18515 address computation performed by the third instruction would end
18516 up with the bottom bit set. Since the ARM is capable of unaligned
18517 word loads, the instruction would then load the incorrect address
18518 out of the jump table, and chaos would ensue. */
18519 if (label_is_thumb_function_name
18520 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18521 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 18522 {
c19d1205
ZW
18523 /* When the address of a Thumb function is taken the bottom
18524 bit of that address should be set. This will allow
18525 interworking between Arm and Thumb functions to work
18526 correctly. */
b99bd4ef 18527
c19d1205 18528 THUMB_SET_FUNC (sym, 1);
b99bd4ef 18529
c19d1205 18530 label_is_thumb_function_name = FALSE;
b99bd4ef 18531 }
07a53e5c 18532
07a53e5c 18533 dwarf2_emit_label (sym);
b99bd4ef
NC
18534}
18535
c921be7d 18536bfd_boolean
c19d1205 18537arm_data_in_code (void)
b99bd4ef 18538{
c19d1205 18539 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 18540 {
c19d1205
ZW
18541 *input_line_pointer = '/';
18542 input_line_pointer += 5;
18543 *input_line_pointer = 0;
c921be7d 18544 return TRUE;
b99bd4ef
NC
18545 }
18546
c921be7d 18547 return FALSE;
b99bd4ef
NC
18548}
18549
c19d1205
ZW
18550char *
18551arm_canonicalize_symbol_name (char * name)
b99bd4ef 18552{
c19d1205 18553 int len;
b99bd4ef 18554
c19d1205
ZW
18555 if (thumb_mode && (len = strlen (name)) > 5
18556 && streq (name + len - 5, "/data"))
18557 *(name + len - 5) = 0;
b99bd4ef 18558
c19d1205 18559 return name;
b99bd4ef 18560}
c19d1205
ZW
18561\f
18562/* Table of all register names defined by default. The user can
18563 define additional names with .req. Note that all register names
18564 should appear in both upper and lowercase variants. Some registers
18565 also have mixed-case names. */
b99bd4ef 18566
dcbf9037 18567#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 18568#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 18569#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
18570#define REGSET(p,t) \
18571 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
18572 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
18573 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
18574 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
18575#define REGSETH(p,t) \
18576 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
18577 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
18578 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
18579 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
18580#define REGSET2(p,t) \
18581 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
18582 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
18583 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
18584 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
18585#define SPLRBANK(base,bank,t) \
18586 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
18587 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
18588 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
18589 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
18590 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
18591 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 18592
c19d1205 18593static const struct reg_entry reg_names[] =
7ed4c4c5 18594{
c19d1205
ZW
18595 /* ARM integer registers. */
18596 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 18597
c19d1205
ZW
18598 /* ATPCS synonyms. */
18599 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
18600 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
18601 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 18602
c19d1205
ZW
18603 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
18604 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
18605 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 18606
c19d1205
ZW
18607 /* Well-known aliases. */
18608 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
18609 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
18610
18611 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
18612 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
18613
18614 /* Coprocessor numbers. */
18615 REGSET(p, CP), REGSET(P, CP),
18616
18617 /* Coprocessor register numbers. The "cr" variants are for backward
18618 compatibility. */
18619 REGSET(c, CN), REGSET(C, CN),
18620 REGSET(cr, CN), REGSET(CR, CN),
18621
90ec0d68
MGD
18622 /* ARM banked registers. */
18623 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
18624 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
18625 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
18626 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
18627 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
18628 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
18629 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
18630
18631 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
18632 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
18633 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
18634 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
18635 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 18636 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
18637 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
18638 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
18639
18640 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
18641 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
18642 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
18643 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
18644 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
18645 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
18646 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 18647 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
18648 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
18649
c19d1205
ZW
18650 /* FPA registers. */
18651 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
18652 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
18653
18654 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
18655 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
18656
18657 /* VFP SP registers. */
5287ad62
JB
18658 REGSET(s,VFS), REGSET(S,VFS),
18659 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
18660
18661 /* VFP DP Registers. */
5287ad62
JB
18662 REGSET(d,VFD), REGSET(D,VFD),
18663 /* Extra Neon DP registers. */
18664 REGSETH(d,VFD), REGSETH(D,VFD),
18665
18666 /* Neon QP registers. */
18667 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
18668
18669 /* VFP control registers. */
18670 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
18671 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
18672 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
18673 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
18674 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
18675 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
18676
18677 /* Maverick DSP coprocessor registers. */
18678 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
18679 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
18680
18681 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
18682 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
18683 REGDEF(dspsc,0,DSPSC),
18684
18685 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
18686 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
18687 REGDEF(DSPSC,0,DSPSC),
18688
18689 /* iWMMXt data registers - p0, c0-15. */
18690 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
18691
18692 /* iWMMXt control registers - p1, c0-3. */
18693 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
18694 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
18695 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
18696 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
18697
18698 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
18699 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
18700 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
18701 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
18702 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
18703
18704 /* XScale accumulator registers. */
18705 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
18706};
18707#undef REGDEF
18708#undef REGNUM
18709#undef REGSET
7ed4c4c5 18710
c19d1205
ZW
18711/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
18712 within psr_required_here. */
18713static const struct asm_psr psrs[] =
18714{
18715 /* Backward compatibility notation. Note that "all" is no longer
18716 truly all possible PSR bits. */
18717 {"all", PSR_c | PSR_f},
18718 {"flg", PSR_f},
18719 {"ctl", PSR_c},
18720
18721 /* Individual flags. */
18722 {"f", PSR_f},
18723 {"c", PSR_c},
18724 {"x", PSR_x},
18725 {"s", PSR_s},
59b42a0d 18726
c19d1205
ZW
18727 /* Combinations of flags. */
18728 {"fs", PSR_f | PSR_s},
18729 {"fx", PSR_f | PSR_x},
18730 {"fc", PSR_f | PSR_c},
18731 {"sf", PSR_s | PSR_f},
18732 {"sx", PSR_s | PSR_x},
18733 {"sc", PSR_s | PSR_c},
18734 {"xf", PSR_x | PSR_f},
18735 {"xs", PSR_x | PSR_s},
18736 {"xc", PSR_x | PSR_c},
18737 {"cf", PSR_c | PSR_f},
18738 {"cs", PSR_c | PSR_s},
18739 {"cx", PSR_c | PSR_x},
18740 {"fsx", PSR_f | PSR_s | PSR_x},
18741 {"fsc", PSR_f | PSR_s | PSR_c},
18742 {"fxs", PSR_f | PSR_x | PSR_s},
18743 {"fxc", PSR_f | PSR_x | PSR_c},
18744 {"fcs", PSR_f | PSR_c | PSR_s},
18745 {"fcx", PSR_f | PSR_c | PSR_x},
18746 {"sfx", PSR_s | PSR_f | PSR_x},
18747 {"sfc", PSR_s | PSR_f | PSR_c},
18748 {"sxf", PSR_s | PSR_x | PSR_f},
18749 {"sxc", PSR_s | PSR_x | PSR_c},
18750 {"scf", PSR_s | PSR_c | PSR_f},
18751 {"scx", PSR_s | PSR_c | PSR_x},
18752 {"xfs", PSR_x | PSR_f | PSR_s},
18753 {"xfc", PSR_x | PSR_f | PSR_c},
18754 {"xsf", PSR_x | PSR_s | PSR_f},
18755 {"xsc", PSR_x | PSR_s | PSR_c},
18756 {"xcf", PSR_x | PSR_c | PSR_f},
18757 {"xcs", PSR_x | PSR_c | PSR_s},
18758 {"cfs", PSR_c | PSR_f | PSR_s},
18759 {"cfx", PSR_c | PSR_f | PSR_x},
18760 {"csf", PSR_c | PSR_s | PSR_f},
18761 {"csx", PSR_c | PSR_s | PSR_x},
18762 {"cxf", PSR_c | PSR_x | PSR_f},
18763 {"cxs", PSR_c | PSR_x | PSR_s},
18764 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
18765 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
18766 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
18767 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
18768 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
18769 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
18770 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
18771 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
18772 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
18773 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
18774 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
18775 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
18776 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
18777 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
18778 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
18779 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
18780 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
18781 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
18782 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
18783 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
18784 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
18785 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
18786 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
18787 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
18788};
18789
62b3e311
PB
18790/* Table of V7M psr names. */
18791static const struct asm_psr v7m_psrs[] =
18792{
2b744c99
PB
18793 {"apsr", 0 }, {"APSR", 0 },
18794 {"iapsr", 1 }, {"IAPSR", 1 },
18795 {"eapsr", 2 }, {"EAPSR", 2 },
18796 {"psr", 3 }, {"PSR", 3 },
18797 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
18798 {"ipsr", 5 }, {"IPSR", 5 },
18799 {"epsr", 6 }, {"EPSR", 6 },
18800 {"iepsr", 7 }, {"IEPSR", 7 },
16a1fa25
TP
18801 {"msp", 8 }, {"MSP", 8 }, {"msp_s", 8 }, {"MSP_S", 8 },
18802 {"psp", 9 }, {"PSP", 9 }, {"psp_s", 9 }, {"PSP_S", 9 },
2b744c99
PB
18803 {"primask", 16}, {"PRIMASK", 16},
18804 {"basepri", 17}, {"BASEPRI", 17},
00bbc0bd
NC
18805 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
18806 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
2b744c99 18807 {"faultmask", 19}, {"FAULTMASK", 19},
16a1fa25
TP
18808 {"control", 20}, {"CONTROL", 20},
18809 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
18810 {"psp_ns", 0x89}, {"PSP_NS", 0x89}
62b3e311
PB
18811};
18812
c19d1205
ZW
18813/* Table of all shift-in-operand names. */
18814static const struct asm_shift_name shift_names [] =
b99bd4ef 18815{
c19d1205
ZW
18816 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
18817 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
18818 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
18819 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
18820 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
18821 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
18822};
b99bd4ef 18823
c19d1205
ZW
18824/* Table of all explicit relocation names. */
18825#ifdef OBJ_ELF
18826static struct reloc_entry reloc_names[] =
18827{
18828 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
18829 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
18830 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
18831 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
18832 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
18833 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
18834 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
18835 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
18836 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
18837 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 18838 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
18839 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
18840 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 18841 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 18842 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 18843 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 18844 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
477330fc 18845 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
18846};
18847#endif
b99bd4ef 18848
c19d1205
ZW
18849/* Table of all conditional affixes. 0xF is not defined as a condition code. */
18850static const struct asm_cond conds[] =
18851{
18852 {"eq", 0x0},
18853 {"ne", 0x1},
18854 {"cs", 0x2}, {"hs", 0x2},
18855 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
18856 {"mi", 0x4},
18857 {"pl", 0x5},
18858 {"vs", 0x6},
18859 {"vc", 0x7},
18860 {"hi", 0x8},
18861 {"ls", 0x9},
18862 {"ge", 0xa},
18863 {"lt", 0xb},
18864 {"gt", 0xc},
18865 {"le", 0xd},
18866 {"al", 0xe}
18867};
bfae80f2 18868
e797f7e0 18869#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
18870 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
18871 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 18872
62b3e311
PB
18873static struct asm_barrier_opt barrier_opt_names[] =
18874{
e797f7e0
MGD
18875 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
18876 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
18877 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
18878 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
18879 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
18880 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
18881 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
18882 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
18883 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
18884 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
18885 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
18886 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
18887 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
18888 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
18889 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
18890 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
18891};
18892
e797f7e0
MGD
18893#undef UL_BARRIER
18894
c19d1205
ZW
18895/* Table of ARM-format instructions. */
18896
18897/* Macros for gluing together operand strings. N.B. In all cases
18898 other than OPS0, the trailing OP_stop comes from default
18899 zero-initialization of the unspecified elements of the array. */
18900#define OPS0() { OP_stop, }
18901#define OPS1(a) { OP_##a, }
18902#define OPS2(a,b) { OP_##a,OP_##b, }
18903#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
18904#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
18905#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
18906#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
18907
5be8be5d
DG
18908/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
18909 This is useful when mixing operands for ARM and THUMB, i.e. using the
18910 MIX_ARM_THUMB_OPERANDS macro.
18911 In order to use these macros, prefix the number of operands with _
18912 e.g. _3. */
18913#define OPS_1(a) { a, }
18914#define OPS_2(a,b) { a,b, }
18915#define OPS_3(a,b,c) { a,b,c, }
18916#define OPS_4(a,b,c,d) { a,b,c,d, }
18917#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
18918#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
18919
c19d1205
ZW
18920/* These macros abstract out the exact format of the mnemonic table and
18921 save some repeated characters. */
18922
18923/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
18924#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18925 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 18926 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18927
18928/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
18929 a T_MNEM_xyz enumerator. */
18930#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18931 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18932#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18933 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
18934
18935/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
18936 infix after the third character. */
18937#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 18938 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 18939 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 18940#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 18941 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 18942 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18943#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18944 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 18945#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 18946 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 18947#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18948 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 18949#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 18950 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 18951
c19d1205 18952/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
18953 field is still 0xE. Many of the Thumb variants can be executed
18954 conditionally, so this is checked separately. */
c19d1205 18955#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 18956 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18957 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 18958
dd5181d5
KT
18959/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
18960 Used by mnemonics that have very minimal differences in the encoding for
18961 ARM and Thumb variants and can be handled in a common function. */
18962#define TUEc(mnem, op, top, nops, ops, en) \
18963 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
18964 THUMB_VARIANT, do_##en, do_##en }
18965
c19d1205
ZW
18966/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
18967 condition code field. */
18968#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 18969 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 18970 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
18971
18972/* ARM-only variants of all the above. */
6a86118a 18973#define CE(mnem, op, nops, ops, ae) \
21d799b5 18974 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
18975
18976#define C3(mnem, op, nops, ops, ae) \
18977 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18978
e3cb604e
PB
18979/* Legacy mnemonics that always have conditional infix after the third
18980 character. */
18981#define CL(mnem, op, nops, ops, ae) \
21d799b5 18982 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
18983 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
18984
8f06b2d8
PB
18985/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
18986#define cCE(mnem, op, nops, ops, ae) \
21d799b5 18987 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 18988
e3cb604e
PB
18989/* Legacy coprocessor instructions where conditional infix and conditional
18990 suffix are ambiguous. For consistency this includes all FPA instructions,
18991 not just the potentially ambiguous ones. */
18992#define cCL(mnem, op, nops, ops, ae) \
21d799b5 18993 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
18994 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
18995
18996/* Coprocessor, takes either a suffix or a position-3 infix
18997 (for an FPA corner case). */
18998#define C3E(mnem, op, nops, ops, ae) \
21d799b5 18999 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 19000 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19001
6a86118a 19002#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
19003 { m1 #m2 m3, OPS##nops ops, \
19004 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
19005 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19006
19007#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
19008 xCM_ (m1, , m2, op, nops, ops, ae), \
19009 xCM_ (m1, eq, m2, op, nops, ops, ae), \
19010 xCM_ (m1, ne, m2, op, nops, ops, ae), \
19011 xCM_ (m1, cs, m2, op, nops, ops, ae), \
19012 xCM_ (m1, hs, m2, op, nops, ops, ae), \
19013 xCM_ (m1, cc, m2, op, nops, ops, ae), \
19014 xCM_ (m1, ul, m2, op, nops, ops, ae), \
19015 xCM_ (m1, lo, m2, op, nops, ops, ae), \
19016 xCM_ (m1, mi, m2, op, nops, ops, ae), \
19017 xCM_ (m1, pl, m2, op, nops, ops, ae), \
19018 xCM_ (m1, vs, m2, op, nops, ops, ae), \
19019 xCM_ (m1, vc, m2, op, nops, ops, ae), \
19020 xCM_ (m1, hi, m2, op, nops, ops, ae), \
19021 xCM_ (m1, ls, m2, op, nops, ops, ae), \
19022 xCM_ (m1, ge, m2, op, nops, ops, ae), \
19023 xCM_ (m1, lt, m2, op, nops, ops, ae), \
19024 xCM_ (m1, gt, m2, op, nops, ops, ae), \
19025 xCM_ (m1, le, m2, op, nops, ops, ae), \
19026 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
19027
19028#define UE(mnem, op, nops, ops, ae) \
19029 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19030
19031#define UF(mnem, op, nops, ops, ae) \
19032 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19033
5287ad62
JB
19034/* Neon data-processing. ARM versions are unconditional with cond=0xf.
19035 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
19036 use the same encoding function for each. */
19037#define NUF(mnem, op, nops, ops, enc) \
19038 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
19039 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19040
19041/* Neon data processing, version which indirects through neon_enc_tab for
19042 the various overloaded versions of opcodes. */
19043#define nUF(mnem, op, nops, ops, enc) \
21d799b5 19044 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19045 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19046
19047/* Neon insn with conditional suffix for the ARM version, non-overloaded
19048 version. */
037e8744
JB
19049#define NCE_tag(mnem, op, nops, ops, enc, tag) \
19050 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
19051 THUMB_VARIANT, do_##enc, do_##enc }
19052
037e8744 19053#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 19054 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19055
19056#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 19057 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19058
5287ad62 19059/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 19060#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 19061 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19062 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19063
037e8744 19064#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 19065 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19066
19067#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 19068 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19069
c19d1205
ZW
19070#define do_0 0
19071
c19d1205 19072static const struct asm_opcode insns[] =
bfae80f2 19073{
74db7efb
NC
19074#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
19075#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
19076 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
19077 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
19078 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
19079 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
19080 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
19081 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
19082 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
19083 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
19084 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
19085 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
19086 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
19087 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
19088 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
19089 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
19090 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
19091 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
19092
19093 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
19094 for setting PSR flag bits. They are obsolete in V6 and do not
19095 have Thumb equivalents. */
21d799b5
NC
19096 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19097 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19098 CL("tstp", 110f000, 2, (RR, SH), cmp),
19099 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19100 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19101 CL("cmpp", 150f000, 2, (RR, SH), cmp),
19102 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19103 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19104 CL("cmnp", 170f000, 2, (RR, SH), cmp),
19105
19106 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 19107 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
19108 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
19109 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
19110
19111 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
19112 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19113 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
19114 OP_RRnpc),
19115 OP_ADDRGLDR),ldst, t_ldst),
19116 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
19117
19118 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19119 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19120 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19121 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19122 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19123 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19124
19125 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
19126 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
19127 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
19128 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 19129
c19d1205 19130 /* Pseudo ops. */
21d799b5 19131 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 19132 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 19133 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 19134 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
19135
19136 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
19137 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
19138 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
19139 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
19140 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
19141 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
19142 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
19143 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
19144 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
19145 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
19146 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
19147 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
19148 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 19149
16a4cf17 19150 /* These may simplify to neg. */
21d799b5
NC
19151 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
19152 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 19153
c921be7d
NC
19154#undef THUMB_VARIANT
19155#define THUMB_VARIANT & arm_ext_v6
19156
21d799b5 19157 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
19158
19159 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
19160#undef THUMB_VARIANT
19161#define THUMB_VARIANT & arm_ext_v6t2
19162
21d799b5
NC
19163 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19164 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19165 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 19166
5be8be5d
DG
19167 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19168 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19169 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19170 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 19171
21d799b5
NC
19172 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19173 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 19174
21d799b5
NC
19175 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19176 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
19177
19178 /* V1 instructions with no Thumb analogue at all. */
21d799b5 19179 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
19180 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19181
19182 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19183 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19184 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19185 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19186 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19187 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19188 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19189 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19190
c921be7d
NC
19191#undef ARM_VARIANT
19192#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19193#undef THUMB_VARIANT
19194#define THUMB_VARIANT & arm_ext_v4t
19195
21d799b5
NC
19196 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19197 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 19198
c921be7d
NC
19199#undef THUMB_VARIANT
19200#define THUMB_VARIANT & arm_ext_v6t2
19201
21d799b5 19202 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
19203 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19204
19205 /* Generic coprocessor instructions. */
21d799b5
NC
19206 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19207 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19208 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19209 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19210 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19211 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 19212 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19213
c921be7d
NC
19214#undef ARM_VARIANT
19215#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19216
21d799b5 19217 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
19218 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19219
c921be7d
NC
19220#undef ARM_VARIANT
19221#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19222#undef THUMB_VARIANT
19223#define THUMB_VARIANT & arm_ext_msr
19224
d2cd1205
JB
19225 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19226 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 19227
c921be7d
NC
19228#undef ARM_VARIANT
19229#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19230#undef THUMB_VARIANT
19231#define THUMB_VARIANT & arm_ext_v6t2
19232
21d799b5
NC
19233 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19234 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19235 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19236 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19237 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19238 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19239 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19240 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 19241
c921be7d
NC
19242#undef ARM_VARIANT
19243#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
19244#undef THUMB_VARIANT
19245#define THUMB_VARIANT & arm_ext_v4t
19246
5be8be5d
DG
19247 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19248 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19249 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19250 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
19251 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19252 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 19253
c921be7d
NC
19254#undef ARM_VARIANT
19255#define ARM_VARIANT & arm_ext_v4t_5
19256
c19d1205
ZW
19257 /* ARM Architecture 4T. */
19258 /* Note: bx (and blx) are required on V5, even if the processor does
19259 not support Thumb. */
21d799b5 19260 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 19261
c921be7d
NC
19262#undef ARM_VARIANT
19263#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
19264#undef THUMB_VARIANT
19265#define THUMB_VARIANT & arm_ext_v5t
19266
c19d1205
ZW
19267 /* Note: blx has 2 variants; the .value coded here is for
19268 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
19269 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
19270 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 19271
c921be7d
NC
19272#undef THUMB_VARIANT
19273#define THUMB_VARIANT & arm_ext_v6t2
19274
21d799b5
NC
19275 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
19276 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19277 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19278 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19279 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19280 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19281 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19282 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19283
c921be7d 19284#undef ARM_VARIANT
74db7efb
NC
19285#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
19286#undef THUMB_VARIANT
19287#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 19288
21d799b5
NC
19289 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19290 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19291 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19292 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19293
21d799b5
NC
19294 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19295 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19296
21d799b5
NC
19297 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19298 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19299 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19300 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 19301
21d799b5
NC
19302 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19303 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19304 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19305 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19306
21d799b5
NC
19307 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19308 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19309
03ee1b7f
NC
19310 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19311 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19312 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19313 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 19314
c921be7d 19315#undef ARM_VARIANT
74db7efb
NC
19316#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
19317#undef THUMB_VARIANT
19318#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19319
21d799b5 19320 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
19321 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
19322 ldrd, t_ldstd),
19323 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
19324 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 19325
21d799b5
NC
19326 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19327 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 19328
c921be7d
NC
19329#undef ARM_VARIANT
19330#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
19331
21d799b5 19332 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 19333
c921be7d
NC
19334#undef ARM_VARIANT
19335#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
19336#undef THUMB_VARIANT
19337#define THUMB_VARIANT & arm_ext_v6
19338
21d799b5
NC
19339 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
19340 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
19341 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19342 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19343 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19344 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19345 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19346 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19347 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19348 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 19349
c921be7d 19350#undef THUMB_VARIANT
ff8646ee 19351#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 19352
5be8be5d
DG
19353 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
19354 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19355 strex, t_strex),
ff8646ee
TP
19356#undef THUMB_VARIANT
19357#define THUMB_VARIANT & arm_ext_v6t2
19358
21d799b5
NC
19359 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19360 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 19361
21d799b5
NC
19362 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
19363 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 19364
9e3c6df6 19365/* ARM V6 not included in V7M. */
c921be7d
NC
19366#undef THUMB_VARIANT
19367#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 19368 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 19369 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
19370 UF(rfeib, 9900a00, 1, (RRw), rfe),
19371 UF(rfeda, 8100a00, 1, (RRw), rfe),
19372 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19373 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
19374 UF(rfefa, 8100a00, 1, (RRw), rfe),
19375 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19376 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 19377 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
19378 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19379 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 19380 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 19381 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 19382 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 19383 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 19384 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 19385 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 19386 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 19387
9e3c6df6
PB
19388/* ARM V6 not included in V7M (eg. integer SIMD). */
19389#undef THUMB_VARIANT
19390#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
19391 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
19392 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
19393 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19394 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19395 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19396 /* Old name for QASX. */
74db7efb 19397 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19398 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19399 /* Old name for QSAX. */
74db7efb 19400 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19401 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19402 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19403 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19404 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19405 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19406 /* Old name for SASX. */
74db7efb 19407 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19408 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19409 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19410 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19411 /* Old name for SHASX. */
21d799b5 19412 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19413 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19414 /* Old name for SHSAX. */
21d799b5
NC
19415 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19416 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19417 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19418 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19419 /* Old name for SSAX. */
74db7efb 19420 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19421 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19422 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19423 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19424 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19425 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19426 /* Old name for UASX. */
74db7efb 19427 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19428 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19429 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19430 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19431 /* Old name for UHASX. */
21d799b5
NC
19432 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19433 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19434 /* Old name for UHSAX. */
21d799b5
NC
19435 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19436 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19437 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19438 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19439 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19440 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19441 /* Old name for UQASX. */
21d799b5
NC
19442 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19443 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19444 /* Old name for UQSAX. */
21d799b5
NC
19445 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19446 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19447 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19448 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19449 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19450 /* Old name for USAX. */
74db7efb 19451 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19452 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19453 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19454 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19455 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19456 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19457 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19458 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19459 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19460 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19461 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19462 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19463 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19464 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19465 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19466 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19467 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19468 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19469 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19470 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19471 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19472 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19473 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19474 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19475 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19476 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19477 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19478 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19479 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
19480 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
19481 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
19482 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19483 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19484 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 19485
c921be7d
NC
19486#undef ARM_VARIANT
19487#define ARM_VARIANT & arm_ext_v6k
19488#undef THUMB_VARIANT
19489#define THUMB_VARIANT & arm_ext_v6k
19490
21d799b5
NC
19491 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
19492 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
19493 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
19494 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 19495
c921be7d
NC
19496#undef THUMB_VARIANT
19497#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
19498 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
19499 ldrexd, t_ldrexd),
19500 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
19501 RRnpcb), strexd, t_strexd),
ebdca51a 19502
c921be7d 19503#undef THUMB_VARIANT
ff8646ee 19504#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
19505 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
19506 rd_rn, rd_rn),
19507 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
19508 rd_rn, rd_rn),
19509 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19510 strex, t_strexbh),
5be8be5d 19511 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19512 strex, t_strexbh),
21d799b5 19513 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 19514
c921be7d 19515#undef ARM_VARIANT
f4c65163 19516#define ARM_VARIANT & arm_ext_sec
74db7efb 19517#undef THUMB_VARIANT
f4c65163 19518#define THUMB_VARIANT & arm_ext_sec
c921be7d 19519
21d799b5 19520 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 19521
90ec0d68
MGD
19522#undef ARM_VARIANT
19523#define ARM_VARIANT & arm_ext_virt
19524#undef THUMB_VARIANT
19525#define THUMB_VARIANT & arm_ext_virt
19526
19527 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
19528 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
19529
ddfded2f
MW
19530#undef ARM_VARIANT
19531#define ARM_VARIANT & arm_ext_pan
19532#undef THUMB_VARIANT
19533#define THUMB_VARIANT & arm_ext_pan
19534
19535 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
19536
c921be7d 19537#undef ARM_VARIANT
74db7efb 19538#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
19539#undef THUMB_VARIANT
19540#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19541
21d799b5
NC
19542 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
19543 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
19544 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
19545 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 19546
21d799b5 19547 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 19548 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 19549
5be8be5d
DG
19550 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19551 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19552 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19553 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 19554
ff8646ee
TP
19555#undef THUMB_VARIANT
19556#define THUMB_VARIANT & arm_ext_v6t2_v8m
19557 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
19558 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
19559
bf3eeda7 19560 /* Thumb-only instructions. */
74db7efb 19561#undef ARM_VARIANT
bf3eeda7
NS
19562#define ARM_VARIANT NULL
19563 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
19564 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
19565
19566 /* ARM does not really have an IT instruction, so always allow it.
19567 The opcode is copied from Thumb in order to allow warnings in
19568 -mimplicit-it=[never | arm] modes. */
19569#undef ARM_VARIANT
19570#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
19571#undef THUMB_VARIANT
19572#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19573
21d799b5
NC
19574 TUE("it", bf08, bf08, 1, (COND), it, t_it),
19575 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
19576 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
19577 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
19578 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
19579 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
19580 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
19581 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
19582 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
19583 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
19584 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
19585 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
19586 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
19587 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
19588 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 19589 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
19590 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
19591 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 19592
92e90b6e 19593 /* Thumb2 only instructions. */
c921be7d
NC
19594#undef ARM_VARIANT
19595#define ARM_VARIANT NULL
92e90b6e 19596
21d799b5
NC
19597 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19598 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19599 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
19600 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
19601 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
19602 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 19603
eea54501
MGD
19604 /* Hardware division instructions. */
19605#undef ARM_VARIANT
19606#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
19607#undef THUMB_VARIANT
19608#define THUMB_VARIANT & arm_ext_div
19609
eea54501
MGD
19610 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
19611 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 19612
7e806470 19613 /* ARM V6M/V7 instructions. */
c921be7d
NC
19614#undef ARM_VARIANT
19615#define ARM_VARIANT & arm_ext_barrier
19616#undef THUMB_VARIANT
19617#define THUMB_VARIANT & arm_ext_barrier
19618
ccb84d65
JB
19619 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
19620 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
19621 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 19622
62b3e311 19623 /* ARM V7 instructions. */
c921be7d
NC
19624#undef ARM_VARIANT
19625#define ARM_VARIANT & arm_ext_v7
19626#undef THUMB_VARIANT
19627#define THUMB_VARIANT & arm_ext_v7
19628
21d799b5
NC
19629 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
19630 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 19631
74db7efb 19632#undef ARM_VARIANT
60e5ef9f 19633#define ARM_VARIANT & arm_ext_mp
74db7efb 19634#undef THUMB_VARIANT
60e5ef9f
MGD
19635#define THUMB_VARIANT & arm_ext_mp
19636
19637 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
19638
53c4b28b
MGD
19639 /* AArchv8 instructions. */
19640#undef ARM_VARIANT
19641#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
19642
19643/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 19644#undef THUMB_VARIANT
4ed7ed8d 19645#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 19646
4ed7ed8d
TP
19647 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19648 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19649 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19650 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19651 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19652 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 19653 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
19654 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
19655 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19656 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
19657 stlex, t_stlex),
4b8c8c02
RE
19658 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
19659 stlex, t_stlex),
19660 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
19661 stlex, t_stlex),
4ed7ed8d
TP
19662#undef THUMB_VARIANT
19663#define THUMB_VARIANT & arm_ext_v8
53c4b28b 19664
4ed7ed8d
TP
19665 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
19666 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
19667 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
19668 ldrexd, t_ldrexd),
19669 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
19670 strexd, t_strexd),
8884b720 19671 /* ARMv8 T32 only. */
74db7efb 19672#undef ARM_VARIANT
b79f7053
MGD
19673#define ARM_VARIANT NULL
19674 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
19675 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
19676 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
19677
33399f07
MGD
19678 /* FP for ARMv8. */
19679#undef ARM_VARIANT
a715796b 19680#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 19681#undef THUMB_VARIANT
a715796b 19682#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
19683
19684 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
19685 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
19686 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
19687 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
19688 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
19689 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
19690 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
19691 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
19692 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
19693 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
19694 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
19695 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
19696 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
19697 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
19698 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
19699 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
19700 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 19701
91ff7894
MGD
19702 /* Crypto v1 extensions. */
19703#undef ARM_VARIANT
19704#define ARM_VARIANT & fpu_crypto_ext_armv8
19705#undef THUMB_VARIANT
19706#define THUMB_VARIANT & fpu_crypto_ext_armv8
19707
19708 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
19709 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
19710 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
19711 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
19712 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
19713 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
19714 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
19715 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
19716 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
19717 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
19718 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
19719 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
19720 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
19721 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 19722
dd5181d5 19723#undef ARM_VARIANT
74db7efb 19724#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
19725#undef THUMB_VARIANT
19726#define THUMB_VARIANT & crc_ext_armv8
19727 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
19728 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
19729 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
19730 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
19731 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
19732 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
19733
105bde57
MW
19734 /* ARMv8.2 RAS extension. */
19735#undef ARM_VARIANT
4d1464f2 19736#define ARM_VARIANT & arm_ext_ras
105bde57 19737#undef THUMB_VARIANT
4d1464f2 19738#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
19739 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
19740
c921be7d
NC
19741#undef ARM_VARIANT
19742#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
19743#undef THUMB_VARIANT
19744#define THUMB_VARIANT NULL
c921be7d 19745
21d799b5
NC
19746 cCE("wfs", e200110, 1, (RR), rd),
19747 cCE("rfs", e300110, 1, (RR), rd),
19748 cCE("wfc", e400110, 1, (RR), rd),
19749 cCE("rfc", e500110, 1, (RR), rd),
19750
19751 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
19752 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
19753 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
19754 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
19755
19756 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
19757 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
19758 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
19759 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
19760
19761 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
19762 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
19763 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
19764 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
19765 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
19766 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
19767 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
19768 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
19769 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
19770 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
19771 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
19772 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
19773
19774 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
19775 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
19776 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
19777 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
19778 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
19779 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
19780 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
19781 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
19782 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
19783 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
19784 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
19785 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
19786
19787 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
19788 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
19789 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
19790 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
19791 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
19792 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
19793 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
19794 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
19795 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
19796 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
19797 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
19798 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
19799
19800 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
19801 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
19802 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
19803 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
19804 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
19805 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
19806 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
19807 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
19808 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
19809 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
19810 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
19811 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
19812
19813 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
19814 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
19815 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
19816 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
19817 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
19818 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
19819 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
19820 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
19821 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
19822 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
19823 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
19824 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
19825
19826 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
19827 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
19828 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
19829 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
19830 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
19831 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
19832 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
19833 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
19834 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
19835 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
19836 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
19837 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
19838
19839 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
19840 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
19841 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
19842 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
19843 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
19844 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
19845 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
19846 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
19847 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
19848 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
19849 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
19850 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
19851
19852 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
19853 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
19854 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
19855 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
19856 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
19857 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
19858 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
19859 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
19860 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
19861 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
19862 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
19863 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
19864
19865 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
19866 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
19867 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
19868 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
19869 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
19870 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
19871 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
19872 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
19873 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
19874 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
19875 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
19876 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
19877
19878 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
19879 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
19880 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
19881 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
19882 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
19883 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
19884 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
19885 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
19886 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
19887 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
19888 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
19889 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
19890
19891 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
19892 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
19893 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
19894 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
19895 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
19896 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
19897 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
19898 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
19899 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
19900 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
19901 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
19902 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
19903
19904 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
19905 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
19906 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
19907 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
19908 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
19909 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
19910 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
19911 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
19912 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
19913 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
19914 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
19915 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
19916
19917 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
19918 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
19919 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
19920 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
19921 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
19922 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
19923 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
19924 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
19925 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
19926 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
19927 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
19928 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
19929
19930 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
19931 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
19932 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
19933 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
19934 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
19935 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
19936 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
19937 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
19938 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
19939 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
19940 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
19941 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
19942
19943 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
19944 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
19945 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
19946 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
19947 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
19948 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
19949 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
19950 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
19951 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
19952 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
19953 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
19954 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
19955
19956 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
19957 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
19958 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
19959 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
19960 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
19961 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
19962 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
19963 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
19964 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
19965 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
19966 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
19967 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
19968
19969 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
19970 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
19971 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
19972 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
19973 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
19974 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19975 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19976 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19977 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
19978 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
19979 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
19980 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
19981
19982 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
19983 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
19984 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
19985 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
19986 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
19987 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
19988 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
19989 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
19990 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
19991 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
19992 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
19993 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
19994
19995 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
19996 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
19997 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
19998 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
19999 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
20000 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20001 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20002 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20003 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
20004 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
20005 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
20006 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
20007
20008 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
20009 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
20010 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
20011 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
20012 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
20013 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20014 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20015 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20016 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
20017 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
20018 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
20019 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
20020
20021 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
20022 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
20023 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
20024 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
20025 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
20026 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20027 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20028 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20029 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
20030 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
20031 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
20032 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
20033
20034 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
20035 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
20036 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
20037 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
20038 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
20039 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20040 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20041 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20042 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
20043 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
20044 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
20045 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
20046
20047 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
20048 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
20049 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
20050 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
20051 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
20052 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20053 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20054 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20055 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
20056 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
20057 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
20058 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
20059
20060 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
20061 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
20062 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
20063 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
20064 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
20065 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20066 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20067 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20068 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
20069 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
20070 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
20071 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
20072
20073 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
20074 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
20075 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
20076 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
20077 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
20078 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20079 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20080 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20081 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
20082 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
20083 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
20084 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
20085
20086 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
20087 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
20088 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
20089 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
20090 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
20091 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20092 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20093 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20094 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
20095 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
20096 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
20097 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
20098
20099 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20100 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20101 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20102 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20103 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20104 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20105 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20106 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20107 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20108 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20109 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20110 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20111
20112 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20113 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20114 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20115 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20116 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20117 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20118 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20119 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20120 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20121 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20122 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20123 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20124
20125 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20126 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20127 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20128 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20129 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20130 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20131 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20132 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20133 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20134 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20135 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20136 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20137
20138 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
20139 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
20140 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
20141 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
20142
20143 cCL("flts", e000110, 2, (RF, RR), rn_rd),
20144 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
20145 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
20146 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
20147 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
20148 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
20149 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
20150 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
20151 cCL("flte", e080110, 2, (RF, RR), rn_rd),
20152 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
20153 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20154 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 20155
c19d1205
ZW
20156 /* The implementation of the FIX instruction is broken on some
20157 assemblers, in that it accepts a precision specifier as well as a
20158 rounding specifier, despite the fact that this is meaningless.
20159 To be more compatible, we accept it as well, though of course it
20160 does not set any bits. */
21d799b5
NC
20161 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20162 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20163 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20164 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20165 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20166 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20167 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20168 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20169 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20170 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20171 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20172 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20173 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 20174
c19d1205 20175 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
20176#undef ARM_VARIANT
20177#define ARM_VARIANT & fpu_fpa_ext_v2
20178
21d799b5
NC
20179 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20180 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20181 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20182 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20183 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20184 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 20185
c921be7d
NC
20186#undef ARM_VARIANT
20187#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20188
c19d1205 20189 /* Moves and type conversions. */
21d799b5
NC
20190 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20191 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20192 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20193 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
20194 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20195 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
20196 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20197 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20198 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
20199 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20200 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
20201 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20202 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
20203 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
20204
20205 /* Memory operations. */
21d799b5
NC
20206 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20207 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
20208 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20209 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20210 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20211 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20212 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20213 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20214 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20215 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20216 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20217 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20218 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20219 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20220 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20221 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20222 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20223 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 20224
c19d1205 20225 /* Monadic operations. */
21d799b5
NC
20226 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
20227 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
20228 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
20229
20230 /* Dyadic operations. */
21d799b5
NC
20231 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20232 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20233 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20234 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20235 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20236 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20237 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20238 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20239 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 20240
c19d1205 20241 /* Comparisons. */
21d799b5
NC
20242 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
20243 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
20244 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
20245 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 20246
62f3b8c8
PB
20247 /* Double precision load/store are still present on single precision
20248 implementations. */
20249 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20250 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
20251 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20252 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20253 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20254 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20255 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20256 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20257 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20258 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 20259
c921be7d
NC
20260#undef ARM_VARIANT
20261#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
20262
c19d1205 20263 /* Moves and type conversions. */
21d799b5
NC
20264 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20265 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20266 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20267 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
20268 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
20269 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
20270 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
20271 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20272 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
20273 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20274 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20275 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20276 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 20277
c19d1205 20278 /* Monadic operations. */
21d799b5
NC
20279 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20280 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20281 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
20282
20283 /* Dyadic operations. */
21d799b5
NC
20284 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20285 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20286 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20287 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20288 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20289 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20290 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20291 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20292 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 20293
c19d1205 20294 /* Comparisons. */
21d799b5
NC
20295 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20296 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
20297 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20298 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 20299
c921be7d
NC
20300#undef ARM_VARIANT
20301#define ARM_VARIANT & fpu_vfp_ext_v2
20302
21d799b5
NC
20303 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
20304 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
20305 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
20306 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 20307
037e8744
JB
20308/* Instructions which may belong to either the Neon or VFP instruction sets.
20309 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
20310#undef ARM_VARIANT
20311#define ARM_VARIANT & fpu_vfp_ext_v1xd
20312#undef THUMB_VARIANT
20313#define THUMB_VARIANT & fpu_vfp_ext_v1xd
20314
037e8744
JB
20315 /* These mnemonics are unique to VFP. */
20316 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
20317 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
20318 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20319 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20320 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
20321 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20322 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
20323 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
20324 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
20325 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
20326
20327 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
20328 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
20329 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20330 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 20331
21d799b5
NC
20332 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20333 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
20334
20335 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20336 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20337
55881a11
MGD
20338 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20339 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20340 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20341 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20342 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20343 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
20344 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20345 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 20346
5f1af56b 20347 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 20348 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
20349 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
20350 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 20351
037e8744
JB
20352
20353 /* NOTE: All VMOV encoding is special-cased! */
20354 NCE(vmov, 0, 1, (VMOV), neon_mov),
20355 NCE(vmovq, 0, 1, (VMOV), neon_mov),
20356
9db2f6b4
RL
20357#undef ARM_VARIANT
20358#define ARM_VARIANT & arm_ext_fp16
20359#undef THUMB_VARIANT
20360#define THUMB_VARIANT & arm_ext_fp16
20361 /* New instructions added from v8.2, allowing the extraction and insertion of
20362 the upper 16 bits of a 32-bit vector register. */
20363 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
20364 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
20365
c921be7d
NC
20366#undef THUMB_VARIANT
20367#define THUMB_VARIANT & fpu_neon_ext_v1
20368#undef ARM_VARIANT
20369#define ARM_VARIANT & fpu_neon_ext_v1
20370
5287ad62
JB
20371 /* Data processing with three registers of the same length. */
20372 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
20373 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
20374 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
20375 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20376 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20377 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20378 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20379 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20380 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20381 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
20382 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20383 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20384 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20385 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
20386 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20387 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20388 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20389 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
20390 /* If not immediate, fall back to neon_dyadic_i64_su.
20391 shl_imm should accept I8 I16 I32 I64,
20392 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
20393 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
20394 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
20395 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
20396 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 20397 /* Logic ops, types optional & ignored. */
4316f0d2
DG
20398 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20399 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20400 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20401 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20402 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20403 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20404 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20405 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20406 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
20407 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
20408 /* Bitfield ops, untyped. */
20409 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20410 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20411 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20412 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20413 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20414 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 20415 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5
NC
20416 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20417 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20418 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20419 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20420 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20421 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
20422 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
20423 back to neon_dyadic_if_su. */
21d799b5
NC
20424 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20425 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20426 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20427 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20428 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20429 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
20430 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20431 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 20432 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
20433 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
20434 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 20435 /* As above, D registers only. */
21d799b5
NC
20436 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
20437 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 20438 /* Int and float variants, signedness unimportant. */
21d799b5
NC
20439 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20440 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20441 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 20442 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
20443 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
20444 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
20445 /* vtst takes sizes 8, 16, 32. */
20446 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
20447 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
20448 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 20449 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 20450 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
20451 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20452 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
20453 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20454 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
20455 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20456 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
20457 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20458 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
20459 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20460 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
20461 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20462 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
20463 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20464 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
20465 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20466 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 20467 /* ARM v8.1 extension. */
643afb90
MW
20468 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20469 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
20470 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20471 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
20472
20473 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 20474 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
20475 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
20476
20477 /* Data processing with two registers and a shift amount. */
20478 /* Right shifts, and variants with rounding.
20479 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
20480 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20481 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20482 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20483 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20484 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20485 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20486 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20487 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20488 /* Shift and insert. Sizes accepted 8 16 32 64. */
20489 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
20490 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
20491 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
20492 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
20493 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
20494 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
20495 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
20496 /* Right shift immediate, saturating & narrowing, with rounding variants.
20497 Types accepted S16 S32 S64 U16 U32 U64. */
20498 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20499 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20500 /* As above, unsigned. Types accepted S16 S32 S64. */
20501 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20502 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20503 /* Right shift narrowing. Types accepted I16 I32 I64. */
20504 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20505 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20506 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 20507 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 20508 /* CVT with optional immediate for fixed-point variant. */
21d799b5 20509 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 20510
4316f0d2
DG
20511 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
20512 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
20513
20514 /* Data processing, three registers of different lengths. */
20515 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
20516 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
20517 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
20518 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
20519 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
20520 /* If not scalar, fall back to neon_dyadic_long.
20521 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
20522 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
20523 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
20524 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
20525 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20526 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20527 /* Dyadic, narrowing insns. Types I16 I32 I64. */
20528 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20529 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20530 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20531 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20532 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
20533 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20534 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20535 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
20536 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
20537 S16 S32 U16 U32. */
21d799b5 20538 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
20539
20540 /* Extract. Size 8. */
3b8d421e
PB
20541 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
20542 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
20543
20544 /* Two registers, miscellaneous. */
20545 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
20546 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
20547 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
20548 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
20549 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
20550 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
20551 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
20552 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
20553 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
20554 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
20555 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
20556 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
20557 /* VMOVN. Types I16 I32 I64. */
21d799b5 20558 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 20559 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 20560 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 20561 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 20562 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
20563 /* VZIP / VUZP. Sizes 8 16 32. */
20564 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
20565 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
20566 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
20567 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
20568 /* VQABS / VQNEG. Types S8 S16 S32. */
20569 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20570 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
20571 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20572 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
20573 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
20574 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
20575 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
20576 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
20577 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 20578 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
20579 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
20580 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
20581 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
20582 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
20583 /* VCLS. Types S8 S16 S32. */
20584 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
20585 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
20586 /* VCLZ. Types I8 I16 I32. */
20587 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
20588 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
20589 /* VCNT. Size 8. */
20590 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
20591 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
20592 /* Two address, untyped. */
20593 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
20594 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
20595 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
20596 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
20597 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
20598
20599 /* Table lookup. Size 8. */
20600 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20601 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20602
c921be7d
NC
20603#undef THUMB_VARIANT
20604#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
20605#undef ARM_VARIANT
20606#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
20607
5287ad62 20608 /* Neon element/structure load/store. */
21d799b5
NC
20609 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20610 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20611 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20612 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20613 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20614 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20615 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
20616 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 20617
c921be7d 20618#undef THUMB_VARIANT
74db7efb
NC
20619#define THUMB_VARIANT & fpu_vfp_ext_v3xd
20620#undef ARM_VARIANT
20621#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
20622 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
20623 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20624 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20625 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20626 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20627 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20628 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20629 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20630 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20631
74db7efb 20632#undef THUMB_VARIANT
c921be7d
NC
20633#define THUMB_VARIANT & fpu_vfp_ext_v3
20634#undef ARM_VARIANT
20635#define ARM_VARIANT & fpu_vfp_ext_v3
20636
21d799b5 20637 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 20638 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20639 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20640 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20641 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20642 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20643 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20644 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20645 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 20646
74db7efb
NC
20647#undef ARM_VARIANT
20648#define ARM_VARIANT & fpu_vfp_ext_fma
20649#undef THUMB_VARIANT
20650#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
20651 /* Mnemonics shared by Neon and VFP. These are included in the
20652 VFP FMA variant; NEON and VFP FMA always includes the NEON
20653 FMA instructions. */
20654 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20655 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20656 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
20657 the v form should always be used. */
20658 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20659 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20660 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20661 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20662 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20663 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20664
5287ad62 20665#undef THUMB_VARIANT
c921be7d
NC
20666#undef ARM_VARIANT
20667#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
20668
21d799b5
NC
20669 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20670 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20671 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20672 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20673 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20674 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20675 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
20676 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 20677
c921be7d
NC
20678#undef ARM_VARIANT
20679#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
20680
21d799b5
NC
20681 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
20682 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
20683 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
20684 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
20685 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
20686 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
20687 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
20688 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
20689 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
20690 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20691 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20692 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20693 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20694 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20695 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
20696 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20697 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20698 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20699 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
20700 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
20701 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20702 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20703 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20704 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20705 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20706 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
20707 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
20708 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
20709 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
20710 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
20711 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
20712 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
20713 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
20714 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
20715 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
20716 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
20717 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
20718 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20719 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20720 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20721 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20722 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20723 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20724 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20725 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20726 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20727 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
20728 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20729 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20730 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20731 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20732 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20733 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20734 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20735 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20736 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20737 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20738 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20739 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20740 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20741 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20742 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20743 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20744 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20745 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20746 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20747 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20748 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20749 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20750 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20751 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20752 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20753 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20754 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20755 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20756 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20757 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20758 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20759 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20760 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20761 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20762 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20763 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20764 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20765 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20766 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20767 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20768 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20769 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
20770 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20771 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20772 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20773 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20774 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20775 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20776 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20777 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20778 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20779 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20780 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20781 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20782 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20783 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20784 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20785 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20786 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20787 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20788 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20789 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20790 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20791 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
20792 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20793 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20794 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20795 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20796 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20797 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20798 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20799 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20800 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20801 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20802 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20803 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20804 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20805 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20806 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20807 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20808 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20809 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20810 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20811 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20812 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20813 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20814 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20815 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20816 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20817 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20818 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20819 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20820 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20821 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20822 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20823 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
20824 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
20825 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
20826 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
20827 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
20828 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
20829 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20830 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20831 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20832 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
20833 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
20834 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
20835 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
20836 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
20837 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
20838 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20839 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20840 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20841 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20842 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 20843
c921be7d
NC
20844#undef ARM_VARIANT
20845#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
20846
21d799b5
NC
20847 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
20848 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
20849 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
20850 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
20851 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
20852 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
20853 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20854 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20855 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20856 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20857 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20858 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20859 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20860 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20861 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20862 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20863 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20864 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20865 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20866 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20867 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
20868 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20869 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20870 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20871 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20872 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20873 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20874 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20875 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20876 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20877 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20878 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20879 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20880 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20881 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20882 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20883 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20884 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20885 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20886 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20887 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20888 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20889 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20890 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20891 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20892 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20893 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20894 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20895 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20896 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20897 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20898 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20899 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20900 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20901 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20902 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20903 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 20904
c921be7d
NC
20905#undef ARM_VARIANT
20906#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
20907
21d799b5
NC
20908 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20909 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20910 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20911 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20912 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
20913 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
20914 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
20915 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
20916 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
20917 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
20918 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
20919 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
20920 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
20921 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
20922 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
20923 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
20924 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
20925 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
20926 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
20927 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
20928 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
20929 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
20930 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
20931 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
20932 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
20933 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
20934 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
20935 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
20936 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
20937 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
20938 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
20939 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
20940 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
20941 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
20942 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
20943 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
20944 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
20945 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
20946 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
20947 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
20948 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
20949 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
20950 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
20951 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
20952 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
20953 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
20954 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
20955 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
20956 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
20957 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
20958 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
20959 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
20960 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
20961 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
20962 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
20963 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
20964 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
20965 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
20966 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
20967 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
20968 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
20969 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
20970 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
20971 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
20972 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20973 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20974 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20975 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20976 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20977 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
20978 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
20979 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
20980 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
20981 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
20982 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
20983 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 20984
16a1fa25 20985 /* ARMv8-M instructions. */
4ed7ed8d
TP
20986#undef ARM_VARIANT
20987#define ARM_VARIANT NULL
20988#undef THUMB_VARIANT
20989#define THUMB_VARIANT & arm_ext_v8m
16a1fa25
TP
20990 TUE("sg", 0, e97fe97f, 0, (), 0, noargs),
20991 TUE("blxns", 0, 4784, 1, (RRnpc), 0, t_blx),
20992 TUE("bxns", 0, 4704, 1, (RRnpc), 0, t_bx),
4ed7ed8d
TP
20993 TUE("tt", 0, e840f000, 2, (RRnpc, RRnpc), 0, tt),
20994 TUE("ttt", 0, e840f040, 2, (RRnpc, RRnpc), 0, tt),
16a1fa25
TP
20995 TUE("tta", 0, e840f080, 2, (RRnpc, RRnpc), 0, tt),
20996 TUE("ttat", 0, e840f0c0, 2, (RRnpc, RRnpc), 0, tt),
20997
20998 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
20999 instructions behave as nop if no VFP is present. */
21000#undef THUMB_VARIANT
21001#define THUMB_VARIANT & arm_ext_v8m_main
21002 TUEc("vlldm", 0, ec300a00, 1, (RRnpc), rn),
21003 TUEc("vlstm", 0, ec200a00, 1, (RRnpc), rn),
c19d1205
ZW
21004};
21005#undef ARM_VARIANT
21006#undef THUMB_VARIANT
21007#undef TCE
c19d1205
ZW
21008#undef TUE
21009#undef TUF
21010#undef TCC
8f06b2d8 21011#undef cCE
e3cb604e
PB
21012#undef cCL
21013#undef C3E
c19d1205
ZW
21014#undef CE
21015#undef CM
21016#undef UE
21017#undef UF
21018#undef UT
5287ad62
JB
21019#undef NUF
21020#undef nUF
21021#undef NCE
21022#undef nCE
c19d1205
ZW
21023#undef OPS0
21024#undef OPS1
21025#undef OPS2
21026#undef OPS3
21027#undef OPS4
21028#undef OPS5
21029#undef OPS6
21030#undef do_0
21031\f
21032/* MD interface: bits in the object file. */
bfae80f2 21033
c19d1205
ZW
21034/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
21035 for use in the a.out file, and stores them in the array pointed to by buf.
21036 This knows about the endian-ness of the target machine and does
21037 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
21038 2 (short) and 4 (long) Floating numbers are put out as a series of
21039 LITTLENUMS (shorts, here at least). */
b99bd4ef 21040
c19d1205
ZW
21041void
21042md_number_to_chars (char * buf, valueT val, int n)
21043{
21044 if (target_big_endian)
21045 number_to_chars_bigendian (buf, val, n);
21046 else
21047 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
21048}
21049
c19d1205
ZW
21050static valueT
21051md_chars_to_number (char * buf, int n)
bfae80f2 21052{
c19d1205
ZW
21053 valueT result = 0;
21054 unsigned char * where = (unsigned char *) buf;
bfae80f2 21055
c19d1205 21056 if (target_big_endian)
b99bd4ef 21057 {
c19d1205
ZW
21058 while (n--)
21059 {
21060 result <<= 8;
21061 result |= (*where++ & 255);
21062 }
b99bd4ef 21063 }
c19d1205 21064 else
b99bd4ef 21065 {
c19d1205
ZW
21066 while (n--)
21067 {
21068 result <<= 8;
21069 result |= (where[n] & 255);
21070 }
bfae80f2 21071 }
b99bd4ef 21072
c19d1205 21073 return result;
bfae80f2 21074}
b99bd4ef 21075
c19d1205 21076/* MD interface: Sections. */
b99bd4ef 21077
fa94de6b
RM
21078/* Calculate the maximum variable size (i.e., excluding fr_fix)
21079 that an rs_machine_dependent frag may reach. */
21080
21081unsigned int
21082arm_frag_max_var (fragS *fragp)
21083{
21084 /* We only use rs_machine_dependent for variable-size Thumb instructions,
21085 which are either THUMB_SIZE (2) or INSN_SIZE (4).
21086
21087 Note that we generate relaxable instructions even for cases that don't
21088 really need it, like an immediate that's a trivial constant. So we're
21089 overestimating the instruction size for some of those cases. Rather
21090 than putting more intelligence here, it would probably be better to
21091 avoid generating a relaxation frag in the first place when it can be
21092 determined up front that a short instruction will suffice. */
21093
21094 gas_assert (fragp->fr_type == rs_machine_dependent);
21095 return INSN_SIZE;
21096}
21097
0110f2b8
PB
21098/* Estimate the size of a frag before relaxing. Assume everything fits in
21099 2 bytes. */
21100
c19d1205 21101int
0110f2b8 21102md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
21103 segT segtype ATTRIBUTE_UNUSED)
21104{
0110f2b8
PB
21105 fragp->fr_var = 2;
21106 return 2;
21107}
21108
21109/* Convert a machine dependent frag. */
21110
21111void
21112md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
21113{
21114 unsigned long insn;
21115 unsigned long old_op;
21116 char *buf;
21117 expressionS exp;
21118 fixS *fixp;
21119 int reloc_type;
21120 int pc_rel;
21121 int opcode;
21122
21123 buf = fragp->fr_literal + fragp->fr_fix;
21124
21125 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
21126 if (fragp->fr_symbol)
21127 {
0110f2b8
PB
21128 exp.X_op = O_symbol;
21129 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
21130 }
21131 else
21132 {
0110f2b8 21133 exp.X_op = O_constant;
5f4273c7 21134 }
0110f2b8
PB
21135 exp.X_add_number = fragp->fr_offset;
21136 opcode = fragp->fr_subtype;
21137 switch (opcode)
21138 {
21139 case T_MNEM_ldr_pc:
21140 case T_MNEM_ldr_pc2:
21141 case T_MNEM_ldr_sp:
21142 case T_MNEM_str_sp:
21143 case T_MNEM_ldr:
21144 case T_MNEM_ldrb:
21145 case T_MNEM_ldrh:
21146 case T_MNEM_str:
21147 case T_MNEM_strb:
21148 case T_MNEM_strh:
21149 if (fragp->fr_var == 4)
21150 {
5f4273c7 21151 insn = THUMB_OP32 (opcode);
0110f2b8
PB
21152 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
21153 {
21154 insn |= (old_op & 0x700) << 4;
21155 }
21156 else
21157 {
21158 insn |= (old_op & 7) << 12;
21159 insn |= (old_op & 0x38) << 13;
21160 }
21161 insn |= 0x00000c00;
21162 put_thumb32_insn (buf, insn);
21163 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
21164 }
21165 else
21166 {
21167 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
21168 }
21169 pc_rel = (opcode == T_MNEM_ldr_pc2);
21170 break;
21171 case T_MNEM_adr:
21172 if (fragp->fr_var == 4)
21173 {
21174 insn = THUMB_OP32 (opcode);
21175 insn |= (old_op & 0xf0) << 4;
21176 put_thumb32_insn (buf, insn);
21177 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
21178 }
21179 else
21180 {
21181 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21182 exp.X_add_number -= 4;
21183 }
21184 pc_rel = 1;
21185 break;
21186 case T_MNEM_mov:
21187 case T_MNEM_movs:
21188 case T_MNEM_cmp:
21189 case T_MNEM_cmn:
21190 if (fragp->fr_var == 4)
21191 {
21192 int r0off = (opcode == T_MNEM_mov
21193 || opcode == T_MNEM_movs) ? 0 : 8;
21194 insn = THUMB_OP32 (opcode);
21195 insn = (insn & 0xe1ffffff) | 0x10000000;
21196 insn |= (old_op & 0x700) << r0off;
21197 put_thumb32_insn (buf, insn);
21198 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21199 }
21200 else
21201 {
21202 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
21203 }
21204 pc_rel = 0;
21205 break;
21206 case T_MNEM_b:
21207 if (fragp->fr_var == 4)
21208 {
21209 insn = THUMB_OP32(opcode);
21210 put_thumb32_insn (buf, insn);
21211 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
21212 }
21213 else
21214 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
21215 pc_rel = 1;
21216 break;
21217 case T_MNEM_bcond:
21218 if (fragp->fr_var == 4)
21219 {
21220 insn = THUMB_OP32(opcode);
21221 insn |= (old_op & 0xf00) << 14;
21222 put_thumb32_insn (buf, insn);
21223 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
21224 }
21225 else
21226 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
21227 pc_rel = 1;
21228 break;
21229 case T_MNEM_add_sp:
21230 case T_MNEM_add_pc:
21231 case T_MNEM_inc_sp:
21232 case T_MNEM_dec_sp:
21233 if (fragp->fr_var == 4)
21234 {
21235 /* ??? Choose between add and addw. */
21236 insn = THUMB_OP32 (opcode);
21237 insn |= (old_op & 0xf0) << 4;
21238 put_thumb32_insn (buf, insn);
16805f35
PB
21239 if (opcode == T_MNEM_add_pc)
21240 reloc_type = BFD_RELOC_ARM_T32_IMM12;
21241 else
21242 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
21243 }
21244 else
21245 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21246 pc_rel = 0;
21247 break;
21248
21249 case T_MNEM_addi:
21250 case T_MNEM_addis:
21251 case T_MNEM_subi:
21252 case T_MNEM_subis:
21253 if (fragp->fr_var == 4)
21254 {
21255 insn = THUMB_OP32 (opcode);
21256 insn |= (old_op & 0xf0) << 4;
21257 insn |= (old_op & 0xf) << 16;
21258 put_thumb32_insn (buf, insn);
16805f35
PB
21259 if (insn & (1 << 20))
21260 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21261 else
21262 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
21263 }
21264 else
21265 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21266 pc_rel = 0;
21267 break;
21268 default:
5f4273c7 21269 abort ();
0110f2b8
PB
21270 }
21271 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 21272 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
21273 fixp->fx_file = fragp->fr_file;
21274 fixp->fx_line = fragp->fr_line;
21275 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
21276
21277 /* Set whether we use thumb-2 ISA based on final relaxation results. */
21278 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
21279 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
21280 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
21281}
21282
21283/* Return the size of a relaxable immediate operand instruction.
21284 SHIFT and SIZE specify the form of the allowable immediate. */
21285static int
21286relax_immediate (fragS *fragp, int size, int shift)
21287{
21288 offsetT offset;
21289 offsetT mask;
21290 offsetT low;
21291
21292 /* ??? Should be able to do better than this. */
21293 if (fragp->fr_symbol)
21294 return 4;
21295
21296 low = (1 << shift) - 1;
21297 mask = (1 << (shift + size)) - (1 << shift);
21298 offset = fragp->fr_offset;
21299 /* Force misaligned offsets to 32-bit variant. */
21300 if (offset & low)
5e77afaa 21301 return 4;
0110f2b8
PB
21302 if (offset & ~mask)
21303 return 4;
21304 return 2;
21305}
21306
5e77afaa
PB
21307/* Get the address of a symbol during relaxation. */
21308static addressT
5f4273c7 21309relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
21310{
21311 fragS *sym_frag;
21312 addressT addr;
21313 symbolS *sym;
21314
21315 sym = fragp->fr_symbol;
21316 sym_frag = symbol_get_frag (sym);
21317 know (S_GET_SEGMENT (sym) != absolute_section
21318 || sym_frag == &zero_address_frag);
21319 addr = S_GET_VALUE (sym) + fragp->fr_offset;
21320
21321 /* If frag has yet to be reached on this pass, assume it will
21322 move by STRETCH just as we did. If this is not so, it will
21323 be because some frag between grows, and that will force
21324 another pass. */
21325
21326 if (stretch != 0
21327 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
21328 {
21329 fragS *f;
21330
21331 /* Adjust stretch for any alignment frag. Note that if have
21332 been expanding the earlier code, the symbol may be
21333 defined in what appears to be an earlier frag. FIXME:
21334 This doesn't handle the fr_subtype field, which specifies
21335 a maximum number of bytes to skip when doing an
21336 alignment. */
21337 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
21338 {
21339 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
21340 {
21341 if (stretch < 0)
21342 stretch = - ((- stretch)
21343 & ~ ((1 << (int) f->fr_offset) - 1));
21344 else
21345 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
21346 if (stretch == 0)
21347 break;
21348 }
21349 }
21350 if (f != NULL)
21351 addr += stretch;
21352 }
5e77afaa
PB
21353
21354 return addr;
21355}
21356
0110f2b8
PB
21357/* Return the size of a relaxable adr pseudo-instruction or PC-relative
21358 load. */
21359static int
5e77afaa 21360relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
21361{
21362 addressT addr;
21363 offsetT val;
21364
21365 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
21366 if (fragp->fr_symbol == NULL
21367 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21368 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21369 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21370 return 4;
21371
5f4273c7 21372 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21373 addr = fragp->fr_address + fragp->fr_fix;
21374 addr = (addr + 4) & ~3;
5e77afaa 21375 /* Force misaligned targets to 32-bit variant. */
0110f2b8 21376 if (val & 3)
5e77afaa 21377 return 4;
0110f2b8
PB
21378 val -= addr;
21379 if (val < 0 || val > 1020)
21380 return 4;
21381 return 2;
21382}
21383
21384/* Return the size of a relaxable add/sub immediate instruction. */
21385static int
21386relax_addsub (fragS *fragp, asection *sec)
21387{
21388 char *buf;
21389 int op;
21390
21391 buf = fragp->fr_literal + fragp->fr_fix;
21392 op = bfd_get_16(sec->owner, buf);
21393 if ((op & 0xf) == ((op >> 4) & 0xf))
21394 return relax_immediate (fragp, 8, 0);
21395 else
21396 return relax_immediate (fragp, 3, 0);
21397}
21398
e83a675f
RE
21399/* Return TRUE iff the definition of symbol S could be pre-empted
21400 (overridden) at link or load time. */
21401static bfd_boolean
21402symbol_preemptible (symbolS *s)
21403{
21404 /* Weak symbols can always be pre-empted. */
21405 if (S_IS_WEAK (s))
21406 return TRUE;
21407
21408 /* Non-global symbols cannot be pre-empted. */
21409 if (! S_IS_EXTERNAL (s))
21410 return FALSE;
21411
21412#ifdef OBJ_ELF
21413 /* In ELF, a global symbol can be marked protected, or private. In that
21414 case it can't be pre-empted (other definitions in the same link unit
21415 would violate the ODR). */
21416 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
21417 return FALSE;
21418#endif
21419
21420 /* Other global symbols might be pre-empted. */
21421 return TRUE;
21422}
0110f2b8
PB
21423
21424/* Return the size of a relaxable branch instruction. BITS is the
21425 size of the offset field in the narrow instruction. */
21426
21427static int
5e77afaa 21428relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
21429{
21430 addressT addr;
21431 offsetT val;
21432 offsetT limit;
21433
21434 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 21435 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21436 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21437 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21438 return 4;
21439
267bf995 21440#ifdef OBJ_ELF
e83a675f 21441 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
21442 if (S_IS_DEFINED (fragp->fr_symbol)
21443 && ARM_IS_FUNC (fragp->fr_symbol))
21444 return 4;
e83a675f 21445#endif
0d9b4b55 21446
e83a675f 21447 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 21448 return 4;
267bf995 21449
5f4273c7 21450 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21451 addr = fragp->fr_address + fragp->fr_fix + 4;
21452 val -= addr;
21453
21454 /* Offset is a signed value *2 */
21455 limit = 1 << bits;
21456 if (val >= limit || val < -limit)
21457 return 4;
21458 return 2;
21459}
21460
21461
21462/* Relax a machine dependent frag. This returns the amount by which
21463 the current size of the frag should change. */
21464
21465int
5e77afaa 21466arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
21467{
21468 int oldsize;
21469 int newsize;
21470
21471 oldsize = fragp->fr_var;
21472 switch (fragp->fr_subtype)
21473 {
21474 case T_MNEM_ldr_pc2:
5f4273c7 21475 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21476 break;
21477 case T_MNEM_ldr_pc:
21478 case T_MNEM_ldr_sp:
21479 case T_MNEM_str_sp:
5f4273c7 21480 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
21481 break;
21482 case T_MNEM_ldr:
21483 case T_MNEM_str:
5f4273c7 21484 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
21485 break;
21486 case T_MNEM_ldrh:
21487 case T_MNEM_strh:
5f4273c7 21488 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
21489 break;
21490 case T_MNEM_ldrb:
21491 case T_MNEM_strb:
5f4273c7 21492 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
21493 break;
21494 case T_MNEM_adr:
5f4273c7 21495 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21496 break;
21497 case T_MNEM_mov:
21498 case T_MNEM_movs:
21499 case T_MNEM_cmp:
21500 case T_MNEM_cmn:
5f4273c7 21501 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
21502 break;
21503 case T_MNEM_b:
5f4273c7 21504 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
21505 break;
21506 case T_MNEM_bcond:
5f4273c7 21507 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
21508 break;
21509 case T_MNEM_add_sp:
21510 case T_MNEM_add_pc:
21511 newsize = relax_immediate (fragp, 8, 2);
21512 break;
21513 case T_MNEM_inc_sp:
21514 case T_MNEM_dec_sp:
21515 newsize = relax_immediate (fragp, 7, 2);
21516 break;
21517 case T_MNEM_addi:
21518 case T_MNEM_addis:
21519 case T_MNEM_subi:
21520 case T_MNEM_subis:
21521 newsize = relax_addsub (fragp, sec);
21522 break;
21523 default:
5f4273c7 21524 abort ();
0110f2b8 21525 }
5e77afaa
PB
21526
21527 fragp->fr_var = newsize;
21528 /* Freeze wide instructions that are at or before the same location as
21529 in the previous pass. This avoids infinite loops.
5f4273c7
NC
21530 Don't freeze them unconditionally because targets may be artificially
21531 misaligned by the expansion of preceding frags. */
5e77afaa 21532 if (stretch <= 0 && newsize > 2)
0110f2b8 21533 {
0110f2b8 21534 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 21535 frag_wane (fragp);
0110f2b8 21536 }
5e77afaa 21537
0110f2b8 21538 return newsize - oldsize;
c19d1205 21539}
b99bd4ef 21540
c19d1205 21541/* Round up a section size to the appropriate boundary. */
b99bd4ef 21542
c19d1205
ZW
21543valueT
21544md_section_align (segT segment ATTRIBUTE_UNUSED,
21545 valueT size)
21546{
f0927246
NC
21547#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
21548 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
21549 {
21550 /* For a.out, force the section size to be aligned. If we don't do
21551 this, BFD will align it for us, but it will not write out the
21552 final bytes of the section. This may be a bug in BFD, but it is
21553 easier to fix it here since that is how the other a.out targets
21554 work. */
21555 int align;
21556
21557 align = bfd_get_section_alignment (stdoutput, segment);
8d3842cd 21558 size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
f0927246 21559 }
c19d1205 21560#endif
f0927246 21561
6844c0cc 21562 return size;
bfae80f2 21563}
b99bd4ef 21564
c19d1205
ZW
21565/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
21566 of an rs_align_code fragment. */
21567
21568void
21569arm_handle_align (fragS * fragP)
bfae80f2 21570{
d9235011 21571 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
21572 {
21573 { /* ARMv1 */
21574 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
21575 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
21576 },
21577 { /* ARMv6k */
21578 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
21579 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
21580 },
21581 };
d9235011 21582 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
21583 {
21584 { /* Thumb-1 */
21585 {0xc0, 0x46}, /* LE */
21586 {0x46, 0xc0}, /* BE */
21587 },
21588 { /* Thumb-2 */
21589 {0x00, 0xbf}, /* LE */
21590 {0xbf, 0x00} /* BE */
21591 }
21592 };
d9235011 21593 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
21594 { /* Wide Thumb-2 */
21595 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
21596 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
21597 };
c921be7d 21598
e7495e45 21599 unsigned bytes, fix, noop_size;
c19d1205 21600 char * p;
d9235011
TS
21601 const unsigned char * noop;
21602 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
21603#ifdef OBJ_ELF
21604 enum mstate state;
21605#endif
bfae80f2 21606
c19d1205 21607 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
21608 return;
21609
c19d1205
ZW
21610 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
21611 p = fragP->fr_literal + fragP->fr_fix;
21612 fix = 0;
bfae80f2 21613
c19d1205
ZW
21614 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
21615 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 21616
cd000bff 21617 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 21618
cd000bff 21619 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 21620 {
7f78eb34
JW
21621 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21622 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
21623 {
21624 narrow_noop = thumb_noop[1][target_big_endian];
21625 noop = wide_thumb_noop[target_big_endian];
21626 }
c19d1205 21627 else
e7495e45
NS
21628 noop = thumb_noop[0][target_big_endian];
21629 noop_size = 2;
cd000bff
DJ
21630#ifdef OBJ_ELF
21631 state = MAP_THUMB;
21632#endif
7ed4c4c5
NC
21633 }
21634 else
21635 {
7f78eb34
JW
21636 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21637 ? selected_cpu : arm_arch_none,
21638 arm_ext_v6k) != 0]
e7495e45
NS
21639 [target_big_endian];
21640 noop_size = 4;
cd000bff
DJ
21641#ifdef OBJ_ELF
21642 state = MAP_ARM;
21643#endif
7ed4c4c5 21644 }
c921be7d 21645
e7495e45 21646 fragP->fr_var = noop_size;
c921be7d 21647
c19d1205 21648 if (bytes & (noop_size - 1))
7ed4c4c5 21649 {
c19d1205 21650 fix = bytes & (noop_size - 1);
cd000bff
DJ
21651#ifdef OBJ_ELF
21652 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
21653#endif
c19d1205
ZW
21654 memset (p, 0, fix);
21655 p += fix;
21656 bytes -= fix;
a737bd4d 21657 }
a737bd4d 21658
e7495e45
NS
21659 if (narrow_noop)
21660 {
21661 if (bytes & noop_size)
21662 {
21663 /* Insert a narrow noop. */
21664 memcpy (p, narrow_noop, noop_size);
21665 p += noop_size;
21666 bytes -= noop_size;
21667 fix += noop_size;
21668 }
21669
21670 /* Use wide noops for the remainder */
21671 noop_size = 4;
21672 }
21673
c19d1205 21674 while (bytes >= noop_size)
a737bd4d 21675 {
c19d1205
ZW
21676 memcpy (p, noop, noop_size);
21677 p += noop_size;
21678 bytes -= noop_size;
21679 fix += noop_size;
a737bd4d
NC
21680 }
21681
c19d1205 21682 fragP->fr_fix += fix;
a737bd4d
NC
21683}
21684
c19d1205
ZW
21685/* Called from md_do_align. Used to create an alignment
21686 frag in a code section. */
21687
21688void
21689arm_frag_align_code (int n, int max)
bfae80f2 21690{
c19d1205 21691 char * p;
7ed4c4c5 21692
c19d1205 21693 /* We assume that there will never be a requirement
6ec8e702 21694 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 21695 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
21696 {
21697 char err_msg[128];
21698
fa94de6b 21699 sprintf (err_msg,
477330fc
RM
21700 _("alignments greater than %d bytes not supported in .text sections."),
21701 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 21702 as_fatal ("%s", err_msg);
6ec8e702 21703 }
bfae80f2 21704
c19d1205
ZW
21705 p = frag_var (rs_align_code,
21706 MAX_MEM_FOR_RS_ALIGN_CODE,
21707 1,
21708 (relax_substateT) max,
21709 (symbolS *) NULL,
21710 (offsetT) n,
21711 (char *) NULL);
21712 *p = 0;
21713}
bfae80f2 21714
8dc2430f
NC
21715/* Perform target specific initialisation of a frag.
21716 Note - despite the name this initialisation is not done when the frag
21717 is created, but only when its type is assigned. A frag can be created
21718 and used a long time before its type is set, so beware of assuming that
21719 this initialisationis performed first. */
bfae80f2 21720
cd000bff
DJ
21721#ifndef OBJ_ELF
21722void
21723arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
21724{
21725 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 21726 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
21727}
21728
21729#else /* OBJ_ELF is defined. */
c19d1205 21730void
cd000bff 21731arm_init_frag (fragS * fragP, int max_chars)
c19d1205 21732{
b968d18a
JW
21733 int frag_thumb_mode;
21734
8dc2430f
NC
21735 /* If the current ARM vs THUMB mode has not already
21736 been recorded into this frag then do so now. */
cd000bff 21737 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
21738 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
21739
21740 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 21741
f9c1b181
RL
21742 /* Record a mapping symbol for alignment frags. We will delete this
21743 later if the alignment ends up empty. */
21744 switch (fragP->fr_type)
21745 {
21746 case rs_align:
21747 case rs_align_test:
21748 case rs_fill:
21749 mapping_state_2 (MAP_DATA, max_chars);
21750 break;
21751 case rs_align_code:
b968d18a 21752 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
21753 break;
21754 default:
21755 break;
cd000bff 21756 }
bfae80f2
RE
21757}
21758
c19d1205
ZW
21759/* When we change sections we need to issue a new mapping symbol. */
21760
21761void
21762arm_elf_change_section (void)
bfae80f2 21763{
c19d1205
ZW
21764 /* Link an unlinked unwind index table section to the .text section. */
21765 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
21766 && elf_linked_to_section (now_seg) == NULL)
21767 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
21768}
21769
c19d1205
ZW
21770int
21771arm_elf_section_type (const char * str, size_t len)
e45d0630 21772{
c19d1205
ZW
21773 if (len == 5 && strncmp (str, "exidx", 5) == 0)
21774 return SHT_ARM_EXIDX;
e45d0630 21775
c19d1205
ZW
21776 return -1;
21777}
21778\f
21779/* Code to deal with unwinding tables. */
e45d0630 21780
c19d1205 21781static void add_unwind_adjustsp (offsetT);
e45d0630 21782
5f4273c7 21783/* Generate any deferred unwind frame offset. */
e45d0630 21784
bfae80f2 21785static void
c19d1205 21786flush_pending_unwind (void)
bfae80f2 21787{
c19d1205 21788 offsetT offset;
bfae80f2 21789
c19d1205
ZW
21790 offset = unwind.pending_offset;
21791 unwind.pending_offset = 0;
21792 if (offset != 0)
21793 add_unwind_adjustsp (offset);
bfae80f2
RE
21794}
21795
c19d1205
ZW
21796/* Add an opcode to this list for this function. Two-byte opcodes should
21797 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
21798 order. */
21799
bfae80f2 21800static void
c19d1205 21801add_unwind_opcode (valueT op, int length)
bfae80f2 21802{
c19d1205
ZW
21803 /* Add any deferred stack adjustment. */
21804 if (unwind.pending_offset)
21805 flush_pending_unwind ();
bfae80f2 21806
c19d1205 21807 unwind.sp_restored = 0;
bfae80f2 21808
c19d1205 21809 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 21810 {
c19d1205
ZW
21811 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
21812 if (unwind.opcodes)
325801bd
TS
21813 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
21814 unwind.opcode_alloc);
c19d1205 21815 else
325801bd 21816 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 21817 }
c19d1205 21818 while (length > 0)
bfae80f2 21819 {
c19d1205
ZW
21820 length--;
21821 unwind.opcodes[unwind.opcode_count] = op & 0xff;
21822 op >>= 8;
21823 unwind.opcode_count++;
bfae80f2 21824 }
bfae80f2
RE
21825}
21826
c19d1205
ZW
21827/* Add unwind opcodes to adjust the stack pointer. */
21828
bfae80f2 21829static void
c19d1205 21830add_unwind_adjustsp (offsetT offset)
bfae80f2 21831{
c19d1205 21832 valueT op;
bfae80f2 21833
c19d1205 21834 if (offset > 0x200)
bfae80f2 21835 {
c19d1205
ZW
21836 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
21837 char bytes[5];
21838 int n;
21839 valueT o;
bfae80f2 21840
c19d1205
ZW
21841 /* Long form: 0xb2, uleb128. */
21842 /* This might not fit in a word so add the individual bytes,
21843 remembering the list is built in reverse order. */
21844 o = (valueT) ((offset - 0x204) >> 2);
21845 if (o == 0)
21846 add_unwind_opcode (0, 1);
bfae80f2 21847
c19d1205
ZW
21848 /* Calculate the uleb128 encoding of the offset. */
21849 n = 0;
21850 while (o)
21851 {
21852 bytes[n] = o & 0x7f;
21853 o >>= 7;
21854 if (o)
21855 bytes[n] |= 0x80;
21856 n++;
21857 }
21858 /* Add the insn. */
21859 for (; n; n--)
21860 add_unwind_opcode (bytes[n - 1], 1);
21861 add_unwind_opcode (0xb2, 1);
21862 }
21863 else if (offset > 0x100)
bfae80f2 21864 {
c19d1205
ZW
21865 /* Two short opcodes. */
21866 add_unwind_opcode (0x3f, 1);
21867 op = (offset - 0x104) >> 2;
21868 add_unwind_opcode (op, 1);
bfae80f2 21869 }
c19d1205
ZW
21870 else if (offset > 0)
21871 {
21872 /* Short opcode. */
21873 op = (offset - 4) >> 2;
21874 add_unwind_opcode (op, 1);
21875 }
21876 else if (offset < 0)
bfae80f2 21877 {
c19d1205
ZW
21878 offset = -offset;
21879 while (offset > 0x100)
bfae80f2 21880 {
c19d1205
ZW
21881 add_unwind_opcode (0x7f, 1);
21882 offset -= 0x100;
bfae80f2 21883 }
c19d1205
ZW
21884 op = ((offset - 4) >> 2) | 0x40;
21885 add_unwind_opcode (op, 1);
bfae80f2 21886 }
bfae80f2
RE
21887}
21888
c19d1205
ZW
21889/* Finish the list of unwind opcodes for this function. */
21890static void
21891finish_unwind_opcodes (void)
bfae80f2 21892{
c19d1205 21893 valueT op;
bfae80f2 21894
c19d1205 21895 if (unwind.fp_used)
bfae80f2 21896 {
708587a4 21897 /* Adjust sp as necessary. */
c19d1205
ZW
21898 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
21899 flush_pending_unwind ();
bfae80f2 21900
c19d1205
ZW
21901 /* After restoring sp from the frame pointer. */
21902 op = 0x90 | unwind.fp_reg;
21903 add_unwind_opcode (op, 1);
21904 }
21905 else
21906 flush_pending_unwind ();
bfae80f2
RE
21907}
21908
bfae80f2 21909
c19d1205
ZW
21910/* Start an exception table entry. If idx is nonzero this is an index table
21911 entry. */
bfae80f2
RE
21912
21913static void
c19d1205 21914start_unwind_section (const segT text_seg, int idx)
bfae80f2 21915{
c19d1205
ZW
21916 const char * text_name;
21917 const char * prefix;
21918 const char * prefix_once;
21919 const char * group_name;
c19d1205 21920 char * sec_name;
c19d1205
ZW
21921 int type;
21922 int flags;
21923 int linkonce;
bfae80f2 21924
c19d1205 21925 if (idx)
bfae80f2 21926 {
c19d1205
ZW
21927 prefix = ELF_STRING_ARM_unwind;
21928 prefix_once = ELF_STRING_ARM_unwind_once;
21929 type = SHT_ARM_EXIDX;
bfae80f2 21930 }
c19d1205 21931 else
bfae80f2 21932 {
c19d1205
ZW
21933 prefix = ELF_STRING_ARM_unwind_info;
21934 prefix_once = ELF_STRING_ARM_unwind_info_once;
21935 type = SHT_PROGBITS;
bfae80f2
RE
21936 }
21937
c19d1205
ZW
21938 text_name = segment_name (text_seg);
21939 if (streq (text_name, ".text"))
21940 text_name = "";
21941
21942 if (strncmp (text_name, ".gnu.linkonce.t.",
21943 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 21944 {
c19d1205
ZW
21945 prefix = prefix_once;
21946 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
21947 }
21948
29a2809e 21949 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 21950
c19d1205
ZW
21951 flags = SHF_ALLOC;
21952 linkonce = 0;
21953 group_name = 0;
bfae80f2 21954
c19d1205
ZW
21955 /* Handle COMDAT group. */
21956 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 21957 {
c19d1205
ZW
21958 group_name = elf_group_name (text_seg);
21959 if (group_name == NULL)
21960 {
bd3ba5d1 21961 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
21962 segment_name (text_seg));
21963 ignore_rest_of_line ();
21964 return;
21965 }
21966 flags |= SHF_GROUP;
21967 linkonce = 1;
bfae80f2
RE
21968 }
21969
c19d1205 21970 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 21971
5f4273c7 21972 /* Set the section link for index tables. */
c19d1205
ZW
21973 if (idx)
21974 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
21975}
21976
bfae80f2 21977
c19d1205
ZW
21978/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
21979 personality routine data. Returns zero, or the index table value for
cad0da33 21980 an inline entry. */
c19d1205
ZW
21981
21982static valueT
21983create_unwind_entry (int have_data)
bfae80f2 21984{
c19d1205
ZW
21985 int size;
21986 addressT where;
21987 char *ptr;
21988 /* The current word of data. */
21989 valueT data;
21990 /* The number of bytes left in this word. */
21991 int n;
bfae80f2 21992
c19d1205 21993 finish_unwind_opcodes ();
bfae80f2 21994
c19d1205
ZW
21995 /* Remember the current text section. */
21996 unwind.saved_seg = now_seg;
21997 unwind.saved_subseg = now_subseg;
bfae80f2 21998
c19d1205 21999 start_unwind_section (now_seg, 0);
bfae80f2 22000
c19d1205 22001 if (unwind.personality_routine == NULL)
bfae80f2 22002 {
c19d1205
ZW
22003 if (unwind.personality_index == -2)
22004 {
22005 if (have_data)
5f4273c7 22006 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
22007 return 1; /* EXIDX_CANTUNWIND. */
22008 }
bfae80f2 22009
c19d1205
ZW
22010 /* Use a default personality routine if none is specified. */
22011 if (unwind.personality_index == -1)
22012 {
22013 if (unwind.opcode_count > 3)
22014 unwind.personality_index = 1;
22015 else
22016 unwind.personality_index = 0;
22017 }
bfae80f2 22018
c19d1205
ZW
22019 /* Space for the personality routine entry. */
22020 if (unwind.personality_index == 0)
22021 {
22022 if (unwind.opcode_count > 3)
22023 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 22024
c19d1205
ZW
22025 if (!have_data)
22026 {
22027 /* All the data is inline in the index table. */
22028 data = 0x80;
22029 n = 3;
22030 while (unwind.opcode_count > 0)
22031 {
22032 unwind.opcode_count--;
22033 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22034 n--;
22035 }
bfae80f2 22036
c19d1205
ZW
22037 /* Pad with "finish" opcodes. */
22038 while (n--)
22039 data = (data << 8) | 0xb0;
bfae80f2 22040
c19d1205
ZW
22041 return data;
22042 }
22043 size = 0;
22044 }
22045 else
22046 /* We get two opcodes "free" in the first word. */
22047 size = unwind.opcode_count - 2;
22048 }
22049 else
5011093d 22050 {
cad0da33
NC
22051 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
22052 if (unwind.personality_index != -1)
22053 {
22054 as_bad (_("attempt to recreate an unwind entry"));
22055 return 1;
22056 }
5011093d
NC
22057
22058 /* An extra byte is required for the opcode count. */
22059 size = unwind.opcode_count + 1;
22060 }
bfae80f2 22061
c19d1205
ZW
22062 size = (size + 3) >> 2;
22063 if (size > 0xff)
22064 as_bad (_("too many unwind opcodes"));
bfae80f2 22065
c19d1205
ZW
22066 frag_align (2, 0, 0);
22067 record_alignment (now_seg, 2);
22068 unwind.table_entry = expr_build_dot ();
22069
22070 /* Allocate the table entry. */
22071 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
22072 /* PR 13449: Zero the table entries in case some of them are not used. */
22073 memset (ptr, 0, (size << 2) + 4);
c19d1205 22074 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 22075
c19d1205 22076 switch (unwind.personality_index)
bfae80f2 22077 {
c19d1205
ZW
22078 case -1:
22079 /* ??? Should this be a PLT generating relocation? */
22080 /* Custom personality routine. */
22081 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
22082 BFD_RELOC_ARM_PREL31);
bfae80f2 22083
c19d1205
ZW
22084 where += 4;
22085 ptr += 4;
bfae80f2 22086
c19d1205 22087 /* Set the first byte to the number of additional words. */
5011093d 22088 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
22089 n = 3;
22090 break;
bfae80f2 22091
c19d1205
ZW
22092 /* ABI defined personality routines. */
22093 case 0:
22094 /* Three opcodes bytes are packed into the first word. */
22095 data = 0x80;
22096 n = 3;
22097 break;
bfae80f2 22098
c19d1205
ZW
22099 case 1:
22100 case 2:
22101 /* The size and first two opcode bytes go in the first word. */
22102 data = ((0x80 + unwind.personality_index) << 8) | size;
22103 n = 2;
22104 break;
bfae80f2 22105
c19d1205
ZW
22106 default:
22107 /* Should never happen. */
22108 abort ();
22109 }
bfae80f2 22110
c19d1205
ZW
22111 /* Pack the opcodes into words (MSB first), reversing the list at the same
22112 time. */
22113 while (unwind.opcode_count > 0)
22114 {
22115 if (n == 0)
22116 {
22117 md_number_to_chars (ptr, data, 4);
22118 ptr += 4;
22119 n = 4;
22120 data = 0;
22121 }
22122 unwind.opcode_count--;
22123 n--;
22124 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22125 }
22126
22127 /* Finish off the last word. */
22128 if (n < 4)
22129 {
22130 /* Pad with "finish" opcodes. */
22131 while (n--)
22132 data = (data << 8) | 0xb0;
22133
22134 md_number_to_chars (ptr, data, 4);
22135 }
22136
22137 if (!have_data)
22138 {
22139 /* Add an empty descriptor if there is no user-specified data. */
22140 ptr = frag_more (4);
22141 md_number_to_chars (ptr, 0, 4);
22142 }
22143
22144 return 0;
bfae80f2
RE
22145}
22146
f0927246
NC
22147
22148/* Initialize the DWARF-2 unwind information for this procedure. */
22149
22150void
22151tc_arm_frame_initial_instructions (void)
22152{
22153 cfi_add_CFA_def_cfa (REG_SP, 0);
22154}
22155#endif /* OBJ_ELF */
22156
c19d1205
ZW
22157/* Convert REGNAME to a DWARF-2 register number. */
22158
22159int
1df69f4f 22160tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 22161{
1df69f4f 22162 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
22163 if (reg != FAIL)
22164 return reg;
c19d1205 22165
1f5afe1c
NC
22166 /* PR 16694: Allow VFP registers as well. */
22167 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22168 if (reg != FAIL)
22169 return 64 + reg;
c19d1205 22170
1f5afe1c
NC
22171 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
22172 if (reg != FAIL)
22173 return reg + 256;
22174
22175 return -1;
bfae80f2
RE
22176}
22177
f0927246 22178#ifdef TE_PE
c19d1205 22179void
f0927246 22180tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 22181{
91d6fa6a 22182 expressionS exp;
bfae80f2 22183
91d6fa6a
NC
22184 exp.X_op = O_secrel;
22185 exp.X_add_symbol = symbol;
22186 exp.X_add_number = 0;
22187 emit_expr (&exp, size);
f0927246
NC
22188}
22189#endif
bfae80f2 22190
c19d1205 22191/* MD interface: Symbol and relocation handling. */
bfae80f2 22192
2fc8bdac
ZW
22193/* Return the address within the segment that a PC-relative fixup is
22194 relative to. For ARM, PC-relative fixups applied to instructions
22195 are generally relative to the location of the fixup plus 8 bytes.
22196 Thumb branches are offset by 4, and Thumb loads relative to PC
22197 require special handling. */
bfae80f2 22198
c19d1205 22199long
2fc8bdac 22200md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 22201{
2fc8bdac
ZW
22202 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
22203
22204 /* If this is pc-relative and we are going to emit a relocation
22205 then we just want to put out any pipeline compensation that the linker
53baae48
NC
22206 will need. Otherwise we want to use the calculated base.
22207 For WinCE we skip the bias for externals as well, since this
22208 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 22209 if (fixP->fx_pcrel
2fc8bdac 22210 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
22211 || (arm_force_relocation (fixP)
22212#ifdef TE_WINCE
22213 && !S_IS_EXTERNAL (fixP->fx_addsy)
22214#endif
22215 )))
2fc8bdac 22216 base = 0;
bfae80f2 22217
267bf995 22218
c19d1205 22219 switch (fixP->fx_r_type)
bfae80f2 22220 {
2fc8bdac
ZW
22221 /* PC relative addressing on the Thumb is slightly odd as the
22222 bottom two bits of the PC are forced to zero for the
22223 calculation. This happens *after* application of the
22224 pipeline offset. However, Thumb adrl already adjusts for
22225 this, so we need not do it again. */
c19d1205 22226 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 22227 return base & ~3;
c19d1205
ZW
22228
22229 case BFD_RELOC_ARM_THUMB_OFFSET:
22230 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 22231 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 22232 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 22233 return (base + 4) & ~3;
c19d1205 22234
2fc8bdac
ZW
22235 /* Thumb branches are simply offset by +4. */
22236 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22237 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22238 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22239 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 22240 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 22241 return base + 4;
bfae80f2 22242
267bf995 22243 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
22244 if (fixP->fx_addsy
22245 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22246 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 22247 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
22248 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22249 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
22250 return base + 4;
22251
00adf2d4
JB
22252 /* BLX is like branches above, but forces the low two bits of PC to
22253 zero. */
486499d0
CL
22254 case BFD_RELOC_THUMB_PCREL_BLX:
22255 if (fixP->fx_addsy
22256 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22257 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22258 && THUMB_IS_FUNC (fixP->fx_addsy)
22259 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22260 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
22261 return (base + 4) & ~3;
22262
2fc8bdac
ZW
22263 /* ARM mode branches are offset by +8. However, the Windows CE
22264 loader expects the relocation not to take this into account. */
267bf995 22265 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
22266 if (fixP->fx_addsy
22267 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22268 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22269 && ARM_IS_FUNC (fixP->fx_addsy)
22270 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22271 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22272 return base + 8;
267bf995 22273
486499d0
CL
22274 case BFD_RELOC_ARM_PCREL_CALL:
22275 if (fixP->fx_addsy
22276 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22277 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22278 && THUMB_IS_FUNC (fixP->fx_addsy)
22279 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22280 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22281 return base + 8;
267bf995 22282
2fc8bdac 22283 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 22284 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 22285 case BFD_RELOC_ARM_PLT32:
c19d1205 22286#ifdef TE_WINCE
5f4273c7 22287 /* When handling fixups immediately, because we have already
477330fc 22288 discovered the value of a symbol, or the address of the frag involved
53baae48 22289 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
22290 see fixup_segment() in write.c
22291 The S_IS_EXTERNAL test handles the case of global symbols.
22292 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
22293 if (fixP->fx_pcrel
22294 && fixP->fx_addsy != NULL
22295 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22296 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
22297 return base + 8;
2fc8bdac 22298 return base;
c19d1205 22299#else
2fc8bdac 22300 return base + 8;
c19d1205 22301#endif
2fc8bdac 22302
267bf995 22303
2fc8bdac
ZW
22304 /* ARM mode loads relative to PC are also offset by +8. Unlike
22305 branches, the Windows CE loader *does* expect the relocation
22306 to take this into account. */
22307 case BFD_RELOC_ARM_OFFSET_IMM:
22308 case BFD_RELOC_ARM_OFFSET_IMM8:
22309 case BFD_RELOC_ARM_HWLITERAL:
22310 case BFD_RELOC_ARM_LITERAL:
22311 case BFD_RELOC_ARM_CP_OFF_IMM:
22312 return base + 8;
22313
22314
22315 /* Other PC-relative relocations are un-offset. */
22316 default:
22317 return base;
22318 }
bfae80f2
RE
22319}
22320
8b2d793c
NC
22321static bfd_boolean flag_warn_syms = TRUE;
22322
ae8714c2
NC
22323bfd_boolean
22324arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 22325{
8b2d793c
NC
22326 /* PR 18347 - Warn if the user attempts to create a symbol with the same
22327 name as an ARM instruction. Whilst strictly speaking it is allowed, it
22328 does mean that the resulting code might be very confusing to the reader.
22329 Also this warning can be triggered if the user omits an operand before
22330 an immediate address, eg:
22331
22332 LDR =foo
22333
22334 GAS treats this as an assignment of the value of the symbol foo to a
22335 symbol LDR, and so (without this code) it will not issue any kind of
22336 warning or error message.
22337
22338 Note - ARM instructions are case-insensitive but the strings in the hash
22339 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
22340 lower case too. */
22341 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
22342 {
22343 char * nbuf = strdup (name);
22344 char * p;
22345
22346 for (p = nbuf; *p; p++)
22347 *p = TOLOWER (*p);
22348 if (hash_find (arm_ops_hsh, nbuf) != NULL)
22349 {
22350 static struct hash_control * already_warned = NULL;
22351
22352 if (already_warned == NULL)
22353 already_warned = hash_new ();
22354 /* Only warn about the symbol once. To keep the code
22355 simple we let hash_insert do the lookup for us. */
22356 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 22357 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
22358 }
22359 else
22360 free (nbuf);
22361 }
3739860c 22362
ae8714c2
NC
22363 return FALSE;
22364}
22365
22366/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
22367 Otherwise we have no need to default values of symbols. */
22368
22369symbolS *
22370md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
22371{
22372#ifdef OBJ_ELF
22373 if (name[0] == '_' && name[1] == 'G'
22374 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
22375 {
22376 if (!GOT_symbol)
22377 {
22378 if (symbol_find (name))
22379 as_bad (_("GOT already in the symbol table"));
22380
22381 GOT_symbol = symbol_new (name, undefined_section,
22382 (valueT) 0, & zero_address_frag);
22383 }
22384
22385 return GOT_symbol;
22386 }
22387#endif
22388
c921be7d 22389 return NULL;
bfae80f2
RE
22390}
22391
55cf6793 22392/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
22393 computed as two separate immediate values, added together. We
22394 already know that this value cannot be computed by just one ARM
22395 instruction. */
22396
22397static unsigned int
22398validate_immediate_twopart (unsigned int val,
22399 unsigned int * highpart)
bfae80f2 22400{
c19d1205
ZW
22401 unsigned int a;
22402 unsigned int i;
bfae80f2 22403
c19d1205
ZW
22404 for (i = 0; i < 32; i += 2)
22405 if (((a = rotate_left (val, i)) & 0xff) != 0)
22406 {
22407 if (a & 0xff00)
22408 {
22409 if (a & ~ 0xffff)
22410 continue;
22411 * highpart = (a >> 8) | ((i + 24) << 7);
22412 }
22413 else if (a & 0xff0000)
22414 {
22415 if (a & 0xff000000)
22416 continue;
22417 * highpart = (a >> 16) | ((i + 16) << 7);
22418 }
22419 else
22420 {
9c2799c2 22421 gas_assert (a & 0xff000000);
c19d1205
ZW
22422 * highpart = (a >> 24) | ((i + 8) << 7);
22423 }
bfae80f2 22424
c19d1205
ZW
22425 return (a & 0xff) | (i << 7);
22426 }
bfae80f2 22427
c19d1205 22428 return FAIL;
bfae80f2
RE
22429}
22430
c19d1205
ZW
22431static int
22432validate_offset_imm (unsigned int val, int hwse)
22433{
22434 if ((hwse && val > 255) || val > 4095)
22435 return FAIL;
22436 return val;
22437}
bfae80f2 22438
55cf6793 22439/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
22440 negative immediate constant by altering the instruction. A bit of
22441 a hack really.
22442 MOV <-> MVN
22443 AND <-> BIC
22444 ADC <-> SBC
22445 by inverting the second operand, and
22446 ADD <-> SUB
22447 CMP <-> CMN
22448 by negating the second operand. */
bfae80f2 22449
c19d1205
ZW
22450static int
22451negate_data_op (unsigned long * instruction,
22452 unsigned long value)
bfae80f2 22453{
c19d1205
ZW
22454 int op, new_inst;
22455 unsigned long negated, inverted;
bfae80f2 22456
c19d1205
ZW
22457 negated = encode_arm_immediate (-value);
22458 inverted = encode_arm_immediate (~value);
bfae80f2 22459
c19d1205
ZW
22460 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
22461 switch (op)
bfae80f2 22462 {
c19d1205
ZW
22463 /* First negates. */
22464 case OPCODE_SUB: /* ADD <-> SUB */
22465 new_inst = OPCODE_ADD;
22466 value = negated;
22467 break;
bfae80f2 22468
c19d1205
ZW
22469 case OPCODE_ADD:
22470 new_inst = OPCODE_SUB;
22471 value = negated;
22472 break;
bfae80f2 22473
c19d1205
ZW
22474 case OPCODE_CMP: /* CMP <-> CMN */
22475 new_inst = OPCODE_CMN;
22476 value = negated;
22477 break;
bfae80f2 22478
c19d1205
ZW
22479 case OPCODE_CMN:
22480 new_inst = OPCODE_CMP;
22481 value = negated;
22482 break;
bfae80f2 22483
c19d1205
ZW
22484 /* Now Inverted ops. */
22485 case OPCODE_MOV: /* MOV <-> MVN */
22486 new_inst = OPCODE_MVN;
22487 value = inverted;
22488 break;
bfae80f2 22489
c19d1205
ZW
22490 case OPCODE_MVN:
22491 new_inst = OPCODE_MOV;
22492 value = inverted;
22493 break;
bfae80f2 22494
c19d1205
ZW
22495 case OPCODE_AND: /* AND <-> BIC */
22496 new_inst = OPCODE_BIC;
22497 value = inverted;
22498 break;
bfae80f2 22499
c19d1205
ZW
22500 case OPCODE_BIC:
22501 new_inst = OPCODE_AND;
22502 value = inverted;
22503 break;
bfae80f2 22504
c19d1205
ZW
22505 case OPCODE_ADC: /* ADC <-> SBC */
22506 new_inst = OPCODE_SBC;
22507 value = inverted;
22508 break;
bfae80f2 22509
c19d1205
ZW
22510 case OPCODE_SBC:
22511 new_inst = OPCODE_ADC;
22512 value = inverted;
22513 break;
bfae80f2 22514
c19d1205
ZW
22515 /* We cannot do anything. */
22516 default:
22517 return FAIL;
b99bd4ef
NC
22518 }
22519
c19d1205
ZW
22520 if (value == (unsigned) FAIL)
22521 return FAIL;
22522
22523 *instruction &= OPCODE_MASK;
22524 *instruction |= new_inst << DATA_OP_SHIFT;
22525 return value;
b99bd4ef
NC
22526}
22527
ef8d22e6
PB
22528/* Like negate_data_op, but for Thumb-2. */
22529
22530static unsigned int
16dd5e42 22531thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
22532{
22533 int op, new_inst;
22534 int rd;
16dd5e42 22535 unsigned int negated, inverted;
ef8d22e6
PB
22536
22537 negated = encode_thumb32_immediate (-value);
22538 inverted = encode_thumb32_immediate (~value);
22539
22540 rd = (*instruction >> 8) & 0xf;
22541 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
22542 switch (op)
22543 {
22544 /* ADD <-> SUB. Includes CMP <-> CMN. */
22545 case T2_OPCODE_SUB:
22546 new_inst = T2_OPCODE_ADD;
22547 value = negated;
22548 break;
22549
22550 case T2_OPCODE_ADD:
22551 new_inst = T2_OPCODE_SUB;
22552 value = negated;
22553 break;
22554
22555 /* ORR <-> ORN. Includes MOV <-> MVN. */
22556 case T2_OPCODE_ORR:
22557 new_inst = T2_OPCODE_ORN;
22558 value = inverted;
22559 break;
22560
22561 case T2_OPCODE_ORN:
22562 new_inst = T2_OPCODE_ORR;
22563 value = inverted;
22564 break;
22565
22566 /* AND <-> BIC. TST has no inverted equivalent. */
22567 case T2_OPCODE_AND:
22568 new_inst = T2_OPCODE_BIC;
22569 if (rd == 15)
22570 value = FAIL;
22571 else
22572 value = inverted;
22573 break;
22574
22575 case T2_OPCODE_BIC:
22576 new_inst = T2_OPCODE_AND;
22577 value = inverted;
22578 break;
22579
22580 /* ADC <-> SBC */
22581 case T2_OPCODE_ADC:
22582 new_inst = T2_OPCODE_SBC;
22583 value = inverted;
22584 break;
22585
22586 case T2_OPCODE_SBC:
22587 new_inst = T2_OPCODE_ADC;
22588 value = inverted;
22589 break;
22590
22591 /* We cannot do anything. */
22592 default:
22593 return FAIL;
22594 }
22595
16dd5e42 22596 if (value == (unsigned int)FAIL)
ef8d22e6
PB
22597 return FAIL;
22598
22599 *instruction &= T2_OPCODE_MASK;
22600 *instruction |= new_inst << T2_DATA_OP_SHIFT;
22601 return value;
22602}
22603
8f06b2d8
PB
22604/* Read a 32-bit thumb instruction from buf. */
22605static unsigned long
22606get_thumb32_insn (char * buf)
22607{
22608 unsigned long insn;
22609 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
22610 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22611
22612 return insn;
22613}
22614
a8bc6c78
PB
22615
22616/* We usually want to set the low bit on the address of thumb function
22617 symbols. In particular .word foo - . should have the low bit set.
22618 Generic code tries to fold the difference of two symbols to
22619 a constant. Prevent this and force a relocation when the first symbols
22620 is a thumb function. */
c921be7d
NC
22621
22622bfd_boolean
a8bc6c78
PB
22623arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
22624{
22625 if (op == O_subtract
22626 && l->X_op == O_symbol
22627 && r->X_op == O_symbol
22628 && THUMB_IS_FUNC (l->X_add_symbol))
22629 {
22630 l->X_op = O_subtract;
22631 l->X_op_symbol = r->X_add_symbol;
22632 l->X_add_number -= r->X_add_number;
c921be7d 22633 return TRUE;
a8bc6c78 22634 }
c921be7d 22635
a8bc6c78 22636 /* Process as normal. */
c921be7d 22637 return FALSE;
a8bc6c78
PB
22638}
22639
4a42ebbc
RR
22640/* Encode Thumb2 unconditional branches and calls. The encoding
22641 for the 2 are identical for the immediate values. */
22642
22643static void
22644encode_thumb2_b_bl_offset (char * buf, offsetT value)
22645{
22646#define T2I1I2MASK ((1 << 13) | (1 << 11))
22647 offsetT newval;
22648 offsetT newval2;
22649 addressT S, I1, I2, lo, hi;
22650
22651 S = (value >> 24) & 0x01;
22652 I1 = (value >> 23) & 0x01;
22653 I2 = (value >> 22) & 0x01;
22654 hi = (value >> 12) & 0x3ff;
fa94de6b 22655 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
22656 newval = md_chars_to_number (buf, THUMB_SIZE);
22657 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22658 newval |= (S << 10) | hi;
22659 newval2 &= ~T2I1I2MASK;
22660 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
22661 md_number_to_chars (buf, newval, THUMB_SIZE);
22662 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22663}
22664
c19d1205 22665void
55cf6793 22666md_apply_fix (fixS * fixP,
c19d1205
ZW
22667 valueT * valP,
22668 segT seg)
22669{
22670 offsetT value = * valP;
22671 offsetT newval;
22672 unsigned int newimm;
22673 unsigned long temp;
22674 int sign;
22675 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 22676
9c2799c2 22677 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 22678
c19d1205 22679 /* Note whether this will delete the relocation. */
4962c51a 22680
c19d1205
ZW
22681 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
22682 fixP->fx_done = 1;
b99bd4ef 22683
adbaf948 22684 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 22685 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
22686 for emit_reloc. */
22687 value &= 0xffffffff;
22688 value ^= 0x80000000;
5f4273c7 22689 value -= 0x80000000;
adbaf948
ZW
22690
22691 *valP = value;
c19d1205 22692 fixP->fx_addnumber = value;
b99bd4ef 22693
adbaf948
ZW
22694 /* Same treatment for fixP->fx_offset. */
22695 fixP->fx_offset &= 0xffffffff;
22696 fixP->fx_offset ^= 0x80000000;
22697 fixP->fx_offset -= 0x80000000;
22698
c19d1205 22699 switch (fixP->fx_r_type)
b99bd4ef 22700 {
c19d1205
ZW
22701 case BFD_RELOC_NONE:
22702 /* This will need to go in the object file. */
22703 fixP->fx_done = 0;
22704 break;
b99bd4ef 22705
c19d1205
ZW
22706 case BFD_RELOC_ARM_IMMEDIATE:
22707 /* We claim that this fixup has been processed here,
22708 even if in fact we generate an error because we do
22709 not have a reloc for it, so tc_gen_reloc will reject it. */
22710 fixP->fx_done = 1;
b99bd4ef 22711
77db8e2e 22712 if (fixP->fx_addsy)
b99bd4ef 22713 {
77db8e2e 22714 const char *msg = 0;
b99bd4ef 22715
77db8e2e
NC
22716 if (! S_IS_DEFINED (fixP->fx_addsy))
22717 msg = _("undefined symbol %s used as an immediate value");
22718 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22719 msg = _("symbol %s is in a different section");
22720 else if (S_IS_WEAK (fixP->fx_addsy))
22721 msg = _("symbol %s is weak and may be overridden later");
22722
22723 if (msg)
22724 {
22725 as_bad_where (fixP->fx_file, fixP->fx_line,
22726 msg, S_GET_NAME (fixP->fx_addsy));
22727 break;
22728 }
42e5fcbf
AS
22729 }
22730
c19d1205
ZW
22731 temp = md_chars_to_number (buf, INSN_SIZE);
22732
5e73442d
SL
22733 /* If the offset is negative, we should use encoding A2 for ADR. */
22734 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
22735 newimm = negate_data_op (&temp, value);
22736 else
22737 {
22738 newimm = encode_arm_immediate (value);
22739
22740 /* If the instruction will fail, see if we can fix things up by
22741 changing the opcode. */
22742 if (newimm == (unsigned int) FAIL)
22743 newimm = negate_data_op (&temp, value);
22744 }
22745
22746 if (newimm == (unsigned int) FAIL)
b99bd4ef 22747 {
c19d1205
ZW
22748 as_bad_where (fixP->fx_file, fixP->fx_line,
22749 _("invalid constant (%lx) after fixup"),
22750 (unsigned long) value);
22751 break;
b99bd4ef 22752 }
b99bd4ef 22753
c19d1205
ZW
22754 newimm |= (temp & 0xfffff000);
22755 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
22756 break;
b99bd4ef 22757
c19d1205
ZW
22758 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22759 {
22760 unsigned int highpart = 0;
22761 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 22762
77db8e2e 22763 if (fixP->fx_addsy)
42e5fcbf 22764 {
77db8e2e 22765 const char *msg = 0;
42e5fcbf 22766
77db8e2e
NC
22767 if (! S_IS_DEFINED (fixP->fx_addsy))
22768 msg = _("undefined symbol %s used as an immediate value");
22769 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22770 msg = _("symbol %s is in a different section");
22771 else if (S_IS_WEAK (fixP->fx_addsy))
22772 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 22773
77db8e2e
NC
22774 if (msg)
22775 {
22776 as_bad_where (fixP->fx_file, fixP->fx_line,
22777 msg, S_GET_NAME (fixP->fx_addsy));
22778 break;
22779 }
22780 }
fa94de6b 22781
c19d1205
ZW
22782 newimm = encode_arm_immediate (value);
22783 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 22784
c19d1205
ZW
22785 /* If the instruction will fail, see if we can fix things up by
22786 changing the opcode. */
22787 if (newimm == (unsigned int) FAIL
22788 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
22789 {
22790 /* No ? OK - try using two ADD instructions to generate
22791 the value. */
22792 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 22793
c19d1205
ZW
22794 /* Yes - then make sure that the second instruction is
22795 also an add. */
22796 if (newimm != (unsigned int) FAIL)
22797 newinsn = temp;
22798 /* Still No ? Try using a negated value. */
22799 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
22800 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
22801 /* Otherwise - give up. */
22802 else
22803 {
22804 as_bad_where (fixP->fx_file, fixP->fx_line,
22805 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
22806 (long) value);
22807 break;
22808 }
b99bd4ef 22809
c19d1205
ZW
22810 /* Replace the first operand in the 2nd instruction (which
22811 is the PC) with the destination register. We have
22812 already added in the PC in the first instruction and we
22813 do not want to do it again. */
22814 newinsn &= ~ 0xf0000;
22815 newinsn |= ((newinsn & 0x0f000) << 4);
22816 }
b99bd4ef 22817
c19d1205
ZW
22818 newimm |= (temp & 0xfffff000);
22819 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 22820
c19d1205
ZW
22821 highpart |= (newinsn & 0xfffff000);
22822 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
22823 }
22824 break;
b99bd4ef 22825
c19d1205 22826 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
22827 if (!fixP->fx_done && seg->use_rela_p)
22828 value = 0;
22829
c19d1205 22830 case BFD_RELOC_ARM_LITERAL:
26d97720 22831 sign = value > 0;
b99bd4ef 22832
c19d1205
ZW
22833 if (value < 0)
22834 value = - value;
b99bd4ef 22835
c19d1205 22836 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 22837 {
c19d1205
ZW
22838 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
22839 as_bad_where (fixP->fx_file, fixP->fx_line,
22840 _("invalid literal constant: pool needs to be closer"));
22841 else
22842 as_bad_where (fixP->fx_file, fixP->fx_line,
22843 _("bad immediate value for offset (%ld)"),
22844 (long) value);
22845 break;
f03698e6
RE
22846 }
22847
c19d1205 22848 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
22849 if (value == 0)
22850 newval &= 0xfffff000;
22851 else
22852 {
22853 newval &= 0xff7ff000;
22854 newval |= value | (sign ? INDEX_UP : 0);
22855 }
c19d1205
ZW
22856 md_number_to_chars (buf, newval, INSN_SIZE);
22857 break;
b99bd4ef 22858
c19d1205
ZW
22859 case BFD_RELOC_ARM_OFFSET_IMM8:
22860 case BFD_RELOC_ARM_HWLITERAL:
26d97720 22861 sign = value > 0;
b99bd4ef 22862
c19d1205
ZW
22863 if (value < 0)
22864 value = - value;
b99bd4ef 22865
c19d1205 22866 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 22867 {
c19d1205
ZW
22868 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
22869 as_bad_where (fixP->fx_file, fixP->fx_line,
22870 _("invalid literal constant: pool needs to be closer"));
22871 else
427d0db6
RM
22872 as_bad_where (fixP->fx_file, fixP->fx_line,
22873 _("bad immediate value for 8-bit offset (%ld)"),
22874 (long) value);
c19d1205 22875 break;
b99bd4ef
NC
22876 }
22877
c19d1205 22878 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
22879 if (value == 0)
22880 newval &= 0xfffff0f0;
22881 else
22882 {
22883 newval &= 0xff7ff0f0;
22884 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
22885 }
c19d1205
ZW
22886 md_number_to_chars (buf, newval, INSN_SIZE);
22887 break;
b99bd4ef 22888
c19d1205
ZW
22889 case BFD_RELOC_ARM_T32_OFFSET_U8:
22890 if (value < 0 || value > 1020 || value % 4 != 0)
22891 as_bad_where (fixP->fx_file, fixP->fx_line,
22892 _("bad immediate value for offset (%ld)"), (long) value);
22893 value /= 4;
b99bd4ef 22894
c19d1205 22895 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
22896 newval |= value;
22897 md_number_to_chars (buf+2, newval, THUMB_SIZE);
22898 break;
b99bd4ef 22899
c19d1205
ZW
22900 case BFD_RELOC_ARM_T32_OFFSET_IMM:
22901 /* This is a complicated relocation used for all varieties of Thumb32
22902 load/store instruction with immediate offset:
22903
22904 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 22905 *4, optional writeback(W)
c19d1205
ZW
22906 (doubleword load/store)
22907
22908 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
22909 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
22910 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
22911 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
22912 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
22913
22914 Uppercase letters indicate bits that are already encoded at
22915 this point. Lowercase letters are our problem. For the
22916 second block of instructions, the secondary opcode nybble
22917 (bits 8..11) is present, and bit 23 is zero, even if this is
22918 a PC-relative operation. */
22919 newval = md_chars_to_number (buf, THUMB_SIZE);
22920 newval <<= 16;
22921 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 22922
c19d1205 22923 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 22924 {
c19d1205
ZW
22925 /* Doubleword load/store: 8-bit offset, scaled by 4. */
22926 if (value >= 0)
22927 newval |= (1 << 23);
22928 else
22929 value = -value;
22930 if (value % 4 != 0)
22931 {
22932 as_bad_where (fixP->fx_file, fixP->fx_line,
22933 _("offset not a multiple of 4"));
22934 break;
22935 }
22936 value /= 4;
216d22bc 22937 if (value > 0xff)
c19d1205
ZW
22938 {
22939 as_bad_where (fixP->fx_file, fixP->fx_line,
22940 _("offset out of range"));
22941 break;
22942 }
22943 newval &= ~0xff;
b99bd4ef 22944 }
c19d1205 22945 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 22946 {
c19d1205
ZW
22947 /* PC-relative, 12-bit offset. */
22948 if (value >= 0)
22949 newval |= (1 << 23);
22950 else
22951 value = -value;
216d22bc 22952 if (value > 0xfff)
c19d1205
ZW
22953 {
22954 as_bad_where (fixP->fx_file, fixP->fx_line,
22955 _("offset out of range"));
22956 break;
22957 }
22958 newval &= ~0xfff;
b99bd4ef 22959 }
c19d1205 22960 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 22961 {
c19d1205
ZW
22962 /* Writeback: 8-bit, +/- offset. */
22963 if (value >= 0)
22964 newval |= (1 << 9);
22965 else
22966 value = -value;
216d22bc 22967 if (value > 0xff)
c19d1205
ZW
22968 {
22969 as_bad_where (fixP->fx_file, fixP->fx_line,
22970 _("offset out of range"));
22971 break;
22972 }
22973 newval &= ~0xff;
b99bd4ef 22974 }
c19d1205 22975 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 22976 {
c19d1205 22977 /* T-instruction: positive 8-bit offset. */
216d22bc 22978 if (value < 0 || value > 0xff)
b99bd4ef 22979 {
c19d1205
ZW
22980 as_bad_where (fixP->fx_file, fixP->fx_line,
22981 _("offset out of range"));
22982 break;
b99bd4ef 22983 }
c19d1205
ZW
22984 newval &= ~0xff;
22985 newval |= value;
b99bd4ef
NC
22986 }
22987 else
b99bd4ef 22988 {
c19d1205
ZW
22989 /* Positive 12-bit or negative 8-bit offset. */
22990 int limit;
22991 if (value >= 0)
b99bd4ef 22992 {
c19d1205
ZW
22993 newval |= (1 << 23);
22994 limit = 0xfff;
22995 }
22996 else
22997 {
22998 value = -value;
22999 limit = 0xff;
23000 }
23001 if (value > limit)
23002 {
23003 as_bad_where (fixP->fx_file, fixP->fx_line,
23004 _("offset out of range"));
23005 break;
b99bd4ef 23006 }
c19d1205 23007 newval &= ~limit;
b99bd4ef 23008 }
b99bd4ef 23009
c19d1205
ZW
23010 newval |= value;
23011 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
23012 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
23013 break;
404ff6b5 23014
c19d1205
ZW
23015 case BFD_RELOC_ARM_SHIFT_IMM:
23016 newval = md_chars_to_number (buf, INSN_SIZE);
23017 if (((unsigned long) value) > 32
23018 || (value == 32
23019 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
23020 {
23021 as_bad_where (fixP->fx_file, fixP->fx_line,
23022 _("shift expression is too large"));
23023 break;
23024 }
404ff6b5 23025
c19d1205
ZW
23026 if (value == 0)
23027 /* Shifts of zero must be done as lsl. */
23028 newval &= ~0x60;
23029 else if (value == 32)
23030 value = 0;
23031 newval &= 0xfffff07f;
23032 newval |= (value & 0x1f) << 7;
23033 md_number_to_chars (buf, newval, INSN_SIZE);
23034 break;
404ff6b5 23035
c19d1205 23036 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 23037 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 23038 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 23039 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
23040 /* We claim that this fixup has been processed here,
23041 even if in fact we generate an error because we do
23042 not have a reloc for it, so tc_gen_reloc will reject it. */
23043 fixP->fx_done = 1;
404ff6b5 23044
c19d1205
ZW
23045 if (fixP->fx_addsy
23046 && ! S_IS_DEFINED (fixP->fx_addsy))
23047 {
23048 as_bad_where (fixP->fx_file, fixP->fx_line,
23049 _("undefined symbol %s used as an immediate value"),
23050 S_GET_NAME (fixP->fx_addsy));
23051 break;
23052 }
404ff6b5 23053
c19d1205
ZW
23054 newval = md_chars_to_number (buf, THUMB_SIZE);
23055 newval <<= 16;
23056 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 23057
16805f35
PB
23058 newimm = FAIL;
23059 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23060 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
23061 {
23062 newimm = encode_thumb32_immediate (value);
23063 if (newimm == (unsigned int) FAIL)
23064 newimm = thumb32_negate_data_op (&newval, value);
23065 }
16805f35
PB
23066 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
23067 && newimm == (unsigned int) FAIL)
92e90b6e 23068 {
16805f35
PB
23069 /* Turn add/sum into addw/subw. */
23070 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23071 newval = (newval & 0xfeffffff) | 0x02000000;
40f246e3
NC
23072 /* No flat 12-bit imm encoding for addsw/subsw. */
23073 if ((newval & 0x00100000) == 0)
e9f89963 23074 {
40f246e3
NC
23075 /* 12 bit immediate for addw/subw. */
23076 if (value < 0)
23077 {
23078 value = -value;
23079 newval ^= 0x00a00000;
23080 }
23081 if (value > 0xfff)
23082 newimm = (unsigned int) FAIL;
23083 else
23084 newimm = value;
e9f89963 23085 }
92e90b6e 23086 }
cc8a6dd0 23087
c19d1205 23088 if (newimm == (unsigned int)FAIL)
3631a3c8 23089 {
c19d1205
ZW
23090 as_bad_where (fixP->fx_file, fixP->fx_line,
23091 _("invalid constant (%lx) after fixup"),
23092 (unsigned long) value);
23093 break;
3631a3c8
NC
23094 }
23095
c19d1205
ZW
23096 newval |= (newimm & 0x800) << 15;
23097 newval |= (newimm & 0x700) << 4;
23098 newval |= (newimm & 0x0ff);
cc8a6dd0 23099
c19d1205
ZW
23100 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
23101 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
23102 break;
a737bd4d 23103
3eb17e6b 23104 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
23105 if (((unsigned long) value) > 0xffff)
23106 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 23107 _("invalid smc expression"));
2fc8bdac 23108 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23109 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23110 md_number_to_chars (buf, newval, INSN_SIZE);
23111 break;
a737bd4d 23112
90ec0d68
MGD
23113 case BFD_RELOC_ARM_HVC:
23114 if (((unsigned long) value) > 0xffff)
23115 as_bad_where (fixP->fx_file, fixP->fx_line,
23116 _("invalid hvc expression"));
23117 newval = md_chars_to_number (buf, INSN_SIZE);
23118 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23119 md_number_to_chars (buf, newval, INSN_SIZE);
23120 break;
23121
c19d1205 23122 case BFD_RELOC_ARM_SWI:
adbaf948 23123 if (fixP->tc_fix_data != 0)
c19d1205
ZW
23124 {
23125 if (((unsigned long) value) > 0xff)
23126 as_bad_where (fixP->fx_file, fixP->fx_line,
23127 _("invalid swi expression"));
2fc8bdac 23128 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
23129 newval |= value;
23130 md_number_to_chars (buf, newval, THUMB_SIZE);
23131 }
23132 else
23133 {
23134 if (((unsigned long) value) > 0x00ffffff)
23135 as_bad_where (fixP->fx_file, fixP->fx_line,
23136 _("invalid swi expression"));
2fc8bdac 23137 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23138 newval |= value;
23139 md_number_to_chars (buf, newval, INSN_SIZE);
23140 }
23141 break;
a737bd4d 23142
c19d1205
ZW
23143 case BFD_RELOC_ARM_MULTI:
23144 if (((unsigned long) value) > 0xffff)
23145 as_bad_where (fixP->fx_file, fixP->fx_line,
23146 _("invalid expression in load/store multiple"));
23147 newval = value | md_chars_to_number (buf, INSN_SIZE);
23148 md_number_to_chars (buf, newval, INSN_SIZE);
23149 break;
a737bd4d 23150
c19d1205 23151#ifdef OBJ_ELF
39b41c9c 23152 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
23153
23154 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23155 && fixP->fx_addsy
34e77a92 23156 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23157 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23158 && THUMB_IS_FUNC (fixP->fx_addsy))
23159 /* Flip the bl to blx. This is a simple flip
23160 bit here because we generate PCREL_CALL for
23161 unconditional bls. */
23162 {
23163 newval = md_chars_to_number (buf, INSN_SIZE);
23164 newval = newval | 0x10000000;
23165 md_number_to_chars (buf, newval, INSN_SIZE);
23166 temp = 1;
23167 fixP->fx_done = 1;
23168 }
39b41c9c
PB
23169 else
23170 temp = 3;
23171 goto arm_branch_common;
23172
23173 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
23174 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23175 && fixP->fx_addsy
34e77a92 23176 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23177 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23178 && THUMB_IS_FUNC (fixP->fx_addsy))
23179 {
23180 /* This would map to a bl<cond>, b<cond>,
23181 b<always> to a Thumb function. We
23182 need to force a relocation for this particular
23183 case. */
23184 newval = md_chars_to_number (buf, INSN_SIZE);
23185 fixP->fx_done = 0;
23186 }
23187
2fc8bdac 23188 case BFD_RELOC_ARM_PLT32:
c19d1205 23189#endif
39b41c9c
PB
23190 case BFD_RELOC_ARM_PCREL_BRANCH:
23191 temp = 3;
23192 goto arm_branch_common;
a737bd4d 23193
39b41c9c 23194 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 23195
39b41c9c 23196 temp = 1;
267bf995
RR
23197 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23198 && fixP->fx_addsy
34e77a92 23199 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23200 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23201 && ARM_IS_FUNC (fixP->fx_addsy))
23202 {
23203 /* Flip the blx to a bl and warn. */
23204 const char *name = S_GET_NAME (fixP->fx_addsy);
23205 newval = 0xeb000000;
23206 as_warn_where (fixP->fx_file, fixP->fx_line,
23207 _("blx to '%s' an ARM ISA state function changed to bl"),
23208 name);
23209 md_number_to_chars (buf, newval, INSN_SIZE);
23210 temp = 3;
23211 fixP->fx_done = 1;
23212 }
23213
23214#ifdef OBJ_ELF
23215 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 23216 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
23217#endif
23218
39b41c9c 23219 arm_branch_common:
c19d1205 23220 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
23221 instruction, in a 24 bit, signed field. Bits 26 through 32 either
23222 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
23223 also be be clear. */
23224 if (value & temp)
c19d1205 23225 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
23226 _("misaligned branch destination"));
23227 if ((value & (offsetT)0xfe000000) != (offsetT)0
23228 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 23229 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23230
2fc8bdac 23231 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23232 {
2fc8bdac
ZW
23233 newval = md_chars_to_number (buf, INSN_SIZE);
23234 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
23235 /* Set the H bit on BLX instructions. */
23236 if (temp == 1)
23237 {
23238 if (value & 2)
23239 newval |= 0x01000000;
23240 else
23241 newval &= ~0x01000000;
23242 }
2fc8bdac 23243 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 23244 }
c19d1205 23245 break;
a737bd4d 23246
25fe350b
MS
23247 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
23248 /* CBZ can only branch forward. */
a737bd4d 23249
738755b0 23250 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
23251 (which, strictly speaking, are prohibited) will be turned into
23252 no-ops.
738755b0
MS
23253
23254 FIXME: It may be better to remove the instruction completely and
23255 perform relaxation. */
23256 if (value == -2)
2fc8bdac
ZW
23257 {
23258 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 23259 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
23260 md_number_to_chars (buf, newval, THUMB_SIZE);
23261 }
738755b0
MS
23262 else
23263 {
23264 if (value & ~0x7e)
08f10d51 23265 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 23266
477330fc 23267 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
23268 {
23269 newval = md_chars_to_number (buf, THUMB_SIZE);
23270 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
23271 md_number_to_chars (buf, newval, THUMB_SIZE);
23272 }
23273 }
c19d1205 23274 break;
a737bd4d 23275
c19d1205 23276 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 23277 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 23278 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23279
2fc8bdac
ZW
23280 if (fixP->fx_done || !seg->use_rela_p)
23281 {
23282 newval = md_chars_to_number (buf, THUMB_SIZE);
23283 newval |= (value & 0x1ff) >> 1;
23284 md_number_to_chars (buf, newval, THUMB_SIZE);
23285 }
c19d1205 23286 break;
a737bd4d 23287
c19d1205 23288 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 23289 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 23290 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23291
2fc8bdac
ZW
23292 if (fixP->fx_done || !seg->use_rela_p)
23293 {
23294 newval = md_chars_to_number (buf, THUMB_SIZE);
23295 newval |= (value & 0xfff) >> 1;
23296 md_number_to_chars (buf, newval, THUMB_SIZE);
23297 }
c19d1205 23298 break;
a737bd4d 23299
c19d1205 23300 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
23301 if (fixP->fx_addsy
23302 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23303 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23304 && ARM_IS_FUNC (fixP->fx_addsy)
23305 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23306 {
23307 /* Force a relocation for a branch 20 bits wide. */
23308 fixP->fx_done = 0;
23309 }
08f10d51 23310 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
23311 as_bad_where (fixP->fx_file, fixP->fx_line,
23312 _("conditional branch out of range"));
404ff6b5 23313
2fc8bdac
ZW
23314 if (fixP->fx_done || !seg->use_rela_p)
23315 {
23316 offsetT newval2;
23317 addressT S, J1, J2, lo, hi;
404ff6b5 23318
2fc8bdac
ZW
23319 S = (value & 0x00100000) >> 20;
23320 J2 = (value & 0x00080000) >> 19;
23321 J1 = (value & 0x00040000) >> 18;
23322 hi = (value & 0x0003f000) >> 12;
23323 lo = (value & 0x00000ffe) >> 1;
6c43fab6 23324
2fc8bdac
ZW
23325 newval = md_chars_to_number (buf, THUMB_SIZE);
23326 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23327 newval |= (S << 10) | hi;
23328 newval2 |= (J1 << 13) | (J2 << 11) | lo;
23329 md_number_to_chars (buf, newval, THUMB_SIZE);
23330 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23331 }
c19d1205 23332 break;
6c43fab6 23333
c19d1205 23334 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
23335 /* If there is a blx from a thumb state function to
23336 another thumb function flip this to a bl and warn
23337 about it. */
23338
23339 if (fixP->fx_addsy
34e77a92 23340 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23341 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23342 && THUMB_IS_FUNC (fixP->fx_addsy))
23343 {
23344 const char *name = S_GET_NAME (fixP->fx_addsy);
23345 as_warn_where (fixP->fx_file, fixP->fx_line,
23346 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
23347 name);
23348 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23349 newval = newval | 0x1000;
23350 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23351 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23352 fixP->fx_done = 1;
23353 }
23354
23355
23356 goto thumb_bl_common;
23357
c19d1205 23358 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
23359 /* A bl from Thumb state ISA to an internal ARM state function
23360 is converted to a blx. */
23361 if (fixP->fx_addsy
23362 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23363 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23364 && ARM_IS_FUNC (fixP->fx_addsy)
23365 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23366 {
23367 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23368 newval = newval & ~0x1000;
23369 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23370 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
23371 fixP->fx_done = 1;
23372 }
23373
23374 thumb_bl_common:
23375
2fc8bdac
ZW
23376 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23377 /* For a BLX instruction, make sure that the relocation is rounded up
23378 to a word boundary. This follows the semantics of the instruction
23379 which specifies that bit 1 of the target address will come from bit
23380 1 of the base address. */
d406f3e4
JB
23381 value = (value + 3) & ~ 3;
23382
23383#ifdef OBJ_ELF
23384 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
23385 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23386 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23387#endif
404ff6b5 23388
2b2f5df9
NC
23389 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
23390 {
fc289b0a 23391 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
23392 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23393 else if ((value & ~0x1ffffff)
23394 && ((value & ~0x1ffffff) != ~0x1ffffff))
23395 as_bad_where (fixP->fx_file, fixP->fx_line,
23396 _("Thumb2 branch out of range"));
23397 }
4a42ebbc
RR
23398
23399 if (fixP->fx_done || !seg->use_rela_p)
23400 encode_thumb2_b_bl_offset (buf, value);
23401
c19d1205 23402 break;
404ff6b5 23403
c19d1205 23404 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
23405 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
23406 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 23407
2fc8bdac 23408 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 23409 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 23410
2fc8bdac 23411 break;
a737bd4d 23412
2fc8bdac
ZW
23413 case BFD_RELOC_8:
23414 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 23415 *buf = value;
c19d1205 23416 break;
a737bd4d 23417
c19d1205 23418 case BFD_RELOC_16:
2fc8bdac 23419 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23420 md_number_to_chars (buf, value, 2);
c19d1205 23421 break;
a737bd4d 23422
c19d1205 23423#ifdef OBJ_ELF
0855e32b
NS
23424 case BFD_RELOC_ARM_TLS_CALL:
23425 case BFD_RELOC_ARM_THM_TLS_CALL:
23426 case BFD_RELOC_ARM_TLS_DESCSEQ:
23427 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 23428 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
23429 case BFD_RELOC_ARM_TLS_GD32:
23430 case BFD_RELOC_ARM_TLS_LE32:
23431 case BFD_RELOC_ARM_TLS_IE32:
23432 case BFD_RELOC_ARM_TLS_LDM32:
23433 case BFD_RELOC_ARM_TLS_LDO32:
23434 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 23435 break;
6c43fab6 23436
c19d1205
ZW
23437 case BFD_RELOC_ARM_GOT32:
23438 case BFD_RELOC_ARM_GOTOFF:
c19d1205 23439 break;
b43420e6
NC
23440
23441 case BFD_RELOC_ARM_GOT_PREL:
23442 if (fixP->fx_done || !seg->use_rela_p)
477330fc 23443 md_number_to_chars (buf, value, 4);
b43420e6
NC
23444 break;
23445
9a6f4e97
NS
23446 case BFD_RELOC_ARM_TARGET2:
23447 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
23448 addend here for REL targets, because it won't be written out
23449 during reloc processing later. */
9a6f4e97
NS
23450 if (fixP->fx_done || !seg->use_rela_p)
23451 md_number_to_chars (buf, fixP->fx_offset, 4);
23452 break;
c19d1205 23453#endif
6c43fab6 23454
c19d1205
ZW
23455 case BFD_RELOC_RVA:
23456 case BFD_RELOC_32:
23457 case BFD_RELOC_ARM_TARGET1:
23458 case BFD_RELOC_ARM_ROSEGREL32:
23459 case BFD_RELOC_ARM_SBREL32:
23460 case BFD_RELOC_32_PCREL:
f0927246
NC
23461#ifdef TE_PE
23462 case BFD_RELOC_32_SECREL:
23463#endif
2fc8bdac 23464 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
23465#ifdef TE_WINCE
23466 /* For WinCE we only do this for pcrel fixups. */
23467 if (fixP->fx_done || fixP->fx_pcrel)
23468#endif
23469 md_number_to_chars (buf, value, 4);
c19d1205 23470 break;
6c43fab6 23471
c19d1205
ZW
23472#ifdef OBJ_ELF
23473 case BFD_RELOC_ARM_PREL31:
2fc8bdac 23474 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
23475 {
23476 newval = md_chars_to_number (buf, 4) & 0x80000000;
23477 if ((value ^ (value >> 1)) & 0x40000000)
23478 {
23479 as_bad_where (fixP->fx_file, fixP->fx_line,
23480 _("rel31 relocation overflow"));
23481 }
23482 newval |= value & 0x7fffffff;
23483 md_number_to_chars (buf, newval, 4);
23484 }
23485 break;
c19d1205 23486#endif
a737bd4d 23487
c19d1205 23488 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 23489 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
9db2f6b4
RL
23490 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
23491 newval = md_chars_to_number (buf, INSN_SIZE);
23492 else
23493 newval = get_thumb32_insn (buf);
23494 if ((newval & 0x0f200f00) == 0x0d000900)
23495 {
23496 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
23497 has permitted values that are multiples of 2, in the range 0
23498 to 510. */
23499 if (value < -510 || value > 510 || (value & 1))
23500 as_bad_where (fixP->fx_file, fixP->fx_line,
23501 _("co-processor offset out of range"));
23502 }
23503 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
23504 as_bad_where (fixP->fx_file, fixP->fx_line,
23505 _("co-processor offset out of range"));
23506 cp_off_common:
26d97720 23507 sign = value > 0;
c19d1205
ZW
23508 if (value < 0)
23509 value = -value;
8f06b2d8
PB
23510 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23511 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23512 newval = md_chars_to_number (buf, INSN_SIZE);
23513 else
23514 newval = get_thumb32_insn (buf);
26d97720
NS
23515 if (value == 0)
23516 newval &= 0xffffff00;
23517 else
23518 {
23519 newval &= 0xff7fff00;
9db2f6b4
RL
23520 if ((newval & 0x0f200f00) == 0x0d000900)
23521 {
23522 /* This is a fp16 vstr/vldr.
23523
23524 It requires the immediate offset in the instruction is shifted
23525 left by 1 to be a half-word offset.
23526
23527 Here, left shift by 1 first, and later right shift by 2
23528 should get the right offset. */
23529 value <<= 1;
23530 }
26d97720
NS
23531 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
23532 }
8f06b2d8
PB
23533 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23534 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23535 md_number_to_chars (buf, newval, INSN_SIZE);
23536 else
23537 put_thumb32_insn (buf, newval);
c19d1205 23538 break;
a737bd4d 23539
c19d1205 23540 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 23541 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
23542 if (value < -255 || value > 255)
23543 as_bad_where (fixP->fx_file, fixP->fx_line,
23544 _("co-processor offset out of range"));
df7849c5 23545 value *= 4;
c19d1205 23546 goto cp_off_common;
6c43fab6 23547
c19d1205
ZW
23548 case BFD_RELOC_ARM_THUMB_OFFSET:
23549 newval = md_chars_to_number (buf, THUMB_SIZE);
23550 /* Exactly what ranges, and where the offset is inserted depends
23551 on the type of instruction, we can establish this from the
23552 top 4 bits. */
23553 switch (newval >> 12)
23554 {
23555 case 4: /* PC load. */
23556 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
23557 forced to zero for these loads; md_pcrel_from has already
23558 compensated for this. */
23559 if (value & 3)
23560 as_bad_where (fixP->fx_file, fixP->fx_line,
23561 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
23562 (((unsigned long) fixP->fx_frag->fr_address
23563 + (unsigned long) fixP->fx_where) & ~3)
23564 + (unsigned long) value);
a737bd4d 23565
c19d1205
ZW
23566 if (value & ~0x3fc)
23567 as_bad_where (fixP->fx_file, fixP->fx_line,
23568 _("invalid offset, value too big (0x%08lX)"),
23569 (long) value);
a737bd4d 23570
c19d1205
ZW
23571 newval |= value >> 2;
23572 break;
a737bd4d 23573
c19d1205
ZW
23574 case 9: /* SP load/store. */
23575 if (value & ~0x3fc)
23576 as_bad_where (fixP->fx_file, fixP->fx_line,
23577 _("invalid offset, value too big (0x%08lX)"),
23578 (long) value);
23579 newval |= value >> 2;
23580 break;
6c43fab6 23581
c19d1205
ZW
23582 case 6: /* Word load/store. */
23583 if (value & ~0x7c)
23584 as_bad_where (fixP->fx_file, fixP->fx_line,
23585 _("invalid offset, value too big (0x%08lX)"),
23586 (long) value);
23587 newval |= value << 4; /* 6 - 2. */
23588 break;
a737bd4d 23589
c19d1205
ZW
23590 case 7: /* Byte load/store. */
23591 if (value & ~0x1f)
23592 as_bad_where (fixP->fx_file, fixP->fx_line,
23593 _("invalid offset, value too big (0x%08lX)"),
23594 (long) value);
23595 newval |= value << 6;
23596 break;
a737bd4d 23597
c19d1205
ZW
23598 case 8: /* Halfword load/store. */
23599 if (value & ~0x3e)
23600 as_bad_where (fixP->fx_file, fixP->fx_line,
23601 _("invalid offset, value too big (0x%08lX)"),
23602 (long) value);
23603 newval |= value << 5; /* 6 - 1. */
23604 break;
a737bd4d 23605
c19d1205
ZW
23606 default:
23607 as_bad_where (fixP->fx_file, fixP->fx_line,
23608 "Unable to process relocation for thumb opcode: %lx",
23609 (unsigned long) newval);
23610 break;
23611 }
23612 md_number_to_chars (buf, newval, THUMB_SIZE);
23613 break;
a737bd4d 23614
c19d1205
ZW
23615 case BFD_RELOC_ARM_THUMB_ADD:
23616 /* This is a complicated relocation, since we use it for all of
23617 the following immediate relocations:
a737bd4d 23618
c19d1205
ZW
23619 3bit ADD/SUB
23620 8bit ADD/SUB
23621 9bit ADD/SUB SP word-aligned
23622 10bit ADD PC/SP word-aligned
a737bd4d 23623
c19d1205
ZW
23624 The type of instruction being processed is encoded in the
23625 instruction field:
a737bd4d 23626
c19d1205
ZW
23627 0x8000 SUB
23628 0x00F0 Rd
23629 0x000F Rs
23630 */
23631 newval = md_chars_to_number (buf, THUMB_SIZE);
23632 {
23633 int rd = (newval >> 4) & 0xf;
23634 int rs = newval & 0xf;
23635 int subtract = !!(newval & 0x8000);
a737bd4d 23636
c19d1205
ZW
23637 /* Check for HI regs, only very restricted cases allowed:
23638 Adjusting SP, and using PC or SP to get an address. */
23639 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
23640 || (rs > 7 && rs != REG_SP && rs != REG_PC))
23641 as_bad_where (fixP->fx_file, fixP->fx_line,
23642 _("invalid Hi register with immediate"));
a737bd4d 23643
c19d1205
ZW
23644 /* If value is negative, choose the opposite instruction. */
23645 if (value < 0)
23646 {
23647 value = -value;
23648 subtract = !subtract;
23649 if (value < 0)
23650 as_bad_where (fixP->fx_file, fixP->fx_line,
23651 _("immediate value out of range"));
23652 }
a737bd4d 23653
c19d1205
ZW
23654 if (rd == REG_SP)
23655 {
75c11999 23656 if (value & ~0x1fc)
c19d1205
ZW
23657 as_bad_where (fixP->fx_file, fixP->fx_line,
23658 _("invalid immediate for stack address calculation"));
23659 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
23660 newval |= value >> 2;
23661 }
23662 else if (rs == REG_PC || rs == REG_SP)
23663 {
c12d2c9d
NC
23664 /* PR gas/18541. If the addition is for a defined symbol
23665 within range of an ADR instruction then accept it. */
23666 if (subtract
23667 && value == 4
23668 && fixP->fx_addsy != NULL)
23669 {
23670 subtract = 0;
23671
23672 if (! S_IS_DEFINED (fixP->fx_addsy)
23673 || S_GET_SEGMENT (fixP->fx_addsy) != seg
23674 || S_IS_WEAK (fixP->fx_addsy))
23675 {
23676 as_bad_where (fixP->fx_file, fixP->fx_line,
23677 _("address calculation needs a strongly defined nearby symbol"));
23678 }
23679 else
23680 {
23681 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
23682
23683 /* Round up to the next 4-byte boundary. */
23684 if (v & 3)
23685 v = (v + 3) & ~ 3;
23686 else
23687 v += 4;
23688 v = S_GET_VALUE (fixP->fx_addsy) - v;
23689
23690 if (v & ~0x3fc)
23691 {
23692 as_bad_where (fixP->fx_file, fixP->fx_line,
23693 _("symbol too far away"));
23694 }
23695 else
23696 {
23697 fixP->fx_done = 1;
23698 value = v;
23699 }
23700 }
23701 }
23702
c19d1205
ZW
23703 if (subtract || value & ~0x3fc)
23704 as_bad_where (fixP->fx_file, fixP->fx_line,
23705 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 23706 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
23707 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
23708 newval |= rd << 8;
23709 newval |= value >> 2;
23710 }
23711 else if (rs == rd)
23712 {
23713 if (value & ~0xff)
23714 as_bad_where (fixP->fx_file, fixP->fx_line,
23715 _("immediate value out of range"));
23716 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
23717 newval |= (rd << 8) | value;
23718 }
23719 else
23720 {
23721 if (value & ~0x7)
23722 as_bad_where (fixP->fx_file, fixP->fx_line,
23723 _("immediate value out of range"));
23724 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
23725 newval |= rd | (rs << 3) | (value << 6);
23726 }
23727 }
23728 md_number_to_chars (buf, newval, THUMB_SIZE);
23729 break;
a737bd4d 23730
c19d1205
ZW
23731 case BFD_RELOC_ARM_THUMB_IMM:
23732 newval = md_chars_to_number (buf, THUMB_SIZE);
23733 if (value < 0 || value > 255)
23734 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 23735 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
23736 (long) value);
23737 newval |= value;
23738 md_number_to_chars (buf, newval, THUMB_SIZE);
23739 break;
a737bd4d 23740
c19d1205
ZW
23741 case BFD_RELOC_ARM_THUMB_SHIFT:
23742 /* 5bit shift value (0..32). LSL cannot take 32. */
23743 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
23744 temp = newval & 0xf800;
23745 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
23746 as_bad_where (fixP->fx_file, fixP->fx_line,
23747 _("invalid shift value: %ld"), (long) value);
23748 /* Shifts of zero must be encoded as LSL. */
23749 if (value == 0)
23750 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
23751 /* Shifts of 32 are encoded as zero. */
23752 else if (value == 32)
23753 value = 0;
23754 newval |= value << 6;
23755 md_number_to_chars (buf, newval, THUMB_SIZE);
23756 break;
a737bd4d 23757
c19d1205
ZW
23758 case BFD_RELOC_VTABLE_INHERIT:
23759 case BFD_RELOC_VTABLE_ENTRY:
23760 fixP->fx_done = 0;
23761 return;
6c43fab6 23762
b6895b4f
PB
23763 case BFD_RELOC_ARM_MOVW:
23764 case BFD_RELOC_ARM_MOVT:
23765 case BFD_RELOC_ARM_THUMB_MOVW:
23766 case BFD_RELOC_ARM_THUMB_MOVT:
23767 if (fixP->fx_done || !seg->use_rela_p)
23768 {
23769 /* REL format relocations are limited to a 16-bit addend. */
23770 if (!fixP->fx_done)
23771 {
39623e12 23772 if (value < -0x8000 || value > 0x7fff)
b6895b4f 23773 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 23774 _("offset out of range"));
b6895b4f
PB
23775 }
23776 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23777 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23778 {
23779 value >>= 16;
23780 }
23781
23782 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23783 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23784 {
23785 newval = get_thumb32_insn (buf);
23786 newval &= 0xfbf08f00;
23787 newval |= (value & 0xf000) << 4;
23788 newval |= (value & 0x0800) << 15;
23789 newval |= (value & 0x0700) << 4;
23790 newval |= (value & 0x00ff);
23791 put_thumb32_insn (buf, newval);
23792 }
23793 else
23794 {
23795 newval = md_chars_to_number (buf, 4);
23796 newval &= 0xfff0f000;
23797 newval |= value & 0x0fff;
23798 newval |= (value & 0xf000) << 4;
23799 md_number_to_chars (buf, newval, 4);
23800 }
23801 }
23802 return;
23803
72d98d16
MG
23804 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
23805 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
23806 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
23807 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
23808 gas_assert (!fixP->fx_done);
23809 {
23810 bfd_vma insn;
23811 bfd_boolean is_mov;
23812 bfd_vma encoded_addend = value;
23813
23814 /* Check that addend can be encoded in instruction. */
23815 if (!seg->use_rela_p && (value < 0 || value > 255))
23816 as_bad_where (fixP->fx_file, fixP->fx_line,
23817 _("the offset 0x%08lX is not representable"),
23818 (unsigned long) encoded_addend);
23819
23820 /* Extract the instruction. */
23821 insn = md_chars_to_number (buf, THUMB_SIZE);
23822 is_mov = (insn & 0xf800) == 0x2000;
23823
23824 /* Encode insn. */
23825 if (is_mov)
23826 {
23827 if (!seg->use_rela_p)
23828 insn |= encoded_addend;
23829 }
23830 else
23831 {
23832 int rd, rs;
23833
23834 /* Extract the instruction. */
23835 /* Encoding is the following
23836 0x8000 SUB
23837 0x00F0 Rd
23838 0x000F Rs
23839 */
23840 /* The following conditions must be true :
23841 - ADD
23842 - Rd == Rs
23843 - Rd <= 7
23844 */
23845 rd = (insn >> 4) & 0xf;
23846 rs = insn & 0xf;
23847 if ((insn & 0x8000) || (rd != rs) || rd > 7)
23848 as_bad_where (fixP->fx_file, fixP->fx_line,
23849 _("Unable to process relocation for thumb opcode: %lx"),
23850 (unsigned long) insn);
23851
23852 /* Encode as ADD immediate8 thumb 1 code. */
23853 insn = 0x3000 | (rd << 8);
23854
23855 /* Place the encoded addend into the first 8 bits of the
23856 instruction. */
23857 if (!seg->use_rela_p)
23858 insn |= encoded_addend;
23859 }
23860
23861 /* Update the instruction. */
23862 md_number_to_chars (buf, insn, THUMB_SIZE);
23863 }
23864 break;
23865
4962c51a
MS
23866 case BFD_RELOC_ARM_ALU_PC_G0_NC:
23867 case BFD_RELOC_ARM_ALU_PC_G0:
23868 case BFD_RELOC_ARM_ALU_PC_G1_NC:
23869 case BFD_RELOC_ARM_ALU_PC_G1:
23870 case BFD_RELOC_ARM_ALU_PC_G2:
23871 case BFD_RELOC_ARM_ALU_SB_G0_NC:
23872 case BFD_RELOC_ARM_ALU_SB_G0:
23873 case BFD_RELOC_ARM_ALU_SB_G1_NC:
23874 case BFD_RELOC_ARM_ALU_SB_G1:
23875 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 23876 gas_assert (!fixP->fx_done);
4962c51a
MS
23877 if (!seg->use_rela_p)
23878 {
477330fc
RM
23879 bfd_vma insn;
23880 bfd_vma encoded_addend;
23881 bfd_vma addend_abs = abs (value);
23882
23883 /* Check that the absolute value of the addend can be
23884 expressed as an 8-bit constant plus a rotation. */
23885 encoded_addend = encode_arm_immediate (addend_abs);
23886 if (encoded_addend == (unsigned int) FAIL)
4962c51a 23887 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23888 _("the offset 0x%08lX is not representable"),
23889 (unsigned long) addend_abs);
23890
23891 /* Extract the instruction. */
23892 insn = md_chars_to_number (buf, INSN_SIZE);
23893
23894 /* If the addend is positive, use an ADD instruction.
23895 Otherwise use a SUB. Take care not to destroy the S bit. */
23896 insn &= 0xff1fffff;
23897 if (value < 0)
23898 insn |= 1 << 22;
23899 else
23900 insn |= 1 << 23;
23901
23902 /* Place the encoded addend into the first 12 bits of the
23903 instruction. */
23904 insn &= 0xfffff000;
23905 insn |= encoded_addend;
23906
23907 /* Update the instruction. */
23908 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
23909 }
23910 break;
23911
23912 case BFD_RELOC_ARM_LDR_PC_G0:
23913 case BFD_RELOC_ARM_LDR_PC_G1:
23914 case BFD_RELOC_ARM_LDR_PC_G2:
23915 case BFD_RELOC_ARM_LDR_SB_G0:
23916 case BFD_RELOC_ARM_LDR_SB_G1:
23917 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 23918 gas_assert (!fixP->fx_done);
4962c51a 23919 if (!seg->use_rela_p)
477330fc
RM
23920 {
23921 bfd_vma insn;
23922 bfd_vma addend_abs = abs (value);
4962c51a 23923
477330fc
RM
23924 /* Check that the absolute value of the addend can be
23925 encoded in 12 bits. */
23926 if (addend_abs >= 0x1000)
4962c51a 23927 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23928 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
23929 (unsigned long) addend_abs);
23930
23931 /* Extract the instruction. */
23932 insn = md_chars_to_number (buf, INSN_SIZE);
23933
23934 /* If the addend is negative, clear bit 23 of the instruction.
23935 Otherwise set it. */
23936 if (value < 0)
23937 insn &= ~(1 << 23);
23938 else
23939 insn |= 1 << 23;
23940
23941 /* Place the absolute value of the addend into the first 12 bits
23942 of the instruction. */
23943 insn &= 0xfffff000;
23944 insn |= addend_abs;
23945
23946 /* Update the instruction. */
23947 md_number_to_chars (buf, insn, INSN_SIZE);
23948 }
4962c51a
MS
23949 break;
23950
23951 case BFD_RELOC_ARM_LDRS_PC_G0:
23952 case BFD_RELOC_ARM_LDRS_PC_G1:
23953 case BFD_RELOC_ARM_LDRS_PC_G2:
23954 case BFD_RELOC_ARM_LDRS_SB_G0:
23955 case BFD_RELOC_ARM_LDRS_SB_G1:
23956 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 23957 gas_assert (!fixP->fx_done);
4962c51a 23958 if (!seg->use_rela_p)
477330fc
RM
23959 {
23960 bfd_vma insn;
23961 bfd_vma addend_abs = abs (value);
4962c51a 23962
477330fc
RM
23963 /* Check that the absolute value of the addend can be
23964 encoded in 8 bits. */
23965 if (addend_abs >= 0x100)
4962c51a 23966 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
23967 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
23968 (unsigned long) addend_abs);
23969
23970 /* Extract the instruction. */
23971 insn = md_chars_to_number (buf, INSN_SIZE);
23972
23973 /* If the addend is negative, clear bit 23 of the instruction.
23974 Otherwise set it. */
23975 if (value < 0)
23976 insn &= ~(1 << 23);
23977 else
23978 insn |= 1 << 23;
23979
23980 /* Place the first four bits of the absolute value of the addend
23981 into the first 4 bits of the instruction, and the remaining
23982 four into bits 8 .. 11. */
23983 insn &= 0xfffff0f0;
23984 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
23985
23986 /* Update the instruction. */
23987 md_number_to_chars (buf, insn, INSN_SIZE);
23988 }
4962c51a
MS
23989 break;
23990
23991 case BFD_RELOC_ARM_LDC_PC_G0:
23992 case BFD_RELOC_ARM_LDC_PC_G1:
23993 case BFD_RELOC_ARM_LDC_PC_G2:
23994 case BFD_RELOC_ARM_LDC_SB_G0:
23995 case BFD_RELOC_ARM_LDC_SB_G1:
23996 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 23997 gas_assert (!fixP->fx_done);
4962c51a 23998 if (!seg->use_rela_p)
477330fc
RM
23999 {
24000 bfd_vma insn;
24001 bfd_vma addend_abs = abs (value);
4962c51a 24002
477330fc
RM
24003 /* Check that the absolute value of the addend is a multiple of
24004 four and, when divided by four, fits in 8 bits. */
24005 if (addend_abs & 0x3)
4962c51a 24006 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24007 _("bad offset 0x%08lX (must be word-aligned)"),
24008 (unsigned long) addend_abs);
4962c51a 24009
477330fc 24010 if ((addend_abs >> 2) > 0xff)
4962c51a 24011 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24012 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
24013 (unsigned long) addend_abs);
24014
24015 /* Extract the instruction. */
24016 insn = md_chars_to_number (buf, INSN_SIZE);
24017
24018 /* If the addend is negative, clear bit 23 of the instruction.
24019 Otherwise set it. */
24020 if (value < 0)
24021 insn &= ~(1 << 23);
24022 else
24023 insn |= 1 << 23;
24024
24025 /* Place the addend (divided by four) into the first eight
24026 bits of the instruction. */
24027 insn &= 0xfffffff0;
24028 insn |= addend_abs >> 2;
24029
24030 /* Update the instruction. */
24031 md_number_to_chars (buf, insn, INSN_SIZE);
24032 }
4962c51a
MS
24033 break;
24034
845b51d6
PB
24035 case BFD_RELOC_ARM_V4BX:
24036 /* This will need to go in the object file. */
24037 fixP->fx_done = 0;
24038 break;
24039
c19d1205
ZW
24040 case BFD_RELOC_UNUSED:
24041 default:
24042 as_bad_where (fixP->fx_file, fixP->fx_line,
24043 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
24044 }
6c43fab6
RE
24045}
24046
c19d1205
ZW
24047/* Translate internal representation of relocation info to BFD target
24048 format. */
a737bd4d 24049
c19d1205 24050arelent *
00a97672 24051tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 24052{
c19d1205
ZW
24053 arelent * reloc;
24054 bfd_reloc_code_real_type code;
a737bd4d 24055
325801bd 24056 reloc = XNEW (arelent);
a737bd4d 24057
325801bd 24058 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
24059 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
24060 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 24061
2fc8bdac 24062 if (fixp->fx_pcrel)
00a97672
RS
24063 {
24064 if (section->use_rela_p)
24065 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
24066 else
24067 fixp->fx_offset = reloc->address;
24068 }
c19d1205 24069 reloc->addend = fixp->fx_offset;
a737bd4d 24070
c19d1205 24071 switch (fixp->fx_r_type)
a737bd4d 24072 {
c19d1205
ZW
24073 case BFD_RELOC_8:
24074 if (fixp->fx_pcrel)
24075 {
24076 code = BFD_RELOC_8_PCREL;
24077 break;
24078 }
a737bd4d 24079
c19d1205
ZW
24080 case BFD_RELOC_16:
24081 if (fixp->fx_pcrel)
24082 {
24083 code = BFD_RELOC_16_PCREL;
24084 break;
24085 }
6c43fab6 24086
c19d1205
ZW
24087 case BFD_RELOC_32:
24088 if (fixp->fx_pcrel)
24089 {
24090 code = BFD_RELOC_32_PCREL;
24091 break;
24092 }
a737bd4d 24093
b6895b4f
PB
24094 case BFD_RELOC_ARM_MOVW:
24095 if (fixp->fx_pcrel)
24096 {
24097 code = BFD_RELOC_ARM_MOVW_PCREL;
24098 break;
24099 }
24100
24101 case BFD_RELOC_ARM_MOVT:
24102 if (fixp->fx_pcrel)
24103 {
24104 code = BFD_RELOC_ARM_MOVT_PCREL;
24105 break;
24106 }
24107
24108 case BFD_RELOC_ARM_THUMB_MOVW:
24109 if (fixp->fx_pcrel)
24110 {
24111 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
24112 break;
24113 }
24114
24115 case BFD_RELOC_ARM_THUMB_MOVT:
24116 if (fixp->fx_pcrel)
24117 {
24118 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
24119 break;
24120 }
24121
c19d1205
ZW
24122 case BFD_RELOC_NONE:
24123 case BFD_RELOC_ARM_PCREL_BRANCH:
24124 case BFD_RELOC_ARM_PCREL_BLX:
24125 case BFD_RELOC_RVA:
24126 case BFD_RELOC_THUMB_PCREL_BRANCH7:
24127 case BFD_RELOC_THUMB_PCREL_BRANCH9:
24128 case BFD_RELOC_THUMB_PCREL_BRANCH12:
24129 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24130 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24131 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
24132 case BFD_RELOC_VTABLE_ENTRY:
24133 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
24134#ifdef TE_PE
24135 case BFD_RELOC_32_SECREL:
24136#endif
c19d1205
ZW
24137 code = fixp->fx_r_type;
24138 break;
a737bd4d 24139
00adf2d4
JB
24140 case BFD_RELOC_THUMB_PCREL_BLX:
24141#ifdef OBJ_ELF
24142 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
24143 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
24144 else
24145#endif
24146 code = BFD_RELOC_THUMB_PCREL_BLX;
24147 break;
24148
c19d1205
ZW
24149 case BFD_RELOC_ARM_LITERAL:
24150 case BFD_RELOC_ARM_HWLITERAL:
24151 /* If this is called then the a literal has
24152 been referenced across a section boundary. */
24153 as_bad_where (fixp->fx_file, fixp->fx_line,
24154 _("literal referenced across section boundary"));
24155 return NULL;
a737bd4d 24156
c19d1205 24157#ifdef OBJ_ELF
0855e32b
NS
24158 case BFD_RELOC_ARM_TLS_CALL:
24159 case BFD_RELOC_ARM_THM_TLS_CALL:
24160 case BFD_RELOC_ARM_TLS_DESCSEQ:
24161 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
24162 case BFD_RELOC_ARM_GOT32:
24163 case BFD_RELOC_ARM_GOTOFF:
b43420e6 24164 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
24165 case BFD_RELOC_ARM_PLT32:
24166 case BFD_RELOC_ARM_TARGET1:
24167 case BFD_RELOC_ARM_ROSEGREL32:
24168 case BFD_RELOC_ARM_SBREL32:
24169 case BFD_RELOC_ARM_PREL31:
24170 case BFD_RELOC_ARM_TARGET2:
c19d1205 24171 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
24172 case BFD_RELOC_ARM_PCREL_CALL:
24173 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
24174 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24175 case BFD_RELOC_ARM_ALU_PC_G0:
24176 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24177 case BFD_RELOC_ARM_ALU_PC_G1:
24178 case BFD_RELOC_ARM_ALU_PC_G2:
24179 case BFD_RELOC_ARM_LDR_PC_G0:
24180 case BFD_RELOC_ARM_LDR_PC_G1:
24181 case BFD_RELOC_ARM_LDR_PC_G2:
24182 case BFD_RELOC_ARM_LDRS_PC_G0:
24183 case BFD_RELOC_ARM_LDRS_PC_G1:
24184 case BFD_RELOC_ARM_LDRS_PC_G2:
24185 case BFD_RELOC_ARM_LDC_PC_G0:
24186 case BFD_RELOC_ARM_LDC_PC_G1:
24187 case BFD_RELOC_ARM_LDC_PC_G2:
24188 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24189 case BFD_RELOC_ARM_ALU_SB_G0:
24190 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24191 case BFD_RELOC_ARM_ALU_SB_G1:
24192 case BFD_RELOC_ARM_ALU_SB_G2:
24193 case BFD_RELOC_ARM_LDR_SB_G0:
24194 case BFD_RELOC_ARM_LDR_SB_G1:
24195 case BFD_RELOC_ARM_LDR_SB_G2:
24196 case BFD_RELOC_ARM_LDRS_SB_G0:
24197 case BFD_RELOC_ARM_LDRS_SB_G1:
24198 case BFD_RELOC_ARM_LDRS_SB_G2:
24199 case BFD_RELOC_ARM_LDC_SB_G0:
24200 case BFD_RELOC_ARM_LDC_SB_G1:
24201 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 24202 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
24203 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24204 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24205 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24206 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
c19d1205
ZW
24207 code = fixp->fx_r_type;
24208 break;
a737bd4d 24209
0855e32b 24210 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 24211 case BFD_RELOC_ARM_TLS_GD32:
75c11999 24212 case BFD_RELOC_ARM_TLS_LE32:
c19d1205
ZW
24213 case BFD_RELOC_ARM_TLS_IE32:
24214 case BFD_RELOC_ARM_TLS_LDM32:
24215 /* BFD will include the symbol's address in the addend.
24216 But we don't want that, so subtract it out again here. */
24217 if (!S_IS_COMMON (fixp->fx_addsy))
24218 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
24219 code = fixp->fx_r_type;
24220 break;
24221#endif
a737bd4d 24222
c19d1205
ZW
24223 case BFD_RELOC_ARM_IMMEDIATE:
24224 as_bad_where (fixp->fx_file, fixp->fx_line,
24225 _("internal relocation (type: IMMEDIATE) not fixed up"));
24226 return NULL;
a737bd4d 24227
c19d1205
ZW
24228 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24229 as_bad_where (fixp->fx_file, fixp->fx_line,
24230 _("ADRL used for a symbol not defined in the same file"));
24231 return NULL;
a737bd4d 24232
c19d1205 24233 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
24234 if (section->use_rela_p)
24235 {
24236 code = fixp->fx_r_type;
24237 break;
24238 }
24239
c19d1205
ZW
24240 if (fixp->fx_addsy != NULL
24241 && !S_IS_DEFINED (fixp->fx_addsy)
24242 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 24243 {
c19d1205
ZW
24244 as_bad_where (fixp->fx_file, fixp->fx_line,
24245 _("undefined local label `%s'"),
24246 S_GET_NAME (fixp->fx_addsy));
24247 return NULL;
a737bd4d
NC
24248 }
24249
c19d1205
ZW
24250 as_bad_where (fixp->fx_file, fixp->fx_line,
24251 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
24252 return NULL;
a737bd4d 24253
c19d1205
ZW
24254 default:
24255 {
e0471c16 24256 const char * type;
6c43fab6 24257
c19d1205
ZW
24258 switch (fixp->fx_r_type)
24259 {
24260 case BFD_RELOC_NONE: type = "NONE"; break;
24261 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
24262 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 24263 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
24264 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
24265 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
24266 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 24267 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 24268 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
24269 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
24270 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
24271 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
24272 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
24273 default: type = _("<unknown>"); break;
24274 }
24275 as_bad_where (fixp->fx_file, fixp->fx_line,
24276 _("cannot represent %s relocation in this object file format"),
24277 type);
24278 return NULL;
24279 }
a737bd4d 24280 }
6c43fab6 24281
c19d1205
ZW
24282#ifdef OBJ_ELF
24283 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
24284 && GOT_symbol
24285 && fixp->fx_addsy == GOT_symbol)
24286 {
24287 code = BFD_RELOC_ARM_GOTPC;
24288 reloc->addend = fixp->fx_offset = reloc->address;
24289 }
24290#endif
6c43fab6 24291
c19d1205 24292 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 24293
c19d1205
ZW
24294 if (reloc->howto == NULL)
24295 {
24296 as_bad_where (fixp->fx_file, fixp->fx_line,
24297 _("cannot represent %s relocation in this object file format"),
24298 bfd_get_reloc_code_name (code));
24299 return NULL;
24300 }
6c43fab6 24301
c19d1205
ZW
24302 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
24303 vtable entry to be used in the relocation's section offset. */
24304 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
24305 reloc->address = fixp->fx_offset;
6c43fab6 24306
c19d1205 24307 return reloc;
6c43fab6
RE
24308}
24309
c19d1205 24310/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 24311
c19d1205
ZW
24312void
24313cons_fix_new_arm (fragS * frag,
24314 int where,
24315 int size,
62ebcb5c
AM
24316 expressionS * exp,
24317 bfd_reloc_code_real_type reloc)
6c43fab6 24318{
c19d1205 24319 int pcrel = 0;
6c43fab6 24320
c19d1205
ZW
24321 /* Pick a reloc.
24322 FIXME: @@ Should look at CPU word size. */
24323 switch (size)
24324 {
24325 case 1:
62ebcb5c 24326 reloc = BFD_RELOC_8;
c19d1205
ZW
24327 break;
24328 case 2:
62ebcb5c 24329 reloc = BFD_RELOC_16;
c19d1205
ZW
24330 break;
24331 case 4:
24332 default:
62ebcb5c 24333 reloc = BFD_RELOC_32;
c19d1205
ZW
24334 break;
24335 case 8:
62ebcb5c 24336 reloc = BFD_RELOC_64;
c19d1205
ZW
24337 break;
24338 }
6c43fab6 24339
f0927246
NC
24340#ifdef TE_PE
24341 if (exp->X_op == O_secrel)
24342 {
24343 exp->X_op = O_symbol;
62ebcb5c 24344 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
24345 }
24346#endif
24347
62ebcb5c 24348 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 24349}
6c43fab6 24350
4343666d 24351#if defined (OBJ_COFF)
c19d1205
ZW
24352void
24353arm_validate_fix (fixS * fixP)
6c43fab6 24354{
c19d1205
ZW
24355 /* If the destination of the branch is a defined symbol which does not have
24356 the THUMB_FUNC attribute, then we must be calling a function which has
24357 the (interfacearm) attribute. We look for the Thumb entry point to that
24358 function and change the branch to refer to that function instead. */
24359 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
24360 && fixP->fx_addsy != NULL
24361 && S_IS_DEFINED (fixP->fx_addsy)
24362 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 24363 {
c19d1205 24364 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 24365 }
c19d1205
ZW
24366}
24367#endif
6c43fab6 24368
267bf995 24369
c19d1205
ZW
24370int
24371arm_force_relocation (struct fix * fixp)
24372{
24373#if defined (OBJ_COFF) && defined (TE_PE)
24374 if (fixp->fx_r_type == BFD_RELOC_RVA)
24375 return 1;
24376#endif
6c43fab6 24377
267bf995
RR
24378 /* In case we have a call or a branch to a function in ARM ISA mode from
24379 a thumb function or vice-versa force the relocation. These relocations
24380 are cleared off for some cores that might have blx and simple transformations
24381 are possible. */
24382
24383#ifdef OBJ_ELF
24384 switch (fixp->fx_r_type)
24385 {
24386 case BFD_RELOC_ARM_PCREL_JUMP:
24387 case BFD_RELOC_ARM_PCREL_CALL:
24388 case BFD_RELOC_THUMB_PCREL_BLX:
24389 if (THUMB_IS_FUNC (fixp->fx_addsy))
24390 return 1;
24391 break;
24392
24393 case BFD_RELOC_ARM_PCREL_BLX:
24394 case BFD_RELOC_THUMB_PCREL_BRANCH25:
24395 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24396 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24397 if (ARM_IS_FUNC (fixp->fx_addsy))
24398 return 1;
24399 break;
24400
24401 default:
24402 break;
24403 }
24404#endif
24405
b5884301
PB
24406 /* Resolve these relocations even if the symbol is extern or weak.
24407 Technically this is probably wrong due to symbol preemption.
24408 In practice these relocations do not have enough range to be useful
24409 at dynamic link time, and some code (e.g. in the Linux kernel)
24410 expects these references to be resolved. */
c19d1205
ZW
24411 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
24412 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 24413 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 24414 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
24415 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24416 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
24417 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 24418 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
24419 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
24420 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
24421 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
24422 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
24423 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
24424 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 24425 return 0;
a737bd4d 24426
4962c51a
MS
24427 /* Always leave these relocations for the linker. */
24428 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24429 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24430 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
24431 return 1;
24432
f0291e4c
PB
24433 /* Always generate relocations against function symbols. */
24434 if (fixp->fx_r_type == BFD_RELOC_32
24435 && fixp->fx_addsy
24436 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
24437 return 1;
24438
c19d1205 24439 return generic_force_reloc (fixp);
404ff6b5
AH
24440}
24441
0ffdc86c 24442#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
24443/* Relocations against function names must be left unadjusted,
24444 so that the linker can use this information to generate interworking
24445 stubs. The MIPS version of this function
c19d1205
ZW
24446 also prevents relocations that are mips-16 specific, but I do not
24447 know why it does this.
404ff6b5 24448
c19d1205
ZW
24449 FIXME:
24450 There is one other problem that ought to be addressed here, but
24451 which currently is not: Taking the address of a label (rather
24452 than a function) and then later jumping to that address. Such
24453 addresses also ought to have their bottom bit set (assuming that
24454 they reside in Thumb code), but at the moment they will not. */
404ff6b5 24455
c19d1205
ZW
24456bfd_boolean
24457arm_fix_adjustable (fixS * fixP)
404ff6b5 24458{
c19d1205
ZW
24459 if (fixP->fx_addsy == NULL)
24460 return 1;
404ff6b5 24461
e28387c3
PB
24462 /* Preserve relocations against symbols with function type. */
24463 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 24464 return FALSE;
e28387c3 24465
c19d1205
ZW
24466 if (THUMB_IS_FUNC (fixP->fx_addsy)
24467 && fixP->fx_subsy == NULL)
c921be7d 24468 return FALSE;
a737bd4d 24469
c19d1205
ZW
24470 /* We need the symbol name for the VTABLE entries. */
24471 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
24472 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 24473 return FALSE;
404ff6b5 24474
c19d1205
ZW
24475 /* Don't allow symbols to be discarded on GOT related relocs. */
24476 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
24477 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
24478 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
24479 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
24480 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
24481 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
24482 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
24483 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
24484 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
24485 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
24486 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
24487 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
24488 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 24489 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 24490 return FALSE;
a737bd4d 24491
4962c51a
MS
24492 /* Similarly for group relocations. */
24493 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24494 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24495 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 24496 return FALSE;
4962c51a 24497
79947c54
CD
24498 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
24499 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
24500 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24501 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
24502 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
24503 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24504 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
24505 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
24506 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 24507 return FALSE;
79947c54 24508
72d98d16
MG
24509 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
24510 offsets, so keep these symbols. */
24511 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
24512 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
24513 return FALSE;
24514
c921be7d 24515 return TRUE;
a737bd4d 24516}
0ffdc86c
NC
24517#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
24518
24519#ifdef OBJ_ELF
c19d1205
ZW
24520const char *
24521elf32_arm_target_format (void)
404ff6b5 24522{
c19d1205
ZW
24523#ifdef TE_SYMBIAN
24524 return (target_big_endian
24525 ? "elf32-bigarm-symbian"
24526 : "elf32-littlearm-symbian");
24527#elif defined (TE_VXWORKS)
24528 return (target_big_endian
24529 ? "elf32-bigarm-vxworks"
24530 : "elf32-littlearm-vxworks");
b38cadfb
NC
24531#elif defined (TE_NACL)
24532 return (target_big_endian
24533 ? "elf32-bigarm-nacl"
24534 : "elf32-littlearm-nacl");
c19d1205
ZW
24535#else
24536 if (target_big_endian)
24537 return "elf32-bigarm";
24538 else
24539 return "elf32-littlearm";
24540#endif
404ff6b5
AH
24541}
24542
c19d1205
ZW
24543void
24544armelf_frob_symbol (symbolS * symp,
24545 int * puntp)
404ff6b5 24546{
c19d1205
ZW
24547 elf_frob_symbol (symp, puntp);
24548}
24549#endif
404ff6b5 24550
c19d1205 24551/* MD interface: Finalization. */
a737bd4d 24552
c19d1205
ZW
24553void
24554arm_cleanup (void)
24555{
24556 literal_pool * pool;
a737bd4d 24557
e07e6e58
NC
24558 /* Ensure that all the IT blocks are properly closed. */
24559 check_it_blocks_finished ();
24560
c19d1205
ZW
24561 for (pool = list_of_pools; pool; pool = pool->next)
24562 {
5f4273c7 24563 /* Put it at the end of the relevant section. */
c19d1205
ZW
24564 subseg_set (pool->section, pool->sub_section);
24565#ifdef OBJ_ELF
24566 arm_elf_change_section ();
24567#endif
24568 s_ltorg (0);
24569 }
404ff6b5
AH
24570}
24571
cd000bff
DJ
24572#ifdef OBJ_ELF
24573/* Remove any excess mapping symbols generated for alignment frags in
24574 SEC. We may have created a mapping symbol before a zero byte
24575 alignment; remove it if there's a mapping symbol after the
24576 alignment. */
24577static void
24578check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
24579 void *dummy ATTRIBUTE_UNUSED)
24580{
24581 segment_info_type *seginfo = seg_info (sec);
24582 fragS *fragp;
24583
24584 if (seginfo == NULL || seginfo->frchainP == NULL)
24585 return;
24586
24587 for (fragp = seginfo->frchainP->frch_root;
24588 fragp != NULL;
24589 fragp = fragp->fr_next)
24590 {
24591 symbolS *sym = fragp->tc_frag_data.last_map;
24592 fragS *next = fragp->fr_next;
24593
24594 /* Variable-sized frags have been converted to fixed size by
24595 this point. But if this was variable-sized to start with,
24596 there will be a fixed-size frag after it. So don't handle
24597 next == NULL. */
24598 if (sym == NULL || next == NULL)
24599 continue;
24600
24601 if (S_GET_VALUE (sym) < next->fr_address)
24602 /* Not at the end of this frag. */
24603 continue;
24604 know (S_GET_VALUE (sym) == next->fr_address);
24605
24606 do
24607 {
24608 if (next->tc_frag_data.first_map != NULL)
24609 {
24610 /* Next frag starts with a mapping symbol. Discard this
24611 one. */
24612 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24613 break;
24614 }
24615
24616 if (next->fr_next == NULL)
24617 {
24618 /* This mapping symbol is at the end of the section. Discard
24619 it. */
24620 know (next->fr_fix == 0 && next->fr_var == 0);
24621 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24622 break;
24623 }
24624
24625 /* As long as we have empty frags without any mapping symbols,
24626 keep looking. */
24627 /* If the next frag is non-empty and does not start with a
24628 mapping symbol, then this mapping symbol is required. */
24629 if (next->fr_address != next->fr_next->fr_address)
24630 break;
24631
24632 next = next->fr_next;
24633 }
24634 while (next != NULL);
24635 }
24636}
24637#endif
24638
c19d1205
ZW
24639/* Adjust the symbol table. This marks Thumb symbols as distinct from
24640 ARM ones. */
404ff6b5 24641
c19d1205
ZW
24642void
24643arm_adjust_symtab (void)
404ff6b5 24644{
c19d1205
ZW
24645#ifdef OBJ_COFF
24646 symbolS * sym;
404ff6b5 24647
c19d1205
ZW
24648 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
24649 {
24650 if (ARM_IS_THUMB (sym))
24651 {
24652 if (THUMB_IS_FUNC (sym))
24653 {
24654 /* Mark the symbol as a Thumb function. */
24655 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
24656 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
24657 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 24658
c19d1205
ZW
24659 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
24660 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
24661 else
24662 as_bad (_("%s: unexpected function type: %d"),
24663 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
24664 }
24665 else switch (S_GET_STORAGE_CLASS (sym))
24666 {
24667 case C_EXT:
24668 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
24669 break;
24670 case C_STAT:
24671 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
24672 break;
24673 case C_LABEL:
24674 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
24675 break;
24676 default:
24677 /* Do nothing. */
24678 break;
24679 }
24680 }
a737bd4d 24681
c19d1205
ZW
24682 if (ARM_IS_INTERWORK (sym))
24683 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 24684 }
c19d1205
ZW
24685#endif
24686#ifdef OBJ_ELF
24687 symbolS * sym;
24688 char bind;
404ff6b5 24689
c19d1205 24690 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 24691 {
c19d1205
ZW
24692 if (ARM_IS_THUMB (sym))
24693 {
24694 elf_symbol_type * elf_sym;
404ff6b5 24695
c19d1205
ZW
24696 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
24697 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 24698
b0796911
PB
24699 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
24700 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
24701 {
24702 /* If it's a .thumb_func, declare it as so,
24703 otherwise tag label as .code 16. */
24704 if (THUMB_IS_FUNC (sym))
39d911fc
TP
24705 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
24706 ST_BRANCH_TO_THUMB);
3ba67470 24707 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
24708 elf_sym->internal_elf_sym.st_info =
24709 ELF_ST_INFO (bind, STT_ARM_16BIT);
24710 }
24711 }
24712 }
cd000bff
DJ
24713
24714 /* Remove any overlapping mapping symbols generated by alignment frags. */
24715 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
24716 /* Now do generic ELF adjustments. */
24717 elf_adjust_symtab ();
c19d1205 24718#endif
404ff6b5
AH
24719}
24720
c19d1205 24721/* MD interface: Initialization. */
404ff6b5 24722
a737bd4d 24723static void
c19d1205 24724set_constant_flonums (void)
a737bd4d 24725{
c19d1205 24726 int i;
404ff6b5 24727
c19d1205
ZW
24728 for (i = 0; i < NUM_FLOAT_VALS; i++)
24729 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
24730 abort ();
a737bd4d 24731}
404ff6b5 24732
3e9e4fcf
JB
24733/* Auto-select Thumb mode if it's the only available instruction set for the
24734 given architecture. */
24735
24736static void
24737autoselect_thumb_from_cpu_variant (void)
24738{
24739 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
24740 opcode_select (16);
24741}
24742
c19d1205
ZW
24743void
24744md_begin (void)
a737bd4d 24745{
c19d1205
ZW
24746 unsigned mach;
24747 unsigned int i;
404ff6b5 24748
c19d1205
ZW
24749 if ( (arm_ops_hsh = hash_new ()) == NULL
24750 || (arm_cond_hsh = hash_new ()) == NULL
24751 || (arm_shift_hsh = hash_new ()) == NULL
24752 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 24753 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 24754 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
24755 || (arm_reloc_hsh = hash_new ()) == NULL
24756 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
24757 as_fatal (_("virtual memory exhausted"));
24758
24759 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 24760 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 24761 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 24762 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 24763 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 24764 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 24765 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24766 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 24767 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24768 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 24769 (void *) (v7m_psrs + i));
c19d1205 24770 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 24771 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
24772 for (i = 0;
24773 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
24774 i++)
d3ce72d0 24775 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 24776 (void *) (barrier_opt_names + i));
c19d1205 24777#ifdef OBJ_ELF
3da1d841
NC
24778 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
24779 {
24780 struct reloc_entry * entry = reloc_names + i;
24781
24782 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
24783 /* This makes encode_branch() use the EABI versions of this relocation. */
24784 entry->reloc = BFD_RELOC_UNUSED;
24785
24786 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
24787 }
c19d1205
ZW
24788#endif
24789
24790 set_constant_flonums ();
404ff6b5 24791
c19d1205
ZW
24792 /* Set the cpu variant based on the command-line options. We prefer
24793 -mcpu= over -march= if both are set (as for GCC); and we prefer
24794 -mfpu= over any other way of setting the floating point unit.
24795 Use of legacy options with new options are faulted. */
e74cfd16 24796 if (legacy_cpu)
404ff6b5 24797 {
e74cfd16 24798 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
24799 as_bad (_("use of old and new-style options to set CPU type"));
24800
24801 mcpu_cpu_opt = legacy_cpu;
404ff6b5 24802 }
e74cfd16 24803 else if (!mcpu_cpu_opt)
c19d1205 24804 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 24805
e74cfd16 24806 if (legacy_fpu)
c19d1205 24807 {
e74cfd16 24808 if (mfpu_opt)
c19d1205 24809 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
24810
24811 mfpu_opt = legacy_fpu;
24812 }
e74cfd16 24813 else if (!mfpu_opt)
03b1477f 24814 {
45eb4c1b
NS
24815#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
24816 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
24817 /* Some environments specify a default FPU. If they don't, infer it
24818 from the processor. */
e74cfd16 24819 if (mcpu_fpu_opt)
03b1477f
RE
24820 mfpu_opt = mcpu_fpu_opt;
24821 else
24822 mfpu_opt = march_fpu_opt;
39c2da32 24823#else
e74cfd16 24824 mfpu_opt = &fpu_default;
39c2da32 24825#endif
03b1477f
RE
24826 }
24827
e74cfd16 24828 if (!mfpu_opt)
03b1477f 24829 {
493cb6ef 24830 if (mcpu_cpu_opt != NULL)
e74cfd16 24831 mfpu_opt = &fpu_default;
493cb6ef 24832 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 24833 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 24834 else
e74cfd16 24835 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
24836 }
24837
ee065d83 24838#ifdef CPU_DEFAULT
e74cfd16 24839 if (!mcpu_cpu_opt)
ee065d83 24840 {
e74cfd16
PB
24841 mcpu_cpu_opt = &cpu_default;
24842 selected_cpu = cpu_default;
ee065d83 24843 }
73f43896
NC
24844 else if (no_cpu_selected ())
24845 selected_cpu = cpu_default;
e74cfd16
PB
24846#else
24847 if (mcpu_cpu_opt)
24848 selected_cpu = *mcpu_cpu_opt;
ee065d83 24849 else
e74cfd16 24850 mcpu_cpu_opt = &arm_arch_any;
ee065d83 24851#endif
03b1477f 24852
e74cfd16 24853 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 24854
3e9e4fcf
JB
24855 autoselect_thumb_from_cpu_variant ();
24856
e74cfd16 24857 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 24858
f17c130b 24859#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 24860 {
7cc69913
NC
24861 unsigned int flags = 0;
24862
24863#if defined OBJ_ELF
24864 flags = meabi_flags;
d507cf36
PB
24865
24866 switch (meabi_flags)
33a392fb 24867 {
d507cf36 24868 case EF_ARM_EABI_UNKNOWN:
7cc69913 24869#endif
d507cf36
PB
24870 /* Set the flags in the private structure. */
24871 if (uses_apcs_26) flags |= F_APCS26;
24872 if (support_interwork) flags |= F_INTERWORK;
24873 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 24874 if (pic_code) flags |= F_PIC;
e74cfd16 24875 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
24876 flags |= F_SOFT_FLOAT;
24877
d507cf36
PB
24878 switch (mfloat_abi_opt)
24879 {
24880 case ARM_FLOAT_ABI_SOFT:
24881 case ARM_FLOAT_ABI_SOFTFP:
24882 flags |= F_SOFT_FLOAT;
24883 break;
33a392fb 24884
d507cf36
PB
24885 case ARM_FLOAT_ABI_HARD:
24886 if (flags & F_SOFT_FLOAT)
24887 as_bad (_("hard-float conflicts with specified fpu"));
24888 break;
24889 }
03b1477f 24890
e74cfd16
PB
24891 /* Using pure-endian doubles (even if soft-float). */
24892 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 24893 flags |= F_VFP_FLOAT;
f17c130b 24894
fde78edd 24895#if defined OBJ_ELF
e74cfd16 24896 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 24897 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
24898 break;
24899
8cb51566 24900 case EF_ARM_EABI_VER4:
3a4a14e9 24901 case EF_ARM_EABI_VER5:
c19d1205 24902 /* No additional flags to set. */
d507cf36
PB
24903 break;
24904
24905 default:
24906 abort ();
24907 }
7cc69913 24908#endif
b99bd4ef
NC
24909 bfd_set_private_flags (stdoutput, flags);
24910
24911 /* We have run out flags in the COFF header to encode the
24912 status of ATPCS support, so instead we create a dummy,
c19d1205 24913 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
24914 if (atpcs)
24915 {
24916 asection * sec;
24917
24918 sec = bfd_make_section (stdoutput, ".arm.atpcs");
24919
24920 if (sec != NULL)
24921 {
24922 bfd_set_section_flags
24923 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
24924 bfd_set_section_size (stdoutput, sec, 0);
24925 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
24926 }
24927 }
7cc69913 24928 }
f17c130b 24929#endif
b99bd4ef
NC
24930
24931 /* Record the CPU type as well. */
2d447fca
JM
24932 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
24933 mach = bfd_mach_arm_iWMMXt2;
24934 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 24935 mach = bfd_mach_arm_iWMMXt;
e74cfd16 24936 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 24937 mach = bfd_mach_arm_XScale;
e74cfd16 24938 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 24939 mach = bfd_mach_arm_ep9312;
e74cfd16 24940 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 24941 mach = bfd_mach_arm_5TE;
e74cfd16 24942 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 24943 {
e74cfd16 24944 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
24945 mach = bfd_mach_arm_5T;
24946 else
24947 mach = bfd_mach_arm_5;
24948 }
e74cfd16 24949 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 24950 {
e74cfd16 24951 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
24952 mach = bfd_mach_arm_4T;
24953 else
24954 mach = bfd_mach_arm_4;
24955 }
e74cfd16 24956 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 24957 mach = bfd_mach_arm_3M;
e74cfd16
PB
24958 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
24959 mach = bfd_mach_arm_3;
24960 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
24961 mach = bfd_mach_arm_2a;
24962 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
24963 mach = bfd_mach_arm_2;
24964 else
24965 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
24966
24967 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
24968}
24969
c19d1205 24970/* Command line processing. */
b99bd4ef 24971
c19d1205
ZW
24972/* md_parse_option
24973 Invocation line includes a switch not recognized by the base assembler.
24974 See if it's a processor-specific option.
b99bd4ef 24975
c19d1205
ZW
24976 This routine is somewhat complicated by the need for backwards
24977 compatibility (since older releases of gcc can't be changed).
24978 The new options try to make the interface as compatible as
24979 possible with GCC.
b99bd4ef 24980
c19d1205 24981 New options (supported) are:
b99bd4ef 24982
c19d1205
ZW
24983 -mcpu=<cpu name> Assemble for selected processor
24984 -march=<architecture name> Assemble for selected architecture
24985 -mfpu=<fpu architecture> Assemble for selected FPU.
24986 -EB/-mbig-endian Big-endian
24987 -EL/-mlittle-endian Little-endian
24988 -k Generate PIC code
24989 -mthumb Start in Thumb mode
24990 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 24991
278df34e 24992 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 24993 -m[no-]warn-syms Warn when symbols match instructions
267bf995 24994
c19d1205 24995 For now we will also provide support for:
b99bd4ef 24996
c19d1205
ZW
24997 -mapcs-32 32-bit Program counter
24998 -mapcs-26 26-bit Program counter
24999 -macps-float Floats passed in FP registers
25000 -mapcs-reentrant Reentrant code
25001 -matpcs
25002 (sometime these will probably be replaced with -mapcs=<list of options>
25003 and -matpcs=<list of options>)
b99bd4ef 25004
c19d1205
ZW
25005 The remaining options are only supported for back-wards compatibility.
25006 Cpu variants, the arm part is optional:
25007 -m[arm]1 Currently not supported.
25008 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
25009 -m[arm]3 Arm 3 processor
25010 -m[arm]6[xx], Arm 6 processors
25011 -m[arm]7[xx][t][[d]m] Arm 7 processors
25012 -m[arm]8[10] Arm 8 processors
25013 -m[arm]9[20][tdmi] Arm 9 processors
25014 -mstrongarm[110[0]] StrongARM processors
25015 -mxscale XScale processors
25016 -m[arm]v[2345[t[e]]] Arm architectures
25017 -mall All (except the ARM1)
25018 FP variants:
25019 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
25020 -mfpe-old (No float load/store multiples)
25021 -mvfpxd VFP Single precision
25022 -mvfp All VFP
25023 -mno-fpu Disable all floating point instructions
b99bd4ef 25024
c19d1205
ZW
25025 The following CPU names are recognized:
25026 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
25027 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
25028 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
25029 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
25030 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
25031 arm10t arm10e, arm1020t, arm1020e, arm10200e,
25032 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 25033
c19d1205 25034 */
b99bd4ef 25035
c19d1205 25036const char * md_shortopts = "m:k";
b99bd4ef 25037
c19d1205
ZW
25038#ifdef ARM_BI_ENDIAN
25039#define OPTION_EB (OPTION_MD_BASE + 0)
25040#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 25041#else
c19d1205
ZW
25042#if TARGET_BYTES_BIG_ENDIAN
25043#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 25044#else
c19d1205
ZW
25045#define OPTION_EL (OPTION_MD_BASE + 1)
25046#endif
b99bd4ef 25047#endif
845b51d6 25048#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 25049
c19d1205 25050struct option md_longopts[] =
b99bd4ef 25051{
c19d1205
ZW
25052#ifdef OPTION_EB
25053 {"EB", no_argument, NULL, OPTION_EB},
25054#endif
25055#ifdef OPTION_EL
25056 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 25057#endif
845b51d6 25058 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
25059 {NULL, no_argument, NULL, 0}
25060};
b99bd4ef 25061
8b2d793c 25062
c19d1205 25063size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 25064
c19d1205 25065struct arm_option_table
b99bd4ef 25066{
e0471c16
TS
25067 const char *option; /* Option name to match. */
25068 const char *help; /* Help information. */
c19d1205
ZW
25069 int *var; /* Variable to change. */
25070 int value; /* What to change it to. */
e0471c16 25071 const char *deprecated; /* If non-null, print this message. */
c19d1205 25072};
b99bd4ef 25073
c19d1205
ZW
25074struct arm_option_table arm_opts[] =
25075{
25076 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
25077 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
25078 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
25079 &support_interwork, 1, NULL},
25080 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
25081 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
25082 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
25083 1, NULL},
25084 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
25085 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
25086 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
25087 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
25088 NULL},
b99bd4ef 25089
c19d1205
ZW
25090 /* These are recognized by the assembler, but have no affect on code. */
25091 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
25092 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
25093
25094 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
25095 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
25096 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
25097 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
25098 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
25099 {NULL, NULL, NULL, 0, NULL}
25100};
25101
25102struct arm_legacy_option_table
25103{
e0471c16 25104 const char *option; /* Option name to match. */
e74cfd16
PB
25105 const arm_feature_set **var; /* Variable to change. */
25106 const arm_feature_set value; /* What to change it to. */
e0471c16 25107 const char *deprecated; /* If non-null, print this message. */
e74cfd16 25108};
b99bd4ef 25109
e74cfd16
PB
25110const struct arm_legacy_option_table arm_legacy_opts[] =
25111{
c19d1205
ZW
25112 /* DON'T add any new processors to this list -- we want the whole list
25113 to go away... Add them to the processors table instead. */
e74cfd16
PB
25114 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25115 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25116 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25117 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25118 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25119 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25120 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25121 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25122 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25123 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25124 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25125 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25126 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25127 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25128 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25129 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25130 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25131 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25132 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25133 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25134 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25135 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25136 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25137 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25138 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25139 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25140 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25141 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25142 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25143 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25144 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25145 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25146 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25147 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25148 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25149 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25150 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25151 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25152 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25153 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25154 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25155 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25156 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25157 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25158 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25159 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25160 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25161 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25162 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25163 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25164 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25165 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25166 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25167 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25168 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25169 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25170 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25171 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25172 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25173 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25174 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25175 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25176 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25177 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25178 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25179 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25180 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25181 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25182 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
25183 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25184 N_("use -mcpu=strongarm110")},
e74cfd16 25185 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25186 N_("use -mcpu=strongarm1100")},
e74cfd16 25187 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25188 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
25189 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
25190 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
25191 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 25192
c19d1205 25193 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
25194 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25195 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25196 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25197 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25198 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25199 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25200 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25201 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25202 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25203 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25204 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25205 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25206 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25207 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25208 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25209 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25210 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
25211 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 25212
c19d1205 25213 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
25214 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
25215 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
25216 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
25217 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 25218 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 25219
e74cfd16 25220 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 25221};
7ed4c4c5 25222
c19d1205 25223struct arm_cpu_option_table
7ed4c4c5 25224{
e0471c16 25225 const char *name;
f3bad469 25226 size_t name_len;
e74cfd16 25227 const arm_feature_set value;
c19d1205
ZW
25228 /* For some CPUs we assume an FPU unless the user explicitly sets
25229 -mfpu=... */
e74cfd16 25230 const arm_feature_set default_fpu;
ee065d83
PB
25231 /* The canonical name of the CPU, or NULL to use NAME converted to upper
25232 case. */
25233 const char *canonical_name;
c19d1205 25234};
7ed4c4c5 25235
c19d1205
ZW
25236/* This list should, at a minimum, contain all the cpu names
25237 recognized by GCC. */
f3bad469 25238#define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
e74cfd16 25239static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 25240{
f3bad469
MGD
25241 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
25242 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
25243 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
25244 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
25245 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
25246 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25247 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25248 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25249 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25250 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25251 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25252 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25253 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25254 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25255 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25256 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25257 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25258 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25259 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25260 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25261 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25262 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25263 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25264 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25265 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25266 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25267 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25268 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25269 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25270 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25271 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25272 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25273 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25274 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25275 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25276 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25277 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25278 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25279 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25280 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
25281 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25282 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25283 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25284 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25285 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25286 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
c19d1205
ZW
25287 /* For V5 or later processors we default to using VFP; but the user
25288 should really set the FPU type explicitly. */
f3bad469
MGD
25289 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25290 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25291 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
25292 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
25293 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
25294 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25295 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
25296 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25297 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25298 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
25299 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25300 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25301 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25302 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25303 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25304 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
25305 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25306 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25307 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25308 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
25309 "ARM1026EJ-S"),
25310 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
25311 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25312 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25313 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25314 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25315 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25316 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
25317 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
25318 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
25319 "ARM1136JF-S"),
25320 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
25321 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
25322 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
25323 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
25324 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
f33026a9
MW
25325 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6KZ, FPU_NONE, NULL),
25326 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6KZ, FPU_ARCH_VFP_V2, NULL),
f3bad469
MGD
25327 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
25328 FPU_NONE, "Cortex-A5"),
c9fb6e58 25329 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469
MGD
25330 "Cortex-A7"),
25331 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
823d2571 25332 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 25333 | FPU_NEON_EXT_V1),
f3bad469
MGD
25334 "Cortex-A8"),
25335 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
823d2571 25336 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 25337 | FPU_NEON_EXT_V1),
f3bad469 25338 "Cortex-A9"),
c9fb6e58 25339 ARM_CPU_OPT ("cortex-a12", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
63a4bc21 25340 "Cortex-A12"),
c9fb6e58 25341 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469 25342 "Cortex-A15"),
d7adf960
KT
25343 ARM_CPU_OPT ("cortex-a17", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
25344 "Cortex-A17"),
6735952f
KT
25345 ARM_CPU_OPT ("cortex-a32", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25346 "Cortex-A32"),
43cdc0a8
RR
25347 ARM_CPU_OPT ("cortex-a35", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25348 "Cortex-A35"),
92eb40d9 25349 ARM_CPU_OPT ("cortex-a53", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 25350 "Cortex-A53"),
92eb40d9 25351 ARM_CPU_OPT ("cortex-a57", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 25352 "Cortex-A57"),
b19f47ad
JW
25353 ARM_CPU_OPT ("cortex-a72", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25354 "Cortex-A72"),
362a3eba
KT
25355 ARM_CPU_OPT ("cortex-a73", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25356 "Cortex-A73"),
f3bad469
MGD
25357 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
25358 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
25359 "Cortex-R4F"),
25360 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
25361 FPU_NONE, "Cortex-R5"),
70a8bc5b 25362 ARM_CPU_OPT ("cortex-r7", ARM_ARCH_V7R_IDIV,
25363 FPU_ARCH_VFP_V3D16,
25364 "Cortex-R7"),
5f474010
TP
25365 ARM_CPU_OPT ("cortex-r8", ARM_ARCH_V7R_IDIV,
25366 FPU_ARCH_VFP_V3D16,
25367 "Cortex-R8"),
a715796b 25368 ARM_CPU_OPT ("cortex-m7", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M7"),
f3bad469
MGD
25369 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
25370 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
25371 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
25372 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
ce32bd10 25373 ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"),
246496bb
EM
25374 ARM_CPU_OPT ("exynos-m1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25375 "Samsung " \
25376 "Exynos M1"),
6b21c2bf
JW
25377 ARM_CPU_OPT ("qdf24xx", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25378 "Qualcomm "
25379 "QDF24XX"),
25380
c19d1205 25381 /* ??? XSCALE is really an architecture. */
f3bad469 25382 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 25383 /* ??? iwmmxt is not a processor. */
f3bad469
MGD
25384 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
25385 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
25386 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 25387 /* Maverick */
823d2571 25388 ARM_CPU_OPT ("ep9312", ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
da4339ed
NC
25389 FPU_ARCH_MAVERICK, "ARM920T"),
25390 /* Marvell processors. */
ff8646ee
TP
25391 ARM_CPU_OPT ("marvell-pj4", ARM_FEATURE_CORE (ARM_AEXT_V7A | ARM_EXT_MP
25392 | ARM_EXT_SEC,
25393 ARM_EXT2_V6T2_V8M),
477330fc 25394 FPU_ARCH_VFP_V3D16, NULL),
ff8646ee
TP
25395 ARM_CPU_OPT ("marvell-whitney", ARM_FEATURE_CORE (ARM_AEXT_V7A | ARM_EXT_MP
25396 | ARM_EXT_SEC,
25397 ARM_EXT2_V6T2_V8M),
4347085a 25398 FPU_ARCH_NEON_VFP_V4, NULL),
ea0d6bb9
PT
25399 /* APM X-Gene family. */
25400 ARM_CPU_OPT ("xgene1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25401 "APM X-Gene 1"),
25402 ARM_CPU_OPT ("xgene2", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25403 "APM X-Gene 2"),
da4339ed 25404
f3bad469 25405 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 25406};
f3bad469 25407#undef ARM_CPU_OPT
7ed4c4c5 25408
c19d1205 25409struct arm_arch_option_table
7ed4c4c5 25410{
e0471c16 25411 const char *name;
f3bad469 25412 size_t name_len;
e74cfd16
PB
25413 const arm_feature_set value;
25414 const arm_feature_set default_fpu;
c19d1205 25415};
7ed4c4c5 25416
c19d1205
ZW
25417/* This list should, at a minimum, contain all the architecture names
25418 recognized by GCC. */
f3bad469 25419#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
e74cfd16 25420static const struct arm_arch_option_table arm_archs[] =
c19d1205 25421{
f3bad469
MGD
25422 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
25423 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
25424 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
25425 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
25426 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
25427 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
25428 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
25429 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
25430 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
25431 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
25432 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
25433 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
25434 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
25435 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
25436 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
25437 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
25438 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
25439 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
25440 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
25441 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
25442 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
f33026a9
MW
25443 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
25444 kept to preserve existing behaviour. */
25445 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
25446 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
f3bad469
MGD
25447 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
25448 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
25449 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
f33026a9
MW
25450 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
25451 kept to preserve existing behaviour. */
25452 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
25453 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
f3bad469
MGD
25454 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
25455 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
25456 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
25457 /* The official spelling of the ARMv7 profile variants is the dashed form.
25458 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 25459 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 25460 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
25461 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
25462 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
25463 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
25464 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
25465 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
25466 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
ff8646ee 25467 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
4ed7ed8d 25468 ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP),
bca38921 25469 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
a5932920 25470 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
56a1b672 25471 ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP),
f3bad469
MGD
25472 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
25473 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
25474 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
25475 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 25476};
f3bad469 25477#undef ARM_ARCH_OPT
7ed4c4c5 25478
69133863
MGD
25479/* ISA extensions in the co-processor and main instruction set space. */
25480struct arm_option_extension_value_table
c19d1205 25481{
e0471c16 25482 const char *name;
f3bad469 25483 size_t name_len;
5a70a223
JB
25484 const arm_feature_set merge_value;
25485 const arm_feature_set clear_value;
d942732e
TP
25486 /* List of architectures for which an extension is available. ARM_ARCH_NONE
25487 indicates that an extension is available for all architectures while
25488 ARM_ANY marks an empty entry. */
25489 const arm_feature_set allowed_archs[2];
c19d1205 25490};
7ed4c4c5 25491
69133863
MGD
25492/* The following table must be in alphabetical order with a NULL last entry.
25493 */
d942732e
TP
25494#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
25495#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
69133863 25496static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 25497{
823d2571
TG
25498 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25499 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 25500 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
25501 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
25502 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
15afaa63
TP
25503 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
25504 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
25505 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
25506 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
25507 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
25508 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25509 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25510 ARM_ARCH_V8_2A),
d942732e 25511 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 25512 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
25513 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
25514 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571 25515 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 25516 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 25517 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 25518 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 25519 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
25520 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
25521 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 25522 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
25523 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
25524 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
25525 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25526 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25527 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
25528 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
25529 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
25530 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
4d1464f2
MW
25531 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
25532 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
25533 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
643afb90
MW
25534 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
25535 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
25536 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
d942732e 25537 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 25538 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
25539 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
25540 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
25541 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
25542 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
25543 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
25544 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
25545 | ARM_EXT_DIV),
25546 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
25547 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
25548 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
25549 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
25550 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 25551};
f3bad469 25552#undef ARM_EXT_OPT
69133863
MGD
25553
25554/* ISA floating-point and Advanced SIMD extensions. */
25555struct arm_option_fpu_value_table
25556{
e0471c16 25557 const char *name;
69133863 25558 const arm_feature_set value;
c19d1205 25559};
7ed4c4c5 25560
c19d1205
ZW
25561/* This list should, at a minimum, contain all the fpu names
25562 recognized by GCC. */
69133863 25563static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
25564{
25565 {"softfpa", FPU_NONE},
25566 {"fpe", FPU_ARCH_FPE},
25567 {"fpe2", FPU_ARCH_FPE},
25568 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
25569 {"fpa", FPU_ARCH_FPA},
25570 {"fpa10", FPU_ARCH_FPA},
25571 {"fpa11", FPU_ARCH_FPA},
25572 {"arm7500fe", FPU_ARCH_FPA},
25573 {"softvfp", FPU_ARCH_VFP},
25574 {"softvfp+vfp", FPU_ARCH_VFP_V2},
25575 {"vfp", FPU_ARCH_VFP_V2},
25576 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 25577 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
25578 {"vfp10", FPU_ARCH_VFP_V2},
25579 {"vfp10-r0", FPU_ARCH_VFP_V1},
25580 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
25581 {"vfpv2", FPU_ARCH_VFP_V2},
25582 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 25583 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 25584 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
25585 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
25586 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
25587 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
25588 {"arm1020t", FPU_ARCH_VFP_V1},
25589 {"arm1020e", FPU_ARCH_VFP_V2},
25590 {"arm1136jfs", FPU_ARCH_VFP_V2},
25591 {"arm1136jf-s", FPU_ARCH_VFP_V2},
25592 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 25593 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 25594 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
25595 {"vfpv4", FPU_ARCH_VFP_V4},
25596 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 25597 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
25598 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
25599 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 25600 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
25601 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
25602 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
25603 {"crypto-neon-fp-armv8",
25604 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 25605 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
25606 {"crypto-neon-fp-armv8.1",
25607 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
25608 {NULL, ARM_ARCH_NONE}
25609};
25610
25611struct arm_option_value_table
25612{
e0471c16 25613 const char *name;
e74cfd16 25614 long value;
c19d1205 25615};
7ed4c4c5 25616
e74cfd16 25617static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
25618{
25619 {"hard", ARM_FLOAT_ABI_HARD},
25620 {"softfp", ARM_FLOAT_ABI_SOFTFP},
25621 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 25622 {NULL, 0}
c19d1205 25623};
7ed4c4c5 25624
c19d1205 25625#ifdef OBJ_ELF
3a4a14e9 25626/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 25627static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
25628{
25629 {"gnu", EF_ARM_EABI_UNKNOWN},
25630 {"4", EF_ARM_EABI_VER4},
3a4a14e9 25631 {"5", EF_ARM_EABI_VER5},
e74cfd16 25632 {NULL, 0}
c19d1205
ZW
25633};
25634#endif
7ed4c4c5 25635
c19d1205
ZW
25636struct arm_long_option_table
25637{
e0471c16
TS
25638 const char * option; /* Substring to match. */
25639 const char * help; /* Help information. */
17b9d67d 25640 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 25641 const char * deprecated; /* If non-null, print this message. */
c19d1205 25642};
7ed4c4c5 25643
c921be7d 25644static bfd_boolean
82b8a785 25645arm_parse_extension (const char *str, const arm_feature_set **opt_p)
7ed4c4c5 25646{
325801bd 25647 arm_feature_set *ext_set = XNEW (arm_feature_set);
e74cfd16 25648
69133863 25649 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
25650 extensions being added before being removed. We achieve this by having
25651 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 25652 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 25653 or removing it (0) and only allowing it to change in the order
69133863
MGD
25654 -1 -> 1 -> 0. */
25655 const struct arm_option_extension_value_table * opt = NULL;
d942732e 25656 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
25657 int adding_value = -1;
25658
e74cfd16
PB
25659 /* Copy the feature set, so that we can modify it. */
25660 *ext_set = **opt_p;
25661 *opt_p = ext_set;
25662
c19d1205 25663 while (str != NULL && *str != 0)
7ed4c4c5 25664 {
82b8a785 25665 const char *ext;
f3bad469 25666 size_t len;
7ed4c4c5 25667
c19d1205
ZW
25668 if (*str != '+')
25669 {
25670 as_bad (_("invalid architectural extension"));
c921be7d 25671 return FALSE;
c19d1205 25672 }
7ed4c4c5 25673
c19d1205
ZW
25674 str++;
25675 ext = strchr (str, '+');
7ed4c4c5 25676
c19d1205 25677 if (ext != NULL)
f3bad469 25678 len = ext - str;
c19d1205 25679 else
f3bad469 25680 len = strlen (str);
7ed4c4c5 25681
f3bad469 25682 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
25683 {
25684 if (adding_value != 0)
25685 {
25686 adding_value = 0;
25687 opt = arm_extensions;
25688 }
25689
f3bad469 25690 len -= 2;
69133863
MGD
25691 str += 2;
25692 }
f3bad469 25693 else if (len > 0)
69133863
MGD
25694 {
25695 if (adding_value == -1)
25696 {
25697 adding_value = 1;
25698 opt = arm_extensions;
25699 }
25700 else if (adding_value != 1)
25701 {
25702 as_bad (_("must specify extensions to add before specifying "
25703 "those to remove"));
25704 return FALSE;
25705 }
25706 }
25707
f3bad469 25708 if (len == 0)
c19d1205
ZW
25709 {
25710 as_bad (_("missing architectural extension"));
c921be7d 25711 return FALSE;
c19d1205 25712 }
7ed4c4c5 25713
69133863
MGD
25714 gas_assert (adding_value != -1);
25715 gas_assert (opt != NULL);
25716
25717 /* Scan over the options table trying to find an exact match. */
25718 for (; opt->name != NULL; opt++)
f3bad469 25719 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25720 {
d942732e
TP
25721 int i, nb_allowed_archs =
25722 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 25723 /* Check we can apply the extension to this architecture. */
d942732e
TP
25724 for (i = 0; i < nb_allowed_archs; i++)
25725 {
25726 /* Empty entry. */
25727 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
25728 continue;
25729 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *ext_set))
25730 break;
25731 }
25732 if (i == nb_allowed_archs)
69133863
MGD
25733 {
25734 as_bad (_("extension does not apply to the base architecture"));
25735 return FALSE;
25736 }
25737
25738 /* Add or remove the extension. */
25739 if (adding_value)
5a70a223 25740 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 25741 else
5a70a223 25742 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 25743
c19d1205
ZW
25744 break;
25745 }
7ed4c4c5 25746
c19d1205
ZW
25747 if (opt->name == NULL)
25748 {
69133863
MGD
25749 /* Did we fail to find an extension because it wasn't specified in
25750 alphabetical order, or because it does not exist? */
25751
25752 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 25753 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
25754 break;
25755
25756 if (opt->name == NULL)
25757 as_bad (_("unknown architectural extension `%s'"), str);
25758 else
25759 as_bad (_("architectural extensions must be specified in "
25760 "alphabetical order"));
25761
c921be7d 25762 return FALSE;
c19d1205 25763 }
69133863
MGD
25764 else
25765 {
25766 /* We should skip the extension we've just matched the next time
25767 round. */
25768 opt++;
25769 }
7ed4c4c5 25770
c19d1205
ZW
25771 str = ext;
25772 };
7ed4c4c5 25773
c921be7d 25774 return TRUE;
c19d1205 25775}
7ed4c4c5 25776
c921be7d 25777static bfd_boolean
17b9d67d 25778arm_parse_cpu (const char *str)
7ed4c4c5 25779{
f3bad469 25780 const struct arm_cpu_option_table *opt;
82b8a785 25781 const char *ext = strchr (str, '+');
f3bad469 25782 size_t len;
7ed4c4c5 25783
c19d1205 25784 if (ext != NULL)
f3bad469 25785 len = ext - str;
7ed4c4c5 25786 else
f3bad469 25787 len = strlen (str);
7ed4c4c5 25788
f3bad469 25789 if (len == 0)
7ed4c4c5 25790 {
c19d1205 25791 as_bad (_("missing cpu name `%s'"), str);
c921be7d 25792 return FALSE;
7ed4c4c5
NC
25793 }
25794
c19d1205 25795 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 25796 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25797 {
e74cfd16
PB
25798 mcpu_cpu_opt = &opt->value;
25799 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 25800 if (opt->canonical_name)
ef8e6722
JW
25801 {
25802 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
25803 strcpy (selected_cpu_name, opt->canonical_name);
25804 }
ee065d83
PB
25805 else
25806 {
f3bad469 25807 size_t i;
c921be7d 25808
ef8e6722
JW
25809 if (len >= sizeof selected_cpu_name)
25810 len = (sizeof selected_cpu_name) - 1;
25811
f3bad469 25812 for (i = 0; i < len; i++)
ee065d83
PB
25813 selected_cpu_name[i] = TOUPPER (opt->name[i]);
25814 selected_cpu_name[i] = 0;
25815 }
7ed4c4c5 25816
c19d1205
ZW
25817 if (ext != NULL)
25818 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 25819
c921be7d 25820 return TRUE;
c19d1205 25821 }
7ed4c4c5 25822
c19d1205 25823 as_bad (_("unknown cpu `%s'"), str);
c921be7d 25824 return FALSE;
7ed4c4c5
NC
25825}
25826
c921be7d 25827static bfd_boolean
17b9d67d 25828arm_parse_arch (const char *str)
7ed4c4c5 25829{
e74cfd16 25830 const struct arm_arch_option_table *opt;
82b8a785 25831 const char *ext = strchr (str, '+');
f3bad469 25832 size_t len;
7ed4c4c5 25833
c19d1205 25834 if (ext != NULL)
f3bad469 25835 len = ext - str;
7ed4c4c5 25836 else
f3bad469 25837 len = strlen (str);
7ed4c4c5 25838
f3bad469 25839 if (len == 0)
7ed4c4c5 25840 {
c19d1205 25841 as_bad (_("missing architecture name `%s'"), str);
c921be7d 25842 return FALSE;
7ed4c4c5
NC
25843 }
25844
c19d1205 25845 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 25846 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25847 {
e74cfd16
PB
25848 march_cpu_opt = &opt->value;
25849 march_fpu_opt = &opt->default_fpu;
5f4273c7 25850 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 25851
c19d1205
ZW
25852 if (ext != NULL)
25853 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 25854
c921be7d 25855 return TRUE;
c19d1205
ZW
25856 }
25857
25858 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 25859 return FALSE;
7ed4c4c5 25860}
eb043451 25861
c921be7d 25862static bfd_boolean
17b9d67d 25863arm_parse_fpu (const char * str)
c19d1205 25864{
69133863 25865 const struct arm_option_fpu_value_table * opt;
b99bd4ef 25866
c19d1205
ZW
25867 for (opt = arm_fpus; opt->name != NULL; opt++)
25868 if (streq (opt->name, str))
25869 {
e74cfd16 25870 mfpu_opt = &opt->value;
c921be7d 25871 return TRUE;
c19d1205 25872 }
b99bd4ef 25873
c19d1205 25874 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 25875 return FALSE;
c19d1205
ZW
25876}
25877
c921be7d 25878static bfd_boolean
17b9d67d 25879arm_parse_float_abi (const char * str)
b99bd4ef 25880{
e74cfd16 25881 const struct arm_option_value_table * opt;
b99bd4ef 25882
c19d1205
ZW
25883 for (opt = arm_float_abis; opt->name != NULL; opt++)
25884 if (streq (opt->name, str))
25885 {
25886 mfloat_abi_opt = opt->value;
c921be7d 25887 return TRUE;
c19d1205 25888 }
cc8a6dd0 25889
c19d1205 25890 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 25891 return FALSE;
c19d1205 25892}
b99bd4ef 25893
c19d1205 25894#ifdef OBJ_ELF
c921be7d 25895static bfd_boolean
17b9d67d 25896arm_parse_eabi (const char * str)
c19d1205 25897{
e74cfd16 25898 const struct arm_option_value_table *opt;
cc8a6dd0 25899
c19d1205
ZW
25900 for (opt = arm_eabis; opt->name != NULL; opt++)
25901 if (streq (opt->name, str))
25902 {
25903 meabi_flags = opt->value;
c921be7d 25904 return TRUE;
c19d1205
ZW
25905 }
25906 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 25907 return FALSE;
c19d1205
ZW
25908}
25909#endif
cc8a6dd0 25910
c921be7d 25911static bfd_boolean
17b9d67d 25912arm_parse_it_mode (const char * str)
e07e6e58 25913{
c921be7d 25914 bfd_boolean ret = TRUE;
e07e6e58
NC
25915
25916 if (streq ("arm", str))
25917 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
25918 else if (streq ("thumb", str))
25919 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
25920 else if (streq ("always", str))
25921 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
25922 else if (streq ("never", str))
25923 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
25924 else
25925 {
25926 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 25927 "arm, thumb, always, or never."), str);
c921be7d 25928 ret = FALSE;
e07e6e58
NC
25929 }
25930
25931 return ret;
25932}
25933
2e6976a8 25934static bfd_boolean
17b9d67d 25935arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
25936{
25937 codecomposer_syntax = TRUE;
25938 arm_comment_chars[0] = ';';
25939 arm_line_separator_chars[0] = 0;
25940 return TRUE;
25941}
25942
c19d1205
ZW
25943struct arm_long_option_table arm_long_opts[] =
25944{
25945 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
25946 arm_parse_cpu, NULL},
25947 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
25948 arm_parse_arch, NULL},
25949 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
25950 arm_parse_fpu, NULL},
25951 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
25952 arm_parse_float_abi, NULL},
25953#ifdef OBJ_ELF
7fac0536 25954 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
25955 arm_parse_eabi, NULL},
25956#endif
e07e6e58
NC
25957 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
25958 arm_parse_it_mode, NULL},
2e6976a8
DG
25959 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
25960 arm_ccs_mode, NULL},
c19d1205
ZW
25961 {NULL, NULL, 0, NULL}
25962};
cc8a6dd0 25963
c19d1205 25964int
17b9d67d 25965md_parse_option (int c, const char * arg)
c19d1205
ZW
25966{
25967 struct arm_option_table *opt;
e74cfd16 25968 const struct arm_legacy_option_table *fopt;
c19d1205 25969 struct arm_long_option_table *lopt;
b99bd4ef 25970
c19d1205 25971 switch (c)
b99bd4ef 25972 {
c19d1205
ZW
25973#ifdef OPTION_EB
25974 case OPTION_EB:
25975 target_big_endian = 1;
25976 break;
25977#endif
cc8a6dd0 25978
c19d1205
ZW
25979#ifdef OPTION_EL
25980 case OPTION_EL:
25981 target_big_endian = 0;
25982 break;
25983#endif
b99bd4ef 25984
845b51d6
PB
25985 case OPTION_FIX_V4BX:
25986 fix_v4bx = TRUE;
25987 break;
25988
c19d1205
ZW
25989 case 'a':
25990 /* Listing option. Just ignore these, we don't support additional
25991 ones. */
25992 return 0;
b99bd4ef 25993
c19d1205
ZW
25994 default:
25995 for (opt = arm_opts; opt->option != NULL; opt++)
25996 {
25997 if (c == opt->option[0]
25998 && ((arg == NULL && opt->option[1] == 0)
25999 || streq (arg, opt->option + 1)))
26000 {
c19d1205 26001 /* If the option is deprecated, tell the user. */
278df34e 26002 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
26003 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26004 arg ? arg : "", _(opt->deprecated));
b99bd4ef 26005
c19d1205
ZW
26006 if (opt->var != NULL)
26007 *opt->var = opt->value;
cc8a6dd0 26008
c19d1205
ZW
26009 return 1;
26010 }
26011 }
b99bd4ef 26012
e74cfd16
PB
26013 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
26014 {
26015 if (c == fopt->option[0]
26016 && ((arg == NULL && fopt->option[1] == 0)
26017 || streq (arg, fopt->option + 1)))
26018 {
e74cfd16 26019 /* If the option is deprecated, tell the user. */
278df34e 26020 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
26021 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26022 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
26023
26024 if (fopt->var != NULL)
26025 *fopt->var = &fopt->value;
26026
26027 return 1;
26028 }
26029 }
26030
c19d1205
ZW
26031 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26032 {
26033 /* These options are expected to have an argument. */
26034 if (c == lopt->option[0]
26035 && arg != NULL
26036 && strncmp (arg, lopt->option + 1,
26037 strlen (lopt->option + 1)) == 0)
26038 {
c19d1205 26039 /* If the option is deprecated, tell the user. */
278df34e 26040 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
26041 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
26042 _(lopt->deprecated));
b99bd4ef 26043
c19d1205
ZW
26044 /* Call the sup-option parser. */
26045 return lopt->func (arg + strlen (lopt->option) - 1);
26046 }
26047 }
a737bd4d 26048
c19d1205
ZW
26049 return 0;
26050 }
a394c00f 26051
c19d1205
ZW
26052 return 1;
26053}
a394c00f 26054
c19d1205
ZW
26055void
26056md_show_usage (FILE * fp)
a394c00f 26057{
c19d1205
ZW
26058 struct arm_option_table *opt;
26059 struct arm_long_option_table *lopt;
a394c00f 26060
c19d1205 26061 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 26062
c19d1205
ZW
26063 for (opt = arm_opts; opt->option != NULL; opt++)
26064 if (opt->help != NULL)
26065 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 26066
c19d1205
ZW
26067 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26068 if (lopt->help != NULL)
26069 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 26070
c19d1205
ZW
26071#ifdef OPTION_EB
26072 fprintf (fp, _("\
26073 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
26074#endif
26075
c19d1205
ZW
26076#ifdef OPTION_EL
26077 fprintf (fp, _("\
26078 -EL assemble code for a little-endian cpu\n"));
a737bd4d 26079#endif
845b51d6
PB
26080
26081 fprintf (fp, _("\
26082 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 26083}
ee065d83
PB
26084
26085
26086#ifdef OBJ_ELF
62b3e311
PB
26087typedef struct
26088{
26089 int val;
26090 arm_feature_set flags;
26091} cpu_arch_ver_table;
26092
4ed7ed8d
TP
26093/* Mapping from CPU features to EABI CPU arch values. As a general rule, table
26094 must be sorted least features first but some reordering is needed, eg. for
26095 Thumb-2 instructions to be detected as coming from ARMv6T2. */
62b3e311
PB
26096static const cpu_arch_ver_table cpu_arch_ver[] =
26097{
26098 {1, ARM_ARCH_V4},
26099 {2, ARM_ARCH_V4T},
26100 {3, ARM_ARCH_V5},
ee3c0378 26101 {3, ARM_ARCH_V5T},
62b3e311
PB
26102 {4, ARM_ARCH_V5TE},
26103 {5, ARM_ARCH_V5TEJ},
26104 {6, ARM_ARCH_V6},
7e806470 26105 {9, ARM_ARCH_V6K},
f4c65163 26106 {7, ARM_ARCH_V6Z},
91e22acd 26107 {11, ARM_ARCH_V6M},
b2a5fbdc 26108 {12, ARM_ARCH_V6SM},
7e806470 26109 {8, ARM_ARCH_V6T2},
c9fb6e58 26110 {10, ARM_ARCH_V7VE},
62b3e311
PB
26111 {10, ARM_ARCH_V7R},
26112 {10, ARM_ARCH_V7M},
bca38921 26113 {14, ARM_ARCH_V8A},
ff8646ee 26114 {16, ARM_ARCH_V8M_BASE},
4ed7ed8d 26115 {17, ARM_ARCH_V8M_MAIN},
62b3e311
PB
26116 {0, ARM_ARCH_NONE}
26117};
26118
ee3c0378
AS
26119/* Set an attribute if it has not already been set by the user. */
26120static void
26121aeabi_set_attribute_int (int tag, int value)
26122{
26123 if (tag < 1
26124 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26125 || !attributes_set_explicitly[tag])
26126 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
26127}
26128
26129static void
26130aeabi_set_attribute_string (int tag, const char *value)
26131{
26132 if (tag < 1
26133 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26134 || !attributes_set_explicitly[tag])
26135 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
26136}
26137
ee065d83 26138/* Set the public EABI object attributes. */
3cfdb781 26139void
ee065d83
PB
26140aeabi_set_public_attributes (void)
26141{
26142 int arch;
69239280 26143 char profile;
90ec0d68 26144 int virt_sec = 0;
bca38921 26145 int fp16_optional = 0;
15afaa63 26146 arm_feature_set arm_arch = ARM_ARCH_NONE;
e74cfd16 26147 arm_feature_set flags;
62b3e311 26148 arm_feature_set tmp;
ff8646ee 26149 arm_feature_set arm_arch_v8m_base = ARM_ARCH_V8M_BASE;
62b3e311 26150 const cpu_arch_ver_table *p;
ee065d83
PB
26151
26152 /* Choose the architecture based on the capabilities of the requested cpu
26153 (if any) and/or the instructions actually used. */
e74cfd16
PB
26154 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
26155 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
26156 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
ddd7f988
RE
26157
26158 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
26159 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
26160
26161 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
26162 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
26163
7f78eb34
JW
26164 selected_cpu = flags;
26165
ddd7f988 26166 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
26167 if (object_arch)
26168 {
26169 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
26170 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
26171 }
26172
251665fc
MGD
26173 /* We need to make sure that the attributes do not identify us as v6S-M
26174 when the only v6S-M feature in use is the Operating System Extensions. */
26175 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
26176 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
477330fc 26177 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
251665fc 26178
62b3e311
PB
26179 tmp = flags;
26180 arch = 0;
26181 for (p = cpu_arch_ver; p->val; p++)
26182 {
26183 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
26184 {
26185 arch = p->val;
15afaa63 26186 arm_arch = p->flags;
62b3e311
PB
26187 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
26188 }
26189 }
ee065d83 26190
9e3c6df6
PB
26191 /* The table lookup above finds the last architecture to contribute
26192 a new feature. Unfortunately, Tag13 is a subset of the union of
26193 v6T2 and v7-M, so it is never seen as contributing a new feature.
26194 We can not search for the last entry which is entirely used,
26195 because if no CPU is specified we build up only those flags
26196 actually used. Perhaps we should separate out the specified
26197 and implicit cases. Avoid taking this path for -march=all by
26198 checking for contradictory v7-A / v7-M features. */
4ed7ed8d 26199 if (arch == TAG_CPU_ARCH_V7
9e3c6df6
PB
26200 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
26201 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
26202 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
15afaa63
TP
26203 {
26204 arch = TAG_CPU_ARCH_V7E_M;
26205 arm_arch = (arm_feature_set) ARM_ARCH_V7EM;
26206 }
4ed7ed8d 26207
ff8646ee
TP
26208 ARM_CLEAR_FEATURE (tmp, flags, arm_arch_v8m_base);
26209 if (arch == TAG_CPU_ARCH_V8M_BASE && ARM_CPU_HAS_FEATURE (tmp, arm_arch_any))
15afaa63
TP
26210 {
26211 arch = TAG_CPU_ARCH_V8M_MAIN;
26212 arm_arch = (arm_feature_set) ARM_ARCH_V8M_MAIN;
26213 }
ff8646ee 26214
4ed7ed8d
TP
26215 /* In cpu_arch_ver ARMv8-A is before ARMv8-M for atomics to be detected as
26216 coming from ARMv8-A. However, since ARMv8-A has more instructions than
26217 ARMv8-M, -march=all must be detected as ARMv8-A. */
26218 if (arch == TAG_CPU_ARCH_V8M_MAIN
26219 && ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
15afaa63
TP
26220 {
26221 arch = TAG_CPU_ARCH_V8;
26222 arm_arch = (arm_feature_set) ARM_ARCH_V8A;
26223 }
9e3c6df6 26224
ee065d83
PB
26225 /* Tag_CPU_name. */
26226 if (selected_cpu_name[0])
26227 {
91d6fa6a 26228 char *q;
ee065d83 26229
91d6fa6a
NC
26230 q = selected_cpu_name;
26231 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
26232 {
26233 int i;
5f4273c7 26234
91d6fa6a
NC
26235 q += 4;
26236 for (i = 0; q[i]; i++)
26237 q[i] = TOUPPER (q[i]);
ee065d83 26238 }
91d6fa6a 26239 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 26240 }
62f3b8c8 26241
ee065d83 26242 /* Tag_CPU_arch. */
ee3c0378 26243 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 26244
62b3e311 26245 /* Tag_CPU_arch_profile. */
10c9892b 26246 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
4ed7ed8d
TP
26247 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26248 || (ARM_CPU_HAS_FEATURE (flags, arm_ext_atomics)
16a1fa25 26249 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only)))
69239280 26250 profile = 'A';
62b3e311 26251 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
69239280 26252 profile = 'R';
7e806470 26253 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
69239280
MGD
26254 profile = 'M';
26255 else
26256 profile = '\0';
26257
26258 if (profile != '\0')
26259 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 26260
15afaa63
TP
26261 /* Tag_DSP_extension. */
26262 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_dsp))
26263 {
26264 arm_feature_set ext;
26265
26266 /* DSP instructions not in architecture. */
26267 ARM_CLEAR_FEATURE (ext, flags, arm_arch);
26268 if (ARM_CPU_HAS_FEATURE (ext, arm_ext_dsp))
26269 aeabi_set_attribute_int (Tag_DSP_extension, 1);
26270 }
26271
ee065d83 26272 /* Tag_ARM_ISA_use. */
ee3c0378
AS
26273 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
26274 || arch == 0)
26275 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 26276
ee065d83 26277 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
26278 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
26279 || arch == 0)
4ed7ed8d
TP
26280 {
26281 int thumb_isa_use;
26282
26283 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 26284 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
26285 thumb_isa_use = 3;
26286 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
26287 thumb_isa_use = 2;
26288 else
26289 thumb_isa_use = 1;
26290 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
26291 }
62f3b8c8 26292
ee065d83 26293 /* Tag_VFP_arch. */
a715796b
TG
26294 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
26295 aeabi_set_attribute_int (Tag_VFP_arch,
26296 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
26297 ? 7 : 8);
bca38921 26298 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
26299 aeabi_set_attribute_int (Tag_VFP_arch,
26300 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
26301 ? 5 : 6);
26302 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
26303 {
26304 fp16_optional = 1;
26305 aeabi_set_attribute_int (Tag_VFP_arch, 3);
26306 }
ada65aa3 26307 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
26308 {
26309 aeabi_set_attribute_int (Tag_VFP_arch, 4);
26310 fp16_optional = 1;
26311 }
ee3c0378
AS
26312 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
26313 aeabi_set_attribute_int (Tag_VFP_arch, 2);
26314 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 26315 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 26316 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 26317
4547cb56
NC
26318 /* Tag_ABI_HardFP_use. */
26319 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
26320 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
26321 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
26322
ee065d83 26323 /* Tag_WMMX_arch. */
ee3c0378
AS
26324 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
26325 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
26326 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
26327 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 26328
ee3c0378 26329 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
26330 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
26331 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
26332 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
26333 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
26334 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
26335 {
26336 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
26337 {
26338 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
26339 }
26340 else
26341 {
26342 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
26343 fp16_optional = 1;
26344 }
26345 }
fa94de6b 26346
ee3c0378 26347 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 26348 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 26349 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 26350
69239280
MGD
26351 /* Tag_DIV_use.
26352
26353 We set Tag_DIV_use to two when integer divide instructions have been used
26354 in ARM state, or when Thumb integer divide instructions have been used,
26355 but we have no architecture profile set, nor have we any ARM instructions.
26356
4ed7ed8d
TP
26357 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
26358 by the base architecture.
bca38921 26359
69239280 26360 For new architectures we will have to check these tests. */
ff8646ee
TP
26361 gas_assert (arch <= TAG_CPU_ARCH_V8
26362 || (arch >= TAG_CPU_ARCH_V8M_BASE
26363 && arch <= TAG_CPU_ARCH_V8M_MAIN));
4ed7ed8d
TP
26364 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26365 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
26366 aeabi_set_attribute_int (Tag_DIV_use, 0);
26367 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
26368 || (profile == '\0'
26369 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
26370 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 26371 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
26372
26373 /* Tag_MP_extension_use. */
26374 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
26375 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
26376
26377 /* Tag Virtualization_use. */
26378 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
26379 virt_sec |= 1;
26380 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
26381 virt_sec |= 2;
26382 if (virt_sec != 0)
26383 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
26384}
26385
104d59d1 26386/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
26387void
26388arm_md_end (void)
26389{
ee065d83
PB
26390 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
26391 return;
26392
26393 aeabi_set_public_attributes ();
ee065d83 26394}
8463be01 26395#endif /* OBJ_ELF */
ee065d83
PB
26396
26397
26398/* Parse a .cpu directive. */
26399
26400static void
26401s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
26402{
e74cfd16 26403 const struct arm_cpu_option_table *opt;
ee065d83
PB
26404 char *name;
26405 char saved_char;
26406
26407 name = input_line_pointer;
5f4273c7 26408 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26409 input_line_pointer++;
26410 saved_char = *input_line_pointer;
26411 *input_line_pointer = 0;
26412
26413 /* Skip the first "all" entry. */
26414 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
26415 if (streq (opt->name, name))
26416 {
e74cfd16
PB
26417 mcpu_cpu_opt = &opt->value;
26418 selected_cpu = opt->value;
ee065d83 26419 if (opt->canonical_name)
5f4273c7 26420 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
26421 else
26422 {
26423 int i;
26424 for (i = 0; opt->name[i]; i++)
26425 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 26426
ee065d83
PB
26427 selected_cpu_name[i] = 0;
26428 }
e74cfd16 26429 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26430 *input_line_pointer = saved_char;
26431 demand_empty_rest_of_line ();
26432 return;
26433 }
26434 as_bad (_("unknown cpu `%s'"), name);
26435 *input_line_pointer = saved_char;
26436 ignore_rest_of_line ();
26437}
26438
26439
26440/* Parse a .arch directive. */
26441
26442static void
26443s_arm_arch (int ignored ATTRIBUTE_UNUSED)
26444{
e74cfd16 26445 const struct arm_arch_option_table *opt;
ee065d83
PB
26446 char saved_char;
26447 char *name;
26448
26449 name = input_line_pointer;
5f4273c7 26450 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26451 input_line_pointer++;
26452 saved_char = *input_line_pointer;
26453 *input_line_pointer = 0;
26454
26455 /* Skip the first "all" entry. */
26456 for (opt = arm_archs + 1; opt->name != NULL; opt++)
26457 if (streq (opt->name, name))
26458 {
e74cfd16
PB
26459 mcpu_cpu_opt = &opt->value;
26460 selected_cpu = opt->value;
5f4273c7 26461 strcpy (selected_cpu_name, opt->name);
e74cfd16 26462 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26463 *input_line_pointer = saved_char;
26464 demand_empty_rest_of_line ();
26465 return;
26466 }
26467
26468 as_bad (_("unknown architecture `%s'\n"), name);
26469 *input_line_pointer = saved_char;
26470 ignore_rest_of_line ();
26471}
26472
26473
7a1d4c38
PB
26474/* Parse a .object_arch directive. */
26475
26476static void
26477s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
26478{
26479 const struct arm_arch_option_table *opt;
26480 char saved_char;
26481 char *name;
26482
26483 name = input_line_pointer;
5f4273c7 26484 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
26485 input_line_pointer++;
26486 saved_char = *input_line_pointer;
26487 *input_line_pointer = 0;
26488
26489 /* Skip the first "all" entry. */
26490 for (opt = arm_archs + 1; opt->name != NULL; opt++)
26491 if (streq (opt->name, name))
26492 {
26493 object_arch = &opt->value;
26494 *input_line_pointer = saved_char;
26495 demand_empty_rest_of_line ();
26496 return;
26497 }
26498
26499 as_bad (_("unknown architecture `%s'\n"), name);
26500 *input_line_pointer = saved_char;
26501 ignore_rest_of_line ();
26502}
26503
69133863
MGD
26504/* Parse a .arch_extension directive. */
26505
26506static void
26507s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
26508{
26509 const struct arm_option_extension_value_table *opt;
d942732e 26510 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
26511 char saved_char;
26512 char *name;
26513 int adding_value = 1;
26514
26515 name = input_line_pointer;
26516 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
26517 input_line_pointer++;
26518 saved_char = *input_line_pointer;
26519 *input_line_pointer = 0;
26520
26521 if (strlen (name) >= 2
26522 && strncmp (name, "no", 2) == 0)
26523 {
26524 adding_value = 0;
26525 name += 2;
26526 }
26527
26528 for (opt = arm_extensions; opt->name != NULL; opt++)
26529 if (streq (opt->name, name))
26530 {
d942732e
TP
26531 int i, nb_allowed_archs =
26532 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
26533 for (i = 0; i < nb_allowed_archs; i++)
26534 {
26535 /* Empty entry. */
26536 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
26537 continue;
26538 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *mcpu_cpu_opt))
26539 break;
26540 }
26541
26542 if (i == nb_allowed_archs)
69133863
MGD
26543 {
26544 as_bad (_("architectural extension `%s' is not allowed for the "
26545 "current base architecture"), name);
26546 break;
26547 }
26548
26549 if (adding_value)
5a70a223
JB
26550 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu,
26551 opt->merge_value);
69133863 26552 else
5a70a223 26553 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->clear_value);
69133863
MGD
26554
26555 mcpu_cpu_opt = &selected_cpu;
26556 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
26557 *input_line_pointer = saved_char;
26558 demand_empty_rest_of_line ();
26559 return;
26560 }
26561
26562 if (opt->name == NULL)
e673710a 26563 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
26564
26565 *input_line_pointer = saved_char;
26566 ignore_rest_of_line ();
26567}
26568
ee065d83
PB
26569/* Parse a .fpu directive. */
26570
26571static void
26572s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
26573{
69133863 26574 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
26575 char saved_char;
26576 char *name;
26577
26578 name = input_line_pointer;
5f4273c7 26579 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26580 input_line_pointer++;
26581 saved_char = *input_line_pointer;
26582 *input_line_pointer = 0;
5f4273c7 26583
ee065d83
PB
26584 for (opt = arm_fpus; opt->name != NULL; opt++)
26585 if (streq (opt->name, name))
26586 {
e74cfd16
PB
26587 mfpu_opt = &opt->value;
26588 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26589 *input_line_pointer = saved_char;
26590 demand_empty_rest_of_line ();
26591 return;
26592 }
26593
26594 as_bad (_("unknown floating point format `%s'\n"), name);
26595 *input_line_pointer = saved_char;
26596 ignore_rest_of_line ();
26597}
ee065d83 26598
794ba86a 26599/* Copy symbol information. */
f31fef98 26600
794ba86a
DJ
26601void
26602arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
26603{
26604 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
26605}
e04befd0 26606
f31fef98 26607#ifdef OBJ_ELF
e04befd0
AS
26608/* Given a symbolic attribute NAME, return the proper integer value.
26609 Returns -1 if the attribute is not known. */
f31fef98 26610
e04befd0
AS
26611int
26612arm_convert_symbolic_attribute (const char *name)
26613{
f31fef98
NC
26614 static const struct
26615 {
26616 const char * name;
26617 const int tag;
26618 }
26619 attribute_table[] =
26620 {
26621 /* When you modify this table you should
26622 also modify the list in doc/c-arm.texi. */
e04befd0 26623#define T(tag) {#tag, tag}
f31fef98
NC
26624 T (Tag_CPU_raw_name),
26625 T (Tag_CPU_name),
26626 T (Tag_CPU_arch),
26627 T (Tag_CPU_arch_profile),
26628 T (Tag_ARM_ISA_use),
26629 T (Tag_THUMB_ISA_use),
75375b3e 26630 T (Tag_FP_arch),
f31fef98
NC
26631 T (Tag_VFP_arch),
26632 T (Tag_WMMX_arch),
26633 T (Tag_Advanced_SIMD_arch),
26634 T (Tag_PCS_config),
26635 T (Tag_ABI_PCS_R9_use),
26636 T (Tag_ABI_PCS_RW_data),
26637 T (Tag_ABI_PCS_RO_data),
26638 T (Tag_ABI_PCS_GOT_use),
26639 T (Tag_ABI_PCS_wchar_t),
26640 T (Tag_ABI_FP_rounding),
26641 T (Tag_ABI_FP_denormal),
26642 T (Tag_ABI_FP_exceptions),
26643 T (Tag_ABI_FP_user_exceptions),
26644 T (Tag_ABI_FP_number_model),
75375b3e 26645 T (Tag_ABI_align_needed),
f31fef98 26646 T (Tag_ABI_align8_needed),
75375b3e 26647 T (Tag_ABI_align_preserved),
f31fef98
NC
26648 T (Tag_ABI_align8_preserved),
26649 T (Tag_ABI_enum_size),
26650 T (Tag_ABI_HardFP_use),
26651 T (Tag_ABI_VFP_args),
26652 T (Tag_ABI_WMMX_args),
26653 T (Tag_ABI_optimization_goals),
26654 T (Tag_ABI_FP_optimization_goals),
26655 T (Tag_compatibility),
26656 T (Tag_CPU_unaligned_access),
75375b3e 26657 T (Tag_FP_HP_extension),
f31fef98
NC
26658 T (Tag_VFP_HP_extension),
26659 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
26660 T (Tag_MPextension_use),
26661 T (Tag_DIV_use),
f31fef98
NC
26662 T (Tag_nodefaults),
26663 T (Tag_also_compatible_with),
26664 T (Tag_conformance),
26665 T (Tag_T2EE_use),
26666 T (Tag_Virtualization_use),
15afaa63 26667 T (Tag_DSP_extension),
cd21e546 26668 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 26669#undef T
f31fef98 26670 };
e04befd0
AS
26671 unsigned int i;
26672
26673 if (name == NULL)
26674 return -1;
26675
f31fef98 26676 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 26677 if (streq (name, attribute_table[i].name))
e04befd0
AS
26678 return attribute_table[i].tag;
26679
26680 return -1;
26681}
267bf995
RR
26682
26683
93ef582d
NC
26684/* Apply sym value for relocations only in the case that they are for
26685 local symbols in the same segment as the fixup and you have the
26686 respective architectural feature for blx and simple switches. */
267bf995 26687int
93ef582d 26688arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
26689{
26690 if (fixP->fx_addsy
26691 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
26692 /* PR 17444: If the local symbol is in a different section then a reloc
26693 will always be generated for it, so applying the symbol value now
26694 will result in a double offset being stored in the relocation. */
26695 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 26696 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
26697 {
26698 switch (fixP->fx_r_type)
26699 {
26700 case BFD_RELOC_ARM_PCREL_BLX:
26701 case BFD_RELOC_THUMB_PCREL_BRANCH23:
26702 if (ARM_IS_FUNC (fixP->fx_addsy))
26703 return 1;
26704 break;
26705
26706 case BFD_RELOC_ARM_PCREL_CALL:
26707 case BFD_RELOC_THUMB_PCREL_BLX:
26708 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 26709 return 1;
267bf995
RR
26710 break;
26711
26712 default:
26713 break;
26714 }
26715
26716 }
26717 return 0;
26718}
f31fef98 26719#endif /* OBJ_ELF */