]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
[ARM] Separate extensions from architectures in arm_cpus
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
2571583a 2 Copyright (C) 1994-2017 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);
49e8a725
SN
237static const arm_feature_set arm_ext_v8_3 =
238 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
e74cfd16
PB
239
240static const arm_feature_set arm_arch_any = ARM_ANY;
f85d59c3 241static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
e74cfd16
PB
242static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
243static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
69c9e028 244#ifdef OBJ_ELF
251665fc 245static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
69c9e028 246#endif
e74cfd16 247
2d447fca 248static const arm_feature_set arm_cext_iwmmxt2 =
823d2571 249 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
e74cfd16 250static const arm_feature_set arm_cext_iwmmxt =
823d2571 251 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
e74cfd16 252static const arm_feature_set arm_cext_xscale =
823d2571 253 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
e74cfd16 254static const arm_feature_set arm_cext_maverick =
823d2571
TG
255 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
256static const arm_feature_set fpu_fpa_ext_v1 =
257 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
258static const arm_feature_set fpu_fpa_ext_v2 =
259 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
e74cfd16 260static const arm_feature_set fpu_vfp_ext_v1xd =
823d2571
TG
261 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
262static const arm_feature_set fpu_vfp_ext_v1 =
263 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
264static const arm_feature_set fpu_vfp_ext_v2 =
265 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
266static const arm_feature_set fpu_vfp_ext_v3xd =
267 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
268static const arm_feature_set fpu_vfp_ext_v3 =
269 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
b1cc4aeb 270static const arm_feature_set fpu_vfp_ext_d32 =
823d2571
TG
271 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
272static const arm_feature_set fpu_neon_ext_v1 =
273 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
5287ad62 274static const arm_feature_set fpu_vfp_v3_or_neon_ext =
823d2571 275 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
69c9e028 276#ifdef OBJ_ELF
823d2571
TG
277static const arm_feature_set fpu_vfp_fp16 =
278 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
279static const arm_feature_set fpu_neon_ext_fma =
280 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
69c9e028 281#endif
823d2571
TG
282static const arm_feature_set fpu_vfp_ext_fma =
283 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
bca38921 284static const arm_feature_set fpu_vfp_ext_armv8 =
823d2571 285 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
a715796b 286static const arm_feature_set fpu_vfp_ext_armv8xd =
823d2571 287 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
bca38921 288static const arm_feature_set fpu_neon_ext_armv8 =
823d2571 289 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
bca38921 290static const arm_feature_set fpu_crypto_ext_armv8 =
823d2571 291 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
dd5181d5 292static const arm_feature_set crc_ext_armv8 =
823d2571 293 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
d6b4b13e 294static const arm_feature_set fpu_neon_ext_v8_1 =
643afb90 295 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
e74cfd16 296
33a392fb 297static int mfloat_abi_opt = -1;
e74cfd16
PB
298/* Record user cpu selection for object attributes. */
299static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83 300/* Must be long enough to hold any of the names in arm_cpus. */
ef8e6722 301static char selected_cpu_name[20];
8d67f500 302
aacf0b33
KT
303extern FLONUM_TYPE generic_floating_point_number;
304
8d67f500
NC
305/* Return if no cpu was selected on command-line. */
306static bfd_boolean
307no_cpu_selected (void)
308{
823d2571 309 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
8d67f500
NC
310}
311
7cc69913 312#ifdef OBJ_ELF
deeaaff8
DJ
313# ifdef EABI_DEFAULT
314static int meabi_flags = EABI_DEFAULT;
315# else
d507cf36 316static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 317# endif
e1da3f5b 318
ee3c0378
AS
319static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
320
e1da3f5b 321bfd_boolean
5f4273c7 322arm_is_eabi (void)
e1da3f5b
PB
323{
324 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
325}
7cc69913 326#endif
b99bd4ef 327
b99bd4ef 328#ifdef OBJ_ELF
c19d1205 329/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
330symbolS * GOT_symbol;
331#endif
332
b99bd4ef
NC
333/* 0: assemble for ARM,
334 1: assemble for Thumb,
335 2: assemble for Thumb even though target CPU does not support thumb
336 instructions. */
337static int thumb_mode = 0;
8dc2430f
NC
338/* A value distinct from the possible values for thumb_mode that we
339 can use to record whether thumb_mode has been copied into the
340 tc_frag_data field of a frag. */
341#define MODE_RECORDED (1 << 4)
b99bd4ef 342
e07e6e58
NC
343/* Specifies the intrinsic IT insn behavior mode. */
344enum implicit_it_mode
345{
346 IMPLICIT_IT_MODE_NEVER = 0x00,
347 IMPLICIT_IT_MODE_ARM = 0x01,
348 IMPLICIT_IT_MODE_THUMB = 0x02,
349 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
350};
351static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
352
c19d1205
ZW
353/* If unified_syntax is true, we are processing the new unified
354 ARM/Thumb syntax. Important differences from the old ARM mode:
355
356 - Immediate operands do not require a # prefix.
357 - Conditional affixes always appear at the end of the
358 instruction. (For backward compatibility, those instructions
359 that formerly had them in the middle, continue to accept them
360 there.)
361 - The IT instruction may appear, and if it does is validated
362 against subsequent conditional affixes. It does not generate
363 machine code.
364
365 Important differences from the old Thumb mode:
366
367 - Immediate operands do not require a # prefix.
368 - Most of the V6T2 instructions are only available in unified mode.
369 - The .N and .W suffixes are recognized and honored (it is an error
370 if they cannot be honored).
371 - All instructions set the flags if and only if they have an 's' affix.
372 - Conditional affixes may be used. They are validated against
373 preceding IT instructions. Unlike ARM mode, you cannot use a
374 conditional affix except in the scope of an IT instruction. */
375
376static bfd_boolean unified_syntax = FALSE;
b99bd4ef 377
bacebabc
RM
378/* An immediate operand can start with #, and ld*, st*, pld operands
379 can contain [ and ]. We need to tell APP not to elide whitespace
477330fc
RM
380 before a [, which can appear as the first operand for pld.
381 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
382const char arm_symbol_chars[] = "#[]{}";
bacebabc 383
5287ad62
JB
384enum neon_el_type
385{
dcbf9037 386 NT_invtype,
5287ad62
JB
387 NT_untyped,
388 NT_integer,
389 NT_float,
390 NT_poly,
391 NT_signed,
dcbf9037 392 NT_unsigned
5287ad62
JB
393};
394
395struct neon_type_el
396{
397 enum neon_el_type type;
398 unsigned size;
399};
400
401#define NEON_MAX_TYPE_ELS 4
402
403struct neon_type
404{
405 struct neon_type_el el[NEON_MAX_TYPE_ELS];
406 unsigned elems;
407};
408
e07e6e58
NC
409enum it_instruction_type
410{
411 OUTSIDE_IT_INSN,
412 INSIDE_IT_INSN,
413 INSIDE_IT_LAST_INSN,
414 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
477330fc 415 if inside, should be the last one. */
e07e6e58 416 NEUTRAL_IT_INSN, /* This could be either inside or outside,
477330fc 417 i.e. BKPT and NOP. */
e07e6e58
NC
418 IT_INSN /* The IT insn has been parsed. */
419};
420
ad6cec43
MGD
421/* The maximum number of operands we need. */
422#define ARM_IT_MAX_OPERANDS 6
423
b99bd4ef
NC
424struct arm_it
425{
c19d1205 426 const char * error;
b99bd4ef 427 unsigned long instruction;
c19d1205
ZW
428 int size;
429 int size_req;
430 int cond;
037e8744
JB
431 /* "uncond_value" is set to the value in place of the conditional field in
432 unconditional versions of the instruction, or -1 if nothing is
433 appropriate. */
434 int uncond_value;
5287ad62 435 struct neon_type vectype;
88714cb8
DG
436 /* This does not indicate an actual NEON instruction, only that
437 the mnemonic accepts neon-style type suffixes. */
438 int is_neon;
0110f2b8
PB
439 /* Set to the opcode if the instruction needs relaxation.
440 Zero if the instruction is not relaxed. */
441 unsigned long relax;
b99bd4ef
NC
442 struct
443 {
444 bfd_reloc_code_real_type type;
c19d1205
ZW
445 expressionS exp;
446 int pc_rel;
b99bd4ef 447 } reloc;
b99bd4ef 448
e07e6e58
NC
449 enum it_instruction_type it_insn_type;
450
c19d1205
ZW
451 struct
452 {
453 unsigned reg;
ca3f61f7 454 signed int imm;
dcbf9037 455 struct neon_type_el vectype;
ca3f61f7
NC
456 unsigned present : 1; /* Operand present. */
457 unsigned isreg : 1; /* Operand was a register. */
458 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
459 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
460 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 461 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
462 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
463 instructions. This allows us to disambiguate ARM <-> vector insns. */
464 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 465 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 466 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 467 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
468 unsigned hasreloc : 1; /* Operand has relocation suffix. */
469 unsigned writeback : 1; /* Operand has trailing ! */
470 unsigned preind : 1; /* Preindexed address. */
471 unsigned postind : 1; /* Postindexed address. */
472 unsigned negative : 1; /* Index register was negated. */
473 unsigned shifted : 1; /* Shift applied to operation. */
474 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
ad6cec43 475 } operands[ARM_IT_MAX_OPERANDS];
b99bd4ef
NC
476};
477
c19d1205 478static struct arm_it inst;
b99bd4ef
NC
479
480#define NUM_FLOAT_VALS 8
481
05d2d07e 482const char * fp_const[] =
b99bd4ef
NC
483{
484 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
485};
486
c19d1205 487/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
488#define MAX_LITTLENUMS 6
489
490LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
491
492#define FAIL (-1)
493#define SUCCESS (0)
494
495#define SUFF_S 1
496#define SUFF_D 2
497#define SUFF_E 3
498#define SUFF_P 4
499
c19d1205
ZW
500#define CP_T_X 0x00008000
501#define CP_T_Y 0x00400000
b99bd4ef 502
c19d1205
ZW
503#define CONDS_BIT 0x00100000
504#define LOAD_BIT 0x00100000
b99bd4ef
NC
505
506#define DOUBLE_LOAD_FLAG 0x00000001
507
508struct asm_cond
509{
d3ce72d0 510 const char * template_name;
c921be7d 511 unsigned long value;
b99bd4ef
NC
512};
513
c19d1205 514#define COND_ALWAYS 0xE
b99bd4ef 515
b99bd4ef
NC
516struct asm_psr
517{
d3ce72d0 518 const char * template_name;
c921be7d 519 unsigned long field;
b99bd4ef
NC
520};
521
62b3e311
PB
522struct asm_barrier_opt
523{
e797f7e0
MGD
524 const char * template_name;
525 unsigned long value;
526 const arm_feature_set arch;
62b3e311
PB
527};
528
2d2255b5 529/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
530#define SPSR_BIT (1 << 22)
531
c19d1205
ZW
532/* The individual PSR flag bits. */
533#define PSR_c (1 << 16)
534#define PSR_x (1 << 17)
535#define PSR_s (1 << 18)
536#define PSR_f (1 << 19)
b99bd4ef 537
c19d1205 538struct reloc_entry
bfae80f2 539{
e0471c16 540 const char * name;
c921be7d 541 bfd_reloc_code_real_type reloc;
bfae80f2
RE
542};
543
5287ad62 544enum vfp_reg_pos
bfae80f2 545{
5287ad62
JB
546 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
547 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
548};
549
550enum vfp_ldstm_type
551{
552 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
553};
554
dcbf9037
JB
555/* Bits for DEFINED field in neon_typed_alias. */
556#define NTA_HASTYPE 1
557#define NTA_HASINDEX 2
558
559struct neon_typed_alias
560{
c921be7d
NC
561 unsigned char defined;
562 unsigned char index;
563 struct neon_type_el eltype;
dcbf9037
JB
564};
565
c19d1205
ZW
566/* ARM register categories. This includes coprocessor numbers and various
567 architecture extensions' registers. */
568enum arm_reg_type
bfae80f2 569{
c19d1205
ZW
570 REG_TYPE_RN,
571 REG_TYPE_CP,
572 REG_TYPE_CN,
573 REG_TYPE_FN,
574 REG_TYPE_VFS,
575 REG_TYPE_VFD,
5287ad62 576 REG_TYPE_NQ,
037e8744 577 REG_TYPE_VFSD,
5287ad62 578 REG_TYPE_NDQ,
037e8744 579 REG_TYPE_NSDQ,
c19d1205
ZW
580 REG_TYPE_VFC,
581 REG_TYPE_MVF,
582 REG_TYPE_MVD,
583 REG_TYPE_MVFX,
584 REG_TYPE_MVDX,
585 REG_TYPE_MVAX,
586 REG_TYPE_DSPSC,
587 REG_TYPE_MMXWR,
588 REG_TYPE_MMXWC,
589 REG_TYPE_MMXWCG,
590 REG_TYPE_XSCALE,
90ec0d68 591 REG_TYPE_RNB
bfae80f2
RE
592};
593
dcbf9037
JB
594/* Structure for a hash table entry for a register.
595 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
596 information which states whether a vector type or index is specified (for a
597 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
598struct reg_entry
599{
c921be7d 600 const char * name;
90ec0d68 601 unsigned int number;
c921be7d
NC
602 unsigned char type;
603 unsigned char builtin;
604 struct neon_typed_alias * neon;
6c43fab6
RE
605};
606
c19d1205 607/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 608const char * const reg_expected_msgs[] =
c19d1205
ZW
609{
610 N_("ARM register expected"),
611 N_("bad or missing co-processor number"),
612 N_("co-processor register expected"),
613 N_("FPA register expected"),
614 N_("VFP single precision register expected"),
5287ad62
JB
615 N_("VFP/Neon double precision register expected"),
616 N_("Neon quad precision register expected"),
037e8744 617 N_("VFP single or double precision register expected"),
5287ad62 618 N_("Neon double or quad precision register expected"),
037e8744 619 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
620 N_("VFP system register expected"),
621 N_("Maverick MVF register expected"),
622 N_("Maverick MVD register expected"),
623 N_("Maverick MVFX register expected"),
624 N_("Maverick MVDX register expected"),
625 N_("Maverick MVAX register expected"),
626 N_("Maverick DSPSC register expected"),
627 N_("iWMMXt data register expected"),
628 N_("iWMMXt control register expected"),
629 N_("iWMMXt scalar register expected"),
630 N_("XScale accumulator register expected"),
6c43fab6
RE
631};
632
c19d1205 633/* Some well known registers that we refer to directly elsewhere. */
bd340a04 634#define REG_R12 12
c19d1205
ZW
635#define REG_SP 13
636#define REG_LR 14
637#define REG_PC 15
404ff6b5 638
b99bd4ef
NC
639/* ARM instructions take 4bytes in the object file, Thumb instructions
640 take 2: */
c19d1205 641#define INSN_SIZE 4
b99bd4ef
NC
642
643struct asm_opcode
644{
645 /* Basic string to match. */
d3ce72d0 646 const char * template_name;
c19d1205
ZW
647
648 /* Parameters to instruction. */
5be8be5d 649 unsigned int operands[8];
c19d1205
ZW
650
651 /* Conditional tag - see opcode_lookup. */
652 unsigned int tag : 4;
b99bd4ef
NC
653
654 /* Basic instruction code. */
c19d1205 655 unsigned int avalue : 28;
b99bd4ef 656
c19d1205
ZW
657 /* Thumb-format instruction code. */
658 unsigned int tvalue;
b99bd4ef 659
90e4755a 660 /* Which architecture variant provides this instruction. */
c921be7d
NC
661 const arm_feature_set * avariant;
662 const arm_feature_set * tvariant;
c19d1205
ZW
663
664 /* Function to call to encode instruction in ARM format. */
665 void (* aencode) (void);
b99bd4ef 666
c19d1205
ZW
667 /* Function to call to encode instruction in Thumb format. */
668 void (* tencode) (void);
b99bd4ef
NC
669};
670
a737bd4d
NC
671/* Defines for various bits that we will want to toggle. */
672#define INST_IMMEDIATE 0x02000000
673#define OFFSET_REG 0x02000000
c19d1205 674#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
675#define SHIFT_BY_REG 0x00000010
676#define PRE_INDEX 0x01000000
677#define INDEX_UP 0x00800000
678#define WRITE_BACK 0x00200000
679#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 680#define CPSI_MMOD 0x00020000
90e4755a 681
a737bd4d
NC
682#define LITERAL_MASK 0xf000f000
683#define OPCODE_MASK 0xfe1fffff
684#define V4_STR_BIT 0x00000020
8335d6aa 685#define VLDR_VMOV_SAME 0x0040f000
90e4755a 686
efd81785
PB
687#define T2_SUBS_PC_LR 0xf3de8f00
688
a737bd4d 689#define DATA_OP_SHIFT 21
bada4342 690#define SBIT_SHIFT 20
90e4755a 691
ef8d22e6
PB
692#define T2_OPCODE_MASK 0xfe1fffff
693#define T2_DATA_OP_SHIFT 21
bada4342 694#define T2_SBIT_SHIFT 20
ef8d22e6 695
6530b175
NC
696#define A_COND_MASK 0xf0000000
697#define A_PUSH_POP_OP_MASK 0x0fff0000
698
699/* Opcodes for pushing/poping registers to/from the stack. */
700#define A1_OPCODE_PUSH 0x092d0000
701#define A2_OPCODE_PUSH 0x052d0004
702#define A2_OPCODE_POP 0x049d0004
703
a737bd4d
NC
704/* Codes to distinguish the arithmetic instructions. */
705#define OPCODE_AND 0
706#define OPCODE_EOR 1
707#define OPCODE_SUB 2
708#define OPCODE_RSB 3
709#define OPCODE_ADD 4
710#define OPCODE_ADC 5
711#define OPCODE_SBC 6
712#define OPCODE_RSC 7
713#define OPCODE_TST 8
714#define OPCODE_TEQ 9
715#define OPCODE_CMP 10
716#define OPCODE_CMN 11
717#define OPCODE_ORR 12
718#define OPCODE_MOV 13
719#define OPCODE_BIC 14
720#define OPCODE_MVN 15
90e4755a 721
ef8d22e6
PB
722#define T2_OPCODE_AND 0
723#define T2_OPCODE_BIC 1
724#define T2_OPCODE_ORR 2
725#define T2_OPCODE_ORN 3
726#define T2_OPCODE_EOR 4
727#define T2_OPCODE_ADD 8
728#define T2_OPCODE_ADC 10
729#define T2_OPCODE_SBC 11
730#define T2_OPCODE_SUB 13
731#define T2_OPCODE_RSB 14
732
a737bd4d
NC
733#define T_OPCODE_MUL 0x4340
734#define T_OPCODE_TST 0x4200
735#define T_OPCODE_CMN 0x42c0
736#define T_OPCODE_NEG 0x4240
737#define T_OPCODE_MVN 0x43c0
90e4755a 738
a737bd4d
NC
739#define T_OPCODE_ADD_R3 0x1800
740#define T_OPCODE_SUB_R3 0x1a00
741#define T_OPCODE_ADD_HI 0x4400
742#define T_OPCODE_ADD_ST 0xb000
743#define T_OPCODE_SUB_ST 0xb080
744#define T_OPCODE_ADD_SP 0xa800
745#define T_OPCODE_ADD_PC 0xa000
746#define T_OPCODE_ADD_I8 0x3000
747#define T_OPCODE_SUB_I8 0x3800
748#define T_OPCODE_ADD_I3 0x1c00
749#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 750
a737bd4d
NC
751#define T_OPCODE_ASR_R 0x4100
752#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
753#define T_OPCODE_LSR_R 0x40c0
754#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
755#define T_OPCODE_ASR_I 0x1000
756#define T_OPCODE_LSL_I 0x0000
757#define T_OPCODE_LSR_I 0x0800
b99bd4ef 758
a737bd4d
NC
759#define T_OPCODE_MOV_I8 0x2000
760#define T_OPCODE_CMP_I8 0x2800
761#define T_OPCODE_CMP_LR 0x4280
762#define T_OPCODE_MOV_HR 0x4600
763#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 764
a737bd4d
NC
765#define T_OPCODE_LDR_PC 0x4800
766#define T_OPCODE_LDR_SP 0x9800
767#define T_OPCODE_STR_SP 0x9000
768#define T_OPCODE_LDR_IW 0x6800
769#define T_OPCODE_STR_IW 0x6000
770#define T_OPCODE_LDR_IH 0x8800
771#define T_OPCODE_STR_IH 0x8000
772#define T_OPCODE_LDR_IB 0x7800
773#define T_OPCODE_STR_IB 0x7000
774#define T_OPCODE_LDR_RW 0x5800
775#define T_OPCODE_STR_RW 0x5000
776#define T_OPCODE_LDR_RH 0x5a00
777#define T_OPCODE_STR_RH 0x5200
778#define T_OPCODE_LDR_RB 0x5c00
779#define T_OPCODE_STR_RB 0x5400
c9b604bd 780
a737bd4d
NC
781#define T_OPCODE_PUSH 0xb400
782#define T_OPCODE_POP 0xbc00
b99bd4ef 783
2fc8bdac 784#define T_OPCODE_BRANCH 0xe000
b99bd4ef 785
a737bd4d 786#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 787#define THUMB_PP_PC_LR 0x0100
c19d1205 788#define THUMB_LOAD_BIT 0x0800
53365c0d 789#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
790
791#define BAD_ARGS _("bad arguments to instruction")
fdfde340 792#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
793#define BAD_PC _("r15 not allowed here")
794#define BAD_COND _("instruction cannot be conditional")
795#define BAD_OVERLAP _("registers may not be the same")
796#define BAD_HIREG _("lo register required")
797#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 798#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
799#define BAD_BRANCH _("branch must be last instruction in IT block")
800#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 801#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
802#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
803#define BAD_IT_COND _("incorrect condition in IT block")
804#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 805#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
5be8be5d
DG
806#define BAD_PC_ADDRESSING \
807 _("cannot use register index with PC-relative addressing")
808#define BAD_PC_WRITEBACK \
809 _("cannot use writeback with PC-relative addressing")
9db2f6b4
RL
810#define BAD_RANGE _("branch out of range")
811#define BAD_FP16 _("selected processor does not support fp16 instruction")
dd5181d5 812#define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
a9f02af8 813#define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
c19d1205 814
c921be7d
NC
815static struct hash_control * arm_ops_hsh;
816static struct hash_control * arm_cond_hsh;
817static struct hash_control * arm_shift_hsh;
818static struct hash_control * arm_psr_hsh;
819static struct hash_control * arm_v7m_psr_hsh;
820static struct hash_control * arm_reg_hsh;
821static struct hash_control * arm_reloc_hsh;
822static struct hash_control * arm_barrier_opt_hsh;
b99bd4ef 823
b99bd4ef
NC
824/* Stuff needed to resolve the label ambiguity
825 As:
826 ...
827 label: <insn>
828 may differ from:
829 ...
830 label:
5f4273c7 831 <insn> */
b99bd4ef
NC
832
833symbolS * last_label_seen;
b34976b6 834static int label_is_thumb_function_name = FALSE;
e07e6e58 835
3d0c9500
NC
836/* Literal pool structure. Held on a per-section
837 and per-sub-section basis. */
a737bd4d 838
c19d1205 839#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 840typedef struct literal_pool
b99bd4ef 841{
c921be7d
NC
842 expressionS literals [MAX_LITERAL_POOL_SIZE];
843 unsigned int next_free_entry;
844 unsigned int id;
845 symbolS * symbol;
846 segT section;
847 subsegT sub_section;
a8040cf2
NC
848#ifdef OBJ_ELF
849 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
850#endif
c921be7d 851 struct literal_pool * next;
8335d6aa 852 unsigned int alignment;
3d0c9500 853} literal_pool;
b99bd4ef 854
3d0c9500
NC
855/* Pointer to a linked list of literal pools. */
856literal_pool * list_of_pools = NULL;
e27ec89e 857
2e6976a8
DG
858typedef enum asmfunc_states
859{
860 OUTSIDE_ASMFUNC,
861 WAITING_ASMFUNC_NAME,
862 WAITING_ENDASMFUNC
863} asmfunc_states;
864
865static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
866
e07e6e58
NC
867#ifdef OBJ_ELF
868# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
869#else
870static struct current_it now_it;
871#endif
872
873static inline int
874now_it_compatible (int cond)
875{
876 return (cond & ~1) == (now_it.cc & ~1);
877}
878
879static inline int
880conditional_insn (void)
881{
882 return inst.cond != COND_ALWAYS;
883}
884
885static int in_it_block (void);
886
887static int handle_it_state (void);
888
889static void force_automatic_it_block_close (void);
890
c921be7d
NC
891static void it_fsm_post_encode (void);
892
e07e6e58
NC
893#define set_it_insn_type(type) \
894 do \
895 { \
896 inst.it_insn_type = type; \
897 if (handle_it_state () == FAIL) \
477330fc 898 return; \
e07e6e58
NC
899 } \
900 while (0)
901
c921be7d
NC
902#define set_it_insn_type_nonvoid(type, failret) \
903 do \
904 { \
905 inst.it_insn_type = type; \
906 if (handle_it_state () == FAIL) \
477330fc 907 return failret; \
c921be7d
NC
908 } \
909 while(0)
910
e07e6e58
NC
911#define set_it_insn_type_last() \
912 do \
913 { \
914 if (inst.cond == COND_ALWAYS) \
477330fc 915 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
e07e6e58 916 else \
477330fc 917 set_it_insn_type (INSIDE_IT_LAST_INSN); \
e07e6e58
NC
918 } \
919 while (0)
920
c19d1205 921/* Pure syntax. */
b99bd4ef 922
c19d1205
ZW
923/* This array holds the chars that always start a comment. If the
924 pre-processor is disabled, these aren't very useful. */
2e6976a8 925char arm_comment_chars[] = "@";
3d0c9500 926
c19d1205
ZW
927/* This array holds the chars that only start a comment at the beginning of
928 a line. If the line seems to have the form '# 123 filename'
929 .line and .file directives will appear in the pre-processed output. */
930/* Note that input_file.c hand checks for '#' at the beginning of the
931 first line of the input file. This is because the compiler outputs
932 #NO_APP at the beginning of its output. */
933/* Also note that comments like this one will always work. */
934const char line_comment_chars[] = "#";
3d0c9500 935
2e6976a8 936char arm_line_separator_chars[] = ";";
b99bd4ef 937
c19d1205
ZW
938/* Chars that can be used to separate mant
939 from exp in floating point numbers. */
940const char EXP_CHARS[] = "eE";
3d0c9500 941
c19d1205
ZW
942/* Chars that mean this number is a floating point constant. */
943/* As in 0f12.456 */
944/* or 0d1.2345e12 */
b99bd4ef 945
c19d1205 946const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 947
c19d1205
ZW
948/* Prefix characters that indicate the start of an immediate
949 value. */
950#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 951
c19d1205
ZW
952/* Separator character handling. */
953
954#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
955
956static inline int
957skip_past_char (char ** str, char c)
958{
8ab8155f
NC
959 /* PR gas/14987: Allow for whitespace before the expected character. */
960 skip_whitespace (*str);
427d0db6 961
c19d1205
ZW
962 if (**str == c)
963 {
964 (*str)++;
965 return SUCCESS;
3d0c9500 966 }
c19d1205
ZW
967 else
968 return FAIL;
969}
c921be7d 970
c19d1205 971#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 972
c19d1205
ZW
973/* Arithmetic expressions (possibly involving symbols). */
974
975/* Return TRUE if anything in the expression is a bignum. */
976
977static int
978walk_no_bignums (symbolS * sp)
979{
980 if (symbol_get_value_expression (sp)->X_op == O_big)
981 return 1;
982
983 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 984 {
c19d1205
ZW
985 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
986 || (symbol_get_value_expression (sp)->X_op_symbol
987 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
988 }
989
c19d1205 990 return 0;
3d0c9500
NC
991}
992
c19d1205
ZW
993static int in_my_get_expression = 0;
994
995/* Third argument to my_get_expression. */
996#define GE_NO_PREFIX 0
997#define GE_IMM_PREFIX 1
998#define GE_OPT_PREFIX 2
5287ad62
JB
999/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1000 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1001#define GE_OPT_PREFIX_BIG 3
a737bd4d 1002
b99bd4ef 1003static int
c19d1205 1004my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 1005{
c19d1205
ZW
1006 char * save_in;
1007 segT seg;
b99bd4ef 1008
c19d1205
ZW
1009 /* In unified syntax, all prefixes are optional. */
1010 if (unified_syntax)
5287ad62 1011 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
477330fc 1012 : GE_OPT_PREFIX;
b99bd4ef 1013
c19d1205 1014 switch (prefix_mode)
b99bd4ef 1015 {
c19d1205
ZW
1016 case GE_NO_PREFIX: break;
1017 case GE_IMM_PREFIX:
1018 if (!is_immediate_prefix (**str))
1019 {
1020 inst.error = _("immediate expression requires a # prefix");
1021 return FAIL;
1022 }
1023 (*str)++;
1024 break;
1025 case GE_OPT_PREFIX:
5287ad62 1026 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
1027 if (is_immediate_prefix (**str))
1028 (*str)++;
1029 break;
1030 default: abort ();
1031 }
b99bd4ef 1032
c19d1205 1033 memset (ep, 0, sizeof (expressionS));
b99bd4ef 1034
c19d1205
ZW
1035 save_in = input_line_pointer;
1036 input_line_pointer = *str;
1037 in_my_get_expression = 1;
1038 seg = expression (ep);
1039 in_my_get_expression = 0;
1040
f86adc07 1041 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 1042 {
f86adc07 1043 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
1044 *str = input_line_pointer;
1045 input_line_pointer = save_in;
1046 if (inst.error == NULL)
f86adc07
NS
1047 inst.error = (ep->X_op == O_absent
1048 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
1049 return 1;
1050 }
b99bd4ef 1051
c19d1205
ZW
1052#ifdef OBJ_AOUT
1053 if (seg != absolute_section
1054 && seg != text_section
1055 && seg != data_section
1056 && seg != bss_section
1057 && seg != undefined_section)
1058 {
1059 inst.error = _("bad segment");
1060 *str = input_line_pointer;
1061 input_line_pointer = save_in;
1062 return 1;
b99bd4ef 1063 }
87975d2a
AM
1064#else
1065 (void) seg;
c19d1205 1066#endif
b99bd4ef 1067
c19d1205
ZW
1068 /* Get rid of any bignums now, so that we don't generate an error for which
1069 we can't establish a line number later on. Big numbers are never valid
1070 in instructions, which is where this routine is always called. */
5287ad62
JB
1071 if (prefix_mode != GE_OPT_PREFIX_BIG
1072 && (ep->X_op == O_big
477330fc 1073 || (ep->X_add_symbol
5287ad62 1074 && (walk_no_bignums (ep->X_add_symbol)
477330fc 1075 || (ep->X_op_symbol
5287ad62 1076 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
1077 {
1078 inst.error = _("invalid constant");
1079 *str = input_line_pointer;
1080 input_line_pointer = save_in;
1081 return 1;
1082 }
b99bd4ef 1083
c19d1205
ZW
1084 *str = input_line_pointer;
1085 input_line_pointer = save_in;
1086 return 0;
b99bd4ef
NC
1087}
1088
c19d1205
ZW
1089/* Turn a string in input_line_pointer into a floating point constant
1090 of type TYPE, and store the appropriate bytes in *LITP. The number
1091 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1092 returned, or NULL on OK.
b99bd4ef 1093
c19d1205
ZW
1094 Note that fp constants aren't represent in the normal way on the ARM.
1095 In big endian mode, things are as expected. However, in little endian
1096 mode fp constants are big-endian word-wise, and little-endian byte-wise
1097 within the words. For example, (double) 1.1 in big endian mode is
1098 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1099 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 1100
c19d1205 1101 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 1102
6d4af3c2 1103const char *
c19d1205
ZW
1104md_atof (int type, char * litP, int * sizeP)
1105{
1106 int prec;
1107 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1108 char *t;
1109 int i;
b99bd4ef 1110
c19d1205
ZW
1111 switch (type)
1112 {
1113 case 'f':
1114 case 'F':
1115 case 's':
1116 case 'S':
1117 prec = 2;
1118 break;
b99bd4ef 1119
c19d1205
ZW
1120 case 'd':
1121 case 'D':
1122 case 'r':
1123 case 'R':
1124 prec = 4;
1125 break;
b99bd4ef 1126
c19d1205
ZW
1127 case 'x':
1128 case 'X':
499ac353 1129 prec = 5;
c19d1205 1130 break;
b99bd4ef 1131
c19d1205
ZW
1132 case 'p':
1133 case 'P':
499ac353 1134 prec = 5;
c19d1205 1135 break;
a737bd4d 1136
c19d1205
ZW
1137 default:
1138 *sizeP = 0;
499ac353 1139 return _("Unrecognized or unsupported floating point constant");
c19d1205 1140 }
b99bd4ef 1141
c19d1205
ZW
1142 t = atof_ieee (input_line_pointer, type, words);
1143 if (t)
1144 input_line_pointer = t;
499ac353 1145 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1146
c19d1205
ZW
1147 if (target_big_endian)
1148 {
1149 for (i = 0; i < prec; i++)
1150 {
499ac353
NC
1151 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1152 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1153 }
1154 }
1155 else
1156 {
e74cfd16 1157 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1158 for (i = prec - 1; i >= 0; i--)
1159 {
499ac353
NC
1160 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1161 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1162 }
1163 else
1164 /* For a 4 byte float the order of elements in `words' is 1 0.
1165 For an 8 byte float the order is 1 0 3 2. */
1166 for (i = 0; i < prec; i += 2)
1167 {
499ac353
NC
1168 md_number_to_chars (litP, (valueT) words[i + 1],
1169 sizeof (LITTLENUM_TYPE));
1170 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1171 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1172 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1173 }
1174 }
b99bd4ef 1175
499ac353 1176 return NULL;
c19d1205 1177}
b99bd4ef 1178
c19d1205
ZW
1179/* We handle all bad expressions here, so that we can report the faulty
1180 instruction in the error message. */
1181void
91d6fa6a 1182md_operand (expressionS * exp)
c19d1205
ZW
1183{
1184 if (in_my_get_expression)
91d6fa6a 1185 exp->X_op = O_illegal;
b99bd4ef
NC
1186}
1187
c19d1205 1188/* Immediate values. */
b99bd4ef 1189
c19d1205
ZW
1190/* Generic immediate-value read function for use in directives.
1191 Accepts anything that 'expression' can fold to a constant.
1192 *val receives the number. */
1193#ifdef OBJ_ELF
1194static int
1195immediate_for_directive (int *val)
b99bd4ef 1196{
c19d1205
ZW
1197 expressionS exp;
1198 exp.X_op = O_illegal;
b99bd4ef 1199
c19d1205
ZW
1200 if (is_immediate_prefix (*input_line_pointer))
1201 {
1202 input_line_pointer++;
1203 expression (&exp);
1204 }
b99bd4ef 1205
c19d1205
ZW
1206 if (exp.X_op != O_constant)
1207 {
1208 as_bad (_("expected #constant"));
1209 ignore_rest_of_line ();
1210 return FAIL;
1211 }
1212 *val = exp.X_add_number;
1213 return SUCCESS;
b99bd4ef 1214}
c19d1205 1215#endif
b99bd4ef 1216
c19d1205 1217/* Register parsing. */
b99bd4ef 1218
c19d1205
ZW
1219/* Generic register parser. CCP points to what should be the
1220 beginning of a register name. If it is indeed a valid register
1221 name, advance CCP over it and return the reg_entry structure;
1222 otherwise return NULL. Does not issue diagnostics. */
1223
1224static struct reg_entry *
1225arm_reg_parse_multi (char **ccp)
b99bd4ef 1226{
c19d1205
ZW
1227 char *start = *ccp;
1228 char *p;
1229 struct reg_entry *reg;
b99bd4ef 1230
477330fc
RM
1231 skip_whitespace (start);
1232
c19d1205
ZW
1233#ifdef REGISTER_PREFIX
1234 if (*start != REGISTER_PREFIX)
01cfc07f 1235 return NULL;
c19d1205
ZW
1236 start++;
1237#endif
1238#ifdef OPTIONAL_REGISTER_PREFIX
1239 if (*start == OPTIONAL_REGISTER_PREFIX)
1240 start++;
1241#endif
b99bd4ef 1242
c19d1205
ZW
1243 p = start;
1244 if (!ISALPHA (*p) || !is_name_beginner (*p))
1245 return NULL;
b99bd4ef 1246
c19d1205
ZW
1247 do
1248 p++;
1249 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1250
1251 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1252
1253 if (!reg)
1254 return NULL;
1255
1256 *ccp = p;
1257 return reg;
b99bd4ef
NC
1258}
1259
1260static int
dcbf9037 1261arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
477330fc 1262 enum arm_reg_type type)
b99bd4ef 1263{
c19d1205
ZW
1264 /* Alternative syntaxes are accepted for a few register classes. */
1265 switch (type)
1266 {
1267 case REG_TYPE_MVF:
1268 case REG_TYPE_MVD:
1269 case REG_TYPE_MVFX:
1270 case REG_TYPE_MVDX:
1271 /* Generic coprocessor register names are allowed for these. */
79134647 1272 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1273 return reg->number;
1274 break;
69b97547 1275
c19d1205
ZW
1276 case REG_TYPE_CP:
1277 /* For backward compatibility, a bare number is valid here. */
1278 {
1279 unsigned long processor = strtoul (start, ccp, 10);
1280 if (*ccp != start && processor <= 15)
1281 return processor;
1282 }
1a0670f3 1283 /* Fall through. */
6057a28f 1284
c19d1205
ZW
1285 case REG_TYPE_MMXWC:
1286 /* WC includes WCG. ??? I'm not sure this is true for all
1287 instructions that take WC registers. */
79134647 1288 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1289 return reg->number;
6057a28f 1290 break;
c19d1205 1291
6057a28f 1292 default:
c19d1205 1293 break;
6057a28f
NC
1294 }
1295
dcbf9037
JB
1296 return FAIL;
1297}
1298
1299/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1300 return value is the register number or FAIL. */
1301
1302static int
1303arm_reg_parse (char **ccp, enum arm_reg_type type)
1304{
1305 char *start = *ccp;
1306 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1307 int ret;
1308
1309 /* Do not allow a scalar (reg+index) to parse as a register. */
1310 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1311 return FAIL;
1312
1313 if (reg && reg->type == type)
1314 return reg->number;
1315
1316 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1317 return ret;
1318
c19d1205
ZW
1319 *ccp = start;
1320 return FAIL;
1321}
69b97547 1322
dcbf9037
JB
1323/* Parse a Neon type specifier. *STR should point at the leading '.'
1324 character. Does no verification at this stage that the type fits the opcode
1325 properly. E.g.,
1326
1327 .i32.i32.s16
1328 .s32.f32
1329 .u16
1330
1331 Can all be legally parsed by this function.
1332
1333 Fills in neon_type struct pointer with parsed information, and updates STR
1334 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1335 type, FAIL if not. */
1336
1337static int
1338parse_neon_type (struct neon_type *type, char **str)
1339{
1340 char *ptr = *str;
1341
1342 if (type)
1343 type->elems = 0;
1344
1345 while (type->elems < NEON_MAX_TYPE_ELS)
1346 {
1347 enum neon_el_type thistype = NT_untyped;
1348 unsigned thissize = -1u;
1349
1350 if (*ptr != '.')
1351 break;
1352
1353 ptr++;
1354
1355 /* Just a size without an explicit type. */
1356 if (ISDIGIT (*ptr))
1357 goto parsesize;
1358
1359 switch (TOLOWER (*ptr))
1360 {
1361 case 'i': thistype = NT_integer; break;
1362 case 'f': thistype = NT_float; break;
1363 case 'p': thistype = NT_poly; break;
1364 case 's': thistype = NT_signed; break;
1365 case 'u': thistype = NT_unsigned; break;
477330fc
RM
1366 case 'd':
1367 thistype = NT_float;
1368 thissize = 64;
1369 ptr++;
1370 goto done;
dcbf9037
JB
1371 default:
1372 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1373 return FAIL;
1374 }
1375
1376 ptr++;
1377
1378 /* .f is an abbreviation for .f32. */
1379 if (thistype == NT_float && !ISDIGIT (*ptr))
1380 thissize = 32;
1381 else
1382 {
1383 parsesize:
1384 thissize = strtoul (ptr, &ptr, 10);
1385
1386 if (thissize != 8 && thissize != 16 && thissize != 32
477330fc
RM
1387 && thissize != 64)
1388 {
1389 as_bad (_("bad size %d in type specifier"), thissize);
dcbf9037
JB
1390 return FAIL;
1391 }
1392 }
1393
037e8744 1394 done:
dcbf9037 1395 if (type)
477330fc
RM
1396 {
1397 type->el[type->elems].type = thistype;
dcbf9037
JB
1398 type->el[type->elems].size = thissize;
1399 type->elems++;
1400 }
1401 }
1402
1403 /* Empty/missing type is not a successful parse. */
1404 if (type->elems == 0)
1405 return FAIL;
1406
1407 *str = ptr;
1408
1409 return SUCCESS;
1410}
1411
1412/* Errors may be set multiple times during parsing or bit encoding
1413 (particularly in the Neon bits), but usually the earliest error which is set
1414 will be the most meaningful. Avoid overwriting it with later (cascading)
1415 errors by calling this function. */
1416
1417static void
1418first_error (const char *err)
1419{
1420 if (!inst.error)
1421 inst.error = err;
1422}
1423
1424/* Parse a single type, e.g. ".s32", leading period included. */
1425static int
1426parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1427{
1428 char *str = *ccp;
1429 struct neon_type optype;
1430
1431 if (*str == '.')
1432 {
1433 if (parse_neon_type (&optype, &str) == SUCCESS)
477330fc
RM
1434 {
1435 if (optype.elems == 1)
1436 *vectype = optype.el[0];
1437 else
1438 {
1439 first_error (_("only one type should be specified for operand"));
1440 return FAIL;
1441 }
1442 }
dcbf9037 1443 else
477330fc
RM
1444 {
1445 first_error (_("vector type expected"));
1446 return FAIL;
1447 }
dcbf9037
JB
1448 }
1449 else
1450 return FAIL;
5f4273c7 1451
dcbf9037 1452 *ccp = str;
5f4273c7 1453
dcbf9037
JB
1454 return SUCCESS;
1455}
1456
1457/* Special meanings for indices (which have a range of 0-7), which will fit into
1458 a 4-bit integer. */
1459
1460#define NEON_ALL_LANES 15
1461#define NEON_INTERLEAVE_LANES 14
1462
1463/* Parse either a register or a scalar, with an optional type. Return the
1464 register number, and optionally fill in the actual type of the register
1465 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1466 type/index information in *TYPEINFO. */
1467
1468static int
1469parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
477330fc
RM
1470 enum arm_reg_type *rtype,
1471 struct neon_typed_alias *typeinfo)
dcbf9037
JB
1472{
1473 char *str = *ccp;
1474 struct reg_entry *reg = arm_reg_parse_multi (&str);
1475 struct neon_typed_alias atype;
1476 struct neon_type_el parsetype;
1477
1478 atype.defined = 0;
1479 atype.index = -1;
1480 atype.eltype.type = NT_invtype;
1481 atype.eltype.size = -1;
1482
1483 /* Try alternate syntax for some types of register. Note these are mutually
1484 exclusive with the Neon syntax extensions. */
1485 if (reg == NULL)
1486 {
1487 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1488 if (altreg != FAIL)
477330fc 1489 *ccp = str;
dcbf9037 1490 if (typeinfo)
477330fc 1491 *typeinfo = atype;
dcbf9037
JB
1492 return altreg;
1493 }
1494
037e8744
JB
1495 /* Undo polymorphism when a set of register types may be accepted. */
1496 if ((type == REG_TYPE_NDQ
1497 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1498 || (type == REG_TYPE_VFSD
477330fc 1499 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
037e8744 1500 || (type == REG_TYPE_NSDQ
477330fc
RM
1501 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1502 || reg->type == REG_TYPE_NQ))
f512f76f
NC
1503 || (type == REG_TYPE_MMXWC
1504 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1505 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1506
1507 if (type != reg->type)
1508 return FAIL;
1509
1510 if (reg->neon)
1511 atype = *reg->neon;
5f4273c7 1512
dcbf9037
JB
1513 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1514 {
1515 if ((atype.defined & NTA_HASTYPE) != 0)
477330fc
RM
1516 {
1517 first_error (_("can't redefine type for operand"));
1518 return FAIL;
1519 }
dcbf9037
JB
1520 atype.defined |= NTA_HASTYPE;
1521 atype.eltype = parsetype;
1522 }
5f4273c7 1523
dcbf9037
JB
1524 if (skip_past_char (&str, '[') == SUCCESS)
1525 {
1526 if (type != REG_TYPE_VFD)
477330fc
RM
1527 {
1528 first_error (_("only D registers may be indexed"));
1529 return FAIL;
1530 }
5f4273c7 1531
dcbf9037 1532 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
1533 {
1534 first_error (_("can't change index for operand"));
1535 return FAIL;
1536 }
dcbf9037
JB
1537
1538 atype.defined |= NTA_HASINDEX;
1539
1540 if (skip_past_char (&str, ']') == SUCCESS)
477330fc 1541 atype.index = NEON_ALL_LANES;
dcbf9037 1542 else
477330fc
RM
1543 {
1544 expressionS exp;
dcbf9037 1545
477330fc 1546 my_get_expression (&exp, &str, GE_NO_PREFIX);
dcbf9037 1547
477330fc
RM
1548 if (exp.X_op != O_constant)
1549 {
1550 first_error (_("constant expression required"));
1551 return FAIL;
1552 }
dcbf9037 1553
477330fc
RM
1554 if (skip_past_char (&str, ']') == FAIL)
1555 return FAIL;
dcbf9037 1556
477330fc
RM
1557 atype.index = exp.X_add_number;
1558 }
dcbf9037 1559 }
5f4273c7 1560
dcbf9037
JB
1561 if (typeinfo)
1562 *typeinfo = atype;
5f4273c7 1563
dcbf9037
JB
1564 if (rtype)
1565 *rtype = type;
5f4273c7 1566
dcbf9037 1567 *ccp = str;
5f4273c7 1568
dcbf9037
JB
1569 return reg->number;
1570}
1571
1572/* Like arm_reg_parse, but allow allow the following extra features:
1573 - If RTYPE is non-zero, return the (possibly restricted) type of the
1574 register (e.g. Neon double or quad reg when either has been requested).
1575 - If this is a Neon vector type with additional type information, fill
1576 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1577 This function will fault on encountering a scalar. */
dcbf9037
JB
1578
1579static int
1580arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
477330fc 1581 enum arm_reg_type *rtype, struct neon_type_el *vectype)
dcbf9037
JB
1582{
1583 struct neon_typed_alias atype;
1584 char *str = *ccp;
1585 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1586
1587 if (reg == FAIL)
1588 return FAIL;
1589
0855e32b
NS
1590 /* Do not allow regname(... to parse as a register. */
1591 if (*str == '(')
1592 return FAIL;
1593
dcbf9037
JB
1594 /* Do not allow a scalar (reg+index) to parse as a register. */
1595 if ((atype.defined & NTA_HASINDEX) != 0)
1596 {
1597 first_error (_("register operand expected, but got scalar"));
1598 return FAIL;
1599 }
1600
1601 if (vectype)
1602 *vectype = atype.eltype;
1603
1604 *ccp = str;
1605
1606 return reg;
1607}
1608
1609#define NEON_SCALAR_REG(X) ((X) >> 4)
1610#define NEON_SCALAR_INDEX(X) ((X) & 15)
1611
5287ad62
JB
1612/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1613 have enough information to be able to do a good job bounds-checking. So, we
1614 just do easy checks here, and do further checks later. */
1615
1616static int
dcbf9037 1617parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1618{
dcbf9037 1619 int reg;
5287ad62 1620 char *str = *ccp;
dcbf9037 1621 struct neon_typed_alias atype;
5f4273c7 1622
dcbf9037 1623 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1624
dcbf9037 1625 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1626 return FAIL;
5f4273c7 1627
dcbf9037 1628 if (atype.index == NEON_ALL_LANES)
5287ad62 1629 {
dcbf9037 1630 first_error (_("scalar must have an index"));
5287ad62
JB
1631 return FAIL;
1632 }
dcbf9037 1633 else if (atype.index >= 64 / elsize)
5287ad62 1634 {
dcbf9037 1635 first_error (_("scalar index out of range"));
5287ad62
JB
1636 return FAIL;
1637 }
5f4273c7 1638
dcbf9037
JB
1639 if (type)
1640 *type = atype.eltype;
5f4273c7 1641
5287ad62 1642 *ccp = str;
5f4273c7 1643
dcbf9037 1644 return reg * 16 + atype.index;
5287ad62
JB
1645}
1646
c19d1205 1647/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1648
c19d1205
ZW
1649static long
1650parse_reg_list (char ** strp)
1651{
1652 char * str = * strp;
1653 long range = 0;
1654 int another_range;
a737bd4d 1655
c19d1205
ZW
1656 /* We come back here if we get ranges concatenated by '+' or '|'. */
1657 do
6057a28f 1658 {
477330fc
RM
1659 skip_whitespace (str);
1660
c19d1205 1661 another_range = 0;
a737bd4d 1662
c19d1205
ZW
1663 if (*str == '{')
1664 {
1665 int in_range = 0;
1666 int cur_reg = -1;
a737bd4d 1667
c19d1205
ZW
1668 str++;
1669 do
1670 {
1671 int reg;
6057a28f 1672
dcbf9037 1673 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1674 {
dcbf9037 1675 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1676 return FAIL;
1677 }
a737bd4d 1678
c19d1205
ZW
1679 if (in_range)
1680 {
1681 int i;
a737bd4d 1682
c19d1205
ZW
1683 if (reg <= cur_reg)
1684 {
dcbf9037 1685 first_error (_("bad range in register list"));
c19d1205
ZW
1686 return FAIL;
1687 }
40a18ebd 1688
c19d1205
ZW
1689 for (i = cur_reg + 1; i < reg; i++)
1690 {
1691 if (range & (1 << i))
1692 as_tsktsk
1693 (_("Warning: duplicated register (r%d) in register list"),
1694 i);
1695 else
1696 range |= 1 << i;
1697 }
1698 in_range = 0;
1699 }
a737bd4d 1700
c19d1205
ZW
1701 if (range & (1 << reg))
1702 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1703 reg);
1704 else if (reg <= cur_reg)
1705 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1706
c19d1205
ZW
1707 range |= 1 << reg;
1708 cur_reg = reg;
1709 }
1710 while (skip_past_comma (&str) != FAIL
1711 || (in_range = 1, *str++ == '-'));
1712 str--;
a737bd4d 1713
d996d970 1714 if (skip_past_char (&str, '}') == FAIL)
c19d1205 1715 {
dcbf9037 1716 first_error (_("missing `}'"));
c19d1205
ZW
1717 return FAIL;
1718 }
1719 }
1720 else
1721 {
91d6fa6a 1722 expressionS exp;
40a18ebd 1723
91d6fa6a 1724 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
c19d1205 1725 return FAIL;
40a18ebd 1726
91d6fa6a 1727 if (exp.X_op == O_constant)
c19d1205 1728 {
91d6fa6a
NC
1729 if (exp.X_add_number
1730 != (exp.X_add_number & 0x0000ffff))
c19d1205
ZW
1731 {
1732 inst.error = _("invalid register mask");
1733 return FAIL;
1734 }
a737bd4d 1735
91d6fa6a 1736 if ((range & exp.X_add_number) != 0)
c19d1205 1737 {
91d6fa6a 1738 int regno = range & exp.X_add_number;
a737bd4d 1739
c19d1205
ZW
1740 regno &= -regno;
1741 regno = (1 << regno) - 1;
1742 as_tsktsk
1743 (_("Warning: duplicated register (r%d) in register list"),
1744 regno);
1745 }
a737bd4d 1746
91d6fa6a 1747 range |= exp.X_add_number;
c19d1205
ZW
1748 }
1749 else
1750 {
1751 if (inst.reloc.type != 0)
1752 {
1753 inst.error = _("expression too complex");
1754 return FAIL;
1755 }
a737bd4d 1756
91d6fa6a 1757 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
c19d1205
ZW
1758 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1759 inst.reloc.pc_rel = 0;
1760 }
1761 }
a737bd4d 1762
c19d1205
ZW
1763 if (*str == '|' || *str == '+')
1764 {
1765 str++;
1766 another_range = 1;
1767 }
a737bd4d 1768 }
c19d1205 1769 while (another_range);
a737bd4d 1770
c19d1205
ZW
1771 *strp = str;
1772 return range;
a737bd4d
NC
1773}
1774
5287ad62
JB
1775/* Types of registers in a list. */
1776
1777enum reg_list_els
1778{
1779 REGLIST_VFP_S,
1780 REGLIST_VFP_D,
1781 REGLIST_NEON_D
1782};
1783
c19d1205
ZW
1784/* Parse a VFP register list. If the string is invalid return FAIL.
1785 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1786 register. Parses registers of type ETYPE.
1787 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1788 - Q registers can be used to specify pairs of D registers
1789 - { } can be omitted from around a singleton register list
477330fc
RM
1790 FIXME: This is not implemented, as it would require backtracking in
1791 some cases, e.g.:
1792 vtbl.8 d3,d4,d5
1793 This could be done (the meaning isn't really ambiguous), but doesn't
1794 fit in well with the current parsing framework.
dcbf9037
JB
1795 - 32 D registers may be used (also true for VFPv3).
1796 FIXME: Types are ignored in these register lists, which is probably a
1797 bug. */
6057a28f 1798
c19d1205 1799static int
037e8744 1800parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1801{
037e8744 1802 char *str = *ccp;
c19d1205
ZW
1803 int base_reg;
1804 int new_base;
21d799b5 1805 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1806 int max_regs = 0;
c19d1205
ZW
1807 int count = 0;
1808 int warned = 0;
1809 unsigned long mask = 0;
a737bd4d 1810 int i;
6057a28f 1811
477330fc 1812 if (skip_past_char (&str, '{') == FAIL)
5287ad62
JB
1813 {
1814 inst.error = _("expecting {");
1815 return FAIL;
1816 }
6057a28f 1817
5287ad62 1818 switch (etype)
c19d1205 1819 {
5287ad62 1820 case REGLIST_VFP_S:
c19d1205
ZW
1821 regtype = REG_TYPE_VFS;
1822 max_regs = 32;
5287ad62 1823 break;
5f4273c7 1824
5287ad62
JB
1825 case REGLIST_VFP_D:
1826 regtype = REG_TYPE_VFD;
b7fc2769 1827 break;
5f4273c7 1828
b7fc2769
JB
1829 case REGLIST_NEON_D:
1830 regtype = REG_TYPE_NDQ;
1831 break;
1832 }
1833
1834 if (etype != REGLIST_VFP_S)
1835 {
b1cc4aeb
PB
1836 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1837 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
1838 {
1839 max_regs = 32;
1840 if (thumb_mode)
1841 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1842 fpu_vfp_ext_d32);
1843 else
1844 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1845 fpu_vfp_ext_d32);
1846 }
5287ad62 1847 else
477330fc 1848 max_regs = 16;
c19d1205 1849 }
6057a28f 1850
c19d1205 1851 base_reg = max_regs;
a737bd4d 1852
c19d1205
ZW
1853 do
1854 {
5287ad62 1855 int setmask = 1, addregs = 1;
dcbf9037 1856
037e8744 1857 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1858
c19d1205 1859 if (new_base == FAIL)
a737bd4d 1860 {
dcbf9037 1861 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1862 return FAIL;
1863 }
5f4273c7 1864
b7fc2769 1865 if (new_base >= max_regs)
477330fc
RM
1866 {
1867 first_error (_("register out of range in list"));
1868 return FAIL;
1869 }
5f4273c7 1870
5287ad62
JB
1871 /* Note: a value of 2 * n is returned for the register Q<n>. */
1872 if (regtype == REG_TYPE_NQ)
477330fc
RM
1873 {
1874 setmask = 3;
1875 addregs = 2;
1876 }
5287ad62 1877
c19d1205
ZW
1878 if (new_base < base_reg)
1879 base_reg = new_base;
a737bd4d 1880
5287ad62 1881 if (mask & (setmask << new_base))
c19d1205 1882 {
dcbf9037 1883 first_error (_("invalid register list"));
c19d1205 1884 return FAIL;
a737bd4d 1885 }
a737bd4d 1886
c19d1205
ZW
1887 if ((mask >> new_base) != 0 && ! warned)
1888 {
1889 as_tsktsk (_("register list not in ascending order"));
1890 warned = 1;
1891 }
0bbf2aa4 1892
5287ad62
JB
1893 mask |= setmask << new_base;
1894 count += addregs;
0bbf2aa4 1895
037e8744 1896 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1897 {
1898 int high_range;
0bbf2aa4 1899
037e8744 1900 str++;
0bbf2aa4 1901
037e8744 1902 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
477330fc 1903 == FAIL)
c19d1205
ZW
1904 {
1905 inst.error = gettext (reg_expected_msgs[regtype]);
1906 return FAIL;
1907 }
0bbf2aa4 1908
477330fc
RM
1909 if (high_range >= max_regs)
1910 {
1911 first_error (_("register out of range in list"));
1912 return FAIL;
1913 }
b7fc2769 1914
477330fc
RM
1915 if (regtype == REG_TYPE_NQ)
1916 high_range = high_range + 1;
5287ad62 1917
c19d1205
ZW
1918 if (high_range <= new_base)
1919 {
1920 inst.error = _("register range not in ascending order");
1921 return FAIL;
1922 }
0bbf2aa4 1923
5287ad62 1924 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1925 {
5287ad62 1926 if (mask & (setmask << new_base))
0bbf2aa4 1927 {
c19d1205
ZW
1928 inst.error = _("invalid register list");
1929 return FAIL;
0bbf2aa4 1930 }
c19d1205 1931
5287ad62
JB
1932 mask |= setmask << new_base;
1933 count += addregs;
0bbf2aa4 1934 }
0bbf2aa4 1935 }
0bbf2aa4 1936 }
037e8744 1937 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1938
037e8744 1939 str++;
0bbf2aa4 1940
c19d1205
ZW
1941 /* Sanity check -- should have raised a parse error above. */
1942 if (count == 0 || count > max_regs)
1943 abort ();
1944
1945 *pbase = base_reg;
1946
1947 /* Final test -- the registers must be consecutive. */
1948 mask >>= base_reg;
1949 for (i = 0; i < count; i++)
1950 {
1951 if ((mask & (1u << i)) == 0)
1952 {
1953 inst.error = _("non-contiguous register range");
1954 return FAIL;
1955 }
1956 }
1957
037e8744
JB
1958 *ccp = str;
1959
c19d1205 1960 return count;
b99bd4ef
NC
1961}
1962
dcbf9037
JB
1963/* True if two alias types are the same. */
1964
c921be7d 1965static bfd_boolean
dcbf9037
JB
1966neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1967{
1968 if (!a && !b)
c921be7d 1969 return TRUE;
5f4273c7 1970
dcbf9037 1971 if (!a || !b)
c921be7d 1972 return FALSE;
dcbf9037
JB
1973
1974 if (a->defined != b->defined)
c921be7d 1975 return FALSE;
5f4273c7 1976
dcbf9037
JB
1977 if ((a->defined & NTA_HASTYPE) != 0
1978 && (a->eltype.type != b->eltype.type
477330fc 1979 || a->eltype.size != b->eltype.size))
c921be7d 1980 return FALSE;
dcbf9037
JB
1981
1982 if ((a->defined & NTA_HASINDEX) != 0
1983 && (a->index != b->index))
c921be7d 1984 return FALSE;
5f4273c7 1985
c921be7d 1986 return TRUE;
dcbf9037
JB
1987}
1988
5287ad62
JB
1989/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1990 The base register is put in *PBASE.
dcbf9037 1991 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1992 the return value.
1993 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1994 Bits [6:5] encode the list length (minus one).
1995 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1996
5287ad62 1997#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1998#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1999#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2000
2001static int
dcbf9037 2002parse_neon_el_struct_list (char **str, unsigned *pbase,
477330fc 2003 struct neon_type_el *eltype)
5287ad62
JB
2004{
2005 char *ptr = *str;
2006 int base_reg = -1;
2007 int reg_incr = -1;
2008 int count = 0;
2009 int lane = -1;
2010 int leading_brace = 0;
2011 enum arm_reg_type rtype = REG_TYPE_NDQ;
20203fb9
NC
2012 const char *const incr_error = _("register stride must be 1 or 2");
2013 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 2014 struct neon_typed_alias firsttype;
f85d59c3
KT
2015 firsttype.defined = 0;
2016 firsttype.eltype.type = NT_invtype;
2017 firsttype.eltype.size = -1;
2018 firsttype.index = -1;
5f4273c7 2019
5287ad62
JB
2020 if (skip_past_char (&ptr, '{') == SUCCESS)
2021 leading_brace = 1;
5f4273c7 2022
5287ad62
JB
2023 do
2024 {
dcbf9037
JB
2025 struct neon_typed_alias atype;
2026 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2027
5287ad62 2028 if (getreg == FAIL)
477330fc
RM
2029 {
2030 first_error (_(reg_expected_msgs[rtype]));
2031 return FAIL;
2032 }
5f4273c7 2033
5287ad62 2034 if (base_reg == -1)
477330fc
RM
2035 {
2036 base_reg = getreg;
2037 if (rtype == REG_TYPE_NQ)
2038 {
2039 reg_incr = 1;
2040 }
2041 firsttype = atype;
2042 }
5287ad62 2043 else if (reg_incr == -1)
477330fc
RM
2044 {
2045 reg_incr = getreg - base_reg;
2046 if (reg_incr < 1 || reg_incr > 2)
2047 {
2048 first_error (_(incr_error));
2049 return FAIL;
2050 }
2051 }
5287ad62 2052 else if (getreg != base_reg + reg_incr * count)
477330fc
RM
2053 {
2054 first_error (_(incr_error));
2055 return FAIL;
2056 }
dcbf9037 2057
c921be7d 2058 if (! neon_alias_types_same (&atype, &firsttype))
477330fc
RM
2059 {
2060 first_error (_(type_error));
2061 return FAIL;
2062 }
5f4273c7 2063
5287ad62 2064 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
477330fc 2065 modes. */
5287ad62 2066 if (ptr[0] == '-')
477330fc
RM
2067 {
2068 struct neon_typed_alias htype;
2069 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2070 if (lane == -1)
2071 lane = NEON_INTERLEAVE_LANES;
2072 else if (lane != NEON_INTERLEAVE_LANES)
2073 {
2074 first_error (_(type_error));
2075 return FAIL;
2076 }
2077 if (reg_incr == -1)
2078 reg_incr = 1;
2079 else if (reg_incr != 1)
2080 {
2081 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2082 return FAIL;
2083 }
2084 ptr++;
2085 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2086 if (hireg == FAIL)
2087 {
2088 first_error (_(reg_expected_msgs[rtype]));
2089 return FAIL;
2090 }
2091 if (! neon_alias_types_same (&htype, &firsttype))
2092 {
2093 first_error (_(type_error));
2094 return FAIL;
2095 }
2096 count += hireg + dregs - getreg;
2097 continue;
2098 }
5f4273c7 2099
5287ad62
JB
2100 /* If we're using Q registers, we can't use [] or [n] syntax. */
2101 if (rtype == REG_TYPE_NQ)
477330fc
RM
2102 {
2103 count += 2;
2104 continue;
2105 }
5f4273c7 2106
dcbf9037 2107 if ((atype.defined & NTA_HASINDEX) != 0)
477330fc
RM
2108 {
2109 if (lane == -1)
2110 lane = atype.index;
2111 else if (lane != atype.index)
2112 {
2113 first_error (_(type_error));
2114 return FAIL;
2115 }
2116 }
5287ad62 2117 else if (lane == -1)
477330fc 2118 lane = NEON_INTERLEAVE_LANES;
5287ad62 2119 else if (lane != NEON_INTERLEAVE_LANES)
477330fc
RM
2120 {
2121 first_error (_(type_error));
2122 return FAIL;
2123 }
5287ad62
JB
2124 count++;
2125 }
2126 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 2127
5287ad62
JB
2128 /* No lane set by [x]. We must be interleaving structures. */
2129 if (lane == -1)
2130 lane = NEON_INTERLEAVE_LANES;
5f4273c7 2131
5287ad62
JB
2132 /* Sanity check. */
2133 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2134 || (count > 1 && reg_incr == -1))
2135 {
dcbf9037 2136 first_error (_("error parsing element/structure list"));
5287ad62
JB
2137 return FAIL;
2138 }
2139
2140 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2141 {
dcbf9037 2142 first_error (_("expected }"));
5287ad62
JB
2143 return FAIL;
2144 }
5f4273c7 2145
5287ad62
JB
2146 if (reg_incr == -1)
2147 reg_incr = 1;
2148
dcbf9037
JB
2149 if (eltype)
2150 *eltype = firsttype.eltype;
2151
5287ad62
JB
2152 *pbase = base_reg;
2153 *str = ptr;
5f4273c7 2154
5287ad62
JB
2155 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2156}
2157
c19d1205
ZW
2158/* Parse an explicit relocation suffix on an expression. This is
2159 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2160 arm_reloc_hsh contains no entries, so this function can only
2161 succeed if there is no () after the word. Returns -1 on error,
2162 BFD_RELOC_UNUSED if there wasn't any suffix. */
3da1d841 2163
c19d1205
ZW
2164static int
2165parse_reloc (char **str)
b99bd4ef 2166{
c19d1205
ZW
2167 struct reloc_entry *r;
2168 char *p, *q;
b99bd4ef 2169
c19d1205
ZW
2170 if (**str != '(')
2171 return BFD_RELOC_UNUSED;
b99bd4ef 2172
c19d1205
ZW
2173 p = *str + 1;
2174 q = p;
2175
2176 while (*q && *q != ')' && *q != ',')
2177 q++;
2178 if (*q != ')')
2179 return -1;
2180
21d799b5
NC
2181 if ((r = (struct reloc_entry *)
2182 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2183 return -1;
2184
2185 *str = q + 1;
2186 return r->reloc;
b99bd4ef
NC
2187}
2188
c19d1205
ZW
2189/* Directives: register aliases. */
2190
dcbf9037 2191static struct reg_entry *
90ec0d68 2192insert_reg_alias (char *str, unsigned number, int type)
b99bd4ef 2193{
d3ce72d0 2194 struct reg_entry *new_reg;
c19d1205 2195 const char *name;
b99bd4ef 2196
d3ce72d0 2197 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2198 {
d3ce72d0 2199 if (new_reg->builtin)
c19d1205 2200 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2201
c19d1205
ZW
2202 /* Only warn about a redefinition if it's not defined as the
2203 same register. */
d3ce72d0 2204 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2205 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2206
d929913e 2207 return NULL;
c19d1205 2208 }
b99bd4ef 2209
c19d1205 2210 name = xstrdup (str);
325801bd 2211 new_reg = XNEW (struct reg_entry);
b99bd4ef 2212
d3ce72d0
NC
2213 new_reg->name = name;
2214 new_reg->number = number;
2215 new_reg->type = type;
2216 new_reg->builtin = FALSE;
2217 new_reg->neon = NULL;
b99bd4ef 2218
d3ce72d0 2219 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2220 abort ();
5f4273c7 2221
d3ce72d0 2222 return new_reg;
dcbf9037
JB
2223}
2224
2225static void
2226insert_neon_reg_alias (char *str, int number, int type,
477330fc 2227 struct neon_typed_alias *atype)
dcbf9037
JB
2228{
2229 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2230
dcbf9037
JB
2231 if (!reg)
2232 {
2233 first_error (_("attempt to redefine typed alias"));
2234 return;
2235 }
5f4273c7 2236
dcbf9037
JB
2237 if (atype)
2238 {
325801bd 2239 reg->neon = XNEW (struct neon_typed_alias);
dcbf9037
JB
2240 *reg->neon = *atype;
2241 }
c19d1205 2242}
b99bd4ef 2243
c19d1205 2244/* Look for the .req directive. This is of the form:
b99bd4ef 2245
c19d1205 2246 new_register_name .req existing_register_name
b99bd4ef 2247
c19d1205 2248 If we find one, or if it looks sufficiently like one that we want to
d929913e 2249 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2250
d929913e 2251static bfd_boolean
c19d1205
ZW
2252create_register_alias (char * newname, char *p)
2253{
2254 struct reg_entry *old;
2255 char *oldname, *nbuf;
2256 size_t nlen;
b99bd4ef 2257
c19d1205
ZW
2258 /* The input scrubber ensures that whitespace after the mnemonic is
2259 collapsed to single spaces. */
2260 oldname = p;
2261 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2262 return FALSE;
b99bd4ef 2263
c19d1205
ZW
2264 oldname += 6;
2265 if (*oldname == '\0')
d929913e 2266 return FALSE;
b99bd4ef 2267
21d799b5 2268 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2269 if (!old)
b99bd4ef 2270 {
c19d1205 2271 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2272 return TRUE;
b99bd4ef
NC
2273 }
2274
c19d1205
ZW
2275 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2276 the desired alias name, and p points to its end. If not, then
2277 the desired alias name is in the global original_case_string. */
2278#ifdef TC_CASE_SENSITIVE
2279 nlen = p - newname;
2280#else
2281 newname = original_case_string;
2282 nlen = strlen (newname);
2283#endif
b99bd4ef 2284
29a2809e 2285 nbuf = xmemdup0 (newname, nlen);
b99bd4ef 2286
c19d1205
ZW
2287 /* Create aliases under the new name as stated; an all-lowercase
2288 version of the new name; and an all-uppercase version of the new
2289 name. */
d929913e
NC
2290 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2291 {
2292 for (p = nbuf; *p; p++)
2293 *p = TOUPPER (*p);
c19d1205 2294
d929913e
NC
2295 if (strncmp (nbuf, newname, nlen))
2296 {
2297 /* If this attempt to create an additional alias fails, do not bother
2298 trying to create the all-lower case alias. We will fail and issue
2299 a second, duplicate error message. This situation arises when the
2300 programmer does something like:
2301 foo .req r0
2302 Foo .req r1
2303 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2304 the artificial FOO alias because it has already been created by the
d929913e
NC
2305 first .req. */
2306 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
e1fa0163
NC
2307 {
2308 free (nbuf);
2309 return TRUE;
2310 }
d929913e 2311 }
c19d1205 2312
d929913e
NC
2313 for (p = nbuf; *p; p++)
2314 *p = TOLOWER (*p);
c19d1205 2315
d929913e
NC
2316 if (strncmp (nbuf, newname, nlen))
2317 insert_reg_alias (nbuf, old->number, old->type);
2318 }
c19d1205 2319
e1fa0163 2320 free (nbuf);
d929913e 2321 return TRUE;
b99bd4ef
NC
2322}
2323
dcbf9037
JB
2324/* Create a Neon typed/indexed register alias using directives, e.g.:
2325 X .dn d5.s32[1]
2326 Y .qn 6.s16
2327 Z .dn d7
2328 T .dn Z[0]
2329 These typed registers can be used instead of the types specified after the
2330 Neon mnemonic, so long as all operands given have types. Types can also be
2331 specified directly, e.g.:
5f4273c7 2332 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2333
c921be7d 2334static bfd_boolean
dcbf9037
JB
2335create_neon_reg_alias (char *newname, char *p)
2336{
2337 enum arm_reg_type basetype;
2338 struct reg_entry *basereg;
2339 struct reg_entry mybasereg;
2340 struct neon_type ntype;
2341 struct neon_typed_alias typeinfo;
12d6b0b7 2342 char *namebuf, *nameend ATTRIBUTE_UNUSED;
dcbf9037 2343 int namelen;
5f4273c7 2344
dcbf9037
JB
2345 typeinfo.defined = 0;
2346 typeinfo.eltype.type = NT_invtype;
2347 typeinfo.eltype.size = -1;
2348 typeinfo.index = -1;
5f4273c7 2349
dcbf9037 2350 nameend = p;
5f4273c7 2351
dcbf9037
JB
2352 if (strncmp (p, " .dn ", 5) == 0)
2353 basetype = REG_TYPE_VFD;
2354 else if (strncmp (p, " .qn ", 5) == 0)
2355 basetype = REG_TYPE_NQ;
2356 else
c921be7d 2357 return FALSE;
5f4273c7 2358
dcbf9037 2359 p += 5;
5f4273c7 2360
dcbf9037 2361 if (*p == '\0')
c921be7d 2362 return FALSE;
5f4273c7 2363
dcbf9037
JB
2364 basereg = arm_reg_parse_multi (&p);
2365
2366 if (basereg && basereg->type != basetype)
2367 {
2368 as_bad (_("bad type for register"));
c921be7d 2369 return FALSE;
dcbf9037
JB
2370 }
2371
2372 if (basereg == NULL)
2373 {
2374 expressionS exp;
2375 /* Try parsing as an integer. */
2376 my_get_expression (&exp, &p, GE_NO_PREFIX);
2377 if (exp.X_op != O_constant)
477330fc
RM
2378 {
2379 as_bad (_("expression must be constant"));
2380 return FALSE;
2381 }
dcbf9037
JB
2382 basereg = &mybasereg;
2383 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
477330fc 2384 : exp.X_add_number;
dcbf9037
JB
2385 basereg->neon = 0;
2386 }
2387
2388 if (basereg->neon)
2389 typeinfo = *basereg->neon;
2390
2391 if (parse_neon_type (&ntype, &p) == SUCCESS)
2392 {
2393 /* We got a type. */
2394 if (typeinfo.defined & NTA_HASTYPE)
477330fc
RM
2395 {
2396 as_bad (_("can't redefine the type of a register alias"));
2397 return FALSE;
2398 }
5f4273c7 2399
dcbf9037
JB
2400 typeinfo.defined |= NTA_HASTYPE;
2401 if (ntype.elems != 1)
477330fc
RM
2402 {
2403 as_bad (_("you must specify a single type only"));
2404 return FALSE;
2405 }
dcbf9037
JB
2406 typeinfo.eltype = ntype.el[0];
2407 }
5f4273c7 2408
dcbf9037
JB
2409 if (skip_past_char (&p, '[') == SUCCESS)
2410 {
2411 expressionS exp;
2412 /* We got a scalar index. */
5f4273c7 2413
dcbf9037 2414 if (typeinfo.defined & NTA_HASINDEX)
477330fc
RM
2415 {
2416 as_bad (_("can't redefine the index of a scalar alias"));
2417 return FALSE;
2418 }
5f4273c7 2419
dcbf9037 2420 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2421
dcbf9037 2422 if (exp.X_op != O_constant)
477330fc
RM
2423 {
2424 as_bad (_("scalar index must be constant"));
2425 return FALSE;
2426 }
5f4273c7 2427
dcbf9037
JB
2428 typeinfo.defined |= NTA_HASINDEX;
2429 typeinfo.index = exp.X_add_number;
5f4273c7 2430
dcbf9037 2431 if (skip_past_char (&p, ']') == FAIL)
477330fc
RM
2432 {
2433 as_bad (_("expecting ]"));
2434 return FALSE;
2435 }
dcbf9037
JB
2436 }
2437
15735687
NS
2438 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2439 the desired alias name, and p points to its end. If not, then
2440 the desired alias name is in the global original_case_string. */
2441#ifdef TC_CASE_SENSITIVE
dcbf9037 2442 namelen = nameend - newname;
15735687
NS
2443#else
2444 newname = original_case_string;
2445 namelen = strlen (newname);
2446#endif
2447
29a2809e 2448 namebuf = xmemdup0 (newname, namelen);
5f4273c7 2449
dcbf9037 2450 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2451 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2452
dcbf9037
JB
2453 /* Insert name in all uppercase. */
2454 for (p = namebuf; *p; p++)
2455 *p = TOUPPER (*p);
5f4273c7 2456
dcbf9037
JB
2457 if (strncmp (namebuf, newname, namelen))
2458 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2459 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2460
dcbf9037
JB
2461 /* Insert name in all lowercase. */
2462 for (p = namebuf; *p; p++)
2463 *p = TOLOWER (*p);
5f4273c7 2464
dcbf9037
JB
2465 if (strncmp (namebuf, newname, namelen))
2466 insert_neon_reg_alias (namebuf, basereg->number, basetype,
477330fc 2467 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2468
e1fa0163 2469 free (namebuf);
c921be7d 2470 return TRUE;
dcbf9037
JB
2471}
2472
c19d1205
ZW
2473/* Should never be called, as .req goes between the alias and the
2474 register name, not at the beginning of the line. */
c921be7d 2475
b99bd4ef 2476static void
c19d1205 2477s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2478{
c19d1205
ZW
2479 as_bad (_("invalid syntax for .req directive"));
2480}
b99bd4ef 2481
dcbf9037
JB
2482static void
2483s_dn (int a ATTRIBUTE_UNUSED)
2484{
2485 as_bad (_("invalid syntax for .dn directive"));
2486}
2487
2488static void
2489s_qn (int a ATTRIBUTE_UNUSED)
2490{
2491 as_bad (_("invalid syntax for .qn directive"));
2492}
2493
c19d1205
ZW
2494/* The .unreq directive deletes an alias which was previously defined
2495 by .req. For example:
b99bd4ef 2496
c19d1205
ZW
2497 my_alias .req r11
2498 .unreq my_alias */
b99bd4ef
NC
2499
2500static void
c19d1205 2501s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2502{
c19d1205
ZW
2503 char * name;
2504 char saved_char;
b99bd4ef 2505
c19d1205
ZW
2506 name = input_line_pointer;
2507
2508 while (*input_line_pointer != 0
2509 && *input_line_pointer != ' '
2510 && *input_line_pointer != '\n')
2511 ++input_line_pointer;
2512
2513 saved_char = *input_line_pointer;
2514 *input_line_pointer = 0;
2515
2516 if (!*name)
2517 as_bad (_("invalid syntax for .unreq directive"));
2518 else
2519 {
21d799b5 2520 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
477330fc 2521 name);
c19d1205
ZW
2522
2523 if (!reg)
2524 as_bad (_("unknown register alias '%s'"), name);
2525 else if (reg->builtin)
a1727c1a 2526 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
c19d1205
ZW
2527 name);
2528 else
2529 {
d929913e
NC
2530 char * p;
2531 char * nbuf;
2532
db0bc284 2533 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2534 free ((char *) reg->name);
477330fc
RM
2535 if (reg->neon)
2536 free (reg->neon);
c19d1205 2537 free (reg);
d929913e
NC
2538
2539 /* Also locate the all upper case and all lower case versions.
2540 Do not complain if we cannot find one or the other as it
2541 was probably deleted above. */
5f4273c7 2542
d929913e
NC
2543 nbuf = strdup (name);
2544 for (p = nbuf; *p; p++)
2545 *p = TOUPPER (*p);
21d799b5 2546 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2547 if (reg)
2548 {
db0bc284 2549 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2550 free ((char *) reg->name);
2551 if (reg->neon)
2552 free (reg->neon);
2553 free (reg);
2554 }
2555
2556 for (p = nbuf; *p; p++)
2557 *p = TOLOWER (*p);
21d799b5 2558 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2559 if (reg)
2560 {
db0bc284 2561 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2562 free ((char *) reg->name);
2563 if (reg->neon)
2564 free (reg->neon);
2565 free (reg);
2566 }
2567
2568 free (nbuf);
c19d1205
ZW
2569 }
2570 }
b99bd4ef 2571
c19d1205 2572 *input_line_pointer = saved_char;
b99bd4ef
NC
2573 demand_empty_rest_of_line ();
2574}
2575
c19d1205
ZW
2576/* Directives: Instruction set selection. */
2577
2578#ifdef OBJ_ELF
2579/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2580 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2581 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2582 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2583
cd000bff
DJ
2584/* Create a new mapping symbol for the transition to STATE. */
2585
2586static void
2587make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2588{
a737bd4d 2589 symbolS * symbolP;
c19d1205
ZW
2590 const char * symname;
2591 int type;
b99bd4ef 2592
c19d1205 2593 switch (state)
b99bd4ef 2594 {
c19d1205
ZW
2595 case MAP_DATA:
2596 symname = "$d";
2597 type = BSF_NO_FLAGS;
2598 break;
2599 case MAP_ARM:
2600 symname = "$a";
2601 type = BSF_NO_FLAGS;
2602 break;
2603 case MAP_THUMB:
2604 symname = "$t";
2605 type = BSF_NO_FLAGS;
2606 break;
c19d1205
ZW
2607 default:
2608 abort ();
2609 }
2610
cd000bff 2611 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2612 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2613
2614 switch (state)
2615 {
2616 case MAP_ARM:
2617 THUMB_SET_FUNC (symbolP, 0);
2618 ARM_SET_THUMB (symbolP, 0);
2619 ARM_SET_INTERWORK (symbolP, support_interwork);
2620 break;
2621
2622 case MAP_THUMB:
2623 THUMB_SET_FUNC (symbolP, 1);
2624 ARM_SET_THUMB (symbolP, 1);
2625 ARM_SET_INTERWORK (symbolP, support_interwork);
2626 break;
2627
2628 case MAP_DATA:
2629 default:
cd000bff
DJ
2630 break;
2631 }
2632
2633 /* Save the mapping symbols for future reference. Also check that
2634 we do not place two mapping symbols at the same offset within a
2635 frag. We'll handle overlap between frags in
2de7820f
JZ
2636 check_mapping_symbols.
2637
2638 If .fill or other data filling directive generates zero sized data,
2639 the mapping symbol for the following code will have the same value
2640 as the one generated for the data filling directive. In this case,
2641 we replace the old symbol with the new one at the same address. */
cd000bff
DJ
2642 if (value == 0)
2643 {
2de7820f
JZ
2644 if (frag->tc_frag_data.first_map != NULL)
2645 {
2646 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2647 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2648 }
cd000bff
DJ
2649 frag->tc_frag_data.first_map = symbolP;
2650 }
2651 if (frag->tc_frag_data.last_map != NULL)
0f020cef
JZ
2652 {
2653 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
0f020cef
JZ
2654 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2655 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2656 }
cd000bff
DJ
2657 frag->tc_frag_data.last_map = symbolP;
2658}
2659
2660/* We must sometimes convert a region marked as code to data during
2661 code alignment, if an odd number of bytes have to be padded. The
2662 code mapping symbol is pushed to an aligned address. */
2663
2664static void
2665insert_data_mapping_symbol (enum mstate state,
2666 valueT value, fragS *frag, offsetT bytes)
2667{
2668 /* If there was already a mapping symbol, remove it. */
2669 if (frag->tc_frag_data.last_map != NULL
2670 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2671 {
2672 symbolS *symp = frag->tc_frag_data.last_map;
2673
2674 if (value == 0)
2675 {
2676 know (frag->tc_frag_data.first_map == symp);
2677 frag->tc_frag_data.first_map = NULL;
2678 }
2679 frag->tc_frag_data.last_map = NULL;
2680 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2681 }
cd000bff
DJ
2682
2683 make_mapping_symbol (MAP_DATA, value, frag);
2684 make_mapping_symbol (state, value + bytes, frag);
2685}
2686
2687static void mapping_state_2 (enum mstate state, int max_chars);
2688
2689/* Set the mapping state to STATE. Only call this when about to
2690 emit some STATE bytes to the file. */
2691
4e9aaefb 2692#define TRANSITION(from, to) (mapstate == (from) && state == (to))
cd000bff
DJ
2693void
2694mapping_state (enum mstate state)
2695{
940b5ce0
DJ
2696 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2697
cd000bff
DJ
2698 if (mapstate == state)
2699 /* The mapping symbol has already been emitted.
2700 There is nothing else to do. */
2701 return;
49c62a33
NC
2702
2703 if (state == MAP_ARM || state == MAP_THUMB)
2704 /* PR gas/12931
2705 All ARM instructions require 4-byte alignment.
2706 (Almost) all Thumb instructions require 2-byte alignment.
2707
2708 When emitting instructions into any section, mark the section
2709 appropriately.
2710
2711 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2712 but themselves require 2-byte alignment; this applies to some
33eaf5de 2713 PC- relative forms. However, these cases will involve implicit
49c62a33
NC
2714 literal pool generation or an explicit .align >=2, both of
2715 which will cause the section to me marked with sufficient
2716 alignment. Thus, we don't handle those cases here. */
2717 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2718
2719 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
4e9aaefb 2720 /* This case will be evaluated later. */
cd000bff 2721 return;
cd000bff
DJ
2722
2723 mapping_state_2 (state, 0);
cd000bff
DJ
2724}
2725
2726/* Same as mapping_state, but MAX_CHARS bytes have already been
2727 allocated. Put the mapping symbol that far back. */
2728
2729static void
2730mapping_state_2 (enum mstate state, int max_chars)
2731{
940b5ce0
DJ
2732 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2733
2734 if (!SEG_NORMAL (now_seg))
2735 return;
2736
cd000bff
DJ
2737 if (mapstate == state)
2738 /* The mapping symbol has already been emitted.
2739 There is nothing else to do. */
2740 return;
2741
4e9aaefb
SA
2742 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2743 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2744 {
2745 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2746 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2747
2748 if (add_symbol)
2749 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2750 }
2751
cd000bff
DJ
2752 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2753 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205 2754}
4e9aaefb 2755#undef TRANSITION
c19d1205 2756#else
d3106081
NS
2757#define mapping_state(x) ((void)0)
2758#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2759#endif
2760
2761/* Find the real, Thumb encoded start of a Thumb function. */
2762
4343666d 2763#ifdef OBJ_COFF
c19d1205
ZW
2764static symbolS *
2765find_real_start (symbolS * symbolP)
2766{
2767 char * real_start;
2768 const char * name = S_GET_NAME (symbolP);
2769 symbolS * new_target;
2770
2771 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2772#define STUB_NAME ".real_start_of"
2773
2774 if (name == NULL)
2775 abort ();
2776
37f6032b
ZW
2777 /* The compiler may generate BL instructions to local labels because
2778 it needs to perform a branch to a far away location. These labels
2779 do not have a corresponding ".real_start_of" label. We check
2780 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2781 the ".real_start_of" convention for nonlocal branches. */
2782 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2783 return symbolP;
2784
e1fa0163 2785 real_start = concat (STUB_NAME, name, NULL);
c19d1205 2786 new_target = symbol_find (real_start);
e1fa0163 2787 free (real_start);
c19d1205
ZW
2788
2789 if (new_target == NULL)
2790 {
bd3ba5d1 2791 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2792 new_target = symbolP;
2793 }
2794
c19d1205
ZW
2795 return new_target;
2796}
4343666d 2797#endif
c19d1205
ZW
2798
2799static void
2800opcode_select (int width)
2801{
2802 switch (width)
2803 {
2804 case 16:
2805 if (! thumb_mode)
2806 {
e74cfd16 2807 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2808 as_bad (_("selected processor does not support THUMB opcodes"));
2809
2810 thumb_mode = 1;
2811 /* No need to force the alignment, since we will have been
2812 coming from ARM mode, which is word-aligned. */
2813 record_alignment (now_seg, 1);
2814 }
c19d1205
ZW
2815 break;
2816
2817 case 32:
2818 if (thumb_mode)
2819 {
e74cfd16 2820 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2821 as_bad (_("selected processor does not support ARM opcodes"));
2822
2823 thumb_mode = 0;
2824
2825 if (!need_pass_2)
2826 frag_align (2, 0, 0);
2827
2828 record_alignment (now_seg, 1);
2829 }
c19d1205
ZW
2830 break;
2831
2832 default:
2833 as_bad (_("invalid instruction size selected (%d)"), width);
2834 }
2835}
2836
2837static void
2838s_arm (int ignore ATTRIBUTE_UNUSED)
2839{
2840 opcode_select (32);
2841 demand_empty_rest_of_line ();
2842}
2843
2844static void
2845s_thumb (int ignore ATTRIBUTE_UNUSED)
2846{
2847 opcode_select (16);
2848 demand_empty_rest_of_line ();
2849}
2850
2851static void
2852s_code (int unused ATTRIBUTE_UNUSED)
2853{
2854 int temp;
2855
2856 temp = get_absolute_expression ();
2857 switch (temp)
2858 {
2859 case 16:
2860 case 32:
2861 opcode_select (temp);
2862 break;
2863
2864 default:
2865 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2866 }
2867}
2868
2869static void
2870s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2871{
2872 /* If we are not already in thumb mode go into it, EVEN if
2873 the target processor does not support thumb instructions.
2874 This is used by gcc/config/arm/lib1funcs.asm for example
2875 to compile interworking support functions even if the
2876 target processor should not support interworking. */
2877 if (! thumb_mode)
2878 {
2879 thumb_mode = 2;
2880 record_alignment (now_seg, 1);
2881 }
2882
2883 demand_empty_rest_of_line ();
2884}
2885
2886static void
2887s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2888{
2889 s_thumb (0);
2890
2891 /* The following label is the name/address of the start of a Thumb function.
2892 We need to know this for the interworking support. */
2893 label_is_thumb_function_name = TRUE;
2894}
2895
2896/* Perform a .set directive, but also mark the alias as
2897 being a thumb function. */
2898
2899static void
2900s_thumb_set (int equiv)
2901{
2902 /* XXX the following is a duplicate of the code for s_set() in read.c
2903 We cannot just call that code as we need to get at the symbol that
2904 is created. */
2905 char * name;
2906 char delim;
2907 char * end_name;
2908 symbolS * symbolP;
2909
2910 /* Especial apologies for the random logic:
2911 This just grew, and could be parsed much more simply!
2912 Dean - in haste. */
d02603dc 2913 delim = get_symbol_name (& name);
c19d1205 2914 end_name = input_line_pointer;
d02603dc 2915 (void) restore_line_pointer (delim);
c19d1205
ZW
2916
2917 if (*input_line_pointer != ',')
2918 {
2919 *end_name = 0;
2920 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2921 *end_name = delim;
2922 ignore_rest_of_line ();
2923 return;
2924 }
2925
2926 input_line_pointer++;
2927 *end_name = 0;
2928
2929 if (name[0] == '.' && name[1] == '\0')
2930 {
2931 /* XXX - this should not happen to .thumb_set. */
2932 abort ();
2933 }
2934
2935 if ((symbolP = symbol_find (name)) == NULL
2936 && (symbolP = md_undefined_symbol (name)) == NULL)
2937 {
2938#ifndef NO_LISTING
2939 /* When doing symbol listings, play games with dummy fragments living
2940 outside the normal fragment chain to record the file and line info
c19d1205 2941 for this symbol. */
b99bd4ef
NC
2942 if (listing & LISTING_SYMBOLS)
2943 {
2944 extern struct list_info_struct * listing_tail;
21d799b5 2945 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2946
2947 memset (dummy_frag, 0, sizeof (fragS));
2948 dummy_frag->fr_type = rs_fill;
2949 dummy_frag->line = listing_tail;
2950 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2951 dummy_frag->fr_symbol = symbolP;
2952 }
2953 else
2954#endif
2955 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2956
2957#ifdef OBJ_COFF
2958 /* "set" symbols are local unless otherwise specified. */
2959 SF_SET_LOCAL (symbolP);
2960#endif /* OBJ_COFF */
2961 } /* Make a new symbol. */
2962
2963 symbol_table_insert (symbolP);
2964
2965 * end_name = delim;
2966
2967 if (equiv
2968 && S_IS_DEFINED (symbolP)
2969 && S_GET_SEGMENT (symbolP) != reg_section)
2970 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2971
2972 pseudo_set (symbolP);
2973
2974 demand_empty_rest_of_line ();
2975
c19d1205 2976 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2977
2978 THUMB_SET_FUNC (symbolP, 1);
2979 ARM_SET_THUMB (symbolP, 1);
2980#if defined OBJ_ELF || defined OBJ_COFF
2981 ARM_SET_INTERWORK (symbolP, support_interwork);
2982#endif
2983}
2984
c19d1205 2985/* Directives: Mode selection. */
b99bd4ef 2986
c19d1205
ZW
2987/* .syntax [unified|divided] - choose the new unified syntax
2988 (same for Arm and Thumb encoding, modulo slight differences in what
2989 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2990static void
c19d1205 2991s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2992{
c19d1205
ZW
2993 char *name, delim;
2994
d02603dc 2995 delim = get_symbol_name (& name);
c19d1205
ZW
2996
2997 if (!strcasecmp (name, "unified"))
2998 unified_syntax = TRUE;
2999 else if (!strcasecmp (name, "divided"))
3000 unified_syntax = FALSE;
3001 else
3002 {
3003 as_bad (_("unrecognized syntax mode \"%s\""), name);
3004 return;
3005 }
d02603dc 3006 (void) restore_line_pointer (delim);
b99bd4ef
NC
3007 demand_empty_rest_of_line ();
3008}
3009
c19d1205
ZW
3010/* Directives: sectioning and alignment. */
3011
c19d1205
ZW
3012static void
3013s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 3014{
c19d1205
ZW
3015 /* We don't support putting frags in the BSS segment, we fake it by
3016 marking in_bss, then looking at s_skip for clues. */
3017 subseg_set (bss_section, 0);
3018 demand_empty_rest_of_line ();
cd000bff
DJ
3019
3020#ifdef md_elf_section_change_hook
3021 md_elf_section_change_hook ();
3022#endif
c19d1205 3023}
b99bd4ef 3024
c19d1205
ZW
3025static void
3026s_even (int ignore ATTRIBUTE_UNUSED)
3027{
3028 /* Never make frag if expect extra pass. */
3029 if (!need_pass_2)
3030 frag_align (1, 0, 0);
b99bd4ef 3031
c19d1205 3032 record_alignment (now_seg, 1);
b99bd4ef 3033
c19d1205 3034 demand_empty_rest_of_line ();
b99bd4ef
NC
3035}
3036
2e6976a8
DG
3037/* Directives: CodeComposer Studio. */
3038
3039/* .ref (for CodeComposer Studio syntax only). */
3040static void
3041s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3042{
3043 if (codecomposer_syntax)
3044 ignore_rest_of_line ();
3045 else
3046 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3047}
3048
3049/* If name is not NULL, then it is used for marking the beginning of a
2b0f3761 3050 function, whereas if it is NULL then it means the function end. */
2e6976a8
DG
3051static void
3052asmfunc_debug (const char * name)
3053{
3054 static const char * last_name = NULL;
3055
3056 if (name != NULL)
3057 {
3058 gas_assert (last_name == NULL);
3059 last_name = name;
3060
3061 if (debug_type == DEBUG_STABS)
3062 stabs_generate_asm_func (name, name);
3063 }
3064 else
3065 {
3066 gas_assert (last_name != NULL);
3067
3068 if (debug_type == DEBUG_STABS)
3069 stabs_generate_asm_endfunc (last_name, last_name);
3070
3071 last_name = NULL;
3072 }
3073}
3074
3075static void
3076s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3077{
3078 if (codecomposer_syntax)
3079 {
3080 switch (asmfunc_state)
3081 {
3082 case OUTSIDE_ASMFUNC:
3083 asmfunc_state = WAITING_ASMFUNC_NAME;
3084 break;
3085
3086 case WAITING_ASMFUNC_NAME:
3087 as_bad (_(".asmfunc repeated."));
3088 break;
3089
3090 case WAITING_ENDASMFUNC:
3091 as_bad (_(".asmfunc without function."));
3092 break;
3093 }
3094 demand_empty_rest_of_line ();
3095 }
3096 else
3097 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3098}
3099
3100static void
3101s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3102{
3103 if (codecomposer_syntax)
3104 {
3105 switch (asmfunc_state)
3106 {
3107 case OUTSIDE_ASMFUNC:
3108 as_bad (_(".endasmfunc without a .asmfunc."));
3109 break;
3110
3111 case WAITING_ASMFUNC_NAME:
3112 as_bad (_(".endasmfunc without function."));
3113 break;
3114
3115 case WAITING_ENDASMFUNC:
3116 asmfunc_state = OUTSIDE_ASMFUNC;
3117 asmfunc_debug (NULL);
3118 break;
3119 }
3120 demand_empty_rest_of_line ();
3121 }
3122 else
3123 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3124}
3125
3126static void
3127s_ccs_def (int name)
3128{
3129 if (codecomposer_syntax)
3130 s_globl (name);
3131 else
3132 as_bad (_(".def pseudo-op only available with -mccs flag."));
3133}
3134
c19d1205 3135/* Directives: Literal pools. */
a737bd4d 3136
c19d1205
ZW
3137static literal_pool *
3138find_literal_pool (void)
a737bd4d 3139{
c19d1205 3140 literal_pool * pool;
a737bd4d 3141
c19d1205 3142 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 3143 {
c19d1205
ZW
3144 if (pool->section == now_seg
3145 && pool->sub_section == now_subseg)
3146 break;
a737bd4d
NC
3147 }
3148
c19d1205 3149 return pool;
a737bd4d
NC
3150}
3151
c19d1205
ZW
3152static literal_pool *
3153find_or_make_literal_pool (void)
a737bd4d 3154{
c19d1205
ZW
3155 /* Next literal pool ID number. */
3156 static unsigned int latest_pool_num = 1;
3157 literal_pool * pool;
a737bd4d 3158
c19d1205 3159 pool = find_literal_pool ();
a737bd4d 3160
c19d1205 3161 if (pool == NULL)
a737bd4d 3162 {
c19d1205 3163 /* Create a new pool. */
325801bd 3164 pool = XNEW (literal_pool);
c19d1205
ZW
3165 if (! pool)
3166 return NULL;
a737bd4d 3167
c19d1205
ZW
3168 pool->next_free_entry = 0;
3169 pool->section = now_seg;
3170 pool->sub_section = now_subseg;
3171 pool->next = list_of_pools;
3172 pool->symbol = NULL;
8335d6aa 3173 pool->alignment = 2;
c19d1205
ZW
3174
3175 /* Add it to the list. */
3176 list_of_pools = pool;
a737bd4d 3177 }
a737bd4d 3178
c19d1205
ZW
3179 /* New pools, and emptied pools, will have a NULL symbol. */
3180 if (pool->symbol == NULL)
a737bd4d 3181 {
c19d1205
ZW
3182 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3183 (valueT) 0, &zero_address_frag);
3184 pool->id = latest_pool_num ++;
a737bd4d
NC
3185 }
3186
c19d1205
ZW
3187 /* Done. */
3188 return pool;
a737bd4d
NC
3189}
3190
c19d1205 3191/* Add the literal in the global 'inst'
5f4273c7 3192 structure to the relevant literal pool. */
b99bd4ef
NC
3193
3194static int
8335d6aa 3195add_to_lit_pool (unsigned int nbytes)
b99bd4ef 3196{
8335d6aa
JW
3197#define PADDING_SLOT 0x1
3198#define LIT_ENTRY_SIZE_MASK 0xFF
c19d1205 3199 literal_pool * pool;
8335d6aa
JW
3200 unsigned int entry, pool_size = 0;
3201 bfd_boolean padding_slot_p = FALSE;
e56c722b 3202 unsigned imm1 = 0;
8335d6aa
JW
3203 unsigned imm2 = 0;
3204
3205 if (nbytes == 8)
3206 {
3207 imm1 = inst.operands[1].imm;
3208 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3209 : inst.reloc.exp.X_unsigned ? 0
2569ceb0 3210 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
8335d6aa
JW
3211 if (target_big_endian)
3212 {
3213 imm1 = imm2;
3214 imm2 = inst.operands[1].imm;
3215 }
3216 }
b99bd4ef 3217
c19d1205
ZW
3218 pool = find_or_make_literal_pool ();
3219
3220 /* Check if this literal value is already in the pool. */
3221 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 3222 {
8335d6aa
JW
3223 if (nbytes == 4)
3224 {
3225 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3226 && (inst.reloc.exp.X_op == O_constant)
3227 && (pool->literals[entry].X_add_number
3228 == inst.reloc.exp.X_add_number)
3229 && (pool->literals[entry].X_md == nbytes)
3230 && (pool->literals[entry].X_unsigned
3231 == inst.reloc.exp.X_unsigned))
3232 break;
3233
3234 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3235 && (inst.reloc.exp.X_op == O_symbol)
3236 && (pool->literals[entry].X_add_number
3237 == inst.reloc.exp.X_add_number)
3238 && (pool->literals[entry].X_add_symbol
3239 == inst.reloc.exp.X_add_symbol)
3240 && (pool->literals[entry].X_op_symbol
3241 == inst.reloc.exp.X_op_symbol)
3242 && (pool->literals[entry].X_md == nbytes))
3243 break;
3244 }
3245 else if ((nbytes == 8)
3246 && !(pool_size & 0x7)
3247 && ((entry + 1) != pool->next_free_entry)
3248 && (pool->literals[entry].X_op == O_constant)
19f2f6a9 3249 && (pool->literals[entry].X_add_number == (offsetT) imm1)
8335d6aa
JW
3250 && (pool->literals[entry].X_unsigned
3251 == inst.reloc.exp.X_unsigned)
3252 && (pool->literals[entry + 1].X_op == O_constant)
19f2f6a9 3253 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
8335d6aa
JW
3254 && (pool->literals[entry + 1].X_unsigned
3255 == inst.reloc.exp.X_unsigned))
c19d1205
ZW
3256 break;
3257
8335d6aa
JW
3258 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3259 if (padding_slot_p && (nbytes == 4))
c19d1205 3260 break;
8335d6aa
JW
3261
3262 pool_size += 4;
b99bd4ef
NC
3263 }
3264
c19d1205
ZW
3265 /* Do we need to create a new entry? */
3266 if (entry == pool->next_free_entry)
3267 {
3268 if (entry >= MAX_LITERAL_POOL_SIZE)
3269 {
3270 inst.error = _("literal pool overflow");
3271 return FAIL;
3272 }
3273
8335d6aa
JW
3274 if (nbytes == 8)
3275 {
3276 /* For 8-byte entries, we align to an 8-byte boundary,
3277 and split it into two 4-byte entries, because on 32-bit
3278 host, 8-byte constants are treated as big num, thus
3279 saved in "generic_bignum" which will be overwritten
3280 by later assignments.
3281
3282 We also need to make sure there is enough space for
3283 the split.
3284
3285 We also check to make sure the literal operand is a
3286 constant number. */
19f2f6a9
JW
3287 if (!(inst.reloc.exp.X_op == O_constant
3288 || inst.reloc.exp.X_op == O_big))
8335d6aa
JW
3289 {
3290 inst.error = _("invalid type for literal pool");
3291 return FAIL;
3292 }
3293 else if (pool_size & 0x7)
3294 {
3295 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3296 {
3297 inst.error = _("literal pool overflow");
3298 return FAIL;
3299 }
3300
3301 pool->literals[entry] = inst.reloc.exp;
a6684f0d 3302 pool->literals[entry].X_op = O_constant;
8335d6aa
JW
3303 pool->literals[entry].X_add_number = 0;
3304 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3305 pool->next_free_entry += 1;
3306 pool_size += 4;
3307 }
3308 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3309 {
3310 inst.error = _("literal pool overflow");
3311 return FAIL;
3312 }
3313
3314 pool->literals[entry] = inst.reloc.exp;
3315 pool->literals[entry].X_op = O_constant;
3316 pool->literals[entry].X_add_number = imm1;
3317 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3318 pool->literals[entry++].X_md = 4;
3319 pool->literals[entry] = inst.reloc.exp;
3320 pool->literals[entry].X_op = O_constant;
3321 pool->literals[entry].X_add_number = imm2;
3322 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3323 pool->literals[entry].X_md = 4;
3324 pool->alignment = 3;
3325 pool->next_free_entry += 1;
3326 }
3327 else
3328 {
3329 pool->literals[entry] = inst.reloc.exp;
3330 pool->literals[entry].X_md = 4;
3331 }
3332
a8040cf2
NC
3333#ifdef OBJ_ELF
3334 /* PR ld/12974: Record the location of the first source line to reference
3335 this entry in the literal pool. If it turns out during linking that the
3336 symbol does not exist we will be able to give an accurate line number for
3337 the (first use of the) missing reference. */
3338 if (debug_type == DEBUG_DWARF2)
3339 dwarf2_where (pool->locs + entry);
3340#endif
c19d1205
ZW
3341 pool->next_free_entry += 1;
3342 }
8335d6aa
JW
3343 else if (padding_slot_p)
3344 {
3345 pool->literals[entry] = inst.reloc.exp;
3346 pool->literals[entry].X_md = nbytes;
3347 }
b99bd4ef 3348
c19d1205 3349 inst.reloc.exp.X_op = O_symbol;
8335d6aa 3350 inst.reloc.exp.X_add_number = pool_size;
c19d1205 3351 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3352
c19d1205 3353 return SUCCESS;
b99bd4ef
NC
3354}
3355
2e6976a8 3356bfd_boolean
2e57ce7b 3357tc_start_label_without_colon (void)
2e6976a8
DG
3358{
3359 bfd_boolean ret = TRUE;
3360
3361 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3362 {
2e57ce7b 3363 const char *label = input_line_pointer;
2e6976a8
DG
3364
3365 while (!is_end_of_line[(int) label[-1]])
3366 --label;
3367
3368 if (*label == '.')
3369 {
3370 as_bad (_("Invalid label '%s'"), label);
3371 ret = FALSE;
3372 }
3373
3374 asmfunc_debug (label);
3375
3376 asmfunc_state = WAITING_ENDASMFUNC;
3377 }
3378
3379 return ret;
3380}
3381
c19d1205 3382/* Can't use symbol_new here, so have to create a symbol and then at
33eaf5de 3383 a later date assign it a value. That's what these functions do. */
e16bb312 3384
c19d1205
ZW
3385static void
3386symbol_locate (symbolS * symbolP,
3387 const char * name, /* It is copied, the caller can modify. */
3388 segT segment, /* Segment identifier (SEG_<something>). */
3389 valueT valu, /* Symbol value. */
3390 fragS * frag) /* Associated fragment. */
3391{
e57e6ddc 3392 size_t name_length;
c19d1205 3393 char * preserved_copy_of_name;
e16bb312 3394
c19d1205
ZW
3395 name_length = strlen (name) + 1; /* +1 for \0. */
3396 obstack_grow (&notes, name, name_length);
21d799b5 3397 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3398
c19d1205
ZW
3399#ifdef tc_canonicalize_symbol_name
3400 preserved_copy_of_name =
3401 tc_canonicalize_symbol_name (preserved_copy_of_name);
3402#endif
b99bd4ef 3403
c19d1205 3404 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3405
c19d1205
ZW
3406 S_SET_SEGMENT (symbolP, segment);
3407 S_SET_VALUE (symbolP, valu);
3408 symbol_clear_list_pointers (symbolP);
b99bd4ef 3409
c19d1205 3410 symbol_set_frag (symbolP, frag);
b99bd4ef 3411
c19d1205
ZW
3412 /* Link to end of symbol chain. */
3413 {
3414 extern int symbol_table_frozen;
b99bd4ef 3415
c19d1205
ZW
3416 if (symbol_table_frozen)
3417 abort ();
3418 }
b99bd4ef 3419
c19d1205 3420 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3421
c19d1205 3422 obj_symbol_new_hook (symbolP);
b99bd4ef 3423
c19d1205
ZW
3424#ifdef tc_symbol_new_hook
3425 tc_symbol_new_hook (symbolP);
3426#endif
3427
3428#ifdef DEBUG_SYMS
3429 verify_symbol_chain (symbol_rootP, symbol_lastP);
3430#endif /* DEBUG_SYMS */
b99bd4ef
NC
3431}
3432
c19d1205
ZW
3433static void
3434s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3435{
c19d1205
ZW
3436 unsigned int entry;
3437 literal_pool * pool;
3438 char sym_name[20];
b99bd4ef 3439
c19d1205
ZW
3440 pool = find_literal_pool ();
3441 if (pool == NULL
3442 || pool->symbol == NULL
3443 || pool->next_free_entry == 0)
3444 return;
b99bd4ef 3445
c19d1205
ZW
3446 /* Align pool as you have word accesses.
3447 Only make a frag if we have to. */
3448 if (!need_pass_2)
8335d6aa 3449 frag_align (pool->alignment, 0, 0);
b99bd4ef 3450
c19d1205 3451 record_alignment (now_seg, 2);
b99bd4ef 3452
aaca88ef 3453#ifdef OBJ_ELF
47fc6e36
WN
3454 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3455 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
aaca88ef 3456#endif
c19d1205 3457 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3458
c19d1205
ZW
3459 symbol_locate (pool->symbol, sym_name, now_seg,
3460 (valueT) frag_now_fix (), frag_now);
3461 symbol_table_insert (pool->symbol);
b99bd4ef 3462
c19d1205 3463 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3464
c19d1205
ZW
3465#if defined OBJ_COFF || defined OBJ_ELF
3466 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3467#endif
6c43fab6 3468
c19d1205 3469 for (entry = 0; entry < pool->next_free_entry; entry ++)
a8040cf2
NC
3470 {
3471#ifdef OBJ_ELF
3472 if (debug_type == DEBUG_DWARF2)
3473 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3474#endif
3475 /* First output the expression in the instruction to the pool. */
8335d6aa
JW
3476 emit_expr (&(pool->literals[entry]),
3477 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
a8040cf2 3478 }
b99bd4ef 3479
c19d1205
ZW
3480 /* Mark the pool as empty. */
3481 pool->next_free_entry = 0;
3482 pool->symbol = NULL;
b99bd4ef
NC
3483}
3484
c19d1205
ZW
3485#ifdef OBJ_ELF
3486/* Forward declarations for functions below, in the MD interface
3487 section. */
3488static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3489static valueT create_unwind_entry (int);
3490static void start_unwind_section (const segT, int);
3491static void add_unwind_opcode (valueT, int);
3492static void flush_pending_unwind (void);
b99bd4ef 3493
c19d1205 3494/* Directives: Data. */
b99bd4ef 3495
c19d1205
ZW
3496static void
3497s_arm_elf_cons (int nbytes)
3498{
3499 expressionS exp;
b99bd4ef 3500
c19d1205
ZW
3501#ifdef md_flush_pending_output
3502 md_flush_pending_output ();
3503#endif
b99bd4ef 3504
c19d1205 3505 if (is_it_end_of_statement ())
b99bd4ef 3506 {
c19d1205
ZW
3507 demand_empty_rest_of_line ();
3508 return;
b99bd4ef
NC
3509 }
3510
c19d1205
ZW
3511#ifdef md_cons_align
3512 md_cons_align (nbytes);
3513#endif
b99bd4ef 3514
c19d1205
ZW
3515 mapping_state (MAP_DATA);
3516 do
b99bd4ef 3517 {
c19d1205
ZW
3518 int reloc;
3519 char *base = input_line_pointer;
b99bd4ef 3520
c19d1205 3521 expression (& exp);
b99bd4ef 3522
c19d1205
ZW
3523 if (exp.X_op != O_symbol)
3524 emit_expr (&exp, (unsigned int) nbytes);
3525 else
3526 {
3527 char *before_reloc = input_line_pointer;
3528 reloc = parse_reloc (&input_line_pointer);
3529 if (reloc == -1)
3530 {
3531 as_bad (_("unrecognized relocation suffix"));
3532 ignore_rest_of_line ();
3533 return;
3534 }
3535 else if (reloc == BFD_RELOC_UNUSED)
3536 emit_expr (&exp, (unsigned int) nbytes);
3537 else
3538 {
21d799b5 3539 reloc_howto_type *howto = (reloc_howto_type *)
477330fc
RM
3540 bfd_reloc_type_lookup (stdoutput,
3541 (bfd_reloc_code_real_type) reloc);
c19d1205 3542 int size = bfd_get_reloc_size (howto);
b99bd4ef 3543
2fc8bdac
ZW
3544 if (reloc == BFD_RELOC_ARM_PLT32)
3545 {
3546 as_bad (_("(plt) is only valid on branch targets"));
3547 reloc = BFD_RELOC_UNUSED;
3548 size = 0;
3549 }
3550
c19d1205 3551 if (size > nbytes)
2fc8bdac 3552 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3553 howto->name, nbytes);
3554 else
3555 {
3556 /* We've parsed an expression stopping at O_symbol.
3557 But there may be more expression left now that we
3558 have parsed the relocation marker. Parse it again.
3559 XXX Surely there is a cleaner way to do this. */
3560 char *p = input_line_pointer;
3561 int offset;
325801bd 3562 char *save_buf = XNEWVEC (char, input_line_pointer - base);
e1fa0163 3563
c19d1205
ZW
3564 memcpy (save_buf, base, input_line_pointer - base);
3565 memmove (base + (input_line_pointer - before_reloc),
3566 base, before_reloc - base);
3567
3568 input_line_pointer = base + (input_line_pointer-before_reloc);
3569 expression (&exp);
3570 memcpy (base, save_buf, p - base);
3571
3572 offset = nbytes - size;
4b1a927e
AM
3573 p = frag_more (nbytes);
3574 memset (p, 0, nbytes);
c19d1205 3575 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3576 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
e1fa0163 3577 free (save_buf);
c19d1205
ZW
3578 }
3579 }
3580 }
b99bd4ef 3581 }
c19d1205 3582 while (*input_line_pointer++ == ',');
b99bd4ef 3583
c19d1205
ZW
3584 /* Put terminator back into stream. */
3585 input_line_pointer --;
3586 demand_empty_rest_of_line ();
b99bd4ef
NC
3587}
3588
c921be7d
NC
3589/* Emit an expression containing a 32-bit thumb instruction.
3590 Implementation based on put_thumb32_insn. */
3591
3592static void
3593emit_thumb32_expr (expressionS * exp)
3594{
3595 expressionS exp_high = *exp;
3596
3597 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3598 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3599 exp->X_add_number &= 0xffff;
3600 emit_expr (exp, (unsigned int) THUMB_SIZE);
3601}
3602
3603/* Guess the instruction size based on the opcode. */
3604
3605static int
3606thumb_insn_size (int opcode)
3607{
3608 if ((unsigned int) opcode < 0xe800u)
3609 return 2;
3610 else if ((unsigned int) opcode >= 0xe8000000u)
3611 return 4;
3612 else
3613 return 0;
3614}
3615
3616static bfd_boolean
3617emit_insn (expressionS *exp, int nbytes)
3618{
3619 int size = 0;
3620
3621 if (exp->X_op == O_constant)
3622 {
3623 size = nbytes;
3624
3625 if (size == 0)
3626 size = thumb_insn_size (exp->X_add_number);
3627
3628 if (size != 0)
3629 {
3630 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3631 {
3632 as_bad (_(".inst.n operand too big. "\
3633 "Use .inst.w instead"));
3634 size = 0;
3635 }
3636 else
3637 {
3638 if (now_it.state == AUTOMATIC_IT_BLOCK)
3639 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3640 else
3641 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3642
3643 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3644 emit_thumb32_expr (exp);
3645 else
3646 emit_expr (exp, (unsigned int) size);
3647
3648 it_fsm_post_encode ();
3649 }
3650 }
3651 else
3652 as_bad (_("cannot determine Thumb instruction size. " \
3653 "Use .inst.n/.inst.w instead"));
3654 }
3655 else
3656 as_bad (_("constant expression required"));
3657
3658 return (size != 0);
3659}
3660
3661/* Like s_arm_elf_cons but do not use md_cons_align and
3662 set the mapping state to MAP_ARM/MAP_THUMB. */
3663
3664static void
3665s_arm_elf_inst (int nbytes)
3666{
3667 if (is_it_end_of_statement ())
3668 {
3669 demand_empty_rest_of_line ();
3670 return;
3671 }
3672
3673 /* Calling mapping_state () here will not change ARM/THUMB,
3674 but will ensure not to be in DATA state. */
3675
3676 if (thumb_mode)
3677 mapping_state (MAP_THUMB);
3678 else
3679 {
3680 if (nbytes != 0)
3681 {
3682 as_bad (_("width suffixes are invalid in ARM mode"));
3683 ignore_rest_of_line ();
3684 return;
3685 }
3686
3687 nbytes = 4;
3688
3689 mapping_state (MAP_ARM);
3690 }
3691
3692 do
3693 {
3694 expressionS exp;
3695
3696 expression (& exp);
3697
3698 if (! emit_insn (& exp, nbytes))
3699 {
3700 ignore_rest_of_line ();
3701 return;
3702 }
3703 }
3704 while (*input_line_pointer++ == ',');
3705
3706 /* Put terminator back into stream. */
3707 input_line_pointer --;
3708 demand_empty_rest_of_line ();
3709}
b99bd4ef 3710
c19d1205 3711/* Parse a .rel31 directive. */
b99bd4ef 3712
c19d1205
ZW
3713static void
3714s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3715{
3716 expressionS exp;
3717 char *p;
3718 valueT highbit;
b99bd4ef 3719
c19d1205
ZW
3720 highbit = 0;
3721 if (*input_line_pointer == '1')
3722 highbit = 0x80000000;
3723 else if (*input_line_pointer != '0')
3724 as_bad (_("expected 0 or 1"));
b99bd4ef 3725
c19d1205
ZW
3726 input_line_pointer++;
3727 if (*input_line_pointer != ',')
3728 as_bad (_("missing comma"));
3729 input_line_pointer++;
b99bd4ef 3730
c19d1205
ZW
3731#ifdef md_flush_pending_output
3732 md_flush_pending_output ();
3733#endif
b99bd4ef 3734
c19d1205
ZW
3735#ifdef md_cons_align
3736 md_cons_align (4);
3737#endif
b99bd4ef 3738
c19d1205 3739 mapping_state (MAP_DATA);
b99bd4ef 3740
c19d1205 3741 expression (&exp);
b99bd4ef 3742
c19d1205
ZW
3743 p = frag_more (4);
3744 md_number_to_chars (p, highbit, 4);
3745 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3746 BFD_RELOC_ARM_PREL31);
b99bd4ef 3747
c19d1205 3748 demand_empty_rest_of_line ();
b99bd4ef
NC
3749}
3750
c19d1205 3751/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3752
c19d1205 3753/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3754
c19d1205
ZW
3755static void
3756s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3757{
3758 demand_empty_rest_of_line ();
921e5f0a
PB
3759 if (unwind.proc_start)
3760 {
c921be7d 3761 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3762 return;
3763 }
3764
c19d1205
ZW
3765 /* Mark the start of the function. */
3766 unwind.proc_start = expr_build_dot ();
b99bd4ef 3767
c19d1205
ZW
3768 /* Reset the rest of the unwind info. */
3769 unwind.opcode_count = 0;
3770 unwind.table_entry = NULL;
3771 unwind.personality_routine = NULL;
3772 unwind.personality_index = -1;
3773 unwind.frame_size = 0;
3774 unwind.fp_offset = 0;
fdfde340 3775 unwind.fp_reg = REG_SP;
c19d1205
ZW
3776 unwind.fp_used = 0;
3777 unwind.sp_restored = 0;
3778}
b99bd4ef 3779
b99bd4ef 3780
c19d1205
ZW
3781/* Parse a handlerdata directive. Creates the exception handling table entry
3782 for the function. */
b99bd4ef 3783
c19d1205
ZW
3784static void
3785s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3786{
3787 demand_empty_rest_of_line ();
921e5f0a 3788 if (!unwind.proc_start)
c921be7d 3789 as_bad (MISSING_FNSTART);
921e5f0a 3790
c19d1205 3791 if (unwind.table_entry)
6decc662 3792 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3793
c19d1205
ZW
3794 create_unwind_entry (1);
3795}
a737bd4d 3796
c19d1205 3797/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3798
c19d1205
ZW
3799static void
3800s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3801{
3802 long where;
3803 char *ptr;
3804 valueT val;
940b5ce0 3805 unsigned int marked_pr_dependency;
f02232aa 3806
c19d1205 3807 demand_empty_rest_of_line ();
f02232aa 3808
921e5f0a
PB
3809 if (!unwind.proc_start)
3810 {
c921be7d 3811 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3812 return;
3813 }
3814
c19d1205
ZW
3815 /* Add eh table entry. */
3816 if (unwind.table_entry == NULL)
3817 val = create_unwind_entry (0);
3818 else
3819 val = 0;
f02232aa 3820
c19d1205
ZW
3821 /* Add index table entry. This is two words. */
3822 start_unwind_section (unwind.saved_seg, 1);
3823 frag_align (2, 0, 0);
3824 record_alignment (now_seg, 2);
b99bd4ef 3825
c19d1205 3826 ptr = frag_more (8);
5011093d 3827 memset (ptr, 0, 8);
c19d1205 3828 where = frag_now_fix () - 8;
f02232aa 3829
c19d1205
ZW
3830 /* Self relative offset of the function start. */
3831 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3832 BFD_RELOC_ARM_PREL31);
f02232aa 3833
c19d1205
ZW
3834 /* Indicate dependency on EHABI-defined personality routines to the
3835 linker, if it hasn't been done already. */
940b5ce0
DJ
3836 marked_pr_dependency
3837 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3838 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3839 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3840 {
5f4273c7
NC
3841 static const char *const name[] =
3842 {
3843 "__aeabi_unwind_cpp_pr0",
3844 "__aeabi_unwind_cpp_pr1",
3845 "__aeabi_unwind_cpp_pr2"
3846 };
c19d1205
ZW
3847 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3848 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3849 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3850 |= 1 << unwind.personality_index;
c19d1205 3851 }
f02232aa 3852
c19d1205
ZW
3853 if (val)
3854 /* Inline exception table entry. */
3855 md_number_to_chars (ptr + 4, val, 4);
3856 else
3857 /* Self relative offset of the table entry. */
3858 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3859 BFD_RELOC_ARM_PREL31);
f02232aa 3860
c19d1205
ZW
3861 /* Restore the original section. */
3862 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3863
3864 unwind.proc_start = NULL;
c19d1205 3865}
f02232aa 3866
f02232aa 3867
c19d1205 3868/* Parse an unwind_cantunwind directive. */
b99bd4ef 3869
c19d1205
ZW
3870static void
3871s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3872{
3873 demand_empty_rest_of_line ();
921e5f0a 3874 if (!unwind.proc_start)
c921be7d 3875 as_bad (MISSING_FNSTART);
921e5f0a 3876
c19d1205
ZW
3877 if (unwind.personality_routine || unwind.personality_index != -1)
3878 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3879
c19d1205
ZW
3880 unwind.personality_index = -2;
3881}
b99bd4ef 3882
b99bd4ef 3883
c19d1205 3884/* Parse a personalityindex directive. */
b99bd4ef 3885
c19d1205
ZW
3886static void
3887s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3888{
3889 expressionS exp;
b99bd4ef 3890
921e5f0a 3891 if (!unwind.proc_start)
c921be7d 3892 as_bad (MISSING_FNSTART);
921e5f0a 3893
c19d1205
ZW
3894 if (unwind.personality_routine || unwind.personality_index != -1)
3895 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3896
c19d1205 3897 expression (&exp);
b99bd4ef 3898
c19d1205
ZW
3899 if (exp.X_op != O_constant
3900 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3901 {
c19d1205
ZW
3902 as_bad (_("bad personality routine number"));
3903 ignore_rest_of_line ();
3904 return;
b99bd4ef
NC
3905 }
3906
c19d1205 3907 unwind.personality_index = exp.X_add_number;
b99bd4ef 3908
c19d1205
ZW
3909 demand_empty_rest_of_line ();
3910}
e16bb312 3911
e16bb312 3912
c19d1205 3913/* Parse a personality directive. */
e16bb312 3914
c19d1205
ZW
3915static void
3916s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3917{
3918 char *name, *p, c;
a737bd4d 3919
921e5f0a 3920 if (!unwind.proc_start)
c921be7d 3921 as_bad (MISSING_FNSTART);
921e5f0a 3922
c19d1205
ZW
3923 if (unwind.personality_routine || unwind.personality_index != -1)
3924 as_bad (_("duplicate .personality directive"));
a737bd4d 3925
d02603dc 3926 c = get_symbol_name (& name);
c19d1205 3927 p = input_line_pointer;
d02603dc
NC
3928 if (c == '"')
3929 ++ input_line_pointer;
c19d1205
ZW
3930 unwind.personality_routine = symbol_find_or_make (name);
3931 *p = c;
3932 demand_empty_rest_of_line ();
3933}
e16bb312 3934
e16bb312 3935
c19d1205 3936/* Parse a directive saving core registers. */
e16bb312 3937
c19d1205
ZW
3938static void
3939s_arm_unwind_save_core (void)
e16bb312 3940{
c19d1205
ZW
3941 valueT op;
3942 long range;
3943 int n;
e16bb312 3944
c19d1205
ZW
3945 range = parse_reg_list (&input_line_pointer);
3946 if (range == FAIL)
e16bb312 3947 {
c19d1205
ZW
3948 as_bad (_("expected register list"));
3949 ignore_rest_of_line ();
3950 return;
3951 }
e16bb312 3952
c19d1205 3953 demand_empty_rest_of_line ();
e16bb312 3954
c19d1205
ZW
3955 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3956 into .unwind_save {..., sp...}. We aren't bothered about the value of
3957 ip because it is clobbered by calls. */
3958 if (unwind.sp_restored && unwind.fp_reg == 12
3959 && (range & 0x3000) == 0x1000)
3960 {
3961 unwind.opcode_count--;
3962 unwind.sp_restored = 0;
3963 range = (range | 0x2000) & ~0x1000;
3964 unwind.pending_offset = 0;
3965 }
e16bb312 3966
01ae4198
DJ
3967 /* Pop r4-r15. */
3968 if (range & 0xfff0)
c19d1205 3969 {
01ae4198
DJ
3970 /* See if we can use the short opcodes. These pop a block of up to 8
3971 registers starting with r4, plus maybe r14. */
3972 for (n = 0; n < 8; n++)
3973 {
3974 /* Break at the first non-saved register. */
3975 if ((range & (1 << (n + 4))) == 0)
3976 break;
3977 }
3978 /* See if there are any other bits set. */
3979 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3980 {
3981 /* Use the long form. */
3982 op = 0x8000 | ((range >> 4) & 0xfff);
3983 add_unwind_opcode (op, 2);
3984 }
0dd132b6 3985 else
01ae4198
DJ
3986 {
3987 /* Use the short form. */
3988 if (range & 0x4000)
3989 op = 0xa8; /* Pop r14. */
3990 else
3991 op = 0xa0; /* Do not pop r14. */
3992 op |= (n - 1);
3993 add_unwind_opcode (op, 1);
3994 }
c19d1205 3995 }
0dd132b6 3996
c19d1205
ZW
3997 /* Pop r0-r3. */
3998 if (range & 0xf)
3999 {
4000 op = 0xb100 | (range & 0xf);
4001 add_unwind_opcode (op, 2);
0dd132b6
NC
4002 }
4003
c19d1205
ZW
4004 /* Record the number of bytes pushed. */
4005 for (n = 0; n < 16; n++)
4006 {
4007 if (range & (1 << n))
4008 unwind.frame_size += 4;
4009 }
0dd132b6
NC
4010}
4011
c19d1205
ZW
4012
4013/* Parse a directive saving FPA registers. */
b99bd4ef
NC
4014
4015static void
c19d1205 4016s_arm_unwind_save_fpa (int reg)
b99bd4ef 4017{
c19d1205
ZW
4018 expressionS exp;
4019 int num_regs;
4020 valueT op;
b99bd4ef 4021
c19d1205
ZW
4022 /* Get Number of registers to transfer. */
4023 if (skip_past_comma (&input_line_pointer) != FAIL)
4024 expression (&exp);
4025 else
4026 exp.X_op = O_illegal;
b99bd4ef 4027
c19d1205 4028 if (exp.X_op != O_constant)
b99bd4ef 4029 {
c19d1205
ZW
4030 as_bad (_("expected , <constant>"));
4031 ignore_rest_of_line ();
b99bd4ef
NC
4032 return;
4033 }
4034
c19d1205
ZW
4035 num_regs = exp.X_add_number;
4036
4037 if (num_regs < 1 || num_regs > 4)
b99bd4ef 4038 {
c19d1205
ZW
4039 as_bad (_("number of registers must be in the range [1:4]"));
4040 ignore_rest_of_line ();
b99bd4ef
NC
4041 return;
4042 }
4043
c19d1205 4044 demand_empty_rest_of_line ();
b99bd4ef 4045
c19d1205
ZW
4046 if (reg == 4)
4047 {
4048 /* Short form. */
4049 op = 0xb4 | (num_regs - 1);
4050 add_unwind_opcode (op, 1);
4051 }
b99bd4ef
NC
4052 else
4053 {
c19d1205
ZW
4054 /* Long form. */
4055 op = 0xc800 | (reg << 4) | (num_regs - 1);
4056 add_unwind_opcode (op, 2);
b99bd4ef 4057 }
c19d1205 4058 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
4059}
4060
c19d1205 4061
fa073d69
MS
4062/* Parse a directive saving VFP registers for ARMv6 and above. */
4063
4064static void
4065s_arm_unwind_save_vfp_armv6 (void)
4066{
4067 int count;
4068 unsigned int start;
4069 valueT op;
4070 int num_vfpv3_regs = 0;
4071 int num_regs_below_16;
4072
4073 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4074 if (count == FAIL)
4075 {
4076 as_bad (_("expected register list"));
4077 ignore_rest_of_line ();
4078 return;
4079 }
4080
4081 demand_empty_rest_of_line ();
4082
4083 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4084 than FSTMX/FLDMX-style ones). */
4085
4086 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4087 if (start >= 16)
4088 num_vfpv3_regs = count;
4089 else if (start + count > 16)
4090 num_vfpv3_regs = start + count - 16;
4091
4092 if (num_vfpv3_regs > 0)
4093 {
4094 int start_offset = start > 16 ? start - 16 : 0;
4095 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4096 add_unwind_opcode (op, 2);
4097 }
4098
4099 /* Generate opcode for registers numbered in the range 0 .. 15. */
4100 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 4101 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
4102 if (num_regs_below_16 > 0)
4103 {
4104 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4105 add_unwind_opcode (op, 2);
4106 }
4107
4108 unwind.frame_size += count * 8;
4109}
4110
4111
4112/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
4113
4114static void
c19d1205 4115s_arm_unwind_save_vfp (void)
b99bd4ef 4116{
c19d1205 4117 int count;
ca3f61f7 4118 unsigned int reg;
c19d1205 4119 valueT op;
b99bd4ef 4120
5287ad62 4121 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 4122 if (count == FAIL)
b99bd4ef 4123 {
c19d1205
ZW
4124 as_bad (_("expected register list"));
4125 ignore_rest_of_line ();
b99bd4ef
NC
4126 return;
4127 }
4128
c19d1205 4129 demand_empty_rest_of_line ();
b99bd4ef 4130
c19d1205 4131 if (reg == 8)
b99bd4ef 4132 {
c19d1205
ZW
4133 /* Short form. */
4134 op = 0xb8 | (count - 1);
4135 add_unwind_opcode (op, 1);
b99bd4ef 4136 }
c19d1205 4137 else
b99bd4ef 4138 {
c19d1205
ZW
4139 /* Long form. */
4140 op = 0xb300 | (reg << 4) | (count - 1);
4141 add_unwind_opcode (op, 2);
b99bd4ef 4142 }
c19d1205
ZW
4143 unwind.frame_size += count * 8 + 4;
4144}
b99bd4ef 4145
b99bd4ef 4146
c19d1205
ZW
4147/* Parse a directive saving iWMMXt data registers. */
4148
4149static void
4150s_arm_unwind_save_mmxwr (void)
4151{
4152 int reg;
4153 int hi_reg;
4154 int i;
4155 unsigned mask = 0;
4156 valueT op;
b99bd4ef 4157
c19d1205
ZW
4158 if (*input_line_pointer == '{')
4159 input_line_pointer++;
b99bd4ef 4160
c19d1205 4161 do
b99bd4ef 4162 {
dcbf9037 4163 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 4164
c19d1205 4165 if (reg == FAIL)
b99bd4ef 4166 {
9b7132d3 4167 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 4168 goto error;
b99bd4ef
NC
4169 }
4170
c19d1205
ZW
4171 if (mask >> reg)
4172 as_tsktsk (_("register list not in ascending order"));
4173 mask |= 1 << reg;
b99bd4ef 4174
c19d1205
ZW
4175 if (*input_line_pointer == '-')
4176 {
4177 input_line_pointer++;
dcbf9037 4178 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
4179 if (hi_reg == FAIL)
4180 {
9b7132d3 4181 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
4182 goto error;
4183 }
4184 else if (reg >= hi_reg)
4185 {
4186 as_bad (_("bad register range"));
4187 goto error;
4188 }
4189 for (; reg < hi_reg; reg++)
4190 mask |= 1 << reg;
4191 }
4192 }
4193 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4194
d996d970 4195 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4196
c19d1205 4197 demand_empty_rest_of_line ();
b99bd4ef 4198
708587a4 4199 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4200 the list. */
4201 flush_pending_unwind ();
b99bd4ef 4202
c19d1205 4203 for (i = 0; i < 16; i++)
b99bd4ef 4204 {
c19d1205
ZW
4205 if (mask & (1 << i))
4206 unwind.frame_size += 8;
b99bd4ef
NC
4207 }
4208
c19d1205
ZW
4209 /* Attempt to combine with a previous opcode. We do this because gcc
4210 likes to output separate unwind directives for a single block of
4211 registers. */
4212 if (unwind.opcode_count > 0)
b99bd4ef 4213 {
c19d1205
ZW
4214 i = unwind.opcodes[unwind.opcode_count - 1];
4215 if ((i & 0xf8) == 0xc0)
4216 {
4217 i &= 7;
4218 /* Only merge if the blocks are contiguous. */
4219 if (i < 6)
4220 {
4221 if ((mask & 0xfe00) == (1 << 9))
4222 {
4223 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4224 unwind.opcode_count--;
4225 }
4226 }
4227 else if (i == 6 && unwind.opcode_count >= 2)
4228 {
4229 i = unwind.opcodes[unwind.opcode_count - 2];
4230 reg = i >> 4;
4231 i &= 0xf;
b99bd4ef 4232
c19d1205
ZW
4233 op = 0xffff << (reg - 1);
4234 if (reg > 0
87a1fd79 4235 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
4236 {
4237 op = (1 << (reg + i + 1)) - 1;
4238 op &= ~((1 << reg) - 1);
4239 mask |= op;
4240 unwind.opcode_count -= 2;
4241 }
4242 }
4243 }
b99bd4ef
NC
4244 }
4245
c19d1205
ZW
4246 hi_reg = 15;
4247 /* We want to generate opcodes in the order the registers have been
4248 saved, ie. descending order. */
4249 for (reg = 15; reg >= -1; reg--)
b99bd4ef 4250 {
c19d1205
ZW
4251 /* Save registers in blocks. */
4252 if (reg < 0
4253 || !(mask & (1 << reg)))
4254 {
4255 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 4256 preceding block. */
c19d1205
ZW
4257 if (reg != hi_reg)
4258 {
4259 if (reg == 9)
4260 {
4261 /* Short form. */
4262 op = 0xc0 | (hi_reg - 10);
4263 add_unwind_opcode (op, 1);
4264 }
4265 else
4266 {
4267 /* Long form. */
4268 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4269 add_unwind_opcode (op, 2);
4270 }
4271 }
4272 hi_reg = reg - 1;
4273 }
b99bd4ef
NC
4274 }
4275
c19d1205
ZW
4276 return;
4277error:
4278 ignore_rest_of_line ();
b99bd4ef
NC
4279}
4280
4281static void
c19d1205 4282s_arm_unwind_save_mmxwcg (void)
b99bd4ef 4283{
c19d1205
ZW
4284 int reg;
4285 int hi_reg;
4286 unsigned mask = 0;
4287 valueT op;
b99bd4ef 4288
c19d1205
ZW
4289 if (*input_line_pointer == '{')
4290 input_line_pointer++;
b99bd4ef 4291
477330fc
RM
4292 skip_whitespace (input_line_pointer);
4293
c19d1205 4294 do
b99bd4ef 4295 {
dcbf9037 4296 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 4297
c19d1205
ZW
4298 if (reg == FAIL)
4299 {
9b7132d3 4300 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4301 goto error;
4302 }
b99bd4ef 4303
c19d1205
ZW
4304 reg -= 8;
4305 if (mask >> reg)
4306 as_tsktsk (_("register list not in ascending order"));
4307 mask |= 1 << reg;
b99bd4ef 4308
c19d1205
ZW
4309 if (*input_line_pointer == '-')
4310 {
4311 input_line_pointer++;
dcbf9037 4312 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
4313 if (hi_reg == FAIL)
4314 {
9b7132d3 4315 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
4316 goto error;
4317 }
4318 else if (reg >= hi_reg)
4319 {
4320 as_bad (_("bad register range"));
4321 goto error;
4322 }
4323 for (; reg < hi_reg; reg++)
4324 mask |= 1 << reg;
4325 }
b99bd4ef 4326 }
c19d1205 4327 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 4328
d996d970 4329 skip_past_char (&input_line_pointer, '}');
b99bd4ef 4330
c19d1205
ZW
4331 demand_empty_rest_of_line ();
4332
708587a4 4333 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
4334 the list. */
4335 flush_pending_unwind ();
b99bd4ef 4336
c19d1205 4337 for (reg = 0; reg < 16; reg++)
b99bd4ef 4338 {
c19d1205
ZW
4339 if (mask & (1 << reg))
4340 unwind.frame_size += 4;
b99bd4ef 4341 }
c19d1205
ZW
4342 op = 0xc700 | mask;
4343 add_unwind_opcode (op, 2);
4344 return;
4345error:
4346 ignore_rest_of_line ();
b99bd4ef
NC
4347}
4348
c19d1205 4349
fa073d69
MS
4350/* Parse an unwind_save directive.
4351 If the argument is non-zero, this is a .vsave directive. */
c19d1205 4352
b99bd4ef 4353static void
fa073d69 4354s_arm_unwind_save (int arch_v6)
b99bd4ef 4355{
c19d1205
ZW
4356 char *peek;
4357 struct reg_entry *reg;
4358 bfd_boolean had_brace = FALSE;
b99bd4ef 4359
921e5f0a 4360 if (!unwind.proc_start)
c921be7d 4361 as_bad (MISSING_FNSTART);
921e5f0a 4362
c19d1205
ZW
4363 /* Figure out what sort of save we have. */
4364 peek = input_line_pointer;
b99bd4ef 4365
c19d1205 4366 if (*peek == '{')
b99bd4ef 4367 {
c19d1205
ZW
4368 had_brace = TRUE;
4369 peek++;
b99bd4ef
NC
4370 }
4371
c19d1205 4372 reg = arm_reg_parse_multi (&peek);
b99bd4ef 4373
c19d1205 4374 if (!reg)
b99bd4ef 4375 {
c19d1205
ZW
4376 as_bad (_("register expected"));
4377 ignore_rest_of_line ();
b99bd4ef
NC
4378 return;
4379 }
4380
c19d1205 4381 switch (reg->type)
b99bd4ef 4382 {
c19d1205
ZW
4383 case REG_TYPE_FN:
4384 if (had_brace)
4385 {
4386 as_bad (_("FPA .unwind_save does not take a register list"));
4387 ignore_rest_of_line ();
4388 return;
4389 }
93ac2687 4390 input_line_pointer = peek;
c19d1205 4391 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4392 return;
c19d1205 4393
1f5afe1c
NC
4394 case REG_TYPE_RN:
4395 s_arm_unwind_save_core ();
4396 return;
4397
fa073d69
MS
4398 case REG_TYPE_VFD:
4399 if (arch_v6)
477330fc 4400 s_arm_unwind_save_vfp_armv6 ();
fa073d69 4401 else
477330fc 4402 s_arm_unwind_save_vfp ();
fa073d69 4403 return;
1f5afe1c
NC
4404
4405 case REG_TYPE_MMXWR:
4406 s_arm_unwind_save_mmxwr ();
4407 return;
4408
4409 case REG_TYPE_MMXWCG:
4410 s_arm_unwind_save_mmxwcg ();
4411 return;
c19d1205
ZW
4412
4413 default:
4414 as_bad (_(".unwind_save does not support this kind of register"));
4415 ignore_rest_of_line ();
b99bd4ef 4416 }
c19d1205 4417}
b99bd4ef 4418
b99bd4ef 4419
c19d1205
ZW
4420/* Parse an unwind_movsp directive. */
4421
4422static void
4423s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4424{
4425 int reg;
4426 valueT op;
4fa3602b 4427 int offset;
c19d1205 4428
921e5f0a 4429 if (!unwind.proc_start)
c921be7d 4430 as_bad (MISSING_FNSTART);
921e5f0a 4431
dcbf9037 4432 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4433 if (reg == FAIL)
b99bd4ef 4434 {
9b7132d3 4435 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4436 ignore_rest_of_line ();
b99bd4ef
NC
4437 return;
4438 }
4fa3602b
PB
4439
4440 /* Optional constant. */
4441 if (skip_past_comma (&input_line_pointer) != FAIL)
4442 {
4443 if (immediate_for_directive (&offset) == FAIL)
4444 return;
4445 }
4446 else
4447 offset = 0;
4448
c19d1205 4449 demand_empty_rest_of_line ();
b99bd4ef 4450
c19d1205 4451 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4452 {
c19d1205 4453 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4454 return;
4455 }
4456
c19d1205
ZW
4457 if (unwind.fp_reg != REG_SP)
4458 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4459
c19d1205
ZW
4460 /* Generate opcode to restore the value. */
4461 op = 0x90 | reg;
4462 add_unwind_opcode (op, 1);
4463
4464 /* Record the information for later. */
4465 unwind.fp_reg = reg;
4fa3602b 4466 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4467 unwind.sp_restored = 1;
b05fe5cf
ZW
4468}
4469
c19d1205
ZW
4470/* Parse an unwind_pad directive. */
4471
b05fe5cf 4472static void
c19d1205 4473s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4474{
c19d1205 4475 int offset;
b05fe5cf 4476
921e5f0a 4477 if (!unwind.proc_start)
c921be7d 4478 as_bad (MISSING_FNSTART);
921e5f0a 4479
c19d1205
ZW
4480 if (immediate_for_directive (&offset) == FAIL)
4481 return;
b99bd4ef 4482
c19d1205
ZW
4483 if (offset & 3)
4484 {
4485 as_bad (_("stack increment must be multiple of 4"));
4486 ignore_rest_of_line ();
4487 return;
4488 }
b99bd4ef 4489
c19d1205
ZW
4490 /* Don't generate any opcodes, just record the details for later. */
4491 unwind.frame_size += offset;
4492 unwind.pending_offset += offset;
4493
4494 demand_empty_rest_of_line ();
4495}
4496
4497/* Parse an unwind_setfp directive. */
4498
4499static void
4500s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4501{
c19d1205
ZW
4502 int sp_reg;
4503 int fp_reg;
4504 int offset;
4505
921e5f0a 4506 if (!unwind.proc_start)
c921be7d 4507 as_bad (MISSING_FNSTART);
921e5f0a 4508
dcbf9037 4509 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4510 if (skip_past_comma (&input_line_pointer) == FAIL)
4511 sp_reg = FAIL;
4512 else
dcbf9037 4513 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4514
c19d1205
ZW
4515 if (fp_reg == FAIL || sp_reg == FAIL)
4516 {
4517 as_bad (_("expected <reg>, <reg>"));
4518 ignore_rest_of_line ();
4519 return;
4520 }
b99bd4ef 4521
c19d1205
ZW
4522 /* Optional constant. */
4523 if (skip_past_comma (&input_line_pointer) != FAIL)
4524 {
4525 if (immediate_for_directive (&offset) == FAIL)
4526 return;
4527 }
4528 else
4529 offset = 0;
a737bd4d 4530
c19d1205 4531 demand_empty_rest_of_line ();
a737bd4d 4532
fdfde340 4533 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4534 {
c19d1205
ZW
4535 as_bad (_("register must be either sp or set by a previous"
4536 "unwind_movsp directive"));
4537 return;
a737bd4d
NC
4538 }
4539
c19d1205
ZW
4540 /* Don't generate any opcodes, just record the information for later. */
4541 unwind.fp_reg = fp_reg;
4542 unwind.fp_used = 1;
fdfde340 4543 if (sp_reg == REG_SP)
c19d1205
ZW
4544 unwind.fp_offset = unwind.frame_size - offset;
4545 else
4546 unwind.fp_offset -= offset;
a737bd4d
NC
4547}
4548
c19d1205
ZW
4549/* Parse an unwind_raw directive. */
4550
4551static void
4552s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4553{
c19d1205 4554 expressionS exp;
708587a4 4555 /* This is an arbitrary limit. */
c19d1205
ZW
4556 unsigned char op[16];
4557 int count;
a737bd4d 4558
921e5f0a 4559 if (!unwind.proc_start)
c921be7d 4560 as_bad (MISSING_FNSTART);
921e5f0a 4561
c19d1205
ZW
4562 expression (&exp);
4563 if (exp.X_op == O_constant
4564 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4565 {
c19d1205
ZW
4566 unwind.frame_size += exp.X_add_number;
4567 expression (&exp);
4568 }
4569 else
4570 exp.X_op = O_illegal;
a737bd4d 4571
c19d1205
ZW
4572 if (exp.X_op != O_constant)
4573 {
4574 as_bad (_("expected <offset>, <opcode>"));
4575 ignore_rest_of_line ();
4576 return;
4577 }
a737bd4d 4578
c19d1205 4579 count = 0;
a737bd4d 4580
c19d1205
ZW
4581 /* Parse the opcode. */
4582 for (;;)
4583 {
4584 if (count >= 16)
4585 {
4586 as_bad (_("unwind opcode too long"));
4587 ignore_rest_of_line ();
a737bd4d 4588 }
c19d1205 4589 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4590 {
c19d1205
ZW
4591 as_bad (_("invalid unwind opcode"));
4592 ignore_rest_of_line ();
4593 return;
a737bd4d 4594 }
c19d1205 4595 op[count++] = exp.X_add_number;
a737bd4d 4596
c19d1205
ZW
4597 /* Parse the next byte. */
4598 if (skip_past_comma (&input_line_pointer) == FAIL)
4599 break;
a737bd4d 4600
c19d1205
ZW
4601 expression (&exp);
4602 }
b99bd4ef 4603
c19d1205
ZW
4604 /* Add the opcode bytes in reverse order. */
4605 while (count--)
4606 add_unwind_opcode (op[count], 1);
b99bd4ef 4607
c19d1205 4608 demand_empty_rest_of_line ();
b99bd4ef 4609}
ee065d83
PB
4610
4611
4612/* Parse a .eabi_attribute directive. */
4613
4614static void
4615s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4616{
0420f52b 4617 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
ee3c0378
AS
4618
4619 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4620 attributes_set_explicitly[tag] = 1;
ee065d83
PB
4621}
4622
0855e32b
NS
4623/* Emit a tls fix for the symbol. */
4624
4625static void
4626s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4627{
4628 char *p;
4629 expressionS exp;
4630#ifdef md_flush_pending_output
4631 md_flush_pending_output ();
4632#endif
4633
4634#ifdef md_cons_align
4635 md_cons_align (4);
4636#endif
4637
4638 /* Since we're just labelling the code, there's no need to define a
4639 mapping symbol. */
4640 expression (&exp);
4641 p = obstack_next_free (&frchain_now->frch_obstack);
4642 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4643 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4644 : BFD_RELOC_ARM_TLS_DESCSEQ);
4645}
cdf9ccec 4646#endif /* OBJ_ELF */
0855e32b 4647
ee065d83 4648static void s_arm_arch (int);
7a1d4c38 4649static void s_arm_object_arch (int);
ee065d83
PB
4650static void s_arm_cpu (int);
4651static void s_arm_fpu (int);
69133863 4652static void s_arm_arch_extension (int);
b99bd4ef 4653
f0927246
NC
4654#ifdef TE_PE
4655
4656static void
5f4273c7 4657pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4658{
4659 expressionS exp;
4660
4661 do
4662 {
4663 expression (&exp);
4664 if (exp.X_op == O_symbol)
4665 exp.X_op = O_secrel;
4666
4667 emit_expr (&exp, 4);
4668 }
4669 while (*input_line_pointer++ == ',');
4670
4671 input_line_pointer--;
4672 demand_empty_rest_of_line ();
4673}
4674#endif /* TE_PE */
4675
c19d1205
ZW
4676/* This table describes all the machine specific pseudo-ops the assembler
4677 has to support. The fields are:
4678 pseudo-op name without dot
4679 function to call to execute this pseudo-op
4680 Integer arg to pass to the function. */
b99bd4ef 4681
c19d1205 4682const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4683{
c19d1205
ZW
4684 /* Never called because '.req' does not start a line. */
4685 { "req", s_req, 0 },
dcbf9037
JB
4686 /* Following two are likewise never called. */
4687 { "dn", s_dn, 0 },
4688 { "qn", s_qn, 0 },
c19d1205
ZW
4689 { "unreq", s_unreq, 0 },
4690 { "bss", s_bss, 0 },
db2ed2e0 4691 { "align", s_align_ptwo, 2 },
c19d1205
ZW
4692 { "arm", s_arm, 0 },
4693 { "thumb", s_thumb, 0 },
4694 { "code", s_code, 0 },
4695 { "force_thumb", s_force_thumb, 0 },
4696 { "thumb_func", s_thumb_func, 0 },
4697 { "thumb_set", s_thumb_set, 0 },
4698 { "even", s_even, 0 },
4699 { "ltorg", s_ltorg, 0 },
4700 { "pool", s_ltorg, 0 },
4701 { "syntax", s_syntax, 0 },
8463be01
PB
4702 { "cpu", s_arm_cpu, 0 },
4703 { "arch", s_arm_arch, 0 },
7a1d4c38 4704 { "object_arch", s_arm_object_arch, 0 },
8463be01 4705 { "fpu", s_arm_fpu, 0 },
69133863 4706 { "arch_extension", s_arm_arch_extension, 0 },
c19d1205 4707#ifdef OBJ_ELF
c921be7d
NC
4708 { "word", s_arm_elf_cons, 4 },
4709 { "long", s_arm_elf_cons, 4 },
4710 { "inst.n", s_arm_elf_inst, 2 },
4711 { "inst.w", s_arm_elf_inst, 4 },
4712 { "inst", s_arm_elf_inst, 0 },
4713 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4714 { "fnstart", s_arm_unwind_fnstart, 0 },
4715 { "fnend", s_arm_unwind_fnend, 0 },
4716 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4717 { "personality", s_arm_unwind_personality, 0 },
4718 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4719 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4720 { "save", s_arm_unwind_save, 0 },
fa073d69 4721 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4722 { "movsp", s_arm_unwind_movsp, 0 },
4723 { "pad", s_arm_unwind_pad, 0 },
4724 { "setfp", s_arm_unwind_setfp, 0 },
4725 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4726 { "eabi_attribute", s_arm_eabi_attribute, 0 },
0855e32b 4727 { "tlsdescseq", s_arm_tls_descseq, 0 },
c19d1205
ZW
4728#else
4729 { "word", cons, 4},
f0927246
NC
4730
4731 /* These are used for dwarf. */
4732 {"2byte", cons, 2},
4733 {"4byte", cons, 4},
4734 {"8byte", cons, 8},
4735 /* These are used for dwarf2. */
4736 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4737 { "loc", dwarf2_directive_loc, 0 },
4738 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4739#endif
4740 { "extend", float_cons, 'x' },
4741 { "ldouble", float_cons, 'x' },
4742 { "packed", float_cons, 'p' },
f0927246
NC
4743#ifdef TE_PE
4744 {"secrel32", pe_directive_secrel, 0},
4745#endif
2e6976a8
DG
4746
4747 /* These are for compatibility with CodeComposer Studio. */
4748 {"ref", s_ccs_ref, 0},
4749 {"def", s_ccs_def, 0},
4750 {"asmfunc", s_ccs_asmfunc, 0},
4751 {"endasmfunc", s_ccs_endasmfunc, 0},
4752
c19d1205
ZW
4753 { 0, 0, 0 }
4754};
4755\f
4756/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4757
c19d1205
ZW
4758/* Generic immediate-value read function for use in insn parsing.
4759 STR points to the beginning of the immediate (the leading #);
4760 VAL receives the value; if the value is outside [MIN, MAX]
4761 issue an error. PREFIX_OPT is true if the immediate prefix is
4762 optional. */
b99bd4ef 4763
c19d1205
ZW
4764static int
4765parse_immediate (char **str, int *val, int min, int max,
4766 bfd_boolean prefix_opt)
4767{
4768 expressionS exp;
4769 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4770 if (exp.X_op != O_constant)
b99bd4ef 4771 {
c19d1205
ZW
4772 inst.error = _("constant expression required");
4773 return FAIL;
4774 }
b99bd4ef 4775
c19d1205
ZW
4776 if (exp.X_add_number < min || exp.X_add_number > max)
4777 {
4778 inst.error = _("immediate value out of range");
4779 return FAIL;
4780 }
b99bd4ef 4781
c19d1205
ZW
4782 *val = exp.X_add_number;
4783 return SUCCESS;
4784}
b99bd4ef 4785
5287ad62 4786/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4787 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4788 instructions. Puts the result directly in inst.operands[i]. */
4789
4790static int
8335d6aa
JW
4791parse_big_immediate (char **str, int i, expressionS *in_exp,
4792 bfd_boolean allow_symbol_p)
5287ad62
JB
4793{
4794 expressionS exp;
8335d6aa 4795 expressionS *exp_p = in_exp ? in_exp : &exp;
5287ad62
JB
4796 char *ptr = *str;
4797
8335d6aa 4798 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5287ad62 4799
8335d6aa 4800 if (exp_p->X_op == O_constant)
036dc3f7 4801 {
8335d6aa 4802 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
036dc3f7
PB
4803 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4804 O_constant. We have to be careful not to break compilation for
4805 32-bit X_add_number, though. */
8335d6aa 4806 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
036dc3f7 4807 {
8335d6aa
JW
4808 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4809 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4810 & 0xffffffff);
036dc3f7
PB
4811 inst.operands[i].regisimm = 1;
4812 }
4813 }
8335d6aa
JW
4814 else if (exp_p->X_op == O_big
4815 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5287ad62
JB
4816 {
4817 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
95b75c01 4818
5287ad62 4819 /* Bignums have their least significant bits in
477330fc
RM
4820 generic_bignum[0]. Make sure we put 32 bits in imm and
4821 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4822 gas_assert (parts != 0);
95b75c01
NC
4823
4824 /* Make sure that the number is not too big.
4825 PR 11972: Bignums can now be sign-extended to the
4826 size of a .octa so check that the out of range bits
4827 are all zero or all one. */
8335d6aa 4828 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
95b75c01
NC
4829 {
4830 LITTLENUM_TYPE m = -1;
4831
4832 if (generic_bignum[parts * 2] != 0
4833 && generic_bignum[parts * 2] != m)
4834 return FAIL;
4835
8335d6aa 4836 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
95b75c01
NC
4837 if (generic_bignum[j] != generic_bignum[j-1])
4838 return FAIL;
4839 }
4840
5287ad62
JB
4841 inst.operands[i].imm = 0;
4842 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4843 inst.operands[i].imm |= generic_bignum[idx]
4844 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4845 inst.operands[i].reg = 0;
4846 for (j = 0; j < parts; j++, idx++)
477330fc
RM
4847 inst.operands[i].reg |= generic_bignum[idx]
4848 << (LITTLENUM_NUMBER_OF_BITS * j);
5287ad62
JB
4849 inst.operands[i].regisimm = 1;
4850 }
8335d6aa 4851 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5287ad62 4852 return FAIL;
5f4273c7 4853
5287ad62
JB
4854 *str = ptr;
4855
4856 return SUCCESS;
4857}
4858
c19d1205
ZW
4859/* Returns the pseudo-register number of an FPA immediate constant,
4860 or FAIL if there isn't a valid constant here. */
b99bd4ef 4861
c19d1205
ZW
4862static int
4863parse_fpa_immediate (char ** str)
4864{
4865 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4866 char * save_in;
4867 expressionS exp;
4868 int i;
4869 int j;
b99bd4ef 4870
c19d1205
ZW
4871 /* First try and match exact strings, this is to guarantee
4872 that some formats will work even for cross assembly. */
b99bd4ef 4873
c19d1205
ZW
4874 for (i = 0; fp_const[i]; i++)
4875 {
4876 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4877 {
c19d1205 4878 char *start = *str;
b99bd4ef 4879
c19d1205
ZW
4880 *str += strlen (fp_const[i]);
4881 if (is_end_of_line[(unsigned char) **str])
4882 return i + 8;
4883 *str = start;
4884 }
4885 }
b99bd4ef 4886
c19d1205
ZW
4887 /* Just because we didn't get a match doesn't mean that the constant
4888 isn't valid, just that it is in a format that we don't
4889 automatically recognize. Try parsing it with the standard
4890 expression routines. */
b99bd4ef 4891
c19d1205 4892 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4893
c19d1205
ZW
4894 /* Look for a raw floating point number. */
4895 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4896 && is_end_of_line[(unsigned char) *save_in])
4897 {
4898 for (i = 0; i < NUM_FLOAT_VALS; i++)
4899 {
4900 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4901 {
c19d1205
ZW
4902 if (words[j] != fp_values[i][j])
4903 break;
b99bd4ef
NC
4904 }
4905
c19d1205 4906 if (j == MAX_LITTLENUMS)
b99bd4ef 4907 {
c19d1205
ZW
4908 *str = save_in;
4909 return i + 8;
b99bd4ef
NC
4910 }
4911 }
4912 }
b99bd4ef 4913
c19d1205
ZW
4914 /* Try and parse a more complex expression, this will probably fail
4915 unless the code uses a floating point prefix (eg "0f"). */
4916 save_in = input_line_pointer;
4917 input_line_pointer = *str;
4918 if (expression (&exp) == absolute_section
4919 && exp.X_op == O_big
4920 && exp.X_add_number < 0)
4921 {
4922 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4923 Ditto for 15. */
ba592044
AM
4924#define X_PRECISION 5
4925#define E_PRECISION 15L
4926 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
c19d1205
ZW
4927 {
4928 for (i = 0; i < NUM_FLOAT_VALS; i++)
4929 {
4930 for (j = 0; j < MAX_LITTLENUMS; j++)
4931 {
4932 if (words[j] != fp_values[i][j])
4933 break;
4934 }
b99bd4ef 4935
c19d1205
ZW
4936 if (j == MAX_LITTLENUMS)
4937 {
4938 *str = input_line_pointer;
4939 input_line_pointer = save_in;
4940 return i + 8;
4941 }
4942 }
4943 }
b99bd4ef
NC
4944 }
4945
c19d1205
ZW
4946 *str = input_line_pointer;
4947 input_line_pointer = save_in;
4948 inst.error = _("invalid FPA immediate expression");
4949 return FAIL;
b99bd4ef
NC
4950}
4951
136da414
JB
4952/* Returns 1 if a number has "quarter-precision" float format
4953 0baBbbbbbc defgh000 00000000 00000000. */
4954
4955static int
4956is_quarter_float (unsigned imm)
4957{
4958 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4959 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4960}
4961
aacf0b33
KT
4962
4963/* Detect the presence of a floating point or integer zero constant,
4964 i.e. #0.0 or #0. */
4965
4966static bfd_boolean
4967parse_ifimm_zero (char **in)
4968{
4969 int error_code;
4970
4971 if (!is_immediate_prefix (**in))
3c6452ae
TP
4972 {
4973 /* In unified syntax, all prefixes are optional. */
4974 if (!unified_syntax)
4975 return FALSE;
4976 }
4977 else
4978 ++*in;
0900a05b
JW
4979
4980 /* Accept #0x0 as a synonym for #0. */
4981 if (strncmp (*in, "0x", 2) == 0)
4982 {
4983 int val;
4984 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
4985 return FALSE;
4986 return TRUE;
4987 }
4988
aacf0b33
KT
4989 error_code = atof_generic (in, ".", EXP_CHARS,
4990 &generic_floating_point_number);
4991
4992 if (!error_code
4993 && generic_floating_point_number.sign == '+'
4994 && (generic_floating_point_number.low
4995 > generic_floating_point_number.leader))
4996 return TRUE;
4997
4998 return FALSE;
4999}
5000
136da414
JB
5001/* Parse an 8-bit "quarter-precision" floating point number of the form:
5002 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
5003 The zero and minus-zero cases need special handling, since they can't be
5004 encoded in the "quarter-precision" float format, but can nonetheless be
5005 loaded as integer constants. */
136da414
JB
5006
5007static unsigned
5008parse_qfloat_immediate (char **ccp, int *immed)
5009{
5010 char *str = *ccp;
c96612cc 5011 char *fpnum;
136da414 5012 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 5013 int found_fpchar = 0;
5f4273c7 5014
136da414 5015 skip_past_char (&str, '#');
5f4273c7 5016
c96612cc
JB
5017 /* We must not accidentally parse an integer as a floating-point number. Make
5018 sure that the value we parse is not an integer by checking for special
5019 characters '.' or 'e'.
5020 FIXME: This is a horrible hack, but doing better is tricky because type
5021 information isn't in a very usable state at parse time. */
5022 fpnum = str;
5023 skip_whitespace (fpnum);
5024
5025 if (strncmp (fpnum, "0x", 2) == 0)
5026 return FAIL;
5027 else
5028 {
5029 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
477330fc
RM
5030 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5031 {
5032 found_fpchar = 1;
5033 break;
5034 }
c96612cc
JB
5035
5036 if (!found_fpchar)
477330fc 5037 return FAIL;
c96612cc 5038 }
5f4273c7 5039
136da414
JB
5040 if ((str = atof_ieee (str, 's', words)) != NULL)
5041 {
5042 unsigned fpword = 0;
5043 int i;
5f4273c7 5044
136da414
JB
5045 /* Our FP word must be 32 bits (single-precision FP). */
5046 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
477330fc
RM
5047 {
5048 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5049 fpword |= words[i];
5050 }
5f4273c7 5051
c96612cc 5052 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
477330fc 5053 *immed = fpword;
136da414 5054 else
477330fc 5055 return FAIL;
136da414
JB
5056
5057 *ccp = str;
5f4273c7 5058
136da414
JB
5059 return SUCCESS;
5060 }
5f4273c7 5061
136da414
JB
5062 return FAIL;
5063}
5064
c19d1205
ZW
5065/* Shift operands. */
5066enum shift_kind
b99bd4ef 5067{
c19d1205
ZW
5068 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5069};
b99bd4ef 5070
c19d1205
ZW
5071struct asm_shift_name
5072{
5073 const char *name;
5074 enum shift_kind kind;
5075};
b99bd4ef 5076
c19d1205
ZW
5077/* Third argument to parse_shift. */
5078enum parse_shift_mode
5079{
5080 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5081 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5082 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5083 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5084 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5085};
b99bd4ef 5086
c19d1205
ZW
5087/* Parse a <shift> specifier on an ARM data processing instruction.
5088 This has three forms:
b99bd4ef 5089
c19d1205
ZW
5090 (LSL|LSR|ASL|ASR|ROR) Rs
5091 (LSL|LSR|ASL|ASR|ROR) #imm
5092 RRX
b99bd4ef 5093
c19d1205
ZW
5094 Note that ASL is assimilated to LSL in the instruction encoding, and
5095 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 5096
c19d1205
ZW
5097static int
5098parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 5099{
c19d1205
ZW
5100 const struct asm_shift_name *shift_name;
5101 enum shift_kind shift;
5102 char *s = *str;
5103 char *p = s;
5104 int reg;
b99bd4ef 5105
c19d1205
ZW
5106 for (p = *str; ISALPHA (*p); p++)
5107 ;
b99bd4ef 5108
c19d1205 5109 if (p == *str)
b99bd4ef 5110 {
c19d1205
ZW
5111 inst.error = _("shift expression expected");
5112 return FAIL;
b99bd4ef
NC
5113 }
5114
21d799b5 5115 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
477330fc 5116 p - *str);
c19d1205
ZW
5117
5118 if (shift_name == NULL)
b99bd4ef 5119 {
c19d1205
ZW
5120 inst.error = _("shift expression expected");
5121 return FAIL;
b99bd4ef
NC
5122 }
5123
c19d1205 5124 shift = shift_name->kind;
b99bd4ef 5125
c19d1205
ZW
5126 switch (mode)
5127 {
5128 case NO_SHIFT_RESTRICT:
5129 case SHIFT_IMMEDIATE: break;
b99bd4ef 5130
c19d1205
ZW
5131 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5132 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5133 {
5134 inst.error = _("'LSL' or 'ASR' required");
5135 return FAIL;
5136 }
5137 break;
b99bd4ef 5138
c19d1205
ZW
5139 case SHIFT_LSL_IMMEDIATE:
5140 if (shift != SHIFT_LSL)
5141 {
5142 inst.error = _("'LSL' required");
5143 return FAIL;
5144 }
5145 break;
b99bd4ef 5146
c19d1205
ZW
5147 case SHIFT_ASR_IMMEDIATE:
5148 if (shift != SHIFT_ASR)
5149 {
5150 inst.error = _("'ASR' required");
5151 return FAIL;
5152 }
5153 break;
b99bd4ef 5154
c19d1205
ZW
5155 default: abort ();
5156 }
b99bd4ef 5157
c19d1205
ZW
5158 if (shift != SHIFT_RRX)
5159 {
5160 /* Whitespace can appear here if the next thing is a bare digit. */
5161 skip_whitespace (p);
b99bd4ef 5162
c19d1205 5163 if (mode == NO_SHIFT_RESTRICT
dcbf9037 5164 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5165 {
5166 inst.operands[i].imm = reg;
5167 inst.operands[i].immisreg = 1;
5168 }
5169 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5170 return FAIL;
5171 }
5172 inst.operands[i].shift_kind = shift;
5173 inst.operands[i].shifted = 1;
5174 *str = p;
5175 return SUCCESS;
b99bd4ef
NC
5176}
5177
c19d1205 5178/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 5179
c19d1205
ZW
5180 #<immediate>
5181 #<immediate>, <rotate>
5182 <Rm>
5183 <Rm>, <shift>
b99bd4ef 5184
c19d1205
ZW
5185 where <shift> is defined by parse_shift above, and <rotate> is a
5186 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 5187 is deferred to md_apply_fix. */
b99bd4ef 5188
c19d1205
ZW
5189static int
5190parse_shifter_operand (char **str, int i)
5191{
5192 int value;
91d6fa6a 5193 expressionS exp;
b99bd4ef 5194
dcbf9037 5195 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
5196 {
5197 inst.operands[i].reg = value;
5198 inst.operands[i].isreg = 1;
b99bd4ef 5199
c19d1205
ZW
5200 /* parse_shift will override this if appropriate */
5201 inst.reloc.exp.X_op = O_constant;
5202 inst.reloc.exp.X_add_number = 0;
b99bd4ef 5203
c19d1205
ZW
5204 if (skip_past_comma (str) == FAIL)
5205 return SUCCESS;
b99bd4ef 5206
c19d1205
ZW
5207 /* Shift operation on register. */
5208 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
5209 }
5210
c19d1205
ZW
5211 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5212 return FAIL;
b99bd4ef 5213
c19d1205 5214 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 5215 {
c19d1205 5216 /* #x, y -- ie explicit rotation by Y. */
91d6fa6a 5217 if (my_get_expression (&exp, str, GE_NO_PREFIX))
c19d1205 5218 return FAIL;
b99bd4ef 5219
91d6fa6a 5220 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
c19d1205
ZW
5221 {
5222 inst.error = _("constant expression expected");
5223 return FAIL;
5224 }
b99bd4ef 5225
91d6fa6a 5226 value = exp.X_add_number;
c19d1205
ZW
5227 if (value < 0 || value > 30 || value % 2 != 0)
5228 {
5229 inst.error = _("invalid rotation");
5230 return FAIL;
5231 }
5232 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5233 {
5234 inst.error = _("invalid constant");
5235 return FAIL;
5236 }
09d92015 5237
a415b1cd
JB
5238 /* Encode as specified. */
5239 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5240 return SUCCESS;
09d92015
MM
5241 }
5242
c19d1205
ZW
5243 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5244 inst.reloc.pc_rel = 0;
5245 return SUCCESS;
09d92015
MM
5246}
5247
4962c51a
MS
5248/* Group relocation information. Each entry in the table contains the
5249 textual name of the relocation as may appear in assembler source
5250 and must end with a colon.
5251 Along with this textual name are the relocation codes to be used if
5252 the corresponding instruction is an ALU instruction (ADD or SUB only),
5253 an LDR, an LDRS, or an LDC. */
5254
5255struct group_reloc_table_entry
5256{
5257 const char *name;
5258 int alu_code;
5259 int ldr_code;
5260 int ldrs_code;
5261 int ldc_code;
5262};
5263
5264typedef enum
5265{
5266 /* Varieties of non-ALU group relocation. */
5267
5268 GROUP_LDR,
5269 GROUP_LDRS,
5270 GROUP_LDC
5271} group_reloc_type;
5272
5273static struct group_reloc_table_entry group_reloc_table[] =
5274 { /* Program counter relative: */
5275 { "pc_g0_nc",
5276 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5277 0, /* LDR */
5278 0, /* LDRS */
5279 0 }, /* LDC */
5280 { "pc_g0",
5281 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5282 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5283 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5284 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5285 { "pc_g1_nc",
5286 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5287 0, /* LDR */
5288 0, /* LDRS */
5289 0 }, /* LDC */
5290 { "pc_g1",
5291 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5292 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5293 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5294 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5295 { "pc_g2",
5296 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5297 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5298 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5299 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5300 /* Section base relative */
5301 { "sb_g0_nc",
5302 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5303 0, /* LDR */
5304 0, /* LDRS */
5305 0 }, /* LDC */
5306 { "sb_g0",
5307 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5308 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5309 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5310 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5311 { "sb_g1_nc",
5312 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5313 0, /* LDR */
5314 0, /* LDRS */
5315 0 }, /* LDC */
5316 { "sb_g1",
5317 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5318 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5319 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5320 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5321 { "sb_g2",
5322 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5323 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5324 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
72d98d16
MG
5325 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5326 /* Absolute thumb alu relocations. */
5327 { "lower0_7",
5328 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5329 0, /* LDR. */
5330 0, /* LDRS. */
5331 0 }, /* LDC. */
5332 { "lower8_15",
5333 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5334 0, /* LDR. */
5335 0, /* LDRS. */
5336 0 }, /* LDC. */
5337 { "upper0_7",
5338 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5339 0, /* LDR. */
5340 0, /* LDRS. */
5341 0 }, /* LDC. */
5342 { "upper8_15",
5343 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5344 0, /* LDR. */
5345 0, /* LDRS. */
5346 0 } }; /* LDC. */
4962c51a
MS
5347
5348/* Given the address of a pointer pointing to the textual name of a group
5349 relocation as may appear in assembler source, attempt to find its details
5350 in group_reloc_table. The pointer will be updated to the character after
5351 the trailing colon. On failure, FAIL will be returned; SUCCESS
5352 otherwise. On success, *entry will be updated to point at the relevant
5353 group_reloc_table entry. */
5354
5355static int
5356find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5357{
5358 unsigned int i;
5359 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5360 {
5361 int length = strlen (group_reloc_table[i].name);
5362
5f4273c7
NC
5363 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5364 && (*str)[length] == ':')
477330fc
RM
5365 {
5366 *out = &group_reloc_table[i];
5367 *str += (length + 1);
5368 return SUCCESS;
5369 }
4962c51a
MS
5370 }
5371
5372 return FAIL;
5373}
5374
5375/* Parse a <shifter_operand> for an ARM data processing instruction
5376 (as for parse_shifter_operand) where group relocations are allowed:
5377
5378 #<immediate>
5379 #<immediate>, <rotate>
5380 #:<group_reloc>:<expression>
5381 <Rm>
5382 <Rm>, <shift>
5383
5384 where <group_reloc> is one of the strings defined in group_reloc_table.
5385 The hashes are optional.
5386
5387 Everything else is as for parse_shifter_operand. */
5388
5389static parse_operand_result
5390parse_shifter_operand_group_reloc (char **str, int i)
5391{
5392 /* Determine if we have the sequence of characters #: or just :
5393 coming next. If we do, then we check for a group relocation.
5394 If we don't, punt the whole lot to parse_shifter_operand. */
5395
5396 if (((*str)[0] == '#' && (*str)[1] == ':')
5397 || (*str)[0] == ':')
5398 {
5399 struct group_reloc_table_entry *entry;
5400
5401 if ((*str)[0] == '#')
477330fc 5402 (*str) += 2;
4962c51a 5403 else
477330fc 5404 (*str)++;
4962c51a
MS
5405
5406 /* Try to parse a group relocation. Anything else is an error. */
5407 if (find_group_reloc_table_entry (str, &entry) == FAIL)
477330fc
RM
5408 {
5409 inst.error = _("unknown group relocation");
5410 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5411 }
4962c51a
MS
5412
5413 /* We now have the group relocation table entry corresponding to
477330fc 5414 the name in the assembler source. Next, we parse the expression. */
4962c51a 5415 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
477330fc 5416 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4962c51a
MS
5417
5418 /* Record the relocation type (always the ALU variant here). */
21d799b5 5419 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 5420 gas_assert (inst.reloc.type != 0);
4962c51a
MS
5421
5422 return PARSE_OPERAND_SUCCESS;
5423 }
5424 else
5425 return parse_shifter_operand (str, i) == SUCCESS
477330fc 5426 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4962c51a
MS
5427
5428 /* Never reached. */
5429}
5430
8e560766
MGD
5431/* Parse a Neon alignment expression. Information is written to
5432 inst.operands[i]. We assume the initial ':' has been skipped.
fa94de6b 5433
8e560766
MGD
5434 align .imm = align << 8, .immisalign=1, .preind=0 */
5435static parse_operand_result
5436parse_neon_alignment (char **str, int i)
5437{
5438 char *p = *str;
5439 expressionS exp;
5440
5441 my_get_expression (&exp, &p, GE_NO_PREFIX);
5442
5443 if (exp.X_op != O_constant)
5444 {
5445 inst.error = _("alignment must be constant");
5446 return PARSE_OPERAND_FAIL;
5447 }
5448
5449 inst.operands[i].imm = exp.X_add_number << 8;
5450 inst.operands[i].immisalign = 1;
5451 /* Alignments are not pre-indexes. */
5452 inst.operands[i].preind = 0;
5453
5454 *str = p;
5455 return PARSE_OPERAND_SUCCESS;
5456}
5457
c19d1205
ZW
5458/* Parse all forms of an ARM address expression. Information is written
5459 to inst.operands[i] and/or inst.reloc.
09d92015 5460
c19d1205 5461 Preindexed addressing (.preind=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 These three may have a trailing ! which causes .writeback to be set also.
09d92015 5469
c19d1205 5470 Postindexed addressing (.postind=1, .writeback=1):
09d92015 5471
c19d1205
ZW
5472 [Rn], #offset .reg=Rn .reloc.exp=offset
5473 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5474 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5475 .shift_kind=shift .reloc.exp=shift_imm
09d92015 5476
c19d1205 5477 Unindexed addressing (.preind=0, .postind=0):
09d92015 5478
c19d1205 5479 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 5480
c19d1205 5481 Other:
09d92015 5482
c19d1205
ZW
5483 [Rn]{!} shorthand for [Rn,#0]{!}
5484 =immediate .isreg=0 .reloc.exp=immediate
5485 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 5486
c19d1205
ZW
5487 It is the caller's responsibility to check for addressing modes not
5488 supported by the instruction, and to set inst.reloc.type. */
5489
4962c51a
MS
5490static parse_operand_result
5491parse_address_main (char **str, int i, int group_relocations,
477330fc 5492 group_reloc_type group_type)
09d92015 5493{
c19d1205
ZW
5494 char *p = *str;
5495 int reg;
09d92015 5496
c19d1205 5497 if (skip_past_char (&p, '[') == FAIL)
09d92015 5498 {
c19d1205
ZW
5499 if (skip_past_char (&p, '=') == FAIL)
5500 {
974da60d 5501 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
5502 inst.reloc.pc_rel = 1;
5503 inst.operands[i].reg = REG_PC;
5504 inst.operands[i].isreg = 1;
5505 inst.operands[i].preind = 1;
09d92015 5506
8335d6aa
JW
5507 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5508 return PARSE_OPERAND_FAIL;
5509 }
5510 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5511 /*allow_symbol_p=*/TRUE))
4962c51a 5512 return PARSE_OPERAND_FAIL;
09d92015 5513
c19d1205 5514 *str = p;
4962c51a 5515 return PARSE_OPERAND_SUCCESS;
09d92015
MM
5516 }
5517
8ab8155f
NC
5518 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5519 skip_whitespace (p);
5520
dcbf9037 5521 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 5522 {
c19d1205 5523 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 5524 return PARSE_OPERAND_FAIL;
09d92015 5525 }
c19d1205
ZW
5526 inst.operands[i].reg = reg;
5527 inst.operands[i].isreg = 1;
09d92015 5528
c19d1205 5529 if (skip_past_comma (&p) == SUCCESS)
09d92015 5530 {
c19d1205 5531 inst.operands[i].preind = 1;
09d92015 5532
c19d1205
ZW
5533 if (*p == '+') p++;
5534 else if (*p == '-') p++, inst.operands[i].negative = 1;
5535
dcbf9037 5536 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5537 {
c19d1205
ZW
5538 inst.operands[i].imm = reg;
5539 inst.operands[i].immisreg = 1;
5540
5541 if (skip_past_comma (&p) == SUCCESS)
5542 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5543 return PARSE_OPERAND_FAIL;
c19d1205 5544 }
5287ad62 5545 else if (skip_past_char (&p, ':') == SUCCESS)
8e560766
MGD
5546 {
5547 /* FIXME: '@' should be used here, but it's filtered out by generic
5548 code before we get to see it here. This may be subject to
5549 change. */
5550 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5551
8e560766
MGD
5552 if (result != PARSE_OPERAND_SUCCESS)
5553 return result;
5554 }
c19d1205
ZW
5555 else
5556 {
5557 if (inst.operands[i].negative)
5558 {
5559 inst.operands[i].negative = 0;
5560 p--;
5561 }
4962c51a 5562
5f4273c7
NC
5563 if (group_relocations
5564 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5565 {
5566 struct group_reloc_table_entry *entry;
5567
477330fc
RM
5568 /* Skip over the #: or : sequence. */
5569 if (*p == '#')
5570 p += 2;
5571 else
5572 p++;
4962c51a
MS
5573
5574 /* Try to parse a group relocation. Anything else is an
477330fc 5575 error. */
4962c51a
MS
5576 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5577 {
5578 inst.error = _("unknown group relocation");
5579 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5580 }
5581
5582 /* We now have the group relocation table entry corresponding to
5583 the name in the assembler source. Next, we parse the
477330fc 5584 expression. */
4962c51a
MS
5585 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5586 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5587
5588 /* Record the relocation type. */
477330fc
RM
5589 switch (group_type)
5590 {
5591 case GROUP_LDR:
5592 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5593 break;
4962c51a 5594
477330fc
RM
5595 case GROUP_LDRS:
5596 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5597 break;
4962c51a 5598
477330fc
RM
5599 case GROUP_LDC:
5600 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5601 break;
4962c51a 5602
477330fc
RM
5603 default:
5604 gas_assert (0);
5605 }
4962c51a 5606
477330fc 5607 if (inst.reloc.type == 0)
4962c51a
MS
5608 {
5609 inst.error = _("this group relocation is not allowed on this instruction");
5610 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5611 }
477330fc
RM
5612 }
5613 else
26d97720
NS
5614 {
5615 char *q = p;
5616 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5617 return PARSE_OPERAND_FAIL;
5618 /* If the offset is 0, find out if it's a +0 or -0. */
5619 if (inst.reloc.exp.X_op == O_constant
5620 && inst.reloc.exp.X_add_number == 0)
5621 {
5622 skip_whitespace (q);
5623 if (*q == '#')
5624 {
5625 q++;
5626 skip_whitespace (q);
5627 }
5628 if (*q == '-')
5629 inst.operands[i].negative = 1;
5630 }
5631 }
09d92015
MM
5632 }
5633 }
8e560766
MGD
5634 else if (skip_past_char (&p, ':') == SUCCESS)
5635 {
5636 /* FIXME: '@' should be used here, but it's filtered out by generic code
5637 before we get to see it here. This may be subject to change. */
5638 parse_operand_result result = parse_neon_alignment (&p, i);
fa94de6b 5639
8e560766
MGD
5640 if (result != PARSE_OPERAND_SUCCESS)
5641 return result;
5642 }
09d92015 5643
c19d1205 5644 if (skip_past_char (&p, ']') == FAIL)
09d92015 5645 {
c19d1205 5646 inst.error = _("']' expected");
4962c51a 5647 return PARSE_OPERAND_FAIL;
09d92015
MM
5648 }
5649
c19d1205
ZW
5650 if (skip_past_char (&p, '!') == SUCCESS)
5651 inst.operands[i].writeback = 1;
09d92015 5652
c19d1205 5653 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5654 {
c19d1205
ZW
5655 if (skip_past_char (&p, '{') == SUCCESS)
5656 {
5657 /* [Rn], {expr} - unindexed, with option */
5658 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5659 0, 255, TRUE) == FAIL)
4962c51a 5660 return PARSE_OPERAND_FAIL;
09d92015 5661
c19d1205
ZW
5662 if (skip_past_char (&p, '}') == FAIL)
5663 {
5664 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5665 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5666 }
5667 if (inst.operands[i].preind)
5668 {
5669 inst.error = _("cannot combine index with option");
4962c51a 5670 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5671 }
5672 *str = p;
4962c51a 5673 return PARSE_OPERAND_SUCCESS;
09d92015 5674 }
c19d1205
ZW
5675 else
5676 {
5677 inst.operands[i].postind = 1;
5678 inst.operands[i].writeback = 1;
09d92015 5679
c19d1205
ZW
5680 if (inst.operands[i].preind)
5681 {
5682 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5683 return PARSE_OPERAND_FAIL;
c19d1205 5684 }
09d92015 5685
c19d1205
ZW
5686 if (*p == '+') p++;
5687 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5688
dcbf9037 5689 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5690 {
477330fc
RM
5691 /* We might be using the immediate for alignment already. If we
5692 are, OR the register number into the low-order bits. */
5693 if (inst.operands[i].immisalign)
5694 inst.operands[i].imm |= reg;
5695 else
5696 inst.operands[i].imm = reg;
c19d1205 5697 inst.operands[i].immisreg = 1;
a737bd4d 5698
c19d1205
ZW
5699 if (skip_past_comma (&p) == SUCCESS)
5700 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5701 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5702 }
5703 else
5704 {
26d97720 5705 char *q = p;
c19d1205
ZW
5706 if (inst.operands[i].negative)
5707 {
5708 inst.operands[i].negative = 0;
5709 p--;
5710 }
5711 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5712 return PARSE_OPERAND_FAIL;
26d97720
NS
5713 /* If the offset is 0, find out if it's a +0 or -0. */
5714 if (inst.reloc.exp.X_op == O_constant
5715 && inst.reloc.exp.X_add_number == 0)
5716 {
5717 skip_whitespace (q);
5718 if (*q == '#')
5719 {
5720 q++;
5721 skip_whitespace (q);
5722 }
5723 if (*q == '-')
5724 inst.operands[i].negative = 1;
5725 }
c19d1205
ZW
5726 }
5727 }
a737bd4d
NC
5728 }
5729
c19d1205
ZW
5730 /* If at this point neither .preind nor .postind is set, we have a
5731 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5732 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5733 {
5734 inst.operands[i].preind = 1;
5735 inst.reloc.exp.X_op = O_constant;
5736 inst.reloc.exp.X_add_number = 0;
5737 }
5738 *str = p;
4962c51a
MS
5739 return PARSE_OPERAND_SUCCESS;
5740}
5741
5742static int
5743parse_address (char **str, int i)
5744{
21d799b5 5745 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
477330fc 5746 ? SUCCESS : FAIL;
4962c51a
MS
5747}
5748
5749static parse_operand_result
5750parse_address_group_reloc (char **str, int i, group_reloc_type type)
5751{
5752 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5753}
5754
b6895b4f
PB
5755/* Parse an operand for a MOVW or MOVT instruction. */
5756static int
5757parse_half (char **str)
5758{
5759 char * p;
5f4273c7 5760
b6895b4f
PB
5761 p = *str;
5762 skip_past_char (&p, '#');
5f4273c7 5763 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5764 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5765 else if (strncasecmp (p, ":upper16:", 9) == 0)
5766 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5767
5768 if (inst.reloc.type != BFD_RELOC_UNUSED)
5769 {
5770 p += 9;
5f4273c7 5771 skip_whitespace (p);
b6895b4f
PB
5772 }
5773
5774 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5775 return FAIL;
5776
5777 if (inst.reloc.type == BFD_RELOC_UNUSED)
5778 {
5779 if (inst.reloc.exp.X_op != O_constant)
5780 {
5781 inst.error = _("constant expression expected");
5782 return FAIL;
5783 }
5784 if (inst.reloc.exp.X_add_number < 0
5785 || inst.reloc.exp.X_add_number > 0xffff)
5786 {
5787 inst.error = _("immediate value out of range");
5788 return FAIL;
5789 }
5790 }
5791 *str = p;
5792 return SUCCESS;
5793}
5794
c19d1205 5795/* Miscellaneous. */
a737bd4d 5796
c19d1205
ZW
5797/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5798 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5799static int
d2cd1205 5800parse_psr (char **str, bfd_boolean lhs)
09d92015 5801{
c19d1205
ZW
5802 char *p;
5803 unsigned long psr_field;
62b3e311
PB
5804 const struct asm_psr *psr;
5805 char *start;
d2cd1205 5806 bfd_boolean is_apsr = FALSE;
ac7f631b 5807 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
09d92015 5808
a4482bb6
NC
5809 /* PR gas/12698: If the user has specified -march=all then m_profile will
5810 be TRUE, but we want to ignore it in this case as we are building for any
5811 CPU type, including non-m variants. */
823d2571 5812 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
a4482bb6
NC
5813 m_profile = FALSE;
5814
c19d1205
ZW
5815 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5816 feature for ease of use and backwards compatibility. */
5817 p = *str;
62b3e311 5818 if (strncasecmp (p, "SPSR", 4) == 0)
d2cd1205
JB
5819 {
5820 if (m_profile)
5821 goto unsupported_psr;
fa94de6b 5822
d2cd1205
JB
5823 psr_field = SPSR_BIT;
5824 }
5825 else if (strncasecmp (p, "CPSR", 4) == 0)
5826 {
5827 if (m_profile)
5828 goto unsupported_psr;
5829
5830 psr_field = 0;
5831 }
5832 else if (strncasecmp (p, "APSR", 4) == 0)
5833 {
5834 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5835 and ARMv7-R architecture CPUs. */
5836 is_apsr = TRUE;
5837 psr_field = 0;
5838 }
5839 else if (m_profile)
62b3e311
PB
5840 {
5841 start = p;
5842 do
5843 p++;
5844 while (ISALNUM (*p) || *p == '_');
5845
d2cd1205
JB
5846 if (strncasecmp (start, "iapsr", 5) == 0
5847 || strncasecmp (start, "eapsr", 5) == 0
5848 || strncasecmp (start, "xpsr", 4) == 0
5849 || strncasecmp (start, "psr", 3) == 0)
5850 p = start + strcspn (start, "rR") + 1;
5851
21d799b5 5852 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
477330fc 5853 p - start);
d2cd1205 5854
62b3e311
PB
5855 if (!psr)
5856 return FAIL;
09d92015 5857
d2cd1205
JB
5858 /* If APSR is being written, a bitfield may be specified. Note that
5859 APSR itself is handled above. */
5860 if (psr->field <= 3)
5861 {
5862 psr_field = psr->field;
5863 is_apsr = TRUE;
5864 goto check_suffix;
5865 }
5866
62b3e311 5867 *str = p;
d2cd1205
JB
5868 /* M-profile MSR instructions have the mask field set to "10", except
5869 *PSR variants which modify APSR, which may use a different mask (and
5870 have been handled already). Do that by setting the PSR_f field
5871 here. */
5872 return psr->field | (lhs ? PSR_f : 0);
62b3e311 5873 }
d2cd1205
JB
5874 else
5875 goto unsupported_psr;
09d92015 5876
62b3e311 5877 p += 4;
d2cd1205 5878check_suffix:
c19d1205
ZW
5879 if (*p == '_')
5880 {
5881 /* A suffix follows. */
c19d1205
ZW
5882 p++;
5883 start = p;
a737bd4d 5884
c19d1205
ZW
5885 do
5886 p++;
5887 while (ISALNUM (*p) || *p == '_');
a737bd4d 5888
d2cd1205
JB
5889 if (is_apsr)
5890 {
5891 /* APSR uses a notation for bits, rather than fields. */
5892 unsigned int nzcvq_bits = 0;
5893 unsigned int g_bit = 0;
5894 char *bit;
fa94de6b 5895
d2cd1205
JB
5896 for (bit = start; bit != p; bit++)
5897 {
5898 switch (TOLOWER (*bit))
477330fc 5899 {
d2cd1205
JB
5900 case 'n':
5901 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5902 break;
5903
5904 case 'z':
5905 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5906 break;
5907
5908 case 'c':
5909 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5910 break;
5911
5912 case 'v':
5913 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5914 break;
fa94de6b 5915
d2cd1205
JB
5916 case 'q':
5917 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5918 break;
fa94de6b 5919
d2cd1205
JB
5920 case 'g':
5921 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5922 break;
fa94de6b 5923
d2cd1205
JB
5924 default:
5925 inst.error = _("unexpected bit specified after APSR");
5926 return FAIL;
5927 }
5928 }
fa94de6b 5929
d2cd1205
JB
5930 if (nzcvq_bits == 0x1f)
5931 psr_field |= PSR_f;
fa94de6b 5932
d2cd1205
JB
5933 if (g_bit == 0x1)
5934 {
5935 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
477330fc 5936 {
d2cd1205
JB
5937 inst.error = _("selected processor does not "
5938 "support DSP extension");
5939 return FAIL;
5940 }
5941
5942 psr_field |= PSR_s;
5943 }
fa94de6b 5944
d2cd1205
JB
5945 if ((nzcvq_bits & 0x20) != 0
5946 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5947 || (g_bit & 0x2) != 0)
5948 {
5949 inst.error = _("bad bitmask specified after APSR");
5950 return FAIL;
5951 }
5952 }
5953 else
477330fc 5954 {
d2cd1205 5955 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
477330fc 5956 p - start);
d2cd1205 5957 if (!psr)
477330fc 5958 goto error;
a737bd4d 5959
d2cd1205
JB
5960 psr_field |= psr->field;
5961 }
a737bd4d 5962 }
c19d1205 5963 else
a737bd4d 5964 {
c19d1205
ZW
5965 if (ISALNUM (*p))
5966 goto error; /* Garbage after "[CS]PSR". */
5967
d2cd1205 5968 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
477330fc 5969 is deprecated, but allow it anyway. */
d2cd1205
JB
5970 if (is_apsr && lhs)
5971 {
5972 psr_field |= PSR_f;
5973 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5974 "deprecated"));
5975 }
5976 else if (!m_profile)
5977 /* These bits are never right for M-profile devices: don't set them
5978 (only code paths which read/write APSR reach here). */
5979 psr_field |= (PSR_c | PSR_f);
a737bd4d 5980 }
c19d1205
ZW
5981 *str = p;
5982 return psr_field;
a737bd4d 5983
d2cd1205
JB
5984 unsupported_psr:
5985 inst.error = _("selected processor does not support requested special "
5986 "purpose register");
5987 return FAIL;
5988
c19d1205
ZW
5989 error:
5990 inst.error = _("flag for {c}psr instruction expected");
5991 return FAIL;
a737bd4d
NC
5992}
5993
c19d1205
ZW
5994/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5995 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5996
c19d1205
ZW
5997static int
5998parse_cps_flags (char **str)
a737bd4d 5999{
c19d1205
ZW
6000 int val = 0;
6001 int saw_a_flag = 0;
6002 char *s = *str;
a737bd4d 6003
c19d1205
ZW
6004 for (;;)
6005 switch (*s++)
6006 {
6007 case '\0': case ',':
6008 goto done;
a737bd4d 6009
c19d1205
ZW
6010 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6011 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6012 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 6013
c19d1205
ZW
6014 default:
6015 inst.error = _("unrecognized CPS flag");
6016 return FAIL;
6017 }
a737bd4d 6018
c19d1205
ZW
6019 done:
6020 if (saw_a_flag == 0)
a737bd4d 6021 {
c19d1205
ZW
6022 inst.error = _("missing CPS flags");
6023 return FAIL;
a737bd4d 6024 }
a737bd4d 6025
c19d1205
ZW
6026 *str = s - 1;
6027 return val;
a737bd4d
NC
6028}
6029
c19d1205
ZW
6030/* Parse an endian specifier ("BE" or "LE", case insensitive);
6031 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
6032
6033static int
c19d1205 6034parse_endian_specifier (char **str)
a737bd4d 6035{
c19d1205
ZW
6036 int little_endian;
6037 char *s = *str;
a737bd4d 6038
c19d1205
ZW
6039 if (strncasecmp (s, "BE", 2))
6040 little_endian = 0;
6041 else if (strncasecmp (s, "LE", 2))
6042 little_endian = 1;
6043 else
a737bd4d 6044 {
c19d1205 6045 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6046 return FAIL;
6047 }
6048
c19d1205 6049 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 6050 {
c19d1205 6051 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
6052 return FAIL;
6053 }
6054
c19d1205
ZW
6055 *str = s + 2;
6056 return little_endian;
6057}
a737bd4d 6058
c19d1205
ZW
6059/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6060 value suitable for poking into the rotate field of an sxt or sxta
6061 instruction, or FAIL on error. */
6062
6063static int
6064parse_ror (char **str)
6065{
6066 int rot;
6067 char *s = *str;
6068
6069 if (strncasecmp (s, "ROR", 3) == 0)
6070 s += 3;
6071 else
a737bd4d 6072 {
c19d1205 6073 inst.error = _("missing rotation field after comma");
a737bd4d
NC
6074 return FAIL;
6075 }
c19d1205
ZW
6076
6077 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6078 return FAIL;
6079
6080 switch (rot)
a737bd4d 6081 {
c19d1205
ZW
6082 case 0: *str = s; return 0x0;
6083 case 8: *str = s; return 0x1;
6084 case 16: *str = s; return 0x2;
6085 case 24: *str = s; return 0x3;
6086
6087 default:
6088 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
6089 return FAIL;
6090 }
c19d1205 6091}
a737bd4d 6092
c19d1205
ZW
6093/* Parse a conditional code (from conds[] below). The value returned is in the
6094 range 0 .. 14, or FAIL. */
6095static int
6096parse_cond (char **str)
6097{
c462b453 6098 char *q;
c19d1205 6099 const struct asm_cond *c;
c462b453
PB
6100 int n;
6101 /* Condition codes are always 2 characters, so matching up to
6102 3 characters is sufficient. */
6103 char cond[3];
a737bd4d 6104
c462b453
PB
6105 q = *str;
6106 n = 0;
6107 while (ISALPHA (*q) && n < 3)
6108 {
e07e6e58 6109 cond[n] = TOLOWER (*q);
c462b453
PB
6110 q++;
6111 n++;
6112 }
a737bd4d 6113
21d799b5 6114 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 6115 if (!c)
a737bd4d 6116 {
c19d1205 6117 inst.error = _("condition required");
a737bd4d
NC
6118 return FAIL;
6119 }
6120
c19d1205
ZW
6121 *str = q;
6122 return c->value;
6123}
6124
643afb90
MW
6125/* Record a use of the given feature. */
6126static void
6127record_feature_use (const arm_feature_set *feature)
6128{
6129 if (thumb_mode)
6130 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6131 else
6132 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6133}
6134
e797f7e0
MGD
6135/* If the given feature available in the selected CPU, mark it as used.
6136 Returns TRUE iff feature is available. */
6137static bfd_boolean
6138mark_feature_used (const arm_feature_set *feature)
6139{
6140 /* Ensure the option is valid on the current architecture. */
6141 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6142 return FALSE;
6143
6144 /* Add the appropriate architecture feature for the barrier option used.
6145 */
643afb90 6146 record_feature_use (feature);
e797f7e0
MGD
6147
6148 return TRUE;
6149}
6150
62b3e311
PB
6151/* Parse an option for a barrier instruction. Returns the encoding for the
6152 option, or FAIL. */
6153static int
6154parse_barrier (char **str)
6155{
6156 char *p, *q;
6157 const struct asm_barrier_opt *o;
6158
6159 p = q = *str;
6160 while (ISALPHA (*q))
6161 q++;
6162
21d799b5 6163 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
477330fc 6164 q - p);
62b3e311
PB
6165 if (!o)
6166 return FAIL;
6167
e797f7e0
MGD
6168 if (!mark_feature_used (&o->arch))
6169 return FAIL;
6170
62b3e311
PB
6171 *str = q;
6172 return o->value;
6173}
6174
92e90b6e
PB
6175/* Parse the operands of a table branch instruction. Similar to a memory
6176 operand. */
6177static int
6178parse_tb (char **str)
6179{
6180 char * p = *str;
6181 int reg;
6182
6183 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
6184 {
6185 inst.error = _("'[' expected");
6186 return FAIL;
6187 }
92e90b6e 6188
dcbf9037 6189 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6190 {
6191 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6192 return FAIL;
6193 }
6194 inst.operands[0].reg = reg;
6195
6196 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
6197 {
6198 inst.error = _("',' expected");
6199 return FAIL;
6200 }
5f4273c7 6201
dcbf9037 6202 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
6203 {
6204 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6205 return FAIL;
6206 }
6207 inst.operands[0].imm = reg;
6208
6209 if (skip_past_comma (&p) == SUCCESS)
6210 {
6211 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6212 return FAIL;
6213 if (inst.reloc.exp.X_add_number != 1)
6214 {
6215 inst.error = _("invalid shift");
6216 return FAIL;
6217 }
6218 inst.operands[0].shifted = 1;
6219 }
6220
6221 if (skip_past_char (&p, ']') == FAIL)
6222 {
6223 inst.error = _("']' expected");
6224 return FAIL;
6225 }
6226 *str = p;
6227 return SUCCESS;
6228}
6229
5287ad62
JB
6230/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6231 information on the types the operands can take and how they are encoded.
037e8744
JB
6232 Up to four operands may be read; this function handles setting the
6233 ".present" field for each read operand itself.
5287ad62
JB
6234 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6235 else returns FAIL. */
6236
6237static int
6238parse_neon_mov (char **str, int *which_operand)
6239{
6240 int i = *which_operand, val;
6241 enum arm_reg_type rtype;
6242 char *ptr = *str;
dcbf9037 6243 struct neon_type_el optype;
5f4273c7 6244
dcbf9037 6245 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
6246 {
6247 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6248 inst.operands[i].reg = val;
6249 inst.operands[i].isscalar = 1;
dcbf9037 6250 inst.operands[i].vectype = optype;
5287ad62
JB
6251 inst.operands[i++].present = 1;
6252
6253 if (skip_past_comma (&ptr) == FAIL)
477330fc 6254 goto wanted_comma;
5f4273c7 6255
dcbf9037 6256 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
477330fc 6257 goto wanted_arm;
5f4273c7 6258
5287ad62
JB
6259 inst.operands[i].reg = val;
6260 inst.operands[i].isreg = 1;
6261 inst.operands[i].present = 1;
6262 }
037e8744 6263 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
477330fc 6264 != FAIL)
5287ad62
JB
6265 {
6266 /* Cases 0, 1, 2, 3, 5 (D only). */
6267 if (skip_past_comma (&ptr) == FAIL)
477330fc 6268 goto wanted_comma;
5f4273c7 6269
5287ad62
JB
6270 inst.operands[i].reg = val;
6271 inst.operands[i].isreg = 1;
6272 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
6273 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6274 inst.operands[i].isvec = 1;
dcbf9037 6275 inst.operands[i].vectype = optype;
5287ad62
JB
6276 inst.operands[i++].present = 1;
6277
dcbf9037 6278 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6279 {
6280 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6281 Case 13: VMOV <Sd>, <Rm> */
6282 inst.operands[i].reg = val;
6283 inst.operands[i].isreg = 1;
6284 inst.operands[i].present = 1;
6285
6286 if (rtype == REG_TYPE_NQ)
6287 {
6288 first_error (_("can't use Neon quad register here"));
6289 return FAIL;
6290 }
6291 else if (rtype != REG_TYPE_VFS)
6292 {
6293 i++;
6294 if (skip_past_comma (&ptr) == FAIL)
6295 goto wanted_comma;
6296 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6297 goto wanted_arm;
6298 inst.operands[i].reg = val;
6299 inst.operands[i].isreg = 1;
6300 inst.operands[i].present = 1;
6301 }
6302 }
037e8744 6303 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
477330fc
RM
6304 &optype)) != FAIL)
6305 {
6306 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6307 Case 1: VMOV<c><q> <Dd>, <Dm>
6308 Case 8: VMOV.F32 <Sd>, <Sm>
6309 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6310
6311 inst.operands[i].reg = val;
6312 inst.operands[i].isreg = 1;
6313 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6314 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6315 inst.operands[i].isvec = 1;
6316 inst.operands[i].vectype = optype;
6317 inst.operands[i].present = 1;
6318
6319 if (skip_past_comma (&ptr) == SUCCESS)
6320 {
6321 /* Case 15. */
6322 i++;
6323
6324 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6325 goto wanted_arm;
6326
6327 inst.operands[i].reg = val;
6328 inst.operands[i].isreg = 1;
6329 inst.operands[i++].present = 1;
6330
6331 if (skip_past_comma (&ptr) == FAIL)
6332 goto wanted_comma;
6333
6334 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6335 goto wanted_arm;
6336
6337 inst.operands[i].reg = val;
6338 inst.operands[i].isreg = 1;
6339 inst.operands[i].present = 1;
6340 }
6341 }
4641781c 6342 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
477330fc
RM
6343 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6344 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6345 Case 10: VMOV.F32 <Sd>, #<imm>
6346 Case 11: VMOV.F64 <Dd>, #<imm> */
6347 inst.operands[i].immisfloat = 1;
8335d6aa
JW
6348 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6349 == SUCCESS)
477330fc
RM
6350 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6351 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6352 ;
5287ad62 6353 else
477330fc
RM
6354 {
6355 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6356 return FAIL;
6357 }
5287ad62 6358 }
dcbf9037 6359 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
6360 {
6361 /* Cases 6, 7. */
6362 inst.operands[i].reg = val;
6363 inst.operands[i].isreg = 1;
6364 inst.operands[i++].present = 1;
5f4273c7 6365
5287ad62 6366 if (skip_past_comma (&ptr) == FAIL)
477330fc 6367 goto wanted_comma;
5f4273c7 6368
dcbf9037 6369 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
477330fc
RM
6370 {
6371 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6372 inst.operands[i].reg = val;
6373 inst.operands[i].isscalar = 1;
6374 inst.operands[i].present = 1;
6375 inst.operands[i].vectype = optype;
6376 }
dcbf9037 6377 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
477330fc
RM
6378 {
6379 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6380 inst.operands[i].reg = val;
6381 inst.operands[i].isreg = 1;
6382 inst.operands[i++].present = 1;
6383
6384 if (skip_past_comma (&ptr) == FAIL)
6385 goto wanted_comma;
6386
6387 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6388 == FAIL)
6389 {
6390 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6391 return FAIL;
6392 }
6393
6394 inst.operands[i].reg = val;
6395 inst.operands[i].isreg = 1;
6396 inst.operands[i].isvec = 1;
6397 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6398 inst.operands[i].vectype = optype;
6399 inst.operands[i].present = 1;
6400
6401 if (rtype == REG_TYPE_VFS)
6402 {
6403 /* Case 14. */
6404 i++;
6405 if (skip_past_comma (&ptr) == FAIL)
6406 goto wanted_comma;
6407 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6408 &optype)) == FAIL)
6409 {
6410 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6411 return FAIL;
6412 }
6413 inst.operands[i].reg = val;
6414 inst.operands[i].isreg = 1;
6415 inst.operands[i].isvec = 1;
6416 inst.operands[i].issingle = 1;
6417 inst.operands[i].vectype = optype;
6418 inst.operands[i].present = 1;
6419 }
6420 }
037e8744 6421 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
477330fc
RM
6422 != FAIL)
6423 {
6424 /* Case 13. */
6425 inst.operands[i].reg = val;
6426 inst.operands[i].isreg = 1;
6427 inst.operands[i].isvec = 1;
6428 inst.operands[i].issingle = 1;
6429 inst.operands[i].vectype = optype;
6430 inst.operands[i].present = 1;
6431 }
5287ad62
JB
6432 }
6433 else
6434 {
dcbf9037 6435 first_error (_("parse error"));
5287ad62
JB
6436 return FAIL;
6437 }
6438
6439 /* Successfully parsed the operands. Update args. */
6440 *which_operand = i;
6441 *str = ptr;
6442 return SUCCESS;
6443
5f4273c7 6444 wanted_comma:
dcbf9037 6445 first_error (_("expected comma"));
5287ad62 6446 return FAIL;
5f4273c7
NC
6447
6448 wanted_arm:
dcbf9037 6449 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 6450 return FAIL;
5287ad62
JB
6451}
6452
5be8be5d
DG
6453/* Use this macro when the operand constraints are different
6454 for ARM and THUMB (e.g. ldrd). */
6455#define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6456 ((arm_operand) | ((thumb_operand) << 16))
6457
c19d1205
ZW
6458/* Matcher codes for parse_operands. */
6459enum operand_parse_code
6460{
6461 OP_stop, /* end of line */
6462
6463 OP_RR, /* ARM register */
6464 OP_RRnpc, /* ARM register, not r15 */
5be8be5d 6465 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
c19d1205 6466 OP_RRnpcb, /* ARM register, not r15, in square brackets */
fa94de6b 6467 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
55881a11 6468 optional trailing ! */
c19d1205
ZW
6469 OP_RRw, /* ARM register, not r15, optional trailing ! */
6470 OP_RCP, /* Coprocessor number */
6471 OP_RCN, /* Coprocessor register */
6472 OP_RF, /* FPA register */
6473 OP_RVS, /* VFP single precision register */
5287ad62
JB
6474 OP_RVD, /* VFP double precision register (0..15) */
6475 OP_RND, /* Neon double precision register (0..31) */
6476 OP_RNQ, /* Neon quad precision register */
037e8744 6477 OP_RVSD, /* VFP single or double precision register */
5287ad62 6478 OP_RNDQ, /* Neon double or quad precision register */
037e8744 6479 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 6480 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
6481 OP_RVC, /* VFP control register */
6482 OP_RMF, /* Maverick F register */
6483 OP_RMD, /* Maverick D register */
6484 OP_RMFX, /* Maverick FX register */
6485 OP_RMDX, /* Maverick DX register */
6486 OP_RMAX, /* Maverick AX register */
6487 OP_RMDS, /* Maverick DSPSC register */
6488 OP_RIWR, /* iWMMXt wR register */
6489 OP_RIWC, /* iWMMXt wC register */
6490 OP_RIWG, /* iWMMXt wCG register */
6491 OP_RXA, /* XScale accumulator register */
6492
6493 OP_REGLST, /* ARM register list */
6494 OP_VRSLST, /* VFP single-precision register list */
6495 OP_VRDLST, /* VFP double-precision register list */
037e8744 6496 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
6497 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6498 OP_NSTRLST, /* Neon element/structure list */
6499
5287ad62 6500 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 6501 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
aacf0b33 6502 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
5287ad62 6503 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 6504 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
6505 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6506 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6507 OP_VMOV, /* Neon VMOV operands. */
4316f0d2 6508 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5287ad62 6509 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 6510 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
6511
6512 OP_I0, /* immediate zero */
c19d1205
ZW
6513 OP_I7, /* immediate value 0 .. 7 */
6514 OP_I15, /* 0 .. 15 */
6515 OP_I16, /* 1 .. 16 */
5287ad62 6516 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
6517 OP_I31, /* 0 .. 31 */
6518 OP_I31w, /* 0 .. 31, optional trailing ! */
6519 OP_I32, /* 1 .. 32 */
5287ad62
JB
6520 OP_I32z, /* 0 .. 32 */
6521 OP_I63, /* 0 .. 63 */
c19d1205 6522 OP_I63s, /* -64 .. 63 */
5287ad62
JB
6523 OP_I64, /* 1 .. 64 */
6524 OP_I64z, /* 0 .. 64 */
c19d1205 6525 OP_I255, /* 0 .. 255 */
c19d1205
ZW
6526
6527 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6528 OP_I7b, /* 0 .. 7 */
6529 OP_I15b, /* 0 .. 15 */
6530 OP_I31b, /* 0 .. 31 */
6531
6532 OP_SH, /* shifter operand */
4962c51a 6533 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 6534 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
6535 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6536 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6537 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
6538 OP_EXP, /* arbitrary expression */
6539 OP_EXPi, /* same, with optional immediate prefix */
6540 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 6541 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c28eeff2
SN
6542 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
6543 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
c19d1205
ZW
6544
6545 OP_CPSF, /* CPS flags */
6546 OP_ENDI, /* Endianness specifier */
d2cd1205
JB
6547 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6548 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
c19d1205 6549 OP_COND, /* conditional code */
92e90b6e 6550 OP_TB, /* Table branch. */
c19d1205 6551
037e8744
JB
6552 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6553
c19d1205 6554 OP_RRnpc_I0, /* ARM register or literal 0 */
33eaf5de 6555 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
c19d1205
ZW
6556 OP_RR_EXi, /* ARM register or expression with imm prefix */
6557 OP_RF_IF, /* FPA register or immediate */
6558 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 6559 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
6560
6561 /* Optional operands. */
6562 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6563 OP_oI31b, /* 0 .. 31 */
5287ad62 6564 OP_oI32b, /* 1 .. 32 */
5f1af56b 6565 OP_oI32z, /* 0 .. 32 */
c19d1205
ZW
6566 OP_oIffffb, /* 0 .. 65535 */
6567 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6568
6569 OP_oRR, /* ARM register */
6570 OP_oRRnpc, /* ARM register, not the PC */
5be8be5d 6571 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
b6702015 6572 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
6573 OP_oRND, /* Optional Neon double precision register */
6574 OP_oRNQ, /* Optional Neon quad precision register */
6575 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 6576 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
6577 OP_oSHll, /* LSL immediate */
6578 OP_oSHar, /* ASR immediate */
6579 OP_oSHllar, /* LSL or ASR immediate */
6580 OP_oROR, /* ROR 0/8/16/24 */
52e7f43d 6581 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
c19d1205 6582
5be8be5d
DG
6583 /* Some pre-defined mixed (ARM/THUMB) operands. */
6584 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6585 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6586 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6587
c19d1205
ZW
6588 OP_FIRST_OPTIONAL = OP_oI7b
6589};
a737bd4d 6590
c19d1205
ZW
6591/* Generic instruction operand parser. This does no encoding and no
6592 semantic validation; it merely squirrels values away in the inst
6593 structure. Returns SUCCESS or FAIL depending on whether the
6594 specified grammar matched. */
6595static int
5be8be5d 6596parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
c19d1205 6597{
5be8be5d 6598 unsigned const int *upat = pattern;
c19d1205
ZW
6599 char *backtrack_pos = 0;
6600 const char *backtrack_error = 0;
99aad254 6601 int i, val = 0, backtrack_index = 0;
5287ad62 6602 enum arm_reg_type rtype;
4962c51a 6603 parse_operand_result result;
5be8be5d 6604 unsigned int op_parse_code;
c19d1205 6605
e07e6e58
NC
6606#define po_char_or_fail(chr) \
6607 do \
6608 { \
6609 if (skip_past_char (&str, chr) == FAIL) \
477330fc 6610 goto bad_args; \
e07e6e58
NC
6611 } \
6612 while (0)
c19d1205 6613
e07e6e58
NC
6614#define po_reg_or_fail(regtype) \
6615 do \
dcbf9037 6616 { \
e07e6e58 6617 val = arm_typed_reg_parse (& str, regtype, & rtype, \
477330fc 6618 & inst.operands[i].vectype); \
e07e6e58 6619 if (val == FAIL) \
477330fc
RM
6620 { \
6621 first_error (_(reg_expected_msgs[regtype])); \
6622 goto failure; \
6623 } \
e07e6e58
NC
6624 inst.operands[i].reg = val; \
6625 inst.operands[i].isreg = 1; \
6626 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6627 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6628 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc
RM
6629 || rtype == REG_TYPE_VFD \
6630 || rtype == REG_TYPE_NQ); \
dcbf9037 6631 } \
e07e6e58
NC
6632 while (0)
6633
6634#define po_reg_or_goto(regtype, label) \
6635 do \
6636 { \
6637 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6638 & inst.operands[i].vectype); \
6639 if (val == FAIL) \
6640 goto label; \
dcbf9037 6641 \
e07e6e58
NC
6642 inst.operands[i].reg = val; \
6643 inst.operands[i].isreg = 1; \
6644 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6645 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6646 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
477330fc 6647 || rtype == REG_TYPE_VFD \
e07e6e58
NC
6648 || rtype == REG_TYPE_NQ); \
6649 } \
6650 while (0)
6651
6652#define po_imm_or_fail(min, max, popt) \
6653 do \
6654 { \
6655 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6656 goto failure; \
6657 inst.operands[i].imm = val; \
6658 } \
6659 while (0)
6660
6661#define po_scalar_or_goto(elsz, label) \
6662 do \
6663 { \
6664 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6665 if (val == FAIL) \
6666 goto label; \
6667 inst.operands[i].reg = val; \
6668 inst.operands[i].isscalar = 1; \
6669 } \
6670 while (0)
6671
6672#define po_misc_or_fail(expr) \
6673 do \
6674 { \
6675 if (expr) \
6676 goto failure; \
6677 } \
6678 while (0)
6679
6680#define po_misc_or_fail_no_backtrack(expr) \
6681 do \
6682 { \
6683 result = expr; \
6684 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6685 backtrack_pos = 0; \
6686 if (result != PARSE_OPERAND_SUCCESS) \
6687 goto failure; \
6688 } \
6689 while (0)
4962c51a 6690
52e7f43d
RE
6691#define po_barrier_or_imm(str) \
6692 do \
6693 { \
6694 val = parse_barrier (&str); \
ccb84d65
JB
6695 if (val == FAIL && ! ISALPHA (*str)) \
6696 goto immediate; \
6697 if (val == FAIL \
6698 /* ISB can only take SY as an option. */ \
6699 || ((inst.instruction & 0xf0) == 0x60 \
6700 && val != 0xf)) \
52e7f43d 6701 { \
ccb84d65
JB
6702 inst.error = _("invalid barrier type"); \
6703 backtrack_pos = 0; \
6704 goto failure; \
52e7f43d
RE
6705 } \
6706 } \
6707 while (0)
6708
c19d1205
ZW
6709 skip_whitespace (str);
6710
6711 for (i = 0; upat[i] != OP_stop; i++)
6712 {
5be8be5d
DG
6713 op_parse_code = upat[i];
6714 if (op_parse_code >= 1<<16)
6715 op_parse_code = thumb ? (op_parse_code >> 16)
6716 : (op_parse_code & ((1<<16)-1));
6717
6718 if (op_parse_code >= OP_FIRST_OPTIONAL)
c19d1205
ZW
6719 {
6720 /* Remember where we are in case we need to backtrack. */
9c2799c2 6721 gas_assert (!backtrack_pos);
c19d1205
ZW
6722 backtrack_pos = str;
6723 backtrack_error = inst.error;
6724 backtrack_index = i;
6725 }
6726
b6702015 6727 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
6728 po_char_or_fail (',');
6729
5be8be5d 6730 switch (op_parse_code)
c19d1205
ZW
6731 {
6732 /* Registers */
6733 case OP_oRRnpc:
5be8be5d 6734 case OP_oRRnpcsp:
c19d1205 6735 case OP_RRnpc:
5be8be5d 6736 case OP_RRnpcsp:
c19d1205
ZW
6737 case OP_oRR:
6738 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6739 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6740 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6741 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6742 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6743 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
477330fc 6744 case OP_oRND:
5287ad62 6745 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
6746 case OP_RVC:
6747 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6748 break;
6749 /* Also accept generic coprocessor regs for unknown registers. */
6750 coproc_reg:
6751 po_reg_or_fail (REG_TYPE_CN);
6752 break;
c19d1205
ZW
6753 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6754 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6755 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6756 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6757 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6758 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6759 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6760 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6761 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6762 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
477330fc 6763 case OP_oRNQ:
5287ad62 6764 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
477330fc 6765 case OP_oRNDQ:
5287ad62 6766 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
477330fc
RM
6767 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6768 case OP_oRNSDQ:
6769 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6770
6771 /* Neon scalar. Using an element size of 8 means that some invalid
6772 scalars are accepted here, so deal with those in later code. */
6773 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6774
6775 case OP_RNDQ_I0:
6776 {
6777 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6778 break;
6779 try_imm0:
6780 po_imm_or_fail (0, 0, TRUE);
6781 }
6782 break;
6783
6784 case OP_RVSD_I0:
6785 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6786 break;
6787
aacf0b33
KT
6788 case OP_RSVD_FI0:
6789 {
6790 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6791 break;
6792 try_ifimm0:
6793 if (parse_ifimm_zero (&str))
6794 inst.operands[i].imm = 0;
6795 else
6796 {
6797 inst.error
6798 = _("only floating point zero is allowed as immediate value");
6799 goto failure;
6800 }
6801 }
6802 break;
6803
477330fc
RM
6804 case OP_RR_RNSC:
6805 {
6806 po_scalar_or_goto (8, try_rr);
6807 break;
6808 try_rr:
6809 po_reg_or_fail (REG_TYPE_RN);
6810 }
6811 break;
6812
6813 case OP_RNSDQ_RNSC:
6814 {
6815 po_scalar_or_goto (8, try_nsdq);
6816 break;
6817 try_nsdq:
6818 po_reg_or_fail (REG_TYPE_NSDQ);
6819 }
6820 break;
6821
6822 case OP_RNDQ_RNSC:
6823 {
6824 po_scalar_or_goto (8, try_ndq);
6825 break;
6826 try_ndq:
6827 po_reg_or_fail (REG_TYPE_NDQ);
6828 }
6829 break;
6830
6831 case OP_RND_RNSC:
6832 {
6833 po_scalar_or_goto (8, try_vfd);
6834 break;
6835 try_vfd:
6836 po_reg_or_fail (REG_TYPE_VFD);
6837 }
6838 break;
6839
6840 case OP_VMOV:
6841 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6842 not careful then bad things might happen. */
6843 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6844 break;
6845
6846 case OP_RNDQ_Ibig:
6847 {
6848 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6849 break;
6850 try_immbig:
6851 /* There's a possibility of getting a 64-bit immediate here, so
6852 we need special handling. */
8335d6aa
JW
6853 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6854 == FAIL)
477330fc
RM
6855 {
6856 inst.error = _("immediate value is out of range");
6857 goto failure;
6858 }
6859 }
6860 break;
6861
6862 case OP_RNDQ_I63b:
6863 {
6864 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6865 break;
6866 try_shimm:
6867 po_imm_or_fail (0, 63, TRUE);
6868 }
6869 break;
c19d1205
ZW
6870
6871 case OP_RRnpcb:
6872 po_char_or_fail ('[');
6873 po_reg_or_fail (REG_TYPE_RN);
6874 po_char_or_fail (']');
6875 break;
a737bd4d 6876
55881a11 6877 case OP_RRnpctw:
c19d1205 6878 case OP_RRw:
b6702015 6879 case OP_oRRw:
c19d1205
ZW
6880 po_reg_or_fail (REG_TYPE_RN);
6881 if (skip_past_char (&str, '!') == SUCCESS)
6882 inst.operands[i].writeback = 1;
6883 break;
6884
6885 /* Immediates */
6886 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6887 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6888 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
477330fc 6889 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6890 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6891 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
477330fc 6892 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6893 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
477330fc
RM
6894 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6895 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6896 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6897 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6898
6899 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6900 case OP_oI7b:
6901 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6902 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6903 case OP_oI31b:
6904 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
477330fc
RM
6905 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6906 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
c19d1205
ZW
6907 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6908
6909 /* Immediate variants */
6910 case OP_oI255c:
6911 po_char_or_fail ('{');
6912 po_imm_or_fail (0, 255, TRUE);
6913 po_char_or_fail ('}');
6914 break;
6915
6916 case OP_I31w:
6917 /* The expression parser chokes on a trailing !, so we have
6918 to find it first and zap it. */
6919 {
6920 char *s = str;
6921 while (*s && *s != ',')
6922 s++;
6923 if (s[-1] == '!')
6924 {
6925 s[-1] = '\0';
6926 inst.operands[i].writeback = 1;
6927 }
6928 po_imm_or_fail (0, 31, TRUE);
6929 if (str == s - 1)
6930 str = s;
6931 }
6932 break;
6933
6934 /* Expressions */
6935 case OP_EXPi: EXPi:
6936 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6937 GE_OPT_PREFIX));
6938 break;
6939
6940 case OP_EXP:
6941 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6942 GE_NO_PREFIX));
6943 break;
6944
6945 case OP_EXPr: EXPr:
6946 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6947 GE_NO_PREFIX));
6948 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6949 {
c19d1205
ZW
6950 val = parse_reloc (&str);
6951 if (val == -1)
6952 {
6953 inst.error = _("unrecognized relocation suffix");
6954 goto failure;
6955 }
6956 else if (val != BFD_RELOC_UNUSED)
6957 {
6958 inst.operands[i].imm = val;
6959 inst.operands[i].hasreloc = 1;
6960 }
a737bd4d 6961 }
c19d1205 6962 break;
a737bd4d 6963
b6895b4f
PB
6964 /* Operand for MOVW or MOVT. */
6965 case OP_HALF:
6966 po_misc_or_fail (parse_half (&str));
6967 break;
6968
e07e6e58 6969 /* Register or expression. */
c19d1205
ZW
6970 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6971 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6972
e07e6e58 6973 /* Register or immediate. */
c19d1205
ZW
6974 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6975 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6976
c19d1205
ZW
6977 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6978 IF:
6979 if (!is_immediate_prefix (*str))
6980 goto bad_args;
6981 str++;
6982 val = parse_fpa_immediate (&str);
6983 if (val == FAIL)
6984 goto failure;
6985 /* FPA immediates are encoded as registers 8-15.
6986 parse_fpa_immediate has already applied the offset. */
6987 inst.operands[i].reg = val;
6988 inst.operands[i].isreg = 1;
6989 break;
09d92015 6990
2d447fca
JM
6991 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6992 I32z: po_imm_or_fail (0, 32, FALSE); break;
6993
e07e6e58 6994 /* Two kinds of register. */
c19d1205
ZW
6995 case OP_RIWR_RIWC:
6996 {
6997 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6998 if (!rege
6999 || (rege->type != REG_TYPE_MMXWR
7000 && rege->type != REG_TYPE_MMXWC
7001 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
7002 {
7003 inst.error = _("iWMMXt data or control register expected");
7004 goto failure;
7005 }
7006 inst.operands[i].reg = rege->number;
7007 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7008 }
7009 break;
09d92015 7010
41adaa5c
JM
7011 case OP_RIWC_RIWG:
7012 {
7013 struct reg_entry *rege = arm_reg_parse_multi (&str);
7014 if (!rege
7015 || (rege->type != REG_TYPE_MMXWC
7016 && rege->type != REG_TYPE_MMXWCG))
7017 {
7018 inst.error = _("iWMMXt control register expected");
7019 goto failure;
7020 }
7021 inst.operands[i].reg = rege->number;
7022 inst.operands[i].isreg = 1;
7023 }
7024 break;
7025
c19d1205
ZW
7026 /* Misc */
7027 case OP_CPSF: val = parse_cps_flags (&str); break;
7028 case OP_ENDI: val = parse_endian_specifier (&str); break;
7029 case OP_oROR: val = parse_ror (&str); break;
c19d1205 7030 case OP_COND: val = parse_cond (&str); break;
52e7f43d
RE
7031 case OP_oBARRIER_I15:
7032 po_barrier_or_imm (str); break;
7033 immediate:
7034 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
477330fc 7035 goto failure;
52e7f43d 7036 break;
c19d1205 7037
fa94de6b 7038 case OP_wPSR:
d2cd1205 7039 case OP_rPSR:
90ec0d68
MGD
7040 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7041 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7042 {
7043 inst.error = _("Banked registers are not available with this "
7044 "architecture.");
7045 goto failure;
7046 }
7047 break;
d2cd1205
JB
7048 try_psr:
7049 val = parse_psr (&str, op_parse_code == OP_wPSR);
7050 break;
037e8744 7051
477330fc
RM
7052 case OP_APSR_RR:
7053 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7054 break;
7055 try_apsr:
7056 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7057 instruction). */
7058 if (strncasecmp (str, "APSR_", 5) == 0)
7059 {
7060 unsigned found = 0;
7061 str += 5;
7062 while (found < 15)
7063 switch (*str++)
7064 {
7065 case 'c': found = (found & 1) ? 16 : found | 1; break;
7066 case 'n': found = (found & 2) ? 16 : found | 2; break;
7067 case 'z': found = (found & 4) ? 16 : found | 4; break;
7068 case 'v': found = (found & 8) ? 16 : found | 8; break;
7069 default: found = 16;
7070 }
7071 if (found != 15)
7072 goto failure;
7073 inst.operands[i].isvec = 1;
f7c21dc7
NC
7074 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7075 inst.operands[i].reg = REG_PC;
477330fc
RM
7076 }
7077 else
7078 goto failure;
7079 break;
037e8744 7080
92e90b6e
PB
7081 case OP_TB:
7082 po_misc_or_fail (parse_tb (&str));
7083 break;
7084
e07e6e58 7085 /* Register lists. */
c19d1205
ZW
7086 case OP_REGLST:
7087 val = parse_reg_list (&str);
7088 if (*str == '^')
7089 {
5e0d7f77 7090 inst.operands[i].writeback = 1;
c19d1205
ZW
7091 str++;
7092 }
7093 break;
09d92015 7094
c19d1205 7095 case OP_VRSLST:
5287ad62 7096 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 7097 break;
09d92015 7098
c19d1205 7099 case OP_VRDLST:
5287ad62 7100 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 7101 break;
a737bd4d 7102
477330fc
RM
7103 case OP_VRSDLST:
7104 /* Allow Q registers too. */
7105 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7106 REGLIST_NEON_D);
7107 if (val == FAIL)
7108 {
7109 inst.error = NULL;
7110 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7111 REGLIST_VFP_S);
7112 inst.operands[i].issingle = 1;
7113 }
7114 break;
7115
7116 case OP_NRDLST:
7117 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7118 REGLIST_NEON_D);
7119 break;
5287ad62
JB
7120
7121 case OP_NSTRLST:
477330fc
RM
7122 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7123 &inst.operands[i].vectype);
7124 break;
5287ad62 7125
c19d1205
ZW
7126 /* Addressing modes */
7127 case OP_ADDR:
7128 po_misc_or_fail (parse_address (&str, i));
7129 break;
09d92015 7130
4962c51a
MS
7131 case OP_ADDRGLDR:
7132 po_misc_or_fail_no_backtrack (
477330fc 7133 parse_address_group_reloc (&str, i, GROUP_LDR));
4962c51a
MS
7134 break;
7135
7136 case OP_ADDRGLDRS:
7137 po_misc_or_fail_no_backtrack (
477330fc 7138 parse_address_group_reloc (&str, i, GROUP_LDRS));
4962c51a
MS
7139 break;
7140
7141 case OP_ADDRGLDC:
7142 po_misc_or_fail_no_backtrack (
477330fc 7143 parse_address_group_reloc (&str, i, GROUP_LDC));
4962c51a
MS
7144 break;
7145
c19d1205
ZW
7146 case OP_SH:
7147 po_misc_or_fail (parse_shifter_operand (&str, i));
7148 break;
09d92015 7149
4962c51a
MS
7150 case OP_SHG:
7151 po_misc_or_fail_no_backtrack (
477330fc 7152 parse_shifter_operand_group_reloc (&str, i));
4962c51a
MS
7153 break;
7154
c19d1205
ZW
7155 case OP_oSHll:
7156 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7157 break;
09d92015 7158
c19d1205
ZW
7159 case OP_oSHar:
7160 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7161 break;
09d92015 7162
c19d1205
ZW
7163 case OP_oSHllar:
7164 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7165 break;
09d92015 7166
c19d1205 7167 default:
5be8be5d 7168 as_fatal (_("unhandled operand code %d"), op_parse_code);
c19d1205 7169 }
09d92015 7170
c19d1205
ZW
7171 /* Various value-based sanity checks and shared operations. We
7172 do not signal immediate failures for the register constraints;
7173 this allows a syntax error to take precedence. */
5be8be5d 7174 switch (op_parse_code)
c19d1205
ZW
7175 {
7176 case OP_oRRnpc:
7177 case OP_RRnpc:
7178 case OP_RRnpcb:
7179 case OP_RRw:
b6702015 7180 case OP_oRRw:
c19d1205
ZW
7181 case OP_RRnpc_I0:
7182 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7183 inst.error = BAD_PC;
7184 break;
09d92015 7185
5be8be5d
DG
7186 case OP_oRRnpcsp:
7187 case OP_RRnpcsp:
7188 if (inst.operands[i].isreg)
7189 {
7190 if (inst.operands[i].reg == REG_PC)
7191 inst.error = BAD_PC;
5c8ed6a4
JW
7192 else if (inst.operands[i].reg == REG_SP
7193 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
7194 relaxed since ARMv8-A. */
7195 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
7196 {
7197 gas_assert (thumb);
7198 inst.error = BAD_SP;
7199 }
5be8be5d
DG
7200 }
7201 break;
7202
55881a11 7203 case OP_RRnpctw:
fa94de6b
RM
7204 if (inst.operands[i].isreg
7205 && inst.operands[i].reg == REG_PC
55881a11
MGD
7206 && (inst.operands[i].writeback || thumb))
7207 inst.error = BAD_PC;
7208 break;
7209
c19d1205
ZW
7210 case OP_CPSF:
7211 case OP_ENDI:
7212 case OP_oROR:
d2cd1205
JB
7213 case OP_wPSR:
7214 case OP_rPSR:
c19d1205 7215 case OP_COND:
52e7f43d 7216 case OP_oBARRIER_I15:
c19d1205
ZW
7217 case OP_REGLST:
7218 case OP_VRSLST:
7219 case OP_VRDLST:
477330fc
RM
7220 case OP_VRSDLST:
7221 case OP_NRDLST:
7222 case OP_NSTRLST:
c19d1205
ZW
7223 if (val == FAIL)
7224 goto failure;
7225 inst.operands[i].imm = val;
7226 break;
a737bd4d 7227
c19d1205
ZW
7228 default:
7229 break;
7230 }
09d92015 7231
c19d1205
ZW
7232 /* If we get here, this operand was successfully parsed. */
7233 inst.operands[i].present = 1;
7234 continue;
09d92015 7235
c19d1205 7236 bad_args:
09d92015 7237 inst.error = BAD_ARGS;
c19d1205
ZW
7238
7239 failure:
7240 if (!backtrack_pos)
d252fdde
PB
7241 {
7242 /* The parse routine should already have set inst.error, but set a
5f4273c7 7243 default here just in case. */
d252fdde
PB
7244 if (!inst.error)
7245 inst.error = _("syntax error");
7246 return FAIL;
7247 }
c19d1205
ZW
7248
7249 /* Do not backtrack over a trailing optional argument that
7250 absorbed some text. We will only fail again, with the
7251 'garbage following instruction' error message, which is
7252 probably less helpful than the current one. */
7253 if (backtrack_index == i && backtrack_pos != str
7254 && upat[i+1] == OP_stop)
d252fdde
PB
7255 {
7256 if (!inst.error)
7257 inst.error = _("syntax error");
7258 return FAIL;
7259 }
c19d1205
ZW
7260
7261 /* Try again, skipping the optional argument at backtrack_pos. */
7262 str = backtrack_pos;
7263 inst.error = backtrack_error;
7264 inst.operands[backtrack_index].present = 0;
7265 i = backtrack_index;
7266 backtrack_pos = 0;
09d92015 7267 }
09d92015 7268
c19d1205
ZW
7269 /* Check that we have parsed all the arguments. */
7270 if (*str != '\0' && !inst.error)
7271 inst.error = _("garbage following instruction");
09d92015 7272
c19d1205 7273 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7274}
7275
c19d1205
ZW
7276#undef po_char_or_fail
7277#undef po_reg_or_fail
7278#undef po_reg_or_goto
7279#undef po_imm_or_fail
5287ad62 7280#undef po_scalar_or_fail
52e7f43d 7281#undef po_barrier_or_imm
e07e6e58 7282
c19d1205 7283/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7284#define constraint(expr, err) \
7285 do \
c19d1205 7286 { \
e07e6e58
NC
7287 if (expr) \
7288 { \
7289 inst.error = err; \
7290 return; \
7291 } \
c19d1205 7292 } \
e07e6e58 7293 while (0)
c19d1205 7294
fdfde340
JM
7295/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7296 instructions are unpredictable if these registers are used. This
5c8ed6a4
JW
7297 is the BadReg predicate in ARM's Thumb-2 documentation.
7298
7299 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
7300 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
7301#define reject_bad_reg(reg) \
7302 do \
7303 if (reg == REG_PC) \
7304 { \
7305 inst.error = BAD_PC; \
7306 return; \
7307 } \
7308 else if (reg == REG_SP \
7309 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
7310 { \
7311 inst.error = BAD_SP; \
7312 return; \
7313 } \
fdfde340
JM
7314 while (0)
7315
94206790
MM
7316/* If REG is R13 (the stack pointer), warn that its use is
7317 deprecated. */
7318#define warn_deprecated_sp(reg) \
7319 do \
7320 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7321 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7322 while (0)
7323
c19d1205
ZW
7324/* Functions for operand encoding. ARM, then Thumb. */
7325
d840c081 7326#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 7327
9db2f6b4
RL
7328/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7329
7330 The only binary encoding difference is the Coprocessor number. Coprocessor
7331 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 7332 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
7333 exists for Single-Precision operation. */
7334
7335static void
7336do_scalar_fp16_v82_encode (void)
7337{
7338 if (inst.cond != COND_ALWAYS)
7339 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7340 " the behaviour is UNPREDICTABLE"));
7341 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7342 _(BAD_FP16));
7343
7344 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7345 mark_feature_used (&arm_ext_fp16);
7346}
7347
c19d1205
ZW
7348/* If VAL can be encoded in the immediate field of an ARM instruction,
7349 return the encoded form. Otherwise, return FAIL. */
7350
7351static unsigned int
7352encode_arm_immediate (unsigned int val)
09d92015 7353{
c19d1205
ZW
7354 unsigned int a, i;
7355
4f1d6205
L
7356 if (val <= 0xff)
7357 return val;
7358
7359 for (i = 2; i < 32; i += 2)
c19d1205
ZW
7360 if ((a = rotate_left (val, i)) <= 0xff)
7361 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7362
7363 return FAIL;
09d92015
MM
7364}
7365
c19d1205
ZW
7366/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7367 return the encoded form. Otherwise, return FAIL. */
7368static unsigned int
7369encode_thumb32_immediate (unsigned int val)
09d92015 7370{
c19d1205 7371 unsigned int a, i;
09d92015 7372
9c3c69f2 7373 if (val <= 0xff)
c19d1205 7374 return val;
a737bd4d 7375
9c3c69f2 7376 for (i = 1; i <= 24; i++)
09d92015 7377 {
9c3c69f2
PB
7378 a = val >> i;
7379 if ((val & ~(0xff << i)) == 0)
7380 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7381 }
a737bd4d 7382
c19d1205
ZW
7383 a = val & 0xff;
7384 if (val == ((a << 16) | a))
7385 return 0x100 | a;
7386 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7387 return 0x300 | a;
09d92015 7388
c19d1205
ZW
7389 a = val & 0xff00;
7390 if (val == ((a << 16) | a))
7391 return 0x200 | (a >> 8);
a737bd4d 7392
c19d1205 7393 return FAIL;
09d92015 7394}
5287ad62 7395/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7396
7397static void
5287ad62
JB
7398encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7399{
7400 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7401 && reg > 15)
7402 {
b1cc4aeb 7403 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7404 {
7405 if (thumb_mode)
7406 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7407 fpu_vfp_ext_d32);
7408 else
7409 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7410 fpu_vfp_ext_d32);
7411 }
5287ad62 7412 else
477330fc
RM
7413 {
7414 first_error (_("D register out of range for selected VFP version"));
7415 return;
7416 }
5287ad62
JB
7417 }
7418
c19d1205 7419 switch (pos)
09d92015 7420 {
c19d1205
ZW
7421 case VFP_REG_Sd:
7422 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7423 break;
7424
7425 case VFP_REG_Sn:
7426 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7427 break;
7428
7429 case VFP_REG_Sm:
7430 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7431 break;
7432
5287ad62
JB
7433 case VFP_REG_Dd:
7434 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7435 break;
5f4273c7 7436
5287ad62
JB
7437 case VFP_REG_Dn:
7438 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7439 break;
5f4273c7 7440
5287ad62
JB
7441 case VFP_REG_Dm:
7442 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7443 break;
7444
c19d1205
ZW
7445 default:
7446 abort ();
09d92015 7447 }
09d92015
MM
7448}
7449
c19d1205 7450/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7451 if any, is handled by md_apply_fix. */
09d92015 7452static void
c19d1205 7453encode_arm_shift (int i)
09d92015 7454{
008a97ef
RL
7455 /* register-shifted register. */
7456 if (inst.operands[i].immisreg)
7457 {
bf355b69
MR
7458 int op_index;
7459 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 7460 {
5689c942
RL
7461 /* Check the operand only when it's presented. In pre-UAL syntax,
7462 if the destination register is the same as the first operand, two
7463 register form of the instruction can be used. */
bf355b69
MR
7464 if (inst.operands[op_index].present && inst.operands[op_index].isreg
7465 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
7466 as_warn (UNPRED_REG ("r15"));
7467 }
7468
7469 if (inst.operands[i].imm == REG_PC)
7470 as_warn (UNPRED_REG ("r15"));
7471 }
7472
c19d1205
ZW
7473 if (inst.operands[i].shift_kind == SHIFT_RRX)
7474 inst.instruction |= SHIFT_ROR << 5;
7475 else
09d92015 7476 {
c19d1205
ZW
7477 inst.instruction |= inst.operands[i].shift_kind << 5;
7478 if (inst.operands[i].immisreg)
7479 {
7480 inst.instruction |= SHIFT_BY_REG;
7481 inst.instruction |= inst.operands[i].imm << 8;
7482 }
7483 else
7484 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7485 }
c19d1205 7486}
09d92015 7487
c19d1205
ZW
7488static void
7489encode_arm_shifter_operand (int i)
7490{
7491 if (inst.operands[i].isreg)
09d92015 7492 {
c19d1205
ZW
7493 inst.instruction |= inst.operands[i].reg;
7494 encode_arm_shift (i);
09d92015 7495 }
c19d1205 7496 else
a415b1cd
JB
7497 {
7498 inst.instruction |= INST_IMMEDIATE;
7499 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7500 inst.instruction |= inst.operands[i].imm;
7501 }
09d92015
MM
7502}
7503
c19d1205 7504/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7505static void
c19d1205 7506encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7507{
2b2f5df9
NC
7508 /* PR 14260:
7509 Generate an error if the operand is not a register. */
7510 constraint (!inst.operands[i].isreg,
7511 _("Instruction does not support =N addresses"));
7512
c19d1205 7513 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7514
c19d1205 7515 if (inst.operands[i].preind)
09d92015 7516 {
c19d1205
ZW
7517 if (is_t)
7518 {
7519 inst.error = _("instruction does not accept preindexed addressing");
7520 return;
7521 }
7522 inst.instruction |= PRE_INDEX;
7523 if (inst.operands[i].writeback)
7524 inst.instruction |= WRITE_BACK;
09d92015 7525
c19d1205
ZW
7526 }
7527 else if (inst.operands[i].postind)
7528 {
9c2799c2 7529 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7530 if (is_t)
7531 inst.instruction |= WRITE_BACK;
7532 }
7533 else /* unindexed - only for coprocessor */
09d92015 7534 {
c19d1205 7535 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7536 return;
7537 }
7538
c19d1205
ZW
7539 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7540 && (((inst.instruction & 0x000f0000) >> 16)
7541 == ((inst.instruction & 0x0000f000) >> 12)))
7542 as_warn ((inst.instruction & LOAD_BIT)
7543 ? _("destination register same as write-back base")
7544 : _("source register same as write-back base"));
09d92015
MM
7545}
7546
c19d1205
ZW
7547/* inst.operands[i] was set up by parse_address. Encode it into an
7548 ARM-format mode 2 load or store instruction. If is_t is true,
7549 reject forms that cannot be used with a T instruction (i.e. not
7550 post-indexed). */
a737bd4d 7551static void
c19d1205 7552encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7553{
5be8be5d
DG
7554 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7555
c19d1205 7556 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7557
c19d1205 7558 if (inst.operands[i].immisreg)
09d92015 7559 {
5be8be5d
DG
7560 constraint ((inst.operands[i].imm == REG_PC
7561 || (is_pc && inst.operands[i].writeback)),
7562 BAD_PC_ADDRESSING);
c19d1205
ZW
7563 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7564 inst.instruction |= inst.operands[i].imm;
7565 if (!inst.operands[i].negative)
7566 inst.instruction |= INDEX_UP;
7567 if (inst.operands[i].shifted)
7568 {
7569 if (inst.operands[i].shift_kind == SHIFT_RRX)
7570 inst.instruction |= SHIFT_ROR << 5;
7571 else
7572 {
7573 inst.instruction |= inst.operands[i].shift_kind << 5;
7574 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7575 }
7576 }
09d92015 7577 }
c19d1205 7578 else /* immediate offset in inst.reloc */
09d92015 7579 {
5be8be5d
DG
7580 if (is_pc && !inst.reloc.pc_rel)
7581 {
7582 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7583
7584 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7585 cannot use PC in addressing.
7586 PC cannot be used in writeback addressing, either. */
7587 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7588 BAD_PC_ADDRESSING);
23a10334 7589
dc5ec521 7590 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7591 if (warn_on_deprecated
7592 && !is_load
7593 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7594 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7595 }
7596
c19d1205 7597 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7598 {
7599 /* Prefer + for zero encoded value. */
7600 if (!inst.operands[i].negative)
7601 inst.instruction |= INDEX_UP;
7602 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7603 }
09d92015 7604 }
09d92015
MM
7605}
7606
c19d1205
ZW
7607/* inst.operands[i] was set up by parse_address. Encode it into an
7608 ARM-format mode 3 load or store instruction. Reject forms that
7609 cannot be used with such instructions. If is_t is true, reject
7610 forms that cannot be used with a T instruction (i.e. not
7611 post-indexed). */
7612static void
7613encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7614{
c19d1205 7615 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7616 {
c19d1205
ZW
7617 inst.error = _("instruction does not accept scaled register index");
7618 return;
09d92015 7619 }
a737bd4d 7620
c19d1205 7621 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7622
c19d1205
ZW
7623 if (inst.operands[i].immisreg)
7624 {
5be8be5d 7625 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7626 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7627 BAD_PC_ADDRESSING);
eb9f3f00
JB
7628 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7629 BAD_PC_WRITEBACK);
c19d1205
ZW
7630 inst.instruction |= inst.operands[i].imm;
7631 if (!inst.operands[i].negative)
7632 inst.instruction |= INDEX_UP;
7633 }
7634 else /* immediate offset in inst.reloc */
7635 {
5be8be5d
DG
7636 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7637 && inst.operands[i].writeback),
7638 BAD_PC_WRITEBACK);
c19d1205
ZW
7639 inst.instruction |= HWOFFSET_IMM;
7640 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7641 {
7642 /* Prefer + for zero encoded value. */
7643 if (!inst.operands[i].negative)
7644 inst.instruction |= INDEX_UP;
7645
7646 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7647 }
c19d1205 7648 }
a737bd4d
NC
7649}
7650
8335d6aa
JW
7651/* Write immediate bits [7:0] to the following locations:
7652
7653 |28/24|23 19|18 16|15 4|3 0|
7654 | 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|
7655
7656 This function is used by VMOV/VMVN/VORR/VBIC. */
7657
7658static void
7659neon_write_immbits (unsigned immbits)
7660{
7661 inst.instruction |= immbits & 0xf;
7662 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7663 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7664}
7665
7666/* Invert low-order SIZE bits of XHI:XLO. */
7667
7668static void
7669neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7670{
7671 unsigned immlo = xlo ? *xlo : 0;
7672 unsigned immhi = xhi ? *xhi : 0;
7673
7674 switch (size)
7675 {
7676 case 8:
7677 immlo = (~immlo) & 0xff;
7678 break;
7679
7680 case 16:
7681 immlo = (~immlo) & 0xffff;
7682 break;
7683
7684 case 64:
7685 immhi = (~immhi) & 0xffffffff;
7686 /* fall through. */
7687
7688 case 32:
7689 immlo = (~immlo) & 0xffffffff;
7690 break;
7691
7692 default:
7693 abort ();
7694 }
7695
7696 if (xlo)
7697 *xlo = immlo;
7698
7699 if (xhi)
7700 *xhi = immhi;
7701}
7702
7703/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7704 A, B, C, D. */
09d92015 7705
c19d1205 7706static int
8335d6aa 7707neon_bits_same_in_bytes (unsigned imm)
09d92015 7708{
8335d6aa
JW
7709 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7710 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7711 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7712 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7713}
a737bd4d 7714
8335d6aa 7715/* For immediate of above form, return 0bABCD. */
09d92015 7716
8335d6aa
JW
7717static unsigned
7718neon_squash_bits (unsigned imm)
7719{
7720 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7721 | ((imm & 0x01000000) >> 21);
7722}
7723
7724/* Compress quarter-float representation to 0b...000 abcdefgh. */
7725
7726static unsigned
7727neon_qfloat_bits (unsigned imm)
7728{
7729 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7730}
7731
7732/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7733 the instruction. *OP is passed as the initial value of the op field, and
7734 may be set to a different value depending on the constant (i.e.
7735 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7736 MVN). If the immediate looks like a repeated pattern then also
7737 try smaller element sizes. */
7738
7739static int
7740neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7741 unsigned *immbits, int *op, int size,
7742 enum neon_el_type type)
7743{
7744 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7745 float. */
7746 if (type == NT_float && !float_p)
7747 return FAIL;
7748
7749 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7750 {
8335d6aa
JW
7751 if (size != 32 || *op == 1)
7752 return FAIL;
7753 *immbits = neon_qfloat_bits (immlo);
7754 return 0xf;
7755 }
7756
7757 if (size == 64)
7758 {
7759 if (neon_bits_same_in_bytes (immhi)
7760 && neon_bits_same_in_bytes (immlo))
c19d1205 7761 {
8335d6aa
JW
7762 if (*op == 1)
7763 return FAIL;
7764 *immbits = (neon_squash_bits (immhi) << 4)
7765 | neon_squash_bits (immlo);
7766 *op = 1;
7767 return 0xe;
c19d1205 7768 }
a737bd4d 7769
8335d6aa
JW
7770 if (immhi != immlo)
7771 return FAIL;
7772 }
a737bd4d 7773
8335d6aa 7774 if (size >= 32)
09d92015 7775 {
8335d6aa 7776 if (immlo == (immlo & 0x000000ff))
c19d1205 7777 {
8335d6aa
JW
7778 *immbits = immlo;
7779 return 0x0;
c19d1205 7780 }
8335d6aa 7781 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7782 {
8335d6aa
JW
7783 *immbits = immlo >> 8;
7784 return 0x2;
c19d1205 7785 }
8335d6aa
JW
7786 else if (immlo == (immlo & 0x00ff0000))
7787 {
7788 *immbits = immlo >> 16;
7789 return 0x4;
7790 }
7791 else if (immlo == (immlo & 0xff000000))
7792 {
7793 *immbits = immlo >> 24;
7794 return 0x6;
7795 }
7796 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7797 {
7798 *immbits = (immlo >> 8) & 0xff;
7799 return 0xc;
7800 }
7801 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7802 {
7803 *immbits = (immlo >> 16) & 0xff;
7804 return 0xd;
7805 }
7806
7807 if ((immlo & 0xffff) != (immlo >> 16))
7808 return FAIL;
7809 immlo &= 0xffff;
09d92015 7810 }
a737bd4d 7811
8335d6aa 7812 if (size >= 16)
4962c51a 7813 {
8335d6aa
JW
7814 if (immlo == (immlo & 0x000000ff))
7815 {
7816 *immbits = immlo;
7817 return 0x8;
7818 }
7819 else if (immlo == (immlo & 0x0000ff00))
7820 {
7821 *immbits = immlo >> 8;
7822 return 0xa;
7823 }
7824
7825 if ((immlo & 0xff) != (immlo >> 8))
7826 return FAIL;
7827 immlo &= 0xff;
4962c51a
MS
7828 }
7829
8335d6aa
JW
7830 if (immlo == (immlo & 0x000000ff))
7831 {
7832 /* Don't allow MVN with 8-bit immediate. */
7833 if (*op == 1)
7834 return FAIL;
7835 *immbits = immlo;
7836 return 0xe;
7837 }
26d97720 7838
8335d6aa 7839 return FAIL;
c19d1205 7840}
a737bd4d 7841
5fc177c8 7842#if defined BFD_HOST_64_BIT
ba592044
AM
7843/* Returns TRUE if double precision value V may be cast
7844 to single precision without loss of accuracy. */
7845
7846static bfd_boolean
5fc177c8 7847is_double_a_single (bfd_int64_t v)
ba592044 7848{
5fc177c8 7849 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7850 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7851
7852 return (exp == 0 || exp == 0x7FF
7853 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7854 && (mantissa & 0x1FFFFFFFl) == 0;
7855}
7856
3739860c 7857/* Returns a double precision value casted to single precision
ba592044
AM
7858 (ignoring the least significant bits in exponent and mantissa). */
7859
7860static int
5fc177c8 7861double_to_single (bfd_int64_t v)
ba592044
AM
7862{
7863 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7864 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7865 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7866
7867 if (exp == 0x7FF)
7868 exp = 0xFF;
7869 else
7870 {
7871 exp = exp - 1023 + 127;
7872 if (exp >= 0xFF)
7873 {
7874 /* Infinity. */
7875 exp = 0x7F;
7876 mantissa = 0;
7877 }
7878 else if (exp < 0)
7879 {
7880 /* No denormalized numbers. */
7881 exp = 0;
7882 mantissa = 0;
7883 }
7884 }
7885 mantissa >>= 29;
7886 return (sign << 31) | (exp << 23) | mantissa;
7887}
5fc177c8 7888#endif /* BFD_HOST_64_BIT */
ba592044 7889
8335d6aa
JW
7890enum lit_type
7891{
7892 CONST_THUMB,
7893 CONST_ARM,
7894 CONST_VEC
7895};
7896
ba592044
AM
7897static void do_vfp_nsyn_opcode (const char *);
7898
c19d1205
ZW
7899/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7900 Determine whether it can be performed with a move instruction; if
7901 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7902 return TRUE; if it can't, convert inst.instruction to a literal-pool
7903 load and return FALSE. If this is not a valid thing to do in the
7904 current context, set inst.error and return TRUE.
a737bd4d 7905
c19d1205
ZW
7906 inst.operands[i] describes the destination register. */
7907
c921be7d 7908static bfd_boolean
8335d6aa 7909move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7910{
53365c0d 7911 unsigned long tbit;
8335d6aa
JW
7912 bfd_boolean thumb_p = (t == CONST_THUMB);
7913 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7914
7915 if (thumb_p)
7916 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7917 else
7918 tbit = LOAD_BIT;
7919
7920 if ((inst.instruction & tbit) == 0)
09d92015 7921 {
c19d1205 7922 inst.error = _("invalid pseudo operation");
c921be7d 7923 return TRUE;
09d92015 7924 }
ba592044 7925
8335d6aa
JW
7926 if (inst.reloc.exp.X_op != O_constant
7927 && inst.reloc.exp.X_op != O_symbol
7928 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7929 {
7930 inst.error = _("constant expression expected");
c921be7d 7931 return TRUE;
09d92015 7932 }
ba592044
AM
7933
7934 if (inst.reloc.exp.X_op == O_constant
7935 || inst.reloc.exp.X_op == O_big)
8335d6aa 7936 {
5fc177c8
NC
7937#if defined BFD_HOST_64_BIT
7938 bfd_int64_t v;
7939#else
ba592044 7940 offsetT v;
5fc177c8 7941#endif
ba592044 7942 if (inst.reloc.exp.X_op == O_big)
8335d6aa 7943 {
ba592044
AM
7944 LITTLENUM_TYPE w[X_PRECISION];
7945 LITTLENUM_TYPE * l;
7946
7947 if (inst.reloc.exp.X_add_number == -1)
8335d6aa 7948 {
ba592044
AM
7949 gen_to_words (w, X_PRECISION, E_PRECISION);
7950 l = w;
7951 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 7952 }
ba592044
AM
7953 else
7954 l = generic_bignum;
3739860c 7955
5fc177c8
NC
7956#if defined BFD_HOST_64_BIT
7957 v =
7958 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
7959 << LITTLENUM_NUMBER_OF_BITS)
7960 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
7961 << LITTLENUM_NUMBER_OF_BITS)
7962 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
7963 << LITTLENUM_NUMBER_OF_BITS)
7964 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
7965#else
ba592044
AM
7966 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
7967 | (l[0] & LITTLENUM_MASK);
5fc177c8 7968#endif
8335d6aa 7969 }
ba592044
AM
7970 else
7971 v = inst.reloc.exp.X_add_number;
7972
7973 if (!inst.operands[i].issingle)
8335d6aa 7974 {
12569877 7975 if (thumb_p)
8335d6aa 7976 {
53445554
TP
7977 /* LDR should not use lead in a flag-setting instruction being
7978 chosen so we do not check whether movs can be used. */
12569877 7979
53445554 7980 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
ff8646ee 7981 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
53445554
TP
7982 && inst.operands[i].reg != 13
7983 && inst.operands[i].reg != 15)
12569877 7984 {
fc289b0a
TP
7985 /* Check if on thumb2 it can be done with a mov.w, mvn or
7986 movw instruction. */
12569877
AM
7987 unsigned int newimm;
7988 bfd_boolean isNegated;
7989
7990 newimm = encode_thumb32_immediate (v);
7991 if (newimm != (unsigned int) FAIL)
7992 isNegated = FALSE;
7993 else
7994 {
582cfe03 7995 newimm = encode_thumb32_immediate (~v);
12569877
AM
7996 if (newimm != (unsigned int) FAIL)
7997 isNegated = TRUE;
7998 }
7999
fc289b0a
TP
8000 /* The number can be loaded with a mov.w or mvn
8001 instruction. */
ff8646ee
TP
8002 if (newimm != (unsigned int) FAIL
8003 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 8004 {
fc289b0a 8005 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 8006 | (inst.operands[i].reg << 8));
fc289b0a 8007 /* Change to MOVN. */
582cfe03 8008 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
8009 inst.instruction |= (newimm & 0x800) << 15;
8010 inst.instruction |= (newimm & 0x700) << 4;
8011 inst.instruction |= (newimm & 0x0ff);
8012 return TRUE;
8013 }
fc289b0a 8014 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8015 else if ((v & ~0xFFFF) == 0
8016 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8017 {
582cfe03 8018 int imm = v & 0xFFFF;
12569877 8019
582cfe03 8020 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8021 inst.instruction |= (inst.operands[i].reg << 8);
8022 inst.instruction |= (imm & 0xf000) << 4;
8023 inst.instruction |= (imm & 0x0800) << 15;
8024 inst.instruction |= (imm & 0x0700) << 4;
8025 inst.instruction |= (imm & 0x00ff);
8026 return TRUE;
8027 }
8028 }
8335d6aa 8029 }
12569877 8030 else if (arm_p)
ba592044
AM
8031 {
8032 int value = encode_arm_immediate (v);
12569877 8033
ba592044
AM
8034 if (value != FAIL)
8035 {
8036 /* This can be done with a mov instruction. */
8037 inst.instruction &= LITERAL_MASK;
8038 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8039 inst.instruction |= value & 0xfff;
8040 return TRUE;
8041 }
8335d6aa 8042
ba592044
AM
8043 value = encode_arm_immediate (~ v);
8044 if (value != FAIL)
8045 {
8046 /* This can be done with a mvn instruction. */
8047 inst.instruction &= LITERAL_MASK;
8048 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8049 inst.instruction |= value & 0xfff;
8050 return TRUE;
8051 }
8052 }
934c2632 8053 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8054 {
ba592044
AM
8055 int op = 0;
8056 unsigned immbits = 0;
8057 unsigned immlo = inst.operands[1].imm;
8058 unsigned immhi = inst.operands[1].regisimm
8059 ? inst.operands[1].reg
8060 : inst.reloc.exp.X_unsigned
8061 ? 0
8062 : ((bfd_int64_t)((int) immlo)) >> 32;
8063 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8064 &op, 64, NT_invtype);
8065
8066 if (cmode == FAIL)
8067 {
8068 neon_invert_size (&immlo, &immhi, 64);
8069 op = !op;
8070 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8071 &op, 64, NT_invtype);
8072 }
8073
8074 if (cmode != FAIL)
8075 {
8076 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8077 | (1 << 23)
8078 | (cmode << 8)
8079 | (op << 5)
8080 | (1 << 4);
8081
8082 /* Fill other bits in vmov encoding for both thumb and arm. */
8083 if (thumb_mode)
eff0bc54 8084 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8085 else
eff0bc54 8086 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8087 neon_write_immbits (immbits);
8088 return TRUE;
8089 }
8335d6aa
JW
8090 }
8091 }
8335d6aa 8092
ba592044
AM
8093 if (t == CONST_VEC)
8094 {
8095 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8096 if (inst.operands[i].issingle
8097 && is_quarter_float (inst.operands[1].imm)
8098 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8099 {
ba592044
AM
8100 inst.operands[1].imm =
8101 neon_qfloat_bits (v);
8102 do_vfp_nsyn_opcode ("fconsts");
8103 return TRUE;
8335d6aa 8104 }
5fc177c8
NC
8105
8106 /* If our host does not support a 64-bit type then we cannot perform
8107 the following optimization. This mean that there will be a
8108 discrepancy between the output produced by an assembler built for
8109 a 32-bit-only host and the output produced from a 64-bit host, but
8110 this cannot be helped. */
8111#if defined BFD_HOST_64_BIT
ba592044
AM
8112 else if (!inst.operands[1].issingle
8113 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8114 {
ba592044
AM
8115 if (is_double_a_single (v)
8116 && is_quarter_float (double_to_single (v)))
8117 {
8118 inst.operands[1].imm =
8119 neon_qfloat_bits (double_to_single (v));
8120 do_vfp_nsyn_opcode ("fconstd");
8121 return TRUE;
8122 }
8335d6aa 8123 }
5fc177c8 8124#endif
8335d6aa
JW
8125 }
8126 }
8127
8128 if (add_to_lit_pool ((!inst.operands[i].isvec
8129 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8130 return TRUE;
8131
8132 inst.operands[1].reg = REG_PC;
8133 inst.operands[1].isreg = 1;
8134 inst.operands[1].preind = 1;
8135 inst.reloc.pc_rel = 1;
8136 inst.reloc.type = (thumb_p
8137 ? BFD_RELOC_ARM_THUMB_OFFSET
8138 : (mode_3
8139 ? BFD_RELOC_ARM_HWLITERAL
8140 : BFD_RELOC_ARM_LITERAL));
8141 return FALSE;
8142}
8143
8144/* inst.operands[i] was set up by parse_address. Encode it into an
8145 ARM-format instruction. Reject all forms which cannot be encoded
8146 into a coprocessor load/store instruction. If wb_ok is false,
8147 reject use of writeback; if unind_ok is false, reject use of
8148 unindexed addressing. If reloc_override is not 0, use it instead
8149 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8150 (in which case it is preserved). */
8151
8152static int
8153encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8154{
8155 if (!inst.operands[i].isreg)
8156 {
99b2a2dd
NC
8157 /* PR 18256 */
8158 if (! inst.operands[0].isvec)
8159 {
8160 inst.error = _("invalid co-processor operand");
8161 return FAIL;
8162 }
8335d6aa
JW
8163 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8164 return SUCCESS;
8165 }
8166
8167 inst.instruction |= inst.operands[i].reg << 16;
8168
8169 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8170
8171 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8172 {
8173 gas_assert (!inst.operands[i].writeback);
8174 if (!unind_ok)
8175 {
8176 inst.error = _("instruction does not support unindexed addressing");
8177 return FAIL;
8178 }
8179 inst.instruction |= inst.operands[i].imm;
8180 inst.instruction |= INDEX_UP;
8181 return SUCCESS;
8182 }
8183
8184 if (inst.operands[i].preind)
8185 inst.instruction |= PRE_INDEX;
8186
8187 if (inst.operands[i].writeback)
09d92015 8188 {
8335d6aa 8189 if (inst.operands[i].reg == REG_PC)
c19d1205 8190 {
8335d6aa
JW
8191 inst.error = _("pc may not be used with write-back");
8192 return FAIL;
c19d1205 8193 }
8335d6aa 8194 if (!wb_ok)
c19d1205 8195 {
8335d6aa
JW
8196 inst.error = _("instruction does not support writeback");
8197 return FAIL;
c19d1205 8198 }
8335d6aa 8199 inst.instruction |= WRITE_BACK;
09d92015
MM
8200 }
8201
8335d6aa
JW
8202 if (reloc_override)
8203 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8204 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8205 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8206 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8207 {
8335d6aa
JW
8208 if (thumb_mode)
8209 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8210 else
8211 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8212 }
8335d6aa
JW
8213
8214 /* Prefer + for zero encoded value. */
8215 if (!inst.operands[i].negative)
8216 inst.instruction |= INDEX_UP;
8217
8218 return SUCCESS;
09d92015
MM
8219}
8220
5f4273c7 8221/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8222 First some generics; their names are taken from the conventional
8223 bit positions for register arguments in ARM format instructions. */
09d92015 8224
a737bd4d 8225static void
c19d1205 8226do_noargs (void)
09d92015 8227{
c19d1205 8228}
a737bd4d 8229
c19d1205
ZW
8230static void
8231do_rd (void)
8232{
8233 inst.instruction |= inst.operands[0].reg << 12;
8234}
a737bd4d 8235
16a1fa25
TP
8236static void
8237do_rn (void)
8238{
8239 inst.instruction |= inst.operands[0].reg << 16;
8240}
8241
c19d1205
ZW
8242static void
8243do_rd_rm (void)
8244{
8245 inst.instruction |= inst.operands[0].reg << 12;
8246 inst.instruction |= inst.operands[1].reg;
8247}
09d92015 8248
9eb6c0f1
MGD
8249static void
8250do_rm_rn (void)
8251{
8252 inst.instruction |= inst.operands[0].reg;
8253 inst.instruction |= inst.operands[1].reg << 16;
8254}
8255
c19d1205
ZW
8256static void
8257do_rd_rn (void)
8258{
8259 inst.instruction |= inst.operands[0].reg << 12;
8260 inst.instruction |= inst.operands[1].reg << 16;
8261}
a737bd4d 8262
c19d1205
ZW
8263static void
8264do_rn_rd (void)
8265{
8266 inst.instruction |= inst.operands[0].reg << 16;
8267 inst.instruction |= inst.operands[1].reg << 12;
8268}
09d92015 8269
4ed7ed8d
TP
8270static void
8271do_tt (void)
8272{
8273 inst.instruction |= inst.operands[0].reg << 8;
8274 inst.instruction |= inst.operands[1].reg << 16;
8275}
8276
59d09be6
MGD
8277static bfd_boolean
8278check_obsolete (const arm_feature_set *feature, const char *msg)
8279{
8280 if (ARM_CPU_IS_ANY (cpu_variant))
8281 {
5c3696f8 8282 as_tsktsk ("%s", msg);
59d09be6
MGD
8283 return TRUE;
8284 }
8285 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8286 {
8287 as_bad ("%s", msg);
8288 return TRUE;
8289 }
8290
8291 return FALSE;
8292}
8293
c19d1205
ZW
8294static void
8295do_rd_rm_rn (void)
8296{
9a64e435 8297 unsigned Rn = inst.operands[2].reg;
708587a4 8298 /* Enforce restrictions on SWP instruction. */
9a64e435 8299 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8300 {
8301 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8302 _("Rn must not overlap other operands"));
8303
59d09be6
MGD
8304 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8305 */
8306 if (!check_obsolete (&arm_ext_v8,
8307 _("swp{b} use is obsoleted for ARMv8 and later"))
8308 && warn_on_deprecated
8309 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8310 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8311 }
59d09be6 8312
c19d1205
ZW
8313 inst.instruction |= inst.operands[0].reg << 12;
8314 inst.instruction |= inst.operands[1].reg;
9a64e435 8315 inst.instruction |= Rn << 16;
c19d1205 8316}
09d92015 8317
c19d1205
ZW
8318static void
8319do_rd_rn_rm (void)
8320{
8321 inst.instruction |= inst.operands[0].reg << 12;
8322 inst.instruction |= inst.operands[1].reg << 16;
8323 inst.instruction |= inst.operands[2].reg;
8324}
a737bd4d 8325
c19d1205
ZW
8326static void
8327do_rm_rd_rn (void)
8328{
5be8be5d
DG
8329 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8330 constraint (((inst.reloc.exp.X_op != O_constant
8331 && inst.reloc.exp.X_op != O_illegal)
8332 || inst.reloc.exp.X_add_number != 0),
8333 BAD_ADDR_MODE);
c19d1205
ZW
8334 inst.instruction |= inst.operands[0].reg;
8335 inst.instruction |= inst.operands[1].reg << 12;
8336 inst.instruction |= inst.operands[2].reg << 16;
8337}
09d92015 8338
c19d1205
ZW
8339static void
8340do_imm0 (void)
8341{
8342 inst.instruction |= inst.operands[0].imm;
8343}
09d92015 8344
c19d1205
ZW
8345static void
8346do_rd_cpaddr (void)
8347{
8348 inst.instruction |= inst.operands[0].reg << 12;
8349 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8350}
a737bd4d 8351
c19d1205
ZW
8352/* ARM instructions, in alphabetical order by function name (except
8353 that wrapper functions appear immediately after the function they
8354 wrap). */
09d92015 8355
c19d1205
ZW
8356/* This is a pseudo-op of the form "adr rd, label" to be converted
8357 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8358
8359static void
c19d1205 8360do_adr (void)
09d92015 8361{
c19d1205 8362 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8363
c19d1205
ZW
8364 /* Frag hacking will turn this into a sub instruction if the offset turns
8365 out to be negative. */
8366 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8367 inst.reloc.pc_rel = 1;
2fc8bdac 8368 inst.reloc.exp.X_add_number -= 8;
52a86f84
NC
8369
8370 if (inst.reloc.exp.X_op == O_symbol
8371 && inst.reloc.exp.X_add_symbol != NULL
8372 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8373 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8374 inst.reloc.exp.X_add_number += 1;
c19d1205 8375}
b99bd4ef 8376
c19d1205
ZW
8377/* This is a pseudo-op of the form "adrl rd, label" to be converted
8378 into a relative address of the form:
8379 add rd, pc, #low(label-.-8)"
8380 add rd, rd, #high(label-.-8)" */
b99bd4ef 8381
c19d1205
ZW
8382static void
8383do_adrl (void)
8384{
8385 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8386
c19d1205
ZW
8387 /* Frag hacking will turn this into a sub instruction if the offset turns
8388 out to be negative. */
8389 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8390 inst.reloc.pc_rel = 1;
8391 inst.size = INSN_SIZE * 2;
2fc8bdac 8392 inst.reloc.exp.X_add_number -= 8;
52a86f84
NC
8393
8394 if (inst.reloc.exp.X_op == O_symbol
8395 && inst.reloc.exp.X_add_symbol != NULL
8396 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8397 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8398 inst.reloc.exp.X_add_number += 1;
b99bd4ef
NC
8399}
8400
b99bd4ef 8401static void
c19d1205 8402do_arit (void)
b99bd4ef 8403{
a9f02af8
MG
8404 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8405 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
8406 THUMB1_RELOC_ONLY);
c19d1205
ZW
8407 if (!inst.operands[1].present)
8408 inst.operands[1].reg = inst.operands[0].reg;
8409 inst.instruction |= inst.operands[0].reg << 12;
8410 inst.instruction |= inst.operands[1].reg << 16;
8411 encode_arm_shifter_operand (2);
8412}
b99bd4ef 8413
62b3e311
PB
8414static void
8415do_barrier (void)
8416{
8417 if (inst.operands[0].present)
ccb84d65 8418 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8419 else
8420 inst.instruction |= 0xf;
8421}
8422
c19d1205
ZW
8423static void
8424do_bfc (void)
8425{
8426 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8427 constraint (msb > 32, _("bit-field extends past end of register"));
8428 /* The instruction encoding stores the LSB and MSB,
8429 not the LSB and width. */
8430 inst.instruction |= inst.operands[0].reg << 12;
8431 inst.instruction |= inst.operands[1].imm << 7;
8432 inst.instruction |= (msb - 1) << 16;
8433}
b99bd4ef 8434
c19d1205
ZW
8435static void
8436do_bfi (void)
8437{
8438 unsigned int msb;
b99bd4ef 8439
c19d1205
ZW
8440 /* #0 in second position is alternative syntax for bfc, which is
8441 the same instruction but with REG_PC in the Rm field. */
8442 if (!inst.operands[1].isreg)
8443 inst.operands[1].reg = REG_PC;
b99bd4ef 8444
c19d1205
ZW
8445 msb = inst.operands[2].imm + inst.operands[3].imm;
8446 constraint (msb > 32, _("bit-field extends past end of register"));
8447 /* The instruction encoding stores the LSB and MSB,
8448 not the LSB and width. */
8449 inst.instruction |= inst.operands[0].reg << 12;
8450 inst.instruction |= inst.operands[1].reg;
8451 inst.instruction |= inst.operands[2].imm << 7;
8452 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8453}
8454
b99bd4ef 8455static void
c19d1205 8456do_bfx (void)
b99bd4ef 8457{
c19d1205
ZW
8458 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8459 _("bit-field extends past end of register"));
8460 inst.instruction |= inst.operands[0].reg << 12;
8461 inst.instruction |= inst.operands[1].reg;
8462 inst.instruction |= inst.operands[2].imm << 7;
8463 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8464}
09d92015 8465
c19d1205
ZW
8466/* ARM V5 breakpoint instruction (argument parse)
8467 BKPT <16 bit unsigned immediate>
8468 Instruction is not conditional.
8469 The bit pattern given in insns[] has the COND_ALWAYS condition,
8470 and it is an error if the caller tried to override that. */
b99bd4ef 8471
c19d1205
ZW
8472static void
8473do_bkpt (void)
8474{
8475 /* Top 12 of 16 bits to bits 19:8. */
8476 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8477
c19d1205
ZW
8478 /* Bottom 4 of 16 bits to bits 3:0. */
8479 inst.instruction |= inst.operands[0].imm & 0xf;
8480}
09d92015 8481
c19d1205
ZW
8482static void
8483encode_branch (int default_reloc)
8484{
8485 if (inst.operands[0].hasreloc)
8486 {
0855e32b
NS
8487 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8488 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8489 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8490 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8491 ? BFD_RELOC_ARM_PLT32
8492 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8493 }
b99bd4ef 8494 else
9ae92b05 8495 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8496 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8497}
8498
b99bd4ef 8499static void
c19d1205 8500do_branch (void)
b99bd4ef 8501{
39b41c9c
PB
8502#ifdef OBJ_ELF
8503 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8504 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8505 else
8506#endif
8507 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8508}
8509
8510static void
8511do_bl (void)
8512{
8513#ifdef OBJ_ELF
8514 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8515 {
8516 if (inst.cond == COND_ALWAYS)
8517 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8518 else
8519 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8520 }
8521 else
8522#endif
8523 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8524}
b99bd4ef 8525
c19d1205
ZW
8526/* ARM V5 branch-link-exchange instruction (argument parse)
8527 BLX <target_addr> ie BLX(1)
8528 BLX{<condition>} <Rm> ie BLX(2)
8529 Unfortunately, there are two different opcodes for this mnemonic.
8530 So, the insns[].value is not used, and the code here zaps values
8531 into inst.instruction.
8532 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8533
c19d1205
ZW
8534static void
8535do_blx (void)
8536{
8537 if (inst.operands[0].isreg)
b99bd4ef 8538 {
c19d1205
ZW
8539 /* Arg is a register; the opcode provided by insns[] is correct.
8540 It is not illegal to do "blx pc", just useless. */
8541 if (inst.operands[0].reg == REG_PC)
8542 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8543
c19d1205
ZW
8544 inst.instruction |= inst.operands[0].reg;
8545 }
8546 else
b99bd4ef 8547 {
c19d1205 8548 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8549 conditionally, and the opcode must be adjusted.
8550 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8551 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8552 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8553 inst.instruction = 0xfa000000;
267bf995 8554 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8555 }
c19d1205
ZW
8556}
8557
8558static void
8559do_bx (void)
8560{
845b51d6
PB
8561 bfd_boolean want_reloc;
8562
c19d1205
ZW
8563 if (inst.operands[0].reg == REG_PC)
8564 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8565
c19d1205 8566 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8567 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8568 it is for ARMv4t or earlier. */
8569 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8570 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
8571 want_reloc = TRUE;
8572
5ad34203 8573#ifdef OBJ_ELF
845b51d6 8574 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8575#endif
584206db 8576 want_reloc = FALSE;
845b51d6
PB
8577
8578 if (want_reloc)
8579 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8580}
8581
c19d1205
ZW
8582
8583/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8584
8585static void
c19d1205 8586do_bxj (void)
a737bd4d 8587{
c19d1205
ZW
8588 if (inst.operands[0].reg == REG_PC)
8589 as_tsktsk (_("use of r15 in bxj is not really useful"));
8590
8591 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8592}
8593
c19d1205
ZW
8594/* Co-processor data operation:
8595 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8596 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8597static void
8598do_cdp (void)
8599{
8600 inst.instruction |= inst.operands[0].reg << 8;
8601 inst.instruction |= inst.operands[1].imm << 20;
8602 inst.instruction |= inst.operands[2].reg << 12;
8603 inst.instruction |= inst.operands[3].reg << 16;
8604 inst.instruction |= inst.operands[4].reg;
8605 inst.instruction |= inst.operands[5].imm << 5;
8606}
a737bd4d
NC
8607
8608static void
c19d1205 8609do_cmp (void)
a737bd4d 8610{
c19d1205
ZW
8611 inst.instruction |= inst.operands[0].reg << 16;
8612 encode_arm_shifter_operand (1);
a737bd4d
NC
8613}
8614
c19d1205
ZW
8615/* Transfer between coprocessor and ARM registers.
8616 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8617 MRC2
8618 MCR{cond}
8619 MCR2
8620
8621 No special properties. */
09d92015 8622
dcbd0d71
MGD
8623struct deprecated_coproc_regs_s
8624{
8625 unsigned cp;
8626 int opc1;
8627 unsigned crn;
8628 unsigned crm;
8629 int opc2;
8630 arm_feature_set deprecated;
8631 arm_feature_set obsoleted;
8632 const char *dep_msg;
8633 const char *obs_msg;
8634};
8635
8636#define DEPR_ACCESS_V8 \
8637 N_("This coprocessor register access is deprecated in ARMv8")
8638
8639/* Table of all deprecated coprocessor registers. */
8640static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8641{
8642 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8643 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8644 DEPR_ACCESS_V8, NULL},
8645 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8646 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8647 DEPR_ACCESS_V8, NULL},
8648 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8649 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8650 DEPR_ACCESS_V8, NULL},
8651 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8652 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8653 DEPR_ACCESS_V8, NULL},
8654 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8655 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8656 DEPR_ACCESS_V8, NULL},
8657};
8658
8659#undef DEPR_ACCESS_V8
8660
8661static const size_t deprecated_coproc_reg_count =
8662 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8663
09d92015 8664static void
c19d1205 8665do_co_reg (void)
09d92015 8666{
fdfde340 8667 unsigned Rd;
dcbd0d71 8668 size_t i;
fdfde340
JM
8669
8670 Rd = inst.operands[2].reg;
8671 if (thumb_mode)
8672 {
8673 if (inst.instruction == 0xee000010
8674 || inst.instruction == 0xfe000010)
8675 /* MCR, MCR2 */
8676 reject_bad_reg (Rd);
5c8ed6a4 8677 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
fdfde340
JM
8678 /* MRC, MRC2 */
8679 constraint (Rd == REG_SP, BAD_SP);
8680 }
8681 else
8682 {
8683 /* MCR */
8684 if (inst.instruction == 0xe000010)
8685 constraint (Rd == REG_PC, BAD_PC);
8686 }
8687
dcbd0d71
MGD
8688 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8689 {
8690 const struct deprecated_coproc_regs_s *r =
8691 deprecated_coproc_regs + i;
8692
8693 if (inst.operands[0].reg == r->cp
8694 && inst.operands[1].imm == r->opc1
8695 && inst.operands[3].reg == r->crn
8696 && inst.operands[4].reg == r->crm
8697 && inst.operands[5].imm == r->opc2)
8698 {
b10bf8c5 8699 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8700 && warn_on_deprecated
dcbd0d71 8701 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8702 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8703 }
8704 }
fdfde340 8705
c19d1205
ZW
8706 inst.instruction |= inst.operands[0].reg << 8;
8707 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8708 inst.instruction |= Rd << 12;
c19d1205
ZW
8709 inst.instruction |= inst.operands[3].reg << 16;
8710 inst.instruction |= inst.operands[4].reg;
8711 inst.instruction |= inst.operands[5].imm << 5;
8712}
09d92015 8713
c19d1205
ZW
8714/* Transfer between coprocessor register and pair of ARM registers.
8715 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8716 MCRR2
8717 MRRC{cond}
8718 MRRC2
b99bd4ef 8719
c19d1205 8720 Two XScale instructions are special cases of these:
09d92015 8721
c19d1205
ZW
8722 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8723 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8724
5f4273c7 8725 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8726
c19d1205
ZW
8727static void
8728do_co_reg2c (void)
8729{
fdfde340
JM
8730 unsigned Rd, Rn;
8731
8732 Rd = inst.operands[2].reg;
8733 Rn = inst.operands[3].reg;
8734
8735 if (thumb_mode)
8736 {
8737 reject_bad_reg (Rd);
8738 reject_bad_reg (Rn);
8739 }
8740 else
8741 {
8742 constraint (Rd == REG_PC, BAD_PC);
8743 constraint (Rn == REG_PC, BAD_PC);
8744 }
8745
873f10f0
TC
8746 /* Only check the MRRC{2} variants. */
8747 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
8748 {
8749 /* If Rd == Rn, error that the operation is
8750 unpredictable (example MRRC p3,#1,r1,r1,c4). */
8751 constraint (Rd == Rn, BAD_OVERLAP);
8752 }
8753
c19d1205
ZW
8754 inst.instruction |= inst.operands[0].reg << 8;
8755 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8756 inst.instruction |= Rd << 12;
8757 inst.instruction |= Rn << 16;
c19d1205 8758 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8759}
8760
c19d1205
ZW
8761static void
8762do_cpsi (void)
8763{
8764 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8765 if (inst.operands[1].present)
8766 {
8767 inst.instruction |= CPSI_MMOD;
8768 inst.instruction |= inst.operands[1].imm;
8769 }
c19d1205 8770}
b99bd4ef 8771
62b3e311
PB
8772static void
8773do_dbg (void)
8774{
8775 inst.instruction |= inst.operands[0].imm;
8776}
8777
eea54501
MGD
8778static void
8779do_div (void)
8780{
8781 unsigned Rd, Rn, Rm;
8782
8783 Rd = inst.operands[0].reg;
8784 Rn = (inst.operands[1].present
8785 ? inst.operands[1].reg : Rd);
8786 Rm = inst.operands[2].reg;
8787
8788 constraint ((Rd == REG_PC), BAD_PC);
8789 constraint ((Rn == REG_PC), BAD_PC);
8790 constraint ((Rm == REG_PC), BAD_PC);
8791
8792 inst.instruction |= Rd << 16;
8793 inst.instruction |= Rn << 0;
8794 inst.instruction |= Rm << 8;
8795}
8796
b99bd4ef 8797static void
c19d1205 8798do_it (void)
b99bd4ef 8799{
c19d1205 8800 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8801 process it to do the validation as if in
8802 thumb mode, just in case the code gets
8803 assembled for thumb using the unified syntax. */
8804
c19d1205 8805 inst.size = 0;
e07e6e58
NC
8806 if (unified_syntax)
8807 {
8808 set_it_insn_type (IT_INSN);
8809 now_it.mask = (inst.instruction & 0xf) | 0x10;
8810 now_it.cc = inst.operands[0].imm;
8811 }
09d92015 8812}
b99bd4ef 8813
6530b175
NC
8814/* If there is only one register in the register list,
8815 then return its register number. Otherwise return -1. */
8816static int
8817only_one_reg_in_list (int range)
8818{
8819 int i = ffs (range) - 1;
8820 return (i > 15 || range != (1 << i)) ? -1 : i;
8821}
8822
09d92015 8823static void
6530b175 8824encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8825{
c19d1205
ZW
8826 int base_reg = inst.operands[0].reg;
8827 int range = inst.operands[1].imm;
6530b175 8828 int one_reg;
ea6ef066 8829
c19d1205
ZW
8830 inst.instruction |= base_reg << 16;
8831 inst.instruction |= range;
ea6ef066 8832
c19d1205
ZW
8833 if (inst.operands[1].writeback)
8834 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8835
c19d1205 8836 if (inst.operands[0].writeback)
ea6ef066 8837 {
c19d1205
ZW
8838 inst.instruction |= WRITE_BACK;
8839 /* Check for unpredictable uses of writeback. */
8840 if (inst.instruction & LOAD_BIT)
09d92015 8841 {
c19d1205
ZW
8842 /* Not allowed in LDM type 2. */
8843 if ((inst.instruction & LDM_TYPE_2_OR_3)
8844 && ((range & (1 << REG_PC)) == 0))
8845 as_warn (_("writeback of base register is UNPREDICTABLE"));
8846 /* Only allowed if base reg not in list for other types. */
8847 else if (range & (1 << base_reg))
8848 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8849 }
8850 else /* STM. */
8851 {
8852 /* Not allowed for type 2. */
8853 if (inst.instruction & LDM_TYPE_2_OR_3)
8854 as_warn (_("writeback of base register is UNPREDICTABLE"));
8855 /* Only allowed if base reg not in list, or first in list. */
8856 else if ((range & (1 << base_reg))
8857 && (range & ((1 << base_reg) - 1)))
8858 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8859 }
ea6ef066 8860 }
6530b175
NC
8861
8862 /* If PUSH/POP has only one register, then use the A2 encoding. */
8863 one_reg = only_one_reg_in_list (range);
8864 if (from_push_pop_mnem && one_reg >= 0)
8865 {
8866 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8867
8868 inst.instruction &= A_COND_MASK;
8869 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8870 inst.instruction |= one_reg << 12;
8871 }
8872}
8873
8874static void
8875do_ldmstm (void)
8876{
8877 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8878}
8879
c19d1205
ZW
8880/* ARMv5TE load-consecutive (argument parse)
8881 Mode is like LDRH.
8882
8883 LDRccD R, mode
8884 STRccD R, mode. */
8885
a737bd4d 8886static void
c19d1205 8887do_ldrd (void)
a737bd4d 8888{
c19d1205 8889 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8890 _("first transfer register must be even"));
c19d1205
ZW
8891 constraint (inst.operands[1].present
8892 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8893 _("can only transfer two consecutive registers"));
c19d1205
ZW
8894 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8895 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8896
c19d1205
ZW
8897 if (!inst.operands[1].present)
8898 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8899
c56791bb
RE
8900 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8901 register and the first register written; we have to diagnose
8902 overlap between the base and the second register written here. */
ea6ef066 8903
c56791bb
RE
8904 if (inst.operands[2].reg == inst.operands[1].reg
8905 && (inst.operands[2].writeback || inst.operands[2].postind))
8906 as_warn (_("base register written back, and overlaps "
8907 "second transfer register"));
b05fe5cf 8908
c56791bb
RE
8909 if (!(inst.instruction & V4_STR_BIT))
8910 {
c19d1205 8911 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8912 destination (even if not write-back). */
8913 if (inst.operands[2].immisreg
8914 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8915 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8916 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8917 }
c19d1205
ZW
8918 inst.instruction |= inst.operands[0].reg << 12;
8919 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8920}
8921
8922static void
c19d1205 8923do_ldrex (void)
b05fe5cf 8924{
c19d1205
ZW
8925 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8926 || inst.operands[1].postind || inst.operands[1].writeback
8927 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8928 || inst.operands[1].negative
8929 /* This can arise if the programmer has written
8930 strex rN, rM, foo
8931 or if they have mistakenly used a register name as the last
8932 operand, eg:
8933 strex rN, rM, rX
8934 It is very difficult to distinguish between these two cases
8935 because "rX" might actually be a label. ie the register
8936 name has been occluded by a symbol of the same name. So we
8937 just generate a general 'bad addressing mode' type error
8938 message and leave it up to the programmer to discover the
8939 true cause and fix their mistake. */
8940 || (inst.operands[1].reg == REG_PC),
8941 BAD_ADDR_MODE);
b05fe5cf 8942
c19d1205
ZW
8943 constraint (inst.reloc.exp.X_op != O_constant
8944 || inst.reloc.exp.X_add_number != 0,
8945 _("offset must be zero in ARM encoding"));
b05fe5cf 8946
5be8be5d
DG
8947 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8948
c19d1205
ZW
8949 inst.instruction |= inst.operands[0].reg << 12;
8950 inst.instruction |= inst.operands[1].reg << 16;
8951 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
8952}
8953
8954static void
c19d1205 8955do_ldrexd (void)
b05fe5cf 8956{
c19d1205
ZW
8957 constraint (inst.operands[0].reg % 2 != 0,
8958 _("even register required"));
8959 constraint (inst.operands[1].present
8960 && inst.operands[1].reg != inst.operands[0].reg + 1,
8961 _("can only load two consecutive registers"));
8962 /* If op 1 were present and equal to PC, this function wouldn't
8963 have been called in the first place. */
8964 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 8965
c19d1205
ZW
8966 inst.instruction |= inst.operands[0].reg << 12;
8967 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
8968}
8969
1be5fd2e
NC
8970/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8971 which is not a multiple of four is UNPREDICTABLE. */
8972static void
8973check_ldr_r15_aligned (void)
8974{
8975 constraint (!(inst.operands[1].immisreg)
8976 && (inst.operands[0].reg == REG_PC
8977 && inst.operands[1].reg == REG_PC
8978 && (inst.reloc.exp.X_add_number & 0x3)),
8979 _("ldr to register 15 must be 4-byte alligned"));
8980}
8981
b05fe5cf 8982static void
c19d1205 8983do_ldst (void)
b05fe5cf 8984{
c19d1205
ZW
8985 inst.instruction |= inst.operands[0].reg << 12;
8986 if (!inst.operands[1].isreg)
8335d6aa 8987 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 8988 return;
c19d1205 8989 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 8990 check_ldr_r15_aligned ();
b05fe5cf
ZW
8991}
8992
8993static void
c19d1205 8994do_ldstt (void)
b05fe5cf 8995{
c19d1205
ZW
8996 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8997 reject [Rn,...]. */
8998 if (inst.operands[1].preind)
b05fe5cf 8999 {
bd3ba5d1
NC
9000 constraint (inst.reloc.exp.X_op != O_constant
9001 || inst.reloc.exp.X_add_number != 0,
c19d1205 9002 _("this instruction requires a post-indexed address"));
b05fe5cf 9003
c19d1205
ZW
9004 inst.operands[1].preind = 0;
9005 inst.operands[1].postind = 1;
9006 inst.operands[1].writeback = 1;
b05fe5cf 9007 }
c19d1205
ZW
9008 inst.instruction |= inst.operands[0].reg << 12;
9009 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9010}
b05fe5cf 9011
c19d1205 9012/* Halfword and signed-byte load/store operations. */
b05fe5cf 9013
c19d1205
ZW
9014static void
9015do_ldstv4 (void)
9016{
ff4a8d2b 9017 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
9018 inst.instruction |= inst.operands[0].reg << 12;
9019 if (!inst.operands[1].isreg)
8335d6aa 9020 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 9021 return;
c19d1205 9022 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9023}
9024
9025static void
c19d1205 9026do_ldsttv4 (void)
b05fe5cf 9027{
c19d1205
ZW
9028 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9029 reject [Rn,...]. */
9030 if (inst.operands[1].preind)
b05fe5cf 9031 {
bd3ba5d1
NC
9032 constraint (inst.reloc.exp.X_op != O_constant
9033 || inst.reloc.exp.X_add_number != 0,
c19d1205 9034 _("this instruction requires a post-indexed address"));
b05fe5cf 9035
c19d1205
ZW
9036 inst.operands[1].preind = 0;
9037 inst.operands[1].postind = 1;
9038 inst.operands[1].writeback = 1;
b05fe5cf 9039 }
c19d1205
ZW
9040 inst.instruction |= inst.operands[0].reg << 12;
9041 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9042}
b05fe5cf 9043
c19d1205
ZW
9044/* Co-processor register load/store.
9045 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9046static void
9047do_lstc (void)
9048{
9049 inst.instruction |= inst.operands[0].reg << 8;
9050 inst.instruction |= inst.operands[1].reg << 12;
9051 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9052}
9053
b05fe5cf 9054static void
c19d1205 9055do_mlas (void)
b05fe5cf 9056{
8fb9d7b9 9057 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9058 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9059 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9060 && !(inst.instruction & 0x00400000))
8fb9d7b9 9061 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9062
c19d1205
ZW
9063 inst.instruction |= inst.operands[0].reg << 16;
9064 inst.instruction |= inst.operands[1].reg;
9065 inst.instruction |= inst.operands[2].reg << 8;
9066 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9067}
b05fe5cf 9068
c19d1205
ZW
9069static void
9070do_mov (void)
9071{
a9f02af8
MG
9072 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9073 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9074 THUMB1_RELOC_ONLY);
c19d1205
ZW
9075 inst.instruction |= inst.operands[0].reg << 12;
9076 encode_arm_shifter_operand (1);
9077}
b05fe5cf 9078
c19d1205
ZW
9079/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9080static void
9081do_mov16 (void)
9082{
b6895b4f
PB
9083 bfd_vma imm;
9084 bfd_boolean top;
9085
9086 top = (inst.instruction & 0x00400000) != 0;
9087 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
33eaf5de 9088 _(":lower16: not allowed in this instruction"));
b6895b4f 9089 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
33eaf5de 9090 _(":upper16: not allowed in this instruction"));
c19d1205 9091 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
9092 if (inst.reloc.type == BFD_RELOC_UNUSED)
9093 {
9094 imm = inst.reloc.exp.X_add_number;
9095 /* The value is in two pieces: 0:11, 16:19. */
9096 inst.instruction |= (imm & 0x00000fff);
9097 inst.instruction |= (imm & 0x0000f000) << 4;
9098 }
b05fe5cf 9099}
b99bd4ef 9100
037e8744
JB
9101static int
9102do_vfp_nsyn_mrs (void)
9103{
9104 if (inst.operands[0].isvec)
9105 {
9106 if (inst.operands[1].reg != 1)
477330fc 9107 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9108 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9109 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9110 do_vfp_nsyn_opcode ("fmstat");
9111 }
9112 else if (inst.operands[1].isvec)
9113 do_vfp_nsyn_opcode ("fmrx");
9114 else
9115 return FAIL;
5f4273c7 9116
037e8744
JB
9117 return SUCCESS;
9118}
9119
9120static int
9121do_vfp_nsyn_msr (void)
9122{
9123 if (inst.operands[0].isvec)
9124 do_vfp_nsyn_opcode ("fmxr");
9125 else
9126 return FAIL;
9127
9128 return SUCCESS;
9129}
9130
f7c21dc7
NC
9131static void
9132do_vmrs (void)
9133{
9134 unsigned Rt = inst.operands[0].reg;
fa94de6b 9135
16d02dc9 9136 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9137 {
9138 inst.error = BAD_SP;
9139 return;
9140 }
9141
9142 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9143 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9144 {
9145 inst.error = BAD_PC;
9146 return;
9147 }
9148
16d02dc9
JB
9149 /* If we get through parsing the register name, we just insert the number
9150 generated into the instruction without further validation. */
9151 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9152 inst.instruction |= (Rt << 12);
9153}
9154
9155static void
9156do_vmsr (void)
9157{
9158 unsigned Rt = inst.operands[1].reg;
fa94de6b 9159
f7c21dc7
NC
9160 if (thumb_mode)
9161 reject_bad_reg (Rt);
9162 else if (Rt == REG_PC)
9163 {
9164 inst.error = BAD_PC;
9165 return;
9166 }
9167
16d02dc9
JB
9168 /* If we get through parsing the register name, we just insert the number
9169 generated into the instruction without further validation. */
9170 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9171 inst.instruction |= (Rt << 12);
9172}
9173
b99bd4ef 9174static void
c19d1205 9175do_mrs (void)
b99bd4ef 9176{
90ec0d68
MGD
9177 unsigned br;
9178
037e8744
JB
9179 if (do_vfp_nsyn_mrs () == SUCCESS)
9180 return;
9181
ff4a8d2b 9182 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9183 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9184
9185 if (inst.operands[1].isreg)
9186 {
9187 br = inst.operands[1].reg;
9188 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
9189 as_bad (_("bad register for mrs"));
9190 }
9191 else
9192 {
9193 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9194 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9195 != (PSR_c|PSR_f),
d2cd1205 9196 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9197 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9198 }
9199
9200 inst.instruction |= br;
c19d1205 9201}
b99bd4ef 9202
c19d1205
ZW
9203/* Two possible forms:
9204 "{C|S}PSR_<field>, Rm",
9205 "{C|S}PSR_f, #expression". */
b99bd4ef 9206
c19d1205
ZW
9207static void
9208do_msr (void)
9209{
037e8744
JB
9210 if (do_vfp_nsyn_msr () == SUCCESS)
9211 return;
9212
c19d1205
ZW
9213 inst.instruction |= inst.operands[0].imm;
9214 if (inst.operands[1].isreg)
9215 inst.instruction |= inst.operands[1].reg;
9216 else
b99bd4ef 9217 {
c19d1205
ZW
9218 inst.instruction |= INST_IMMEDIATE;
9219 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9220 inst.reloc.pc_rel = 0;
b99bd4ef 9221 }
b99bd4ef
NC
9222}
9223
c19d1205
ZW
9224static void
9225do_mul (void)
a737bd4d 9226{
ff4a8d2b
NC
9227 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9228
c19d1205
ZW
9229 if (!inst.operands[2].present)
9230 inst.operands[2].reg = inst.operands[0].reg;
9231 inst.instruction |= inst.operands[0].reg << 16;
9232 inst.instruction |= inst.operands[1].reg;
9233 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9234
8fb9d7b9
MS
9235 if (inst.operands[0].reg == inst.operands[1].reg
9236 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9237 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9238}
9239
c19d1205
ZW
9240/* Long Multiply Parser
9241 UMULL RdLo, RdHi, Rm, Rs
9242 SMULL RdLo, RdHi, Rm, Rs
9243 UMLAL RdLo, RdHi, Rm, Rs
9244 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9245
9246static void
c19d1205 9247do_mull (void)
b99bd4ef 9248{
c19d1205
ZW
9249 inst.instruction |= inst.operands[0].reg << 12;
9250 inst.instruction |= inst.operands[1].reg << 16;
9251 inst.instruction |= inst.operands[2].reg;
9252 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9253
682b27ad
PB
9254 /* rdhi and rdlo must be different. */
9255 if (inst.operands[0].reg == inst.operands[1].reg)
9256 as_tsktsk (_("rdhi and rdlo must be different"));
9257
9258 /* rdhi, rdlo and rm must all be different before armv6. */
9259 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9260 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9261 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9262 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9263}
b99bd4ef 9264
c19d1205
ZW
9265static void
9266do_nop (void)
9267{
e7495e45
NS
9268 if (inst.operands[0].present
9269 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9270 {
9271 /* Architectural NOP hints are CPSR sets with no bits selected. */
9272 inst.instruction &= 0xf0000000;
e7495e45
NS
9273 inst.instruction |= 0x0320f000;
9274 if (inst.operands[0].present)
9275 inst.instruction |= inst.operands[0].imm;
c19d1205 9276 }
b99bd4ef
NC
9277}
9278
c19d1205
ZW
9279/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9280 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9281 Condition defaults to COND_ALWAYS.
9282 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9283
9284static void
c19d1205 9285do_pkhbt (void)
b99bd4ef 9286{
c19d1205
ZW
9287 inst.instruction |= inst.operands[0].reg << 12;
9288 inst.instruction |= inst.operands[1].reg << 16;
9289 inst.instruction |= inst.operands[2].reg;
9290 if (inst.operands[3].present)
9291 encode_arm_shift (3);
9292}
b99bd4ef 9293
c19d1205 9294/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9295
c19d1205
ZW
9296static void
9297do_pkhtb (void)
9298{
9299 if (!inst.operands[3].present)
b99bd4ef 9300 {
c19d1205
ZW
9301 /* If the shift specifier is omitted, turn the instruction
9302 into pkhbt rd, rm, rn. */
9303 inst.instruction &= 0xfff00010;
9304 inst.instruction |= inst.operands[0].reg << 12;
9305 inst.instruction |= inst.operands[1].reg;
9306 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9307 }
9308 else
9309 {
c19d1205
ZW
9310 inst.instruction |= inst.operands[0].reg << 12;
9311 inst.instruction |= inst.operands[1].reg << 16;
9312 inst.instruction |= inst.operands[2].reg;
9313 encode_arm_shift (3);
b99bd4ef
NC
9314 }
9315}
9316
c19d1205 9317/* ARMv5TE: Preload-Cache
60e5ef9f 9318 MP Extensions: Preload for write
c19d1205 9319
60e5ef9f 9320 PLD(W) <addr_mode>
c19d1205
ZW
9321
9322 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9323
9324static void
c19d1205 9325do_pld (void)
b99bd4ef 9326{
c19d1205
ZW
9327 constraint (!inst.operands[0].isreg,
9328 _("'[' expected after PLD mnemonic"));
9329 constraint (inst.operands[0].postind,
9330 _("post-indexed expression used in preload instruction"));
9331 constraint (inst.operands[0].writeback,
9332 _("writeback used in preload instruction"));
9333 constraint (!inst.operands[0].preind,
9334 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9335 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9336}
b99bd4ef 9337
62b3e311
PB
9338/* ARMv7: PLI <addr_mode> */
9339static void
9340do_pli (void)
9341{
9342 constraint (!inst.operands[0].isreg,
9343 _("'[' expected after PLI mnemonic"));
9344 constraint (inst.operands[0].postind,
9345 _("post-indexed expression used in preload instruction"));
9346 constraint (inst.operands[0].writeback,
9347 _("writeback used in preload instruction"));
9348 constraint (!inst.operands[0].preind,
9349 _("unindexed addressing used in preload instruction"));
9350 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9351 inst.instruction &= ~PRE_INDEX;
9352}
9353
c19d1205
ZW
9354static void
9355do_push_pop (void)
9356{
5e0d7f77
MP
9357 constraint (inst.operands[0].writeback,
9358 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9359 inst.operands[1] = inst.operands[0];
9360 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9361 inst.operands[0].isreg = 1;
9362 inst.operands[0].writeback = 1;
9363 inst.operands[0].reg = REG_SP;
6530b175 9364 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9365}
b99bd4ef 9366
c19d1205
ZW
9367/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9368 word at the specified address and the following word
9369 respectively.
9370 Unconditionally executed.
9371 Error if Rn is R15. */
b99bd4ef 9372
c19d1205
ZW
9373static void
9374do_rfe (void)
9375{
9376 inst.instruction |= inst.operands[0].reg << 16;
9377 if (inst.operands[0].writeback)
9378 inst.instruction |= WRITE_BACK;
9379}
b99bd4ef 9380
c19d1205 9381/* ARM V6 ssat (argument parse). */
b99bd4ef 9382
c19d1205
ZW
9383static void
9384do_ssat (void)
9385{
9386 inst.instruction |= inst.operands[0].reg << 12;
9387 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9388 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9389
c19d1205
ZW
9390 if (inst.operands[3].present)
9391 encode_arm_shift (3);
b99bd4ef
NC
9392}
9393
c19d1205 9394/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9395
9396static void
c19d1205 9397do_usat (void)
b99bd4ef 9398{
c19d1205
ZW
9399 inst.instruction |= inst.operands[0].reg << 12;
9400 inst.instruction |= inst.operands[1].imm << 16;
9401 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9402
c19d1205
ZW
9403 if (inst.operands[3].present)
9404 encode_arm_shift (3);
b99bd4ef
NC
9405}
9406
c19d1205 9407/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9408
9409static void
c19d1205 9410do_ssat16 (void)
09d92015 9411{
c19d1205
ZW
9412 inst.instruction |= inst.operands[0].reg << 12;
9413 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9414 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9415}
9416
c19d1205
ZW
9417static void
9418do_usat16 (void)
a737bd4d 9419{
c19d1205
ZW
9420 inst.instruction |= inst.operands[0].reg << 12;
9421 inst.instruction |= inst.operands[1].imm << 16;
9422 inst.instruction |= inst.operands[2].reg;
9423}
a737bd4d 9424
c19d1205
ZW
9425/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9426 preserving the other bits.
a737bd4d 9427
c19d1205
ZW
9428 setend <endian_specifier>, where <endian_specifier> is either
9429 BE or LE. */
a737bd4d 9430
c19d1205
ZW
9431static void
9432do_setend (void)
9433{
12e37cbc
MGD
9434 if (warn_on_deprecated
9435 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9436 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9437
c19d1205
ZW
9438 if (inst.operands[0].imm)
9439 inst.instruction |= 0x200;
a737bd4d
NC
9440}
9441
9442static void
c19d1205 9443do_shift (void)
a737bd4d 9444{
c19d1205
ZW
9445 unsigned int Rm = (inst.operands[1].present
9446 ? inst.operands[1].reg
9447 : inst.operands[0].reg);
a737bd4d 9448
c19d1205
ZW
9449 inst.instruction |= inst.operands[0].reg << 12;
9450 inst.instruction |= Rm;
9451 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9452 {
c19d1205
ZW
9453 inst.instruction |= inst.operands[2].reg << 8;
9454 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9455 /* PR 12854: Error on extraneous shifts. */
9456 constraint (inst.operands[2].shifted,
9457 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9458 }
9459 else
c19d1205 9460 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9461}
9462
09d92015 9463static void
3eb17e6b 9464do_smc (void)
09d92015 9465{
3eb17e6b 9466 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9467 inst.reloc.pc_rel = 0;
09d92015
MM
9468}
9469
90ec0d68
MGD
9470static void
9471do_hvc (void)
9472{
9473 inst.reloc.type = BFD_RELOC_ARM_HVC;
9474 inst.reloc.pc_rel = 0;
9475}
9476
09d92015 9477static void
c19d1205 9478do_swi (void)
09d92015 9479{
c19d1205
ZW
9480 inst.reloc.type = BFD_RELOC_ARM_SWI;
9481 inst.reloc.pc_rel = 0;
09d92015
MM
9482}
9483
ddfded2f
MW
9484static void
9485do_setpan (void)
9486{
9487 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9488 _("selected processor does not support SETPAN instruction"));
9489
9490 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9491}
9492
9493static void
9494do_t_setpan (void)
9495{
9496 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9497 _("selected processor does not support SETPAN instruction"));
9498
9499 inst.instruction |= (inst.operands[0].imm << 3);
9500}
9501
c19d1205
ZW
9502/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9503 SMLAxy{cond} Rd,Rm,Rs,Rn
9504 SMLAWy{cond} Rd,Rm,Rs,Rn
9505 Error if any register is R15. */
e16bb312 9506
c19d1205
ZW
9507static void
9508do_smla (void)
e16bb312 9509{
c19d1205
ZW
9510 inst.instruction |= inst.operands[0].reg << 16;
9511 inst.instruction |= inst.operands[1].reg;
9512 inst.instruction |= inst.operands[2].reg << 8;
9513 inst.instruction |= inst.operands[3].reg << 12;
9514}
a737bd4d 9515
c19d1205
ZW
9516/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9517 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9518 Error if any register is R15.
9519 Warning if Rdlo == Rdhi. */
a737bd4d 9520
c19d1205
ZW
9521static void
9522do_smlal (void)
9523{
9524 inst.instruction |= inst.operands[0].reg << 12;
9525 inst.instruction |= inst.operands[1].reg << 16;
9526 inst.instruction |= inst.operands[2].reg;
9527 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9528
c19d1205
ZW
9529 if (inst.operands[0].reg == inst.operands[1].reg)
9530 as_tsktsk (_("rdhi and rdlo must be different"));
9531}
a737bd4d 9532
c19d1205
ZW
9533/* ARM V5E (El Segundo) signed-multiply (argument parse)
9534 SMULxy{cond} Rd,Rm,Rs
9535 Error if any register is R15. */
a737bd4d 9536
c19d1205
ZW
9537static void
9538do_smul (void)
9539{
9540 inst.instruction |= inst.operands[0].reg << 16;
9541 inst.instruction |= inst.operands[1].reg;
9542 inst.instruction |= inst.operands[2].reg << 8;
9543}
a737bd4d 9544
b6702015
PB
9545/* ARM V6 srs (argument parse). The variable fields in the encoding are
9546 the same for both ARM and Thumb-2. */
a737bd4d 9547
c19d1205
ZW
9548static void
9549do_srs (void)
9550{
b6702015
PB
9551 int reg;
9552
9553 if (inst.operands[0].present)
9554 {
9555 reg = inst.operands[0].reg;
fdfde340 9556 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9557 }
9558 else
fdfde340 9559 reg = REG_SP;
b6702015
PB
9560
9561 inst.instruction |= reg << 16;
9562 inst.instruction |= inst.operands[1].imm;
9563 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9564 inst.instruction |= WRITE_BACK;
9565}
a737bd4d 9566
c19d1205 9567/* ARM V6 strex (argument parse). */
a737bd4d 9568
c19d1205
ZW
9569static void
9570do_strex (void)
9571{
9572 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9573 || inst.operands[2].postind || inst.operands[2].writeback
9574 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9575 || inst.operands[2].negative
9576 /* See comment in do_ldrex(). */
9577 || (inst.operands[2].reg == REG_PC),
9578 BAD_ADDR_MODE);
a737bd4d 9579
c19d1205
ZW
9580 constraint (inst.operands[0].reg == inst.operands[1].reg
9581 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9582
c19d1205
ZW
9583 constraint (inst.reloc.exp.X_op != O_constant
9584 || inst.reloc.exp.X_add_number != 0,
9585 _("offset must be zero in ARM encoding"));
a737bd4d 9586
c19d1205
ZW
9587 inst.instruction |= inst.operands[0].reg << 12;
9588 inst.instruction |= inst.operands[1].reg;
9589 inst.instruction |= inst.operands[2].reg << 16;
9590 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9591}
9592
877807f8
NC
9593static void
9594do_t_strexbh (void)
9595{
9596 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9597 || inst.operands[2].postind || inst.operands[2].writeback
9598 || inst.operands[2].immisreg || inst.operands[2].shifted
9599 || inst.operands[2].negative,
9600 BAD_ADDR_MODE);
9601
9602 constraint (inst.operands[0].reg == inst.operands[1].reg
9603 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9604
9605 do_rm_rd_rn ();
9606}
9607
e16bb312 9608static void
c19d1205 9609do_strexd (void)
e16bb312 9610{
c19d1205
ZW
9611 constraint (inst.operands[1].reg % 2 != 0,
9612 _("even register required"));
9613 constraint (inst.operands[2].present
9614 && inst.operands[2].reg != inst.operands[1].reg + 1,
9615 _("can only store two consecutive registers"));
9616 /* If op 2 were present and equal to PC, this function wouldn't
9617 have been called in the first place. */
9618 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9619
c19d1205
ZW
9620 constraint (inst.operands[0].reg == inst.operands[1].reg
9621 || inst.operands[0].reg == inst.operands[1].reg + 1
9622 || inst.operands[0].reg == inst.operands[3].reg,
9623 BAD_OVERLAP);
e16bb312 9624
c19d1205
ZW
9625 inst.instruction |= inst.operands[0].reg << 12;
9626 inst.instruction |= inst.operands[1].reg;
9627 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9628}
9629
9eb6c0f1
MGD
9630/* ARM V8 STRL. */
9631static void
4b8c8c02 9632do_stlex (void)
9eb6c0f1
MGD
9633{
9634 constraint (inst.operands[0].reg == inst.operands[1].reg
9635 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9636
9637 do_rd_rm_rn ();
9638}
9639
9640static void
4b8c8c02 9641do_t_stlex (void)
9eb6c0f1
MGD
9642{
9643 constraint (inst.operands[0].reg == inst.operands[1].reg
9644 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9645
9646 do_rm_rd_rn ();
9647}
9648
c19d1205
ZW
9649/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9650 extends it to 32-bits, and adds the result to a value in another
9651 register. You can specify a rotation by 0, 8, 16, or 24 bits
9652 before extracting the 16-bit value.
9653 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9654 Condition defaults to COND_ALWAYS.
9655 Error if any register uses R15. */
9656
e16bb312 9657static void
c19d1205 9658do_sxtah (void)
e16bb312 9659{
c19d1205
ZW
9660 inst.instruction |= inst.operands[0].reg << 12;
9661 inst.instruction |= inst.operands[1].reg << 16;
9662 inst.instruction |= inst.operands[2].reg;
9663 inst.instruction |= inst.operands[3].imm << 10;
9664}
e16bb312 9665
c19d1205 9666/* ARM V6 SXTH.
e16bb312 9667
c19d1205
ZW
9668 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9669 Condition defaults to COND_ALWAYS.
9670 Error if any register uses R15. */
e16bb312
NC
9671
9672static void
c19d1205 9673do_sxth (void)
e16bb312 9674{
c19d1205
ZW
9675 inst.instruction |= inst.operands[0].reg << 12;
9676 inst.instruction |= inst.operands[1].reg;
9677 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9678}
c19d1205
ZW
9679\f
9680/* VFP instructions. In a logical order: SP variant first, monad
9681 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9682
9683static void
c19d1205 9684do_vfp_sp_monadic (void)
e16bb312 9685{
5287ad62
JB
9686 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9687 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9688}
9689
9690static void
c19d1205 9691do_vfp_sp_dyadic (void)
e16bb312 9692{
5287ad62
JB
9693 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9694 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9695 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9696}
9697
9698static void
c19d1205 9699do_vfp_sp_compare_z (void)
e16bb312 9700{
5287ad62 9701 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9702}
9703
9704static void
c19d1205 9705do_vfp_dp_sp_cvt (void)
e16bb312 9706{
5287ad62
JB
9707 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9708 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9709}
9710
9711static void
c19d1205 9712do_vfp_sp_dp_cvt (void)
e16bb312 9713{
5287ad62
JB
9714 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9715 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9716}
9717
9718static void
c19d1205 9719do_vfp_reg_from_sp (void)
e16bb312 9720{
c19d1205 9721 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9722 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9723}
9724
9725static void
c19d1205 9726do_vfp_reg2_from_sp2 (void)
e16bb312 9727{
c19d1205
ZW
9728 constraint (inst.operands[2].imm != 2,
9729 _("only two consecutive VFP SP registers allowed here"));
9730 inst.instruction |= inst.operands[0].reg << 12;
9731 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9732 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9733}
9734
9735static void
c19d1205 9736do_vfp_sp_from_reg (void)
e16bb312 9737{
5287ad62 9738 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9739 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9740}
9741
9742static void
c19d1205 9743do_vfp_sp2_from_reg2 (void)
e16bb312 9744{
c19d1205
ZW
9745 constraint (inst.operands[0].imm != 2,
9746 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9747 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9748 inst.instruction |= inst.operands[1].reg << 12;
9749 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9750}
9751
9752static void
c19d1205 9753do_vfp_sp_ldst (void)
e16bb312 9754{
5287ad62 9755 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9756 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9757}
9758
9759static void
c19d1205 9760do_vfp_dp_ldst (void)
e16bb312 9761{
5287ad62 9762 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9763 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9764}
9765
c19d1205 9766
e16bb312 9767static void
c19d1205 9768vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9769{
c19d1205
ZW
9770 if (inst.operands[0].writeback)
9771 inst.instruction |= WRITE_BACK;
9772 else
9773 constraint (ldstm_type != VFP_LDSTMIA,
9774 _("this addressing mode requires base-register writeback"));
9775 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9776 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9777 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9778}
9779
9780static void
c19d1205 9781vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9782{
c19d1205 9783 int count;
e16bb312 9784
c19d1205
ZW
9785 if (inst.operands[0].writeback)
9786 inst.instruction |= WRITE_BACK;
9787 else
9788 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9789 _("this addressing mode requires base-register writeback"));
e16bb312 9790
c19d1205 9791 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9792 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9793
c19d1205
ZW
9794 count = inst.operands[1].imm << 1;
9795 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9796 count += 1;
e16bb312 9797
c19d1205 9798 inst.instruction |= count;
e16bb312
NC
9799}
9800
9801static void
c19d1205 9802do_vfp_sp_ldstmia (void)
e16bb312 9803{
c19d1205 9804 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9805}
9806
9807static void
c19d1205 9808do_vfp_sp_ldstmdb (void)
e16bb312 9809{
c19d1205 9810 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9811}
9812
9813static void
c19d1205 9814do_vfp_dp_ldstmia (void)
e16bb312 9815{
c19d1205 9816 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9817}
9818
9819static void
c19d1205 9820do_vfp_dp_ldstmdb (void)
e16bb312 9821{
c19d1205 9822 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9823}
9824
9825static void
c19d1205 9826do_vfp_xp_ldstmia (void)
e16bb312 9827{
c19d1205
ZW
9828 vfp_dp_ldstm (VFP_LDSTMIAX);
9829}
e16bb312 9830
c19d1205
ZW
9831static void
9832do_vfp_xp_ldstmdb (void)
9833{
9834 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9835}
5287ad62
JB
9836
9837static void
9838do_vfp_dp_rd_rm (void)
9839{
9840 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9841 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9842}
9843
9844static void
9845do_vfp_dp_rn_rd (void)
9846{
9847 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9848 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9849}
9850
9851static void
9852do_vfp_dp_rd_rn (void)
9853{
9854 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9855 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9856}
9857
9858static void
9859do_vfp_dp_rd_rn_rm (void)
9860{
9861 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9862 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9863 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9864}
9865
9866static void
9867do_vfp_dp_rd (void)
9868{
9869 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9870}
9871
9872static void
9873do_vfp_dp_rm_rd_rn (void)
9874{
9875 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9876 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9877 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9878}
9879
9880/* VFPv3 instructions. */
9881static void
9882do_vfp_sp_const (void)
9883{
9884 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9885 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9886 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9887}
9888
9889static void
9890do_vfp_dp_const (void)
9891{
9892 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9893 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9894 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9895}
9896
9897static void
9898vfp_conv (int srcsize)
9899{
5f1af56b
MGD
9900 int immbits = srcsize - inst.operands[1].imm;
9901
fa94de6b
RM
9902 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9903 {
5f1af56b 9904 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9905 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9906 inst.error = _("immediate value out of range, expected range [0, 16]");
9907 return;
9908 }
fa94de6b 9909 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9910 {
9911 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9912 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9913 inst.error = _("immediate value out of range, expected range [1, 32]");
9914 return;
9915 }
9916
5287ad62
JB
9917 inst.instruction |= (immbits & 1) << 5;
9918 inst.instruction |= (immbits >> 1);
9919}
9920
9921static void
9922do_vfp_sp_conv_16 (void)
9923{
9924 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9925 vfp_conv (16);
9926}
9927
9928static void
9929do_vfp_dp_conv_16 (void)
9930{
9931 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9932 vfp_conv (16);
9933}
9934
9935static void
9936do_vfp_sp_conv_32 (void)
9937{
9938 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9939 vfp_conv (32);
9940}
9941
9942static void
9943do_vfp_dp_conv_32 (void)
9944{
9945 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9946 vfp_conv (32);
9947}
c19d1205
ZW
9948\f
9949/* FPA instructions. Also in a logical order. */
e16bb312 9950
c19d1205
ZW
9951static void
9952do_fpa_cmp (void)
9953{
9954 inst.instruction |= inst.operands[0].reg << 16;
9955 inst.instruction |= inst.operands[1].reg;
9956}
b99bd4ef
NC
9957
9958static void
c19d1205 9959do_fpa_ldmstm (void)
b99bd4ef 9960{
c19d1205
ZW
9961 inst.instruction |= inst.operands[0].reg << 12;
9962 switch (inst.operands[1].imm)
9963 {
9964 case 1: inst.instruction |= CP_T_X; break;
9965 case 2: inst.instruction |= CP_T_Y; break;
9966 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9967 case 4: break;
9968 default: abort ();
9969 }
b99bd4ef 9970
c19d1205
ZW
9971 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9972 {
9973 /* The instruction specified "ea" or "fd", so we can only accept
9974 [Rn]{!}. The instruction does not really support stacking or
9975 unstacking, so we have to emulate these by setting appropriate
9976 bits and offsets. */
9977 constraint (inst.reloc.exp.X_op != O_constant
9978 || inst.reloc.exp.X_add_number != 0,
9979 _("this instruction does not support indexing"));
b99bd4ef 9980
c19d1205
ZW
9981 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9982 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 9983
c19d1205
ZW
9984 if (!(inst.instruction & INDEX_UP))
9985 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 9986
c19d1205
ZW
9987 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
9988 {
9989 inst.operands[2].preind = 0;
9990 inst.operands[2].postind = 1;
9991 }
9992 }
b99bd4ef 9993
c19d1205 9994 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 9995}
c19d1205
ZW
9996\f
9997/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 9998
c19d1205
ZW
9999static void
10000do_iwmmxt_tandorc (void)
10001{
10002 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
10003}
b99bd4ef 10004
c19d1205
ZW
10005static void
10006do_iwmmxt_textrc (void)
10007{
10008 inst.instruction |= inst.operands[0].reg << 12;
10009 inst.instruction |= inst.operands[1].imm;
10010}
b99bd4ef
NC
10011
10012static void
c19d1205 10013do_iwmmxt_textrm (void)
b99bd4ef 10014{
c19d1205
ZW
10015 inst.instruction |= inst.operands[0].reg << 12;
10016 inst.instruction |= inst.operands[1].reg << 16;
10017 inst.instruction |= inst.operands[2].imm;
10018}
b99bd4ef 10019
c19d1205
ZW
10020static void
10021do_iwmmxt_tinsr (void)
10022{
10023 inst.instruction |= inst.operands[0].reg << 16;
10024 inst.instruction |= inst.operands[1].reg << 12;
10025 inst.instruction |= inst.operands[2].imm;
10026}
b99bd4ef 10027
c19d1205
ZW
10028static void
10029do_iwmmxt_tmia (void)
10030{
10031 inst.instruction |= inst.operands[0].reg << 5;
10032 inst.instruction |= inst.operands[1].reg;
10033 inst.instruction |= inst.operands[2].reg << 12;
10034}
b99bd4ef 10035
c19d1205
ZW
10036static void
10037do_iwmmxt_waligni (void)
10038{
10039 inst.instruction |= inst.operands[0].reg << 12;
10040 inst.instruction |= inst.operands[1].reg << 16;
10041 inst.instruction |= inst.operands[2].reg;
10042 inst.instruction |= inst.operands[3].imm << 20;
10043}
b99bd4ef 10044
2d447fca
JM
10045static void
10046do_iwmmxt_wmerge (void)
10047{
10048 inst.instruction |= inst.operands[0].reg << 12;
10049 inst.instruction |= inst.operands[1].reg << 16;
10050 inst.instruction |= inst.operands[2].reg;
10051 inst.instruction |= inst.operands[3].imm << 21;
10052}
10053
c19d1205
ZW
10054static void
10055do_iwmmxt_wmov (void)
10056{
10057 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10058 inst.instruction |= inst.operands[0].reg << 12;
10059 inst.instruction |= inst.operands[1].reg << 16;
10060 inst.instruction |= inst.operands[1].reg;
10061}
b99bd4ef 10062
c19d1205
ZW
10063static void
10064do_iwmmxt_wldstbh (void)
10065{
8f06b2d8 10066 int reloc;
c19d1205 10067 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
10068 if (thumb_mode)
10069 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10070 else
10071 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10072 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
10073}
10074
c19d1205
ZW
10075static void
10076do_iwmmxt_wldstw (void)
10077{
10078 /* RIWR_RIWC clears .isreg for a control register. */
10079 if (!inst.operands[0].isreg)
10080 {
10081 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10082 inst.instruction |= 0xf0000000;
10083 }
b99bd4ef 10084
c19d1205
ZW
10085 inst.instruction |= inst.operands[0].reg << 12;
10086 encode_arm_cp_address (1, TRUE, TRUE, 0);
10087}
b99bd4ef
NC
10088
10089static void
c19d1205 10090do_iwmmxt_wldstd (void)
b99bd4ef 10091{
c19d1205 10092 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
10093 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10094 && inst.operands[1].immisreg)
10095 {
10096 inst.instruction &= ~0x1a000ff;
eff0bc54 10097 inst.instruction |= (0xfU << 28);
2d447fca
JM
10098 if (inst.operands[1].preind)
10099 inst.instruction |= PRE_INDEX;
10100 if (!inst.operands[1].negative)
10101 inst.instruction |= INDEX_UP;
10102 if (inst.operands[1].writeback)
10103 inst.instruction |= WRITE_BACK;
10104 inst.instruction |= inst.operands[1].reg << 16;
10105 inst.instruction |= inst.reloc.exp.X_add_number << 4;
10106 inst.instruction |= inst.operands[1].imm;
10107 }
10108 else
10109 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10110}
b99bd4ef 10111
c19d1205
ZW
10112static void
10113do_iwmmxt_wshufh (void)
10114{
10115 inst.instruction |= inst.operands[0].reg << 12;
10116 inst.instruction |= inst.operands[1].reg << 16;
10117 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10118 inst.instruction |= (inst.operands[2].imm & 0x0f);
10119}
b99bd4ef 10120
c19d1205
ZW
10121static void
10122do_iwmmxt_wzero (void)
10123{
10124 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10125 inst.instruction |= inst.operands[0].reg;
10126 inst.instruction |= inst.operands[0].reg << 12;
10127 inst.instruction |= inst.operands[0].reg << 16;
10128}
2d447fca
JM
10129
10130static void
10131do_iwmmxt_wrwrwr_or_imm5 (void)
10132{
10133 if (inst.operands[2].isreg)
10134 do_rd_rn_rm ();
10135 else {
10136 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10137 _("immediate operand requires iWMMXt2"));
10138 do_rd_rn ();
10139 if (inst.operands[2].imm == 0)
10140 {
10141 switch ((inst.instruction >> 20) & 0xf)
10142 {
10143 case 4:
10144 case 5:
10145 case 6:
5f4273c7 10146 case 7:
2d447fca
JM
10147 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10148 inst.operands[2].imm = 16;
10149 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10150 break;
10151 case 8:
10152 case 9:
10153 case 10:
10154 case 11:
10155 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10156 inst.operands[2].imm = 32;
10157 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10158 break;
10159 case 12:
10160 case 13:
10161 case 14:
10162 case 15:
10163 {
10164 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10165 unsigned long wrn;
10166 wrn = (inst.instruction >> 16) & 0xf;
10167 inst.instruction &= 0xff0fff0f;
10168 inst.instruction |= wrn;
10169 /* Bail out here; the instruction is now assembled. */
10170 return;
10171 }
10172 }
10173 }
10174 /* Map 32 -> 0, etc. */
10175 inst.operands[2].imm &= 0x1f;
eff0bc54 10176 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10177 }
10178}
c19d1205
ZW
10179\f
10180/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10181 operations first, then control, shift, and load/store. */
b99bd4ef 10182
c19d1205 10183/* Insns like "foo X,Y,Z". */
b99bd4ef 10184
c19d1205
ZW
10185static void
10186do_mav_triple (void)
10187{
10188 inst.instruction |= inst.operands[0].reg << 16;
10189 inst.instruction |= inst.operands[1].reg;
10190 inst.instruction |= inst.operands[2].reg << 12;
10191}
b99bd4ef 10192
c19d1205
ZW
10193/* Insns like "foo W,X,Y,Z".
10194 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10195
c19d1205
ZW
10196static void
10197do_mav_quad (void)
10198{
10199 inst.instruction |= inst.operands[0].reg << 5;
10200 inst.instruction |= inst.operands[1].reg << 12;
10201 inst.instruction |= inst.operands[2].reg << 16;
10202 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10203}
10204
c19d1205
ZW
10205/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10206static void
10207do_mav_dspsc (void)
a737bd4d 10208{
c19d1205
ZW
10209 inst.instruction |= inst.operands[1].reg << 12;
10210}
a737bd4d 10211
c19d1205
ZW
10212/* Maverick shift immediate instructions.
10213 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10214 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10215
c19d1205
ZW
10216static void
10217do_mav_shift (void)
10218{
10219 int imm = inst.operands[2].imm;
a737bd4d 10220
c19d1205
ZW
10221 inst.instruction |= inst.operands[0].reg << 12;
10222 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10223
c19d1205
ZW
10224 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10225 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10226 Bit 4 should be 0. */
10227 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10228
c19d1205
ZW
10229 inst.instruction |= imm;
10230}
10231\f
10232/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10233
c19d1205
ZW
10234/* Xscale multiply-accumulate (argument parse)
10235 MIAcc acc0,Rm,Rs
10236 MIAPHcc acc0,Rm,Rs
10237 MIAxycc acc0,Rm,Rs. */
a737bd4d 10238
c19d1205
ZW
10239static void
10240do_xsc_mia (void)
10241{
10242 inst.instruction |= inst.operands[1].reg;
10243 inst.instruction |= inst.operands[2].reg << 12;
10244}
a737bd4d 10245
c19d1205 10246/* Xscale move-accumulator-register (argument parse)
a737bd4d 10247
c19d1205 10248 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10249
c19d1205
ZW
10250static void
10251do_xsc_mar (void)
10252{
10253 inst.instruction |= inst.operands[1].reg << 12;
10254 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10255}
10256
c19d1205 10257/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10258
c19d1205 10259 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10260
10261static void
c19d1205 10262do_xsc_mra (void)
b99bd4ef 10263{
c19d1205
ZW
10264 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10265 inst.instruction |= inst.operands[0].reg << 12;
10266 inst.instruction |= inst.operands[1].reg << 16;
10267}
10268\f
10269/* Encoding functions relevant only to Thumb. */
b99bd4ef 10270
c19d1205
ZW
10271/* inst.operands[i] is a shifted-register operand; encode
10272 it into inst.instruction in the format used by Thumb32. */
10273
10274static void
10275encode_thumb32_shifted_operand (int i)
10276{
10277 unsigned int value = inst.reloc.exp.X_add_number;
10278 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10279
9c3c69f2
PB
10280 constraint (inst.operands[i].immisreg,
10281 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10282 inst.instruction |= inst.operands[i].reg;
10283 if (shift == SHIFT_RRX)
10284 inst.instruction |= SHIFT_ROR << 4;
10285 else
b99bd4ef 10286 {
c19d1205
ZW
10287 constraint (inst.reloc.exp.X_op != O_constant,
10288 _("expression too complex"));
10289
10290 constraint (value > 32
10291 || (value == 32 && (shift == SHIFT_LSL
10292 || shift == SHIFT_ROR)),
10293 _("shift expression is too large"));
10294
10295 if (value == 0)
10296 shift = SHIFT_LSL;
10297 else if (value == 32)
10298 value = 0;
10299
10300 inst.instruction |= shift << 4;
10301 inst.instruction |= (value & 0x1c) << 10;
10302 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10303 }
c19d1205 10304}
b99bd4ef 10305
b99bd4ef 10306
c19d1205
ZW
10307/* inst.operands[i] was set up by parse_address. Encode it into a
10308 Thumb32 format load or store instruction. Reject forms that cannot
10309 be used with such instructions. If is_t is true, reject forms that
10310 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10311 that cannot be used with a D instruction. If it is a store insn,
10312 reject PC in Rn. */
b99bd4ef 10313
c19d1205
ZW
10314static void
10315encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10316{
5be8be5d 10317 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10318
10319 constraint (!inst.operands[i].isreg,
53365c0d 10320 _("Instruction does not support =N addresses"));
b99bd4ef 10321
c19d1205
ZW
10322 inst.instruction |= inst.operands[i].reg << 16;
10323 if (inst.operands[i].immisreg)
b99bd4ef 10324 {
5be8be5d 10325 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10326 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10327 constraint (inst.operands[i].negative,
10328 _("Thumb does not support negative register indexing"));
10329 constraint (inst.operands[i].postind,
10330 _("Thumb does not support register post-indexing"));
10331 constraint (inst.operands[i].writeback,
10332 _("Thumb does not support register indexing with writeback"));
10333 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10334 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10335
f40d1643 10336 inst.instruction |= inst.operands[i].imm;
c19d1205 10337 if (inst.operands[i].shifted)
b99bd4ef 10338 {
c19d1205
ZW
10339 constraint (inst.reloc.exp.X_op != O_constant,
10340 _("expression too complex"));
9c3c69f2
PB
10341 constraint (inst.reloc.exp.X_add_number < 0
10342 || inst.reloc.exp.X_add_number > 3,
c19d1205 10343 _("shift out of range"));
9c3c69f2 10344 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10345 }
10346 inst.reloc.type = BFD_RELOC_UNUSED;
10347 }
10348 else if (inst.operands[i].preind)
10349 {
5be8be5d 10350 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10351 constraint (is_t && inst.operands[i].writeback,
c19d1205 10352 _("cannot use writeback with this instruction"));
4755303e
WN
10353 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10354 BAD_PC_ADDRESSING);
c19d1205
ZW
10355
10356 if (is_d)
10357 {
10358 inst.instruction |= 0x01000000;
10359 if (inst.operands[i].writeback)
10360 inst.instruction |= 0x00200000;
b99bd4ef 10361 }
c19d1205 10362 else
b99bd4ef 10363 {
c19d1205
ZW
10364 inst.instruction |= 0x00000c00;
10365 if (inst.operands[i].writeback)
10366 inst.instruction |= 0x00000100;
b99bd4ef 10367 }
c19d1205 10368 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10369 }
c19d1205 10370 else if (inst.operands[i].postind)
b99bd4ef 10371 {
9c2799c2 10372 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10373 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10374 constraint (is_t, _("cannot use post-indexing with this instruction"));
10375
10376 if (is_d)
10377 inst.instruction |= 0x00200000;
10378 else
10379 inst.instruction |= 0x00000900;
10380 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10381 }
10382 else /* unindexed - only for coprocessor */
10383 inst.error = _("instruction does not accept unindexed addressing");
10384}
10385
10386/* Table of Thumb instructions which exist in both 16- and 32-bit
10387 encodings (the latter only in post-V6T2 cores). The index is the
10388 value used in the insns table below. When there is more than one
10389 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10390 holds variant (1).
10391 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10392#define T16_32_TAB \
21d799b5
NC
10393 X(_adc, 4140, eb400000), \
10394 X(_adcs, 4140, eb500000), \
10395 X(_add, 1c00, eb000000), \
10396 X(_adds, 1c00, eb100000), \
10397 X(_addi, 0000, f1000000), \
10398 X(_addis, 0000, f1100000), \
10399 X(_add_pc,000f, f20f0000), \
10400 X(_add_sp,000d, f10d0000), \
10401 X(_adr, 000f, f20f0000), \
10402 X(_and, 4000, ea000000), \
10403 X(_ands, 4000, ea100000), \
10404 X(_asr, 1000, fa40f000), \
10405 X(_asrs, 1000, fa50f000), \
10406 X(_b, e000, f000b000), \
10407 X(_bcond, d000, f0008000), \
10408 X(_bic, 4380, ea200000), \
10409 X(_bics, 4380, ea300000), \
10410 X(_cmn, 42c0, eb100f00), \
10411 X(_cmp, 2800, ebb00f00), \
10412 X(_cpsie, b660, f3af8400), \
10413 X(_cpsid, b670, f3af8600), \
10414 X(_cpy, 4600, ea4f0000), \
10415 X(_dec_sp,80dd, f1ad0d00), \
10416 X(_eor, 4040, ea800000), \
10417 X(_eors, 4040, ea900000), \
10418 X(_inc_sp,00dd, f10d0d00), \
10419 X(_ldmia, c800, e8900000), \
10420 X(_ldr, 6800, f8500000), \
10421 X(_ldrb, 7800, f8100000), \
10422 X(_ldrh, 8800, f8300000), \
10423 X(_ldrsb, 5600, f9100000), \
10424 X(_ldrsh, 5e00, f9300000), \
10425 X(_ldr_pc,4800, f85f0000), \
10426 X(_ldr_pc2,4800, f85f0000), \
10427 X(_ldr_sp,9800, f85d0000), \
10428 X(_lsl, 0000, fa00f000), \
10429 X(_lsls, 0000, fa10f000), \
10430 X(_lsr, 0800, fa20f000), \
10431 X(_lsrs, 0800, fa30f000), \
10432 X(_mov, 2000, ea4f0000), \
10433 X(_movs, 2000, ea5f0000), \
10434 X(_mul, 4340, fb00f000), \
10435 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10436 X(_mvn, 43c0, ea6f0000), \
10437 X(_mvns, 43c0, ea7f0000), \
10438 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10439 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10440 X(_orr, 4300, ea400000), \
10441 X(_orrs, 4300, ea500000), \
10442 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10443 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10444 X(_rev, ba00, fa90f080), \
10445 X(_rev16, ba40, fa90f090), \
10446 X(_revsh, bac0, fa90f0b0), \
10447 X(_ror, 41c0, fa60f000), \
10448 X(_rors, 41c0, fa70f000), \
10449 X(_sbc, 4180, eb600000), \
10450 X(_sbcs, 4180, eb700000), \
10451 X(_stmia, c000, e8800000), \
10452 X(_str, 6000, f8400000), \
10453 X(_strb, 7000, f8000000), \
10454 X(_strh, 8000, f8200000), \
10455 X(_str_sp,9000, f84d0000), \
10456 X(_sub, 1e00, eba00000), \
10457 X(_subs, 1e00, ebb00000), \
10458 X(_subi, 8000, f1a00000), \
10459 X(_subis, 8000, f1b00000), \
10460 X(_sxtb, b240, fa4ff080), \
10461 X(_sxth, b200, fa0ff080), \
10462 X(_tst, 4200, ea100f00), \
10463 X(_uxtb, b2c0, fa5ff080), \
10464 X(_uxth, b280, fa1ff080), \
10465 X(_nop, bf00, f3af8000), \
10466 X(_yield, bf10, f3af8001), \
10467 X(_wfe, bf20, f3af8002), \
10468 X(_wfi, bf30, f3af8003), \
53c4b28b 10469 X(_sev, bf40, f3af8004), \
74db7efb
NC
10470 X(_sevl, bf50, f3af8005), \
10471 X(_udf, de00, f7f0a000)
c19d1205
ZW
10472
10473/* To catch errors in encoding functions, the codes are all offset by
10474 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10475 as 16-bit instructions. */
21d799b5 10476#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10477enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10478#undef X
10479
10480#define X(a,b,c) 0x##b
10481static const unsigned short thumb_op16[] = { T16_32_TAB };
10482#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10483#undef X
10484
10485#define X(a,b,c) 0x##c
10486static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10487#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10488#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10489#undef X
10490#undef T16_32_TAB
10491
10492/* Thumb instruction encoders, in alphabetical order. */
10493
92e90b6e 10494/* ADDW or SUBW. */
c921be7d 10495
92e90b6e
PB
10496static void
10497do_t_add_sub_w (void)
10498{
10499 int Rd, Rn;
10500
10501 Rd = inst.operands[0].reg;
10502 Rn = inst.operands[1].reg;
10503
539d4391
NC
10504 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10505 is the SP-{plus,minus}-immediate form of the instruction. */
10506 if (Rn == REG_SP)
10507 constraint (Rd == REG_PC, BAD_PC);
10508 else
10509 reject_bad_reg (Rd);
fdfde340 10510
92e90b6e
PB
10511 inst.instruction |= (Rn << 16) | (Rd << 8);
10512 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10513}
10514
c19d1205 10515/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 10516 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
10517
10518static void
10519do_t_add_sub (void)
10520{
10521 int Rd, Rs, Rn;
10522
10523 Rd = inst.operands[0].reg;
10524 Rs = (inst.operands[1].present
10525 ? inst.operands[1].reg /* Rd, Rs, foo */
10526 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10527
e07e6e58
NC
10528 if (Rd == REG_PC)
10529 set_it_insn_type_last ();
10530
c19d1205
ZW
10531 if (unified_syntax)
10532 {
0110f2b8
PB
10533 bfd_boolean flags;
10534 bfd_boolean narrow;
10535 int opcode;
10536
10537 flags = (inst.instruction == T_MNEM_adds
10538 || inst.instruction == T_MNEM_subs);
10539 if (flags)
e07e6e58 10540 narrow = !in_it_block ();
0110f2b8 10541 else
e07e6e58 10542 narrow = in_it_block ();
c19d1205 10543 if (!inst.operands[2].isreg)
b99bd4ef 10544 {
16805f35
PB
10545 int add;
10546
5c8ed6a4
JW
10547 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10548 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340 10549
16805f35
PB
10550 add = (inst.instruction == T_MNEM_add
10551 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10552 opcode = 0;
10553 if (inst.size_req != 4)
10554 {
0110f2b8 10555 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10556 appropriate. */
0110f2b8
PB
10557 if (Rd == REG_SP && Rs == REG_SP && !flags)
10558 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10559 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10560 opcode = T_MNEM_add_sp;
10561 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10562 opcode = T_MNEM_add_pc;
10563 else if (Rd <= 7 && Rs <= 7 && narrow)
10564 {
10565 if (flags)
10566 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10567 else
10568 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10569 }
10570 if (opcode)
10571 {
10572 inst.instruction = THUMB_OP16(opcode);
10573 inst.instruction |= (Rd << 4) | Rs;
72d98d16
MG
10574 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10575 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
a9f02af8
MG
10576 {
10577 if (inst.size_req == 2)
10578 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10579 else
10580 inst.relax = opcode;
10581 }
0110f2b8
PB
10582 }
10583 else
10584 constraint (inst.size_req == 2, BAD_HIREG);
10585 }
10586 if (inst.size_req == 4
10587 || (inst.size_req != 2 && !opcode))
10588 {
a9f02af8
MG
10589 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10590 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
10591 THUMB1_RELOC_ONLY);
efd81785
PB
10592 if (Rd == REG_PC)
10593 {
fdfde340 10594 constraint (add, BAD_PC);
efd81785
PB
10595 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10596 _("only SUBS PC, LR, #const allowed"));
10597 constraint (inst.reloc.exp.X_op != O_constant,
10598 _("expression too complex"));
10599 constraint (inst.reloc.exp.X_add_number < 0
10600 || inst.reloc.exp.X_add_number > 0xff,
10601 _("immediate value out of range"));
10602 inst.instruction = T2_SUBS_PC_LR
10603 | inst.reloc.exp.X_add_number;
10604 inst.reloc.type = BFD_RELOC_UNUSED;
10605 return;
10606 }
10607 else if (Rs == REG_PC)
16805f35
PB
10608 {
10609 /* Always use addw/subw. */
10610 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10611 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10612 }
10613 else
10614 {
10615 inst.instruction = THUMB_OP32 (inst.instruction);
10616 inst.instruction = (inst.instruction & 0xe1ffffff)
10617 | 0x10000000;
10618 if (flags)
10619 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10620 else
10621 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10622 }
dc4503c6
PB
10623 inst.instruction |= Rd << 8;
10624 inst.instruction |= Rs << 16;
0110f2b8 10625 }
b99bd4ef 10626 }
c19d1205
ZW
10627 else
10628 {
5f4cb198
NC
10629 unsigned int value = inst.reloc.exp.X_add_number;
10630 unsigned int shift = inst.operands[2].shift_kind;
10631
c19d1205
ZW
10632 Rn = inst.operands[2].reg;
10633 /* See if we can do this with a 16-bit instruction. */
10634 if (!inst.operands[2].shifted && inst.size_req != 4)
10635 {
e27ec89e
PB
10636 if (Rd > 7 || Rs > 7 || Rn > 7)
10637 narrow = FALSE;
10638
10639 if (narrow)
c19d1205 10640 {
e27ec89e
PB
10641 inst.instruction = ((inst.instruction == T_MNEM_adds
10642 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10643 ? T_OPCODE_ADD_R3
10644 : T_OPCODE_SUB_R3);
10645 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10646 return;
10647 }
b99bd4ef 10648
7e806470 10649 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10650 {
7e806470
PB
10651 /* Thumb-1 cores (except v6-M) require at least one high
10652 register in a narrow non flag setting add. */
10653 if (Rd > 7 || Rn > 7
10654 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10655 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10656 {
7e806470
PB
10657 if (Rd == Rn)
10658 {
10659 Rn = Rs;
10660 Rs = Rd;
10661 }
c19d1205
ZW
10662 inst.instruction = T_OPCODE_ADD_HI;
10663 inst.instruction |= (Rd & 8) << 4;
10664 inst.instruction |= (Rd & 7);
10665 inst.instruction |= Rn << 3;
10666 return;
10667 }
c19d1205
ZW
10668 }
10669 }
c921be7d 10670
fdfde340 10671 constraint (Rd == REG_PC, BAD_PC);
5c8ed6a4
JW
10672 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10673 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
fdfde340
JM
10674 constraint (Rs == REG_PC, BAD_PC);
10675 reject_bad_reg (Rn);
10676
c19d1205
ZW
10677 /* If we get here, it can't be done in 16 bits. */
10678 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10679 _("shift must be constant"));
10680 inst.instruction = THUMB_OP32 (inst.instruction);
10681 inst.instruction |= Rd << 8;
10682 inst.instruction |= Rs << 16;
5f4cb198
NC
10683 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10684 _("shift value over 3 not allowed in thumb mode"));
10685 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10686 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10687 encode_thumb32_shifted_operand (2);
10688 }
10689 }
10690 else
10691 {
10692 constraint (inst.instruction == T_MNEM_adds
10693 || inst.instruction == T_MNEM_subs,
10694 BAD_THUMB32);
b99bd4ef 10695
c19d1205 10696 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10697 {
c19d1205
ZW
10698 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10699 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10700 BAD_HIREG);
10701
10702 inst.instruction = (inst.instruction == T_MNEM_add
10703 ? 0x0000 : 0x8000);
10704 inst.instruction |= (Rd << 4) | Rs;
10705 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10706 return;
10707 }
10708
c19d1205
ZW
10709 Rn = inst.operands[2].reg;
10710 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10711
c19d1205
ZW
10712 /* We now have Rd, Rs, and Rn set to registers. */
10713 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10714 {
c19d1205
ZW
10715 /* Can't do this for SUB. */
10716 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10717 inst.instruction = T_OPCODE_ADD_HI;
10718 inst.instruction |= (Rd & 8) << 4;
10719 inst.instruction |= (Rd & 7);
10720 if (Rs == Rd)
10721 inst.instruction |= Rn << 3;
10722 else if (Rn == Rd)
10723 inst.instruction |= Rs << 3;
10724 else
10725 constraint (1, _("dest must overlap one source register"));
10726 }
10727 else
10728 {
10729 inst.instruction = (inst.instruction == T_MNEM_add
10730 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10731 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10732 }
b99bd4ef 10733 }
b99bd4ef
NC
10734}
10735
c19d1205
ZW
10736static void
10737do_t_adr (void)
10738{
fdfde340
JM
10739 unsigned Rd;
10740
10741 Rd = inst.operands[0].reg;
10742 reject_bad_reg (Rd);
10743
10744 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10745 {
10746 /* Defer to section relaxation. */
10747 inst.relax = inst.instruction;
10748 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10749 inst.instruction |= Rd << 4;
0110f2b8
PB
10750 }
10751 else if (unified_syntax && inst.size_req != 2)
e9f89963 10752 {
0110f2b8 10753 /* Generate a 32-bit opcode. */
e9f89963 10754 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10755 inst.instruction |= Rd << 8;
e9f89963
PB
10756 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10757 inst.reloc.pc_rel = 1;
10758 }
10759 else
10760 {
0110f2b8 10761 /* Generate a 16-bit opcode. */
e9f89963
PB
10762 inst.instruction = THUMB_OP16 (inst.instruction);
10763 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10764 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10765 inst.reloc.pc_rel = 1;
fdfde340 10766 inst.instruction |= Rd << 4;
e9f89963 10767 }
52a86f84
NC
10768
10769 if (inst.reloc.exp.X_op == O_symbol
10770 && inst.reloc.exp.X_add_symbol != NULL
10771 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10772 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10773 inst.reloc.exp.X_add_number += 1;
c19d1205 10774}
b99bd4ef 10775
c19d1205
ZW
10776/* Arithmetic instructions for which there is just one 16-bit
10777 instruction encoding, and it allows only two low registers.
10778 For maximal compatibility with ARM syntax, we allow three register
10779 operands even when Thumb-32 instructions are not available, as long
10780 as the first two are identical. For instance, both "sbc r0,r1" and
10781 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10782static void
c19d1205 10783do_t_arit3 (void)
b99bd4ef 10784{
c19d1205 10785 int Rd, Rs, Rn;
b99bd4ef 10786
c19d1205
ZW
10787 Rd = inst.operands[0].reg;
10788 Rs = (inst.operands[1].present
10789 ? inst.operands[1].reg /* Rd, Rs, foo */
10790 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10791 Rn = inst.operands[2].reg;
b99bd4ef 10792
fdfde340
JM
10793 reject_bad_reg (Rd);
10794 reject_bad_reg (Rs);
10795 if (inst.operands[2].isreg)
10796 reject_bad_reg (Rn);
10797
c19d1205 10798 if (unified_syntax)
b99bd4ef 10799 {
c19d1205
ZW
10800 if (!inst.operands[2].isreg)
10801 {
10802 /* For an immediate, we always generate a 32-bit opcode;
10803 section relaxation will shrink it later if possible. */
10804 inst.instruction = THUMB_OP32 (inst.instruction);
10805 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10806 inst.instruction |= Rd << 8;
10807 inst.instruction |= Rs << 16;
10808 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10809 }
10810 else
10811 {
e27ec89e
PB
10812 bfd_boolean narrow;
10813
c19d1205 10814 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10815 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10816 narrow = !in_it_block ();
e27ec89e 10817 else
e07e6e58 10818 narrow = in_it_block ();
e27ec89e
PB
10819
10820 if (Rd > 7 || Rn > 7 || Rs > 7)
10821 narrow = FALSE;
10822 if (inst.operands[2].shifted)
10823 narrow = FALSE;
10824 if (inst.size_req == 4)
10825 narrow = FALSE;
10826
10827 if (narrow
c19d1205
ZW
10828 && Rd == Rs)
10829 {
10830 inst.instruction = THUMB_OP16 (inst.instruction);
10831 inst.instruction |= Rd;
10832 inst.instruction |= Rn << 3;
10833 return;
10834 }
b99bd4ef 10835
c19d1205
ZW
10836 /* If we get here, it can't be done in 16 bits. */
10837 constraint (inst.operands[2].shifted
10838 && inst.operands[2].immisreg,
10839 _("shift must be constant"));
10840 inst.instruction = THUMB_OP32 (inst.instruction);
10841 inst.instruction |= Rd << 8;
10842 inst.instruction |= Rs << 16;
10843 encode_thumb32_shifted_operand (2);
10844 }
a737bd4d 10845 }
c19d1205 10846 else
b99bd4ef 10847 {
c19d1205
ZW
10848 /* On its face this is a lie - the instruction does set the
10849 flags. However, the only supported mnemonic in this mode
10850 says it doesn't. */
10851 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10852
c19d1205
ZW
10853 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10854 _("unshifted register required"));
10855 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10856 constraint (Rd != Rs,
10857 _("dest and source1 must be the same register"));
a737bd4d 10858
c19d1205
ZW
10859 inst.instruction = THUMB_OP16 (inst.instruction);
10860 inst.instruction |= Rd;
10861 inst.instruction |= Rn << 3;
b99bd4ef 10862 }
a737bd4d 10863}
b99bd4ef 10864
c19d1205
ZW
10865/* Similarly, but for instructions where the arithmetic operation is
10866 commutative, so we can allow either of them to be different from
10867 the destination operand in a 16-bit instruction. For instance, all
10868 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10869 accepted. */
10870static void
10871do_t_arit3c (void)
a737bd4d 10872{
c19d1205 10873 int Rd, Rs, Rn;
b99bd4ef 10874
c19d1205
ZW
10875 Rd = inst.operands[0].reg;
10876 Rs = (inst.operands[1].present
10877 ? inst.operands[1].reg /* Rd, Rs, foo */
10878 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10879 Rn = inst.operands[2].reg;
c921be7d 10880
fdfde340
JM
10881 reject_bad_reg (Rd);
10882 reject_bad_reg (Rs);
10883 if (inst.operands[2].isreg)
10884 reject_bad_reg (Rn);
a737bd4d 10885
c19d1205 10886 if (unified_syntax)
a737bd4d 10887 {
c19d1205 10888 if (!inst.operands[2].isreg)
b99bd4ef 10889 {
c19d1205
ZW
10890 /* For an immediate, we always generate a 32-bit opcode;
10891 section relaxation will shrink it later if possible. */
10892 inst.instruction = THUMB_OP32 (inst.instruction);
10893 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10894 inst.instruction |= Rd << 8;
10895 inst.instruction |= Rs << 16;
10896 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10897 }
c19d1205 10898 else
a737bd4d 10899 {
e27ec89e
PB
10900 bfd_boolean narrow;
10901
c19d1205 10902 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10903 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10904 narrow = !in_it_block ();
e27ec89e 10905 else
e07e6e58 10906 narrow = in_it_block ();
e27ec89e
PB
10907
10908 if (Rd > 7 || Rn > 7 || Rs > 7)
10909 narrow = FALSE;
10910 if (inst.operands[2].shifted)
10911 narrow = FALSE;
10912 if (inst.size_req == 4)
10913 narrow = FALSE;
10914
10915 if (narrow)
a737bd4d 10916 {
c19d1205 10917 if (Rd == Rs)
a737bd4d 10918 {
c19d1205
ZW
10919 inst.instruction = THUMB_OP16 (inst.instruction);
10920 inst.instruction |= Rd;
10921 inst.instruction |= Rn << 3;
10922 return;
a737bd4d 10923 }
c19d1205 10924 if (Rd == Rn)
a737bd4d 10925 {
c19d1205
ZW
10926 inst.instruction = THUMB_OP16 (inst.instruction);
10927 inst.instruction |= Rd;
10928 inst.instruction |= Rs << 3;
10929 return;
a737bd4d
NC
10930 }
10931 }
c19d1205
ZW
10932
10933 /* If we get here, it can't be done in 16 bits. */
10934 constraint (inst.operands[2].shifted
10935 && inst.operands[2].immisreg,
10936 _("shift must be constant"));
10937 inst.instruction = THUMB_OP32 (inst.instruction);
10938 inst.instruction |= Rd << 8;
10939 inst.instruction |= Rs << 16;
10940 encode_thumb32_shifted_operand (2);
a737bd4d 10941 }
b99bd4ef 10942 }
c19d1205
ZW
10943 else
10944 {
10945 /* On its face this is a lie - the instruction does set the
10946 flags. However, the only supported mnemonic in this mode
10947 says it doesn't. */
10948 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10949
c19d1205
ZW
10950 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10951 _("unshifted register required"));
10952 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10953
10954 inst.instruction = THUMB_OP16 (inst.instruction);
10955 inst.instruction |= Rd;
10956
10957 if (Rd == Rs)
10958 inst.instruction |= Rn << 3;
10959 else if (Rd == Rn)
10960 inst.instruction |= Rs << 3;
10961 else
10962 constraint (1, _("dest must overlap one source register"));
10963 }
a737bd4d
NC
10964}
10965
c19d1205
ZW
10966static void
10967do_t_bfc (void)
a737bd4d 10968{
fdfde340 10969 unsigned Rd;
c19d1205
ZW
10970 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10971 constraint (msb > 32, _("bit-field extends past end of register"));
10972 /* The instruction encoding stores the LSB and MSB,
10973 not the LSB and width. */
fdfde340
JM
10974 Rd = inst.operands[0].reg;
10975 reject_bad_reg (Rd);
10976 inst.instruction |= Rd << 8;
c19d1205
ZW
10977 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10978 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10979 inst.instruction |= msb - 1;
b99bd4ef
NC
10980}
10981
c19d1205
ZW
10982static void
10983do_t_bfi (void)
b99bd4ef 10984{
fdfde340 10985 int Rd, Rn;
c19d1205 10986 unsigned int msb;
b99bd4ef 10987
fdfde340
JM
10988 Rd = inst.operands[0].reg;
10989 reject_bad_reg (Rd);
10990
c19d1205
ZW
10991 /* #0 in second position is alternative syntax for bfc, which is
10992 the same instruction but with REG_PC in the Rm field. */
10993 if (!inst.operands[1].isreg)
fdfde340
JM
10994 Rn = REG_PC;
10995 else
10996 {
10997 Rn = inst.operands[1].reg;
10998 reject_bad_reg (Rn);
10999 }
b99bd4ef 11000
c19d1205
ZW
11001 msb = inst.operands[2].imm + inst.operands[3].imm;
11002 constraint (msb > 32, _("bit-field extends past end of register"));
11003 /* The instruction encoding stores the LSB and MSB,
11004 not the LSB and width. */
fdfde340
JM
11005 inst.instruction |= Rd << 8;
11006 inst.instruction |= Rn << 16;
c19d1205
ZW
11007 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11008 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11009 inst.instruction |= msb - 1;
b99bd4ef
NC
11010}
11011
c19d1205
ZW
11012static void
11013do_t_bfx (void)
b99bd4ef 11014{
fdfde340
JM
11015 unsigned Rd, Rn;
11016
11017 Rd = inst.operands[0].reg;
11018 Rn = inst.operands[1].reg;
11019
11020 reject_bad_reg (Rd);
11021 reject_bad_reg (Rn);
11022
c19d1205
ZW
11023 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
11024 _("bit-field extends past end of register"));
fdfde340
JM
11025 inst.instruction |= Rd << 8;
11026 inst.instruction |= Rn << 16;
c19d1205
ZW
11027 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11028 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11029 inst.instruction |= inst.operands[3].imm - 1;
11030}
b99bd4ef 11031
c19d1205
ZW
11032/* ARM V5 Thumb BLX (argument parse)
11033 BLX <target_addr> which is BLX(1)
11034 BLX <Rm> which is BLX(2)
11035 Unfortunately, there are two different opcodes for this mnemonic.
11036 So, the insns[].value is not used, and the code here zaps values
11037 into inst.instruction.
b99bd4ef 11038
c19d1205
ZW
11039 ??? How to take advantage of the additional two bits of displacement
11040 available in Thumb32 mode? Need new relocation? */
b99bd4ef 11041
c19d1205
ZW
11042static void
11043do_t_blx (void)
11044{
e07e6e58
NC
11045 set_it_insn_type_last ();
11046
c19d1205 11047 if (inst.operands[0].isreg)
fdfde340
JM
11048 {
11049 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11050 /* We have a register, so this is BLX(2). */
11051 inst.instruction |= inst.operands[0].reg << 3;
11052 }
b99bd4ef
NC
11053 else
11054 {
c19d1205 11055 /* No register. This must be BLX(1). */
2fc8bdac 11056 inst.instruction = 0xf000e800;
0855e32b 11057 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
11058 }
11059}
11060
c19d1205
ZW
11061static void
11062do_t_branch (void)
b99bd4ef 11063{
0110f2b8 11064 int opcode;
dfa9f0d5 11065 int cond;
2fe88214 11066 bfd_reloc_code_real_type reloc;
dfa9f0d5 11067
e07e6e58
NC
11068 cond = inst.cond;
11069 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
11070
11071 if (in_it_block ())
dfa9f0d5
PB
11072 {
11073 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 11074 branches. */
dfa9f0d5 11075 cond = COND_ALWAYS;
dfa9f0d5
PB
11076 }
11077 else
11078 cond = inst.cond;
11079
11080 if (cond != COND_ALWAYS)
0110f2b8
PB
11081 opcode = T_MNEM_bcond;
11082 else
11083 opcode = inst.instruction;
11084
12d6b0b7
RS
11085 if (unified_syntax
11086 && (inst.size_req == 4
10960bfb
PB
11087 || (inst.size_req != 2
11088 && (inst.operands[0].hasreloc
11089 || inst.reloc.exp.X_op == O_constant))))
c19d1205 11090 {
0110f2b8 11091 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 11092 if (cond == COND_ALWAYS)
9ae92b05 11093 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
11094 else
11095 {
ff8646ee
TP
11096 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11097 _("selected architecture does not support "
11098 "wide conditional branch instruction"));
11099
9c2799c2 11100 gas_assert (cond != 0xF);
dfa9f0d5 11101 inst.instruction |= cond << 22;
9ae92b05 11102 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
11103 }
11104 }
b99bd4ef
NC
11105 else
11106 {
0110f2b8 11107 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 11108 if (cond == COND_ALWAYS)
9ae92b05 11109 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 11110 else
b99bd4ef 11111 {
dfa9f0d5 11112 inst.instruction |= cond << 8;
9ae92b05 11113 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 11114 }
0110f2b8
PB
11115 /* Allow section relaxation. */
11116 if (unified_syntax && inst.size_req != 2)
11117 inst.relax = opcode;
b99bd4ef 11118 }
9ae92b05 11119 inst.reloc.type = reloc;
c19d1205 11120 inst.reloc.pc_rel = 1;
b99bd4ef
NC
11121}
11122
8884b720 11123/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11124 between the two is the maximum immediate allowed - which is passed in
8884b720 11125 RANGE. */
b99bd4ef 11126static void
8884b720 11127do_t_bkpt_hlt1 (int range)
b99bd4ef 11128{
dfa9f0d5
PB
11129 constraint (inst.cond != COND_ALWAYS,
11130 _("instruction is always unconditional"));
c19d1205 11131 if (inst.operands[0].present)
b99bd4ef 11132 {
8884b720 11133 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11134 _("immediate value out of range"));
11135 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11136 }
8884b720
MGD
11137
11138 set_it_insn_type (NEUTRAL_IT_INSN);
11139}
11140
11141static void
11142do_t_hlt (void)
11143{
11144 do_t_bkpt_hlt1 (63);
11145}
11146
11147static void
11148do_t_bkpt (void)
11149{
11150 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11151}
11152
11153static void
c19d1205 11154do_t_branch23 (void)
b99bd4ef 11155{
e07e6e58 11156 set_it_insn_type_last ();
0855e32b 11157 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11158
0855e32b
NS
11159 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11160 this file. We used to simply ignore the PLT reloc type here --
11161 the branch encoding is now needed to deal with TLSCALL relocs.
11162 So if we see a PLT reloc now, put it back to how it used to be to
11163 keep the preexisting behaviour. */
11164 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
11165 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11166
4343666d 11167#if defined(OBJ_COFF)
c19d1205
ZW
11168 /* If the destination of the branch is a defined symbol which does not have
11169 the THUMB_FUNC attribute, then we must be calling a function which has
11170 the (interfacearm) attribute. We look for the Thumb entry point to that
11171 function and change the branch to refer to that function instead. */
11172 if ( inst.reloc.exp.X_op == O_symbol
11173 && inst.reloc.exp.X_add_symbol != NULL
11174 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
11175 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
11176 inst.reloc.exp.X_add_symbol =
11177 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 11178#endif
90e4755a
RE
11179}
11180
11181static void
c19d1205 11182do_t_bx (void)
90e4755a 11183{
e07e6e58 11184 set_it_insn_type_last ();
c19d1205
ZW
11185 inst.instruction |= inst.operands[0].reg << 3;
11186 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11187 should cause the alignment to be checked once it is known. This is
11188 because BX PC only works if the instruction is word aligned. */
11189}
90e4755a 11190
c19d1205
ZW
11191static void
11192do_t_bxj (void)
11193{
fdfde340 11194 int Rm;
90e4755a 11195
e07e6e58 11196 set_it_insn_type_last ();
fdfde340
JM
11197 Rm = inst.operands[0].reg;
11198 reject_bad_reg (Rm);
11199 inst.instruction |= Rm << 16;
90e4755a
RE
11200}
11201
11202static void
c19d1205 11203do_t_clz (void)
90e4755a 11204{
fdfde340
JM
11205 unsigned Rd;
11206 unsigned Rm;
11207
11208 Rd = inst.operands[0].reg;
11209 Rm = inst.operands[1].reg;
11210
11211 reject_bad_reg (Rd);
11212 reject_bad_reg (Rm);
11213
11214 inst.instruction |= Rd << 8;
11215 inst.instruction |= Rm << 16;
11216 inst.instruction |= Rm;
c19d1205 11217}
90e4755a 11218
dfa9f0d5
PB
11219static void
11220do_t_cps (void)
11221{
e07e6e58 11222 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11223 inst.instruction |= inst.operands[0].imm;
11224}
11225
c19d1205
ZW
11226static void
11227do_t_cpsi (void)
11228{
e07e6e58 11229 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11230 if (unified_syntax
62b3e311
PB
11231 && (inst.operands[1].present || inst.size_req == 4)
11232 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11233 {
c19d1205
ZW
11234 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11235 inst.instruction = 0xf3af8000;
11236 inst.instruction |= imod << 9;
11237 inst.instruction |= inst.operands[0].imm << 5;
11238 if (inst.operands[1].present)
11239 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11240 }
c19d1205 11241 else
90e4755a 11242 {
62b3e311
PB
11243 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11244 && (inst.operands[0].imm & 4),
11245 _("selected processor does not support 'A' form "
11246 "of this instruction"));
11247 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11248 _("Thumb does not support the 2-argument "
11249 "form of this instruction"));
11250 inst.instruction |= inst.operands[0].imm;
90e4755a 11251 }
90e4755a
RE
11252}
11253
c19d1205
ZW
11254/* THUMB CPY instruction (argument parse). */
11255
90e4755a 11256static void
c19d1205 11257do_t_cpy (void)
90e4755a 11258{
c19d1205 11259 if (inst.size_req == 4)
90e4755a 11260 {
c19d1205
ZW
11261 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11262 inst.instruction |= inst.operands[0].reg << 8;
11263 inst.instruction |= inst.operands[1].reg;
90e4755a 11264 }
c19d1205 11265 else
90e4755a 11266 {
c19d1205
ZW
11267 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11268 inst.instruction |= (inst.operands[0].reg & 0x7);
11269 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11270 }
90e4755a
RE
11271}
11272
90e4755a 11273static void
25fe350b 11274do_t_cbz (void)
90e4755a 11275{
e07e6e58 11276 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11277 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11278 inst.instruction |= inst.operands[0].reg;
11279 inst.reloc.pc_rel = 1;
11280 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11281}
90e4755a 11282
62b3e311
PB
11283static void
11284do_t_dbg (void)
11285{
11286 inst.instruction |= inst.operands[0].imm;
11287}
11288
11289static void
11290do_t_div (void)
11291{
fdfde340
JM
11292 unsigned Rd, Rn, Rm;
11293
11294 Rd = inst.operands[0].reg;
11295 Rn = (inst.operands[1].present
11296 ? inst.operands[1].reg : Rd);
11297 Rm = inst.operands[2].reg;
11298
11299 reject_bad_reg (Rd);
11300 reject_bad_reg (Rn);
11301 reject_bad_reg (Rm);
11302
11303 inst.instruction |= Rd << 8;
11304 inst.instruction |= Rn << 16;
11305 inst.instruction |= Rm;
62b3e311
PB
11306}
11307
c19d1205
ZW
11308static void
11309do_t_hint (void)
11310{
11311 if (unified_syntax && inst.size_req == 4)
11312 inst.instruction = THUMB_OP32 (inst.instruction);
11313 else
11314 inst.instruction = THUMB_OP16 (inst.instruction);
11315}
90e4755a 11316
c19d1205
ZW
11317static void
11318do_t_it (void)
11319{
11320 unsigned int cond = inst.operands[0].imm;
e27ec89e 11321
e07e6e58
NC
11322 set_it_insn_type (IT_INSN);
11323 now_it.mask = (inst.instruction & 0xf) | 0x10;
11324 now_it.cc = cond;
5a01bb1d 11325 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11326
11327 /* If the condition is a negative condition, invert the mask. */
c19d1205 11328 if ((cond & 0x1) == 0x0)
90e4755a 11329 {
c19d1205 11330 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11331
c19d1205 11332 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11333 {
11334 /* No conversion needed. */
11335 now_it.block_length = 1;
11336 }
c19d1205 11337 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11338 {
11339 mask ^= 0x8;
11340 now_it.block_length = 2;
11341 }
e27ec89e 11342 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11343 {
11344 mask ^= 0xC;
11345 now_it.block_length = 3;
11346 }
c19d1205 11347 else
5a01bb1d
MGD
11348 {
11349 mask ^= 0xE;
11350 now_it.block_length = 4;
11351 }
90e4755a 11352
e27ec89e
PB
11353 inst.instruction &= 0xfff0;
11354 inst.instruction |= mask;
c19d1205 11355 }
90e4755a 11356
c19d1205
ZW
11357 inst.instruction |= cond << 4;
11358}
90e4755a 11359
3c707909
PB
11360/* Helper function used for both push/pop and ldm/stm. */
11361static void
11362encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11363{
11364 bfd_boolean load;
11365
11366 load = (inst.instruction & (1 << 20)) != 0;
11367
11368 if (mask & (1 << 13))
11369 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11370
11371 if ((mask & (1 << base)) != 0
11372 && writeback)
11373 inst.error = _("having the base register in the register list when "
11374 "using write back is UNPREDICTABLE");
11375
3c707909
PB
11376 if (load)
11377 {
e07e6e58 11378 if (mask & (1 << 15))
477330fc
RM
11379 {
11380 if (mask & (1 << 14))
11381 inst.error = _("LR and PC should not both be in register list");
11382 else
11383 set_it_insn_type_last ();
11384 }
3c707909
PB
11385 }
11386 else
11387 {
11388 if (mask & (1 << 15))
11389 inst.error = _("PC not allowed in register list");
3c707909
PB
11390 }
11391
11392 if ((mask & (mask - 1)) == 0)
11393 {
11394 /* Single register transfers implemented as str/ldr. */
11395 if (writeback)
11396 {
11397 if (inst.instruction & (1 << 23))
11398 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11399 else
11400 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11401 }
11402 else
11403 {
11404 if (inst.instruction & (1 << 23))
11405 inst.instruction = 0x00800000; /* ia -> [base] */
11406 else
11407 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11408 }
11409
11410 inst.instruction |= 0xf8400000;
11411 if (load)
11412 inst.instruction |= 0x00100000;
11413
5f4273c7 11414 mask = ffs (mask) - 1;
3c707909
PB
11415 mask <<= 12;
11416 }
11417 else if (writeback)
11418 inst.instruction |= WRITE_BACK;
11419
11420 inst.instruction |= mask;
11421 inst.instruction |= base << 16;
11422}
11423
c19d1205
ZW
11424static void
11425do_t_ldmstm (void)
11426{
11427 /* This really doesn't seem worth it. */
11428 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11429 _("expression too complex"));
11430 constraint (inst.operands[1].writeback,
11431 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11432
c19d1205
ZW
11433 if (unified_syntax)
11434 {
3c707909
PB
11435 bfd_boolean narrow;
11436 unsigned mask;
11437
11438 narrow = FALSE;
c19d1205
ZW
11439 /* See if we can use a 16-bit instruction. */
11440 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11441 && inst.size_req != 4
3c707909 11442 && !(inst.operands[1].imm & ~0xff))
90e4755a 11443 {
3c707909 11444 mask = 1 << inst.operands[0].reg;
90e4755a 11445
eab4f823 11446 if (inst.operands[0].reg <= 7)
90e4755a 11447 {
3c707909 11448 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11449 ? inst.operands[0].writeback
11450 : (inst.operands[0].writeback
11451 == !(inst.operands[1].imm & mask)))
477330fc 11452 {
eab4f823
MGD
11453 if (inst.instruction == T_MNEM_stmia
11454 && (inst.operands[1].imm & mask)
11455 && (inst.operands[1].imm & (mask - 1)))
11456 as_warn (_("value stored for r%d is UNKNOWN"),
11457 inst.operands[0].reg);
3c707909 11458
eab4f823
MGD
11459 inst.instruction = THUMB_OP16 (inst.instruction);
11460 inst.instruction |= inst.operands[0].reg << 8;
11461 inst.instruction |= inst.operands[1].imm;
11462 narrow = TRUE;
11463 }
11464 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11465 {
11466 /* This means 1 register in reg list one of 3 situations:
11467 1. Instruction is stmia, but without writeback.
11468 2. lmdia without writeback, but with Rn not in
477330fc 11469 reglist.
eab4f823
MGD
11470 3. ldmia with writeback, but with Rn in reglist.
11471 Case 3 is UNPREDICTABLE behaviour, so we handle
11472 case 1 and 2 which can be converted into a 16-bit
11473 str or ldr. The SP cases are handled below. */
11474 unsigned long opcode;
11475 /* First, record an error for Case 3. */
11476 if (inst.operands[1].imm & mask
11477 && inst.operands[0].writeback)
fa94de6b 11478 inst.error =
eab4f823
MGD
11479 _("having the base register in the register list when "
11480 "using write back is UNPREDICTABLE");
fa94de6b
RM
11481
11482 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11483 : T_MNEM_ldr);
11484 inst.instruction = THUMB_OP16 (opcode);
11485 inst.instruction |= inst.operands[0].reg << 3;
11486 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11487 narrow = TRUE;
11488 }
90e4755a 11489 }
eab4f823 11490 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11491 {
eab4f823
MGD
11492 if (inst.operands[0].writeback)
11493 {
fa94de6b 11494 inst.instruction =
eab4f823 11495 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11496 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11497 inst.instruction |= inst.operands[1].imm;
477330fc 11498 narrow = TRUE;
eab4f823
MGD
11499 }
11500 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11501 {
fa94de6b 11502 inst.instruction =
eab4f823 11503 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11504 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11505 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11506 narrow = TRUE;
eab4f823 11507 }
90e4755a 11508 }
3c707909
PB
11509 }
11510
11511 if (!narrow)
11512 {
c19d1205
ZW
11513 if (inst.instruction < 0xffff)
11514 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11515
5f4273c7
NC
11516 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11517 inst.operands[0].writeback);
90e4755a
RE
11518 }
11519 }
c19d1205 11520 else
90e4755a 11521 {
c19d1205
ZW
11522 constraint (inst.operands[0].reg > 7
11523 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11524 constraint (inst.instruction != T_MNEM_ldmia
11525 && inst.instruction != T_MNEM_stmia,
11526 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11527 if (inst.instruction == T_MNEM_stmia)
f03698e6 11528 {
c19d1205
ZW
11529 if (!inst.operands[0].writeback)
11530 as_warn (_("this instruction will write back the base register"));
11531 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11532 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11533 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11534 inst.operands[0].reg);
f03698e6 11535 }
c19d1205 11536 else
90e4755a 11537 {
c19d1205
ZW
11538 if (!inst.operands[0].writeback
11539 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11540 as_warn (_("this instruction will write back the base register"));
11541 else if (inst.operands[0].writeback
11542 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11543 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11544 }
11545
c19d1205
ZW
11546 inst.instruction = THUMB_OP16 (inst.instruction);
11547 inst.instruction |= inst.operands[0].reg << 8;
11548 inst.instruction |= inst.operands[1].imm;
11549 }
11550}
e28cd48c 11551
c19d1205
ZW
11552static void
11553do_t_ldrex (void)
11554{
11555 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11556 || inst.operands[1].postind || inst.operands[1].writeback
11557 || inst.operands[1].immisreg || inst.operands[1].shifted
11558 || inst.operands[1].negative,
01cfc07f 11559 BAD_ADDR_MODE);
e28cd48c 11560
5be8be5d
DG
11561 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11562
c19d1205
ZW
11563 inst.instruction |= inst.operands[0].reg << 12;
11564 inst.instruction |= inst.operands[1].reg << 16;
11565 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11566}
e28cd48c 11567
c19d1205
ZW
11568static void
11569do_t_ldrexd (void)
11570{
11571 if (!inst.operands[1].present)
1cac9012 11572 {
c19d1205
ZW
11573 constraint (inst.operands[0].reg == REG_LR,
11574 _("r14 not allowed as first register "
11575 "when second register is omitted"));
11576 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11577 }
c19d1205
ZW
11578 constraint (inst.operands[0].reg == inst.operands[1].reg,
11579 BAD_OVERLAP);
b99bd4ef 11580
c19d1205
ZW
11581 inst.instruction |= inst.operands[0].reg << 12;
11582 inst.instruction |= inst.operands[1].reg << 8;
11583 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11584}
11585
11586static void
c19d1205 11587do_t_ldst (void)
b99bd4ef 11588{
0110f2b8
PB
11589 unsigned long opcode;
11590 int Rn;
11591
e07e6e58
NC
11592 if (inst.operands[0].isreg
11593 && !inst.operands[0].preind
11594 && inst.operands[0].reg == REG_PC)
11595 set_it_insn_type_last ();
11596
0110f2b8 11597 opcode = inst.instruction;
c19d1205 11598 if (unified_syntax)
b99bd4ef 11599 {
53365c0d
PB
11600 if (!inst.operands[1].isreg)
11601 {
11602 if (opcode <= 0xffff)
11603 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11604 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11605 return;
11606 }
0110f2b8
PB
11607 if (inst.operands[1].isreg
11608 && !inst.operands[1].writeback
c19d1205
ZW
11609 && !inst.operands[1].shifted && !inst.operands[1].postind
11610 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11611 && opcode <= 0xffff
11612 && inst.size_req != 4)
c19d1205 11613 {
0110f2b8
PB
11614 /* Insn may have a 16-bit form. */
11615 Rn = inst.operands[1].reg;
11616 if (inst.operands[1].immisreg)
11617 {
11618 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11619 /* [Rn, Rik] */
0110f2b8
PB
11620 if (Rn <= 7 && inst.operands[1].imm <= 7)
11621 goto op16;
5be8be5d
DG
11622 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11623 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11624 }
11625 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11626 && opcode != T_MNEM_ldrsb)
11627 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11628 || (Rn == REG_SP && opcode == T_MNEM_str))
11629 {
11630 /* [Rn, #const] */
11631 if (Rn > 7)
11632 {
11633 if (Rn == REG_PC)
11634 {
11635 if (inst.reloc.pc_rel)
11636 opcode = T_MNEM_ldr_pc2;
11637 else
11638 opcode = T_MNEM_ldr_pc;
11639 }
11640 else
11641 {
11642 if (opcode == T_MNEM_ldr)
11643 opcode = T_MNEM_ldr_sp;
11644 else
11645 opcode = T_MNEM_str_sp;
11646 }
11647 inst.instruction = inst.operands[0].reg << 8;
11648 }
11649 else
11650 {
11651 inst.instruction = inst.operands[0].reg;
11652 inst.instruction |= inst.operands[1].reg << 3;
11653 }
11654 inst.instruction |= THUMB_OP16 (opcode);
11655 if (inst.size_req == 2)
11656 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11657 else
11658 inst.relax = opcode;
11659 return;
11660 }
c19d1205 11661 }
0110f2b8 11662 /* Definitely a 32-bit variant. */
5be8be5d 11663
8d67f500
NC
11664 /* Warning for Erratum 752419. */
11665 if (opcode == T_MNEM_ldr
11666 && inst.operands[0].reg == REG_SP
11667 && inst.operands[1].writeback == 1
11668 && !inst.operands[1].immisreg)
11669 {
11670 if (no_cpu_selected ()
11671 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11672 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11673 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11674 as_warn (_("This instruction may be unpredictable "
11675 "if executed on M-profile cores "
11676 "with interrupts enabled."));
11677 }
11678
5be8be5d 11679 /* Do some validations regarding addressing modes. */
1be5fd2e 11680 if (inst.operands[1].immisreg)
5be8be5d
DG
11681 reject_bad_reg (inst.operands[1].imm);
11682
1be5fd2e
NC
11683 constraint (inst.operands[1].writeback == 1
11684 && inst.operands[0].reg == inst.operands[1].reg,
11685 BAD_OVERLAP);
11686
0110f2b8 11687 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11688 inst.instruction |= inst.operands[0].reg << 12;
11689 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11690 check_ldr_r15_aligned ();
b99bd4ef
NC
11691 return;
11692 }
11693
c19d1205
ZW
11694 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11695
11696 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11697 {
c19d1205
ZW
11698 /* Only [Rn,Rm] is acceptable. */
11699 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11700 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11701 || inst.operands[1].postind || inst.operands[1].shifted
11702 || inst.operands[1].negative,
11703 _("Thumb does not support this addressing mode"));
11704 inst.instruction = THUMB_OP16 (inst.instruction);
11705 goto op16;
b99bd4ef 11706 }
5f4273c7 11707
c19d1205
ZW
11708 inst.instruction = THUMB_OP16 (inst.instruction);
11709 if (!inst.operands[1].isreg)
8335d6aa 11710 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11711 return;
b99bd4ef 11712
c19d1205
ZW
11713 constraint (!inst.operands[1].preind
11714 || inst.operands[1].shifted
11715 || inst.operands[1].writeback,
11716 _("Thumb does not support this addressing mode"));
11717 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11718 {
c19d1205
ZW
11719 constraint (inst.instruction & 0x0600,
11720 _("byte or halfword not valid for base register"));
11721 constraint (inst.operands[1].reg == REG_PC
11722 && !(inst.instruction & THUMB_LOAD_BIT),
11723 _("r15 based store not allowed"));
11724 constraint (inst.operands[1].immisreg,
11725 _("invalid base register for register offset"));
b99bd4ef 11726
c19d1205
ZW
11727 if (inst.operands[1].reg == REG_PC)
11728 inst.instruction = T_OPCODE_LDR_PC;
11729 else if (inst.instruction & THUMB_LOAD_BIT)
11730 inst.instruction = T_OPCODE_LDR_SP;
11731 else
11732 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11733
c19d1205
ZW
11734 inst.instruction |= inst.operands[0].reg << 8;
11735 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11736 return;
11737 }
90e4755a 11738
c19d1205
ZW
11739 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11740 if (!inst.operands[1].immisreg)
11741 {
11742 /* Immediate offset. */
11743 inst.instruction |= inst.operands[0].reg;
11744 inst.instruction |= inst.operands[1].reg << 3;
11745 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11746 return;
11747 }
90e4755a 11748
c19d1205
ZW
11749 /* Register offset. */
11750 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11751 constraint (inst.operands[1].negative,
11752 _("Thumb does not support this addressing mode"));
90e4755a 11753
c19d1205
ZW
11754 op16:
11755 switch (inst.instruction)
11756 {
11757 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11758 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11759 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11760 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11761 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11762 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11763 case 0x5600 /* ldrsb */:
11764 case 0x5e00 /* ldrsh */: break;
11765 default: abort ();
11766 }
90e4755a 11767
c19d1205
ZW
11768 inst.instruction |= inst.operands[0].reg;
11769 inst.instruction |= inst.operands[1].reg << 3;
11770 inst.instruction |= inst.operands[1].imm << 6;
11771}
90e4755a 11772
c19d1205
ZW
11773static void
11774do_t_ldstd (void)
11775{
11776 if (!inst.operands[1].present)
b99bd4ef 11777 {
c19d1205
ZW
11778 inst.operands[1].reg = inst.operands[0].reg + 1;
11779 constraint (inst.operands[0].reg == REG_LR,
11780 _("r14 not allowed here"));
bd340a04 11781 constraint (inst.operands[0].reg == REG_R12,
477330fc 11782 _("r12 not allowed here"));
b99bd4ef 11783 }
bd340a04
MGD
11784
11785 if (inst.operands[2].writeback
11786 && (inst.operands[0].reg == inst.operands[2].reg
11787 || inst.operands[1].reg == inst.operands[2].reg))
11788 as_warn (_("base register written back, and overlaps "
477330fc 11789 "one of transfer registers"));
bd340a04 11790
c19d1205
ZW
11791 inst.instruction |= inst.operands[0].reg << 12;
11792 inst.instruction |= inst.operands[1].reg << 8;
11793 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11794}
11795
c19d1205
ZW
11796static void
11797do_t_ldstt (void)
11798{
11799 inst.instruction |= inst.operands[0].reg << 12;
11800 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11801}
a737bd4d 11802
b99bd4ef 11803static void
c19d1205 11804do_t_mla (void)
b99bd4ef 11805{
fdfde340 11806 unsigned Rd, Rn, Rm, Ra;
c921be7d 11807
fdfde340
JM
11808 Rd = inst.operands[0].reg;
11809 Rn = inst.operands[1].reg;
11810 Rm = inst.operands[2].reg;
11811 Ra = inst.operands[3].reg;
11812
11813 reject_bad_reg (Rd);
11814 reject_bad_reg (Rn);
11815 reject_bad_reg (Rm);
11816 reject_bad_reg (Ra);
11817
11818 inst.instruction |= Rd << 8;
11819 inst.instruction |= Rn << 16;
11820 inst.instruction |= Rm;
11821 inst.instruction |= Ra << 12;
c19d1205 11822}
b99bd4ef 11823
c19d1205
ZW
11824static void
11825do_t_mlal (void)
11826{
fdfde340
JM
11827 unsigned RdLo, RdHi, Rn, Rm;
11828
11829 RdLo = inst.operands[0].reg;
11830 RdHi = inst.operands[1].reg;
11831 Rn = inst.operands[2].reg;
11832 Rm = inst.operands[3].reg;
11833
11834 reject_bad_reg (RdLo);
11835 reject_bad_reg (RdHi);
11836 reject_bad_reg (Rn);
11837 reject_bad_reg (Rm);
11838
11839 inst.instruction |= RdLo << 12;
11840 inst.instruction |= RdHi << 8;
11841 inst.instruction |= Rn << 16;
11842 inst.instruction |= Rm;
c19d1205 11843}
b99bd4ef 11844
c19d1205
ZW
11845static void
11846do_t_mov_cmp (void)
11847{
fdfde340
JM
11848 unsigned Rn, Rm;
11849
11850 Rn = inst.operands[0].reg;
11851 Rm = inst.operands[1].reg;
11852
e07e6e58
NC
11853 if (Rn == REG_PC)
11854 set_it_insn_type_last ();
11855
c19d1205 11856 if (unified_syntax)
b99bd4ef 11857 {
c19d1205
ZW
11858 int r0off = (inst.instruction == T_MNEM_mov
11859 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11860 unsigned long opcode;
3d388997
PB
11861 bfd_boolean narrow;
11862 bfd_boolean low_regs;
11863
fdfde340 11864 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11865 opcode = inst.instruction;
e07e6e58 11866 if (in_it_block ())
0110f2b8 11867 narrow = opcode != T_MNEM_movs;
3d388997 11868 else
0110f2b8 11869 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11870 if (inst.size_req == 4
11871 || inst.operands[1].shifted)
11872 narrow = FALSE;
11873
efd81785
PB
11874 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11875 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11876 && !inst.operands[1].shifted
fdfde340
JM
11877 && Rn == REG_PC
11878 && Rm == REG_LR)
efd81785
PB
11879 {
11880 inst.instruction = T2_SUBS_PC_LR;
11881 return;
11882 }
11883
fdfde340
JM
11884 if (opcode == T_MNEM_cmp)
11885 {
11886 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11887 if (narrow)
11888 {
11889 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11890 but valid. */
11891 warn_deprecated_sp (Rm);
11892 /* R15 was documented as a valid choice for Rm in ARMv6,
11893 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11894 tools reject R15, so we do too. */
11895 constraint (Rm == REG_PC, BAD_PC);
11896 }
11897 else
11898 reject_bad_reg (Rm);
fdfde340
JM
11899 }
11900 else if (opcode == T_MNEM_mov
11901 || opcode == T_MNEM_movs)
11902 {
11903 if (inst.operands[1].isreg)
11904 {
11905 if (opcode == T_MNEM_movs)
11906 {
11907 reject_bad_reg (Rn);
11908 reject_bad_reg (Rm);
11909 }
76fa04a4
MGD
11910 else if (narrow)
11911 {
11912 /* This is mov.n. */
11913 if ((Rn == REG_SP || Rn == REG_PC)
11914 && (Rm == REG_SP || Rm == REG_PC))
11915 {
5c3696f8 11916 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
11917 "deprecated when r%u is the destination "
11918 "register."), Rm, Rn);
11919 }
11920 }
11921 else
11922 {
11923 /* This is mov.w. */
11924 constraint (Rn == REG_PC, BAD_PC);
11925 constraint (Rm == REG_PC, BAD_PC);
5c8ed6a4
JW
11926 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11927 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
76fa04a4 11928 }
fdfde340
JM
11929 }
11930 else
11931 reject_bad_reg (Rn);
11932 }
11933
c19d1205
ZW
11934 if (!inst.operands[1].isreg)
11935 {
0110f2b8 11936 /* Immediate operand. */
e07e6e58 11937 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
11938 narrow = 0;
11939 if (low_regs && narrow)
11940 {
11941 inst.instruction = THUMB_OP16 (opcode);
fdfde340 11942 inst.instruction |= Rn << 8;
a9f02af8
MG
11943 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11944 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 11945 {
a9f02af8 11946 if (inst.size_req == 2)
72d98d16 11947 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
11948 else
11949 inst.relax = opcode;
72d98d16 11950 }
0110f2b8
PB
11951 }
11952 else
11953 {
a9f02af8
MG
11954 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11955 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
11956 THUMB1_RELOC_ONLY);
11957
0110f2b8
PB
11958 inst.instruction = THUMB_OP32 (inst.instruction);
11959 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11960 inst.instruction |= Rn << r0off;
0110f2b8
PB
11961 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11962 }
c19d1205 11963 }
728ca7c9
PB
11964 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11965 && (inst.instruction == T_MNEM_mov
11966 || inst.instruction == T_MNEM_movs))
11967 {
11968 /* Register shifts are encoded as separate shift instructions. */
11969 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11970
e07e6e58 11971 if (in_it_block ())
728ca7c9
PB
11972 narrow = !flags;
11973 else
11974 narrow = flags;
11975
11976 if (inst.size_req == 4)
11977 narrow = FALSE;
11978
11979 if (!low_regs || inst.operands[1].imm > 7)
11980 narrow = FALSE;
11981
fdfde340 11982 if (Rn != Rm)
728ca7c9
PB
11983 narrow = FALSE;
11984
11985 switch (inst.operands[1].shift_kind)
11986 {
11987 case SHIFT_LSL:
11988 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
11989 break;
11990 case SHIFT_ASR:
11991 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
11992 break;
11993 case SHIFT_LSR:
11994 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
11995 break;
11996 case SHIFT_ROR:
11997 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
11998 break;
11999 default:
5f4273c7 12000 abort ();
728ca7c9
PB
12001 }
12002
12003 inst.instruction = opcode;
12004 if (narrow)
12005 {
fdfde340 12006 inst.instruction |= Rn;
728ca7c9
PB
12007 inst.instruction |= inst.operands[1].imm << 3;
12008 }
12009 else
12010 {
12011 if (flags)
12012 inst.instruction |= CONDS_BIT;
12013
fdfde340
JM
12014 inst.instruction |= Rn << 8;
12015 inst.instruction |= Rm << 16;
728ca7c9
PB
12016 inst.instruction |= inst.operands[1].imm;
12017 }
12018 }
3d388997 12019 else if (!narrow)
c19d1205 12020 {
728ca7c9
PB
12021 /* Some mov with immediate shift have narrow variants.
12022 Register shifts are handled above. */
12023 if (low_regs && inst.operands[1].shifted
12024 && (inst.instruction == T_MNEM_mov
12025 || inst.instruction == T_MNEM_movs))
12026 {
e07e6e58 12027 if (in_it_block ())
728ca7c9
PB
12028 narrow = (inst.instruction == T_MNEM_mov);
12029 else
12030 narrow = (inst.instruction == T_MNEM_movs);
12031 }
12032
12033 if (narrow)
12034 {
12035 switch (inst.operands[1].shift_kind)
12036 {
12037 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12038 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12039 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12040 default: narrow = FALSE; break;
12041 }
12042 }
12043
12044 if (narrow)
12045 {
fdfde340
JM
12046 inst.instruction |= Rn;
12047 inst.instruction |= Rm << 3;
728ca7c9
PB
12048 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12049 }
12050 else
12051 {
12052 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12053 inst.instruction |= Rn << r0off;
728ca7c9
PB
12054 encode_thumb32_shifted_operand (1);
12055 }
c19d1205
ZW
12056 }
12057 else
12058 switch (inst.instruction)
12059 {
12060 case T_MNEM_mov:
837b3435 12061 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
12062 results. Don't allow this. */
12063 if (low_regs)
12064 {
12065 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
12066 "MOV Rd, Rs with two low registers is not "
12067 "permitted on this architecture");
fa94de6b 12068 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
12069 arm_ext_v6);
12070 }
12071
c19d1205 12072 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
12073 inst.instruction |= (Rn & 0x8) << 4;
12074 inst.instruction |= (Rn & 0x7);
12075 inst.instruction |= Rm << 3;
c19d1205 12076 break;
b99bd4ef 12077
c19d1205
ZW
12078 case T_MNEM_movs:
12079 /* We know we have low registers at this point.
941a8a52
MGD
12080 Generate LSLS Rd, Rs, #0. */
12081 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
12082 inst.instruction |= Rn;
12083 inst.instruction |= Rm << 3;
c19d1205
ZW
12084 break;
12085
12086 case T_MNEM_cmp:
3d388997 12087 if (low_regs)
c19d1205
ZW
12088 {
12089 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
12090 inst.instruction |= Rn;
12091 inst.instruction |= Rm << 3;
c19d1205
ZW
12092 }
12093 else
12094 {
12095 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
12096 inst.instruction |= (Rn & 0x8) << 4;
12097 inst.instruction |= (Rn & 0x7);
12098 inst.instruction |= Rm << 3;
c19d1205
ZW
12099 }
12100 break;
12101 }
b99bd4ef
NC
12102 return;
12103 }
12104
c19d1205 12105 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
12106
12107 /* PR 10443: Do not silently ignore shifted operands. */
12108 constraint (inst.operands[1].shifted,
12109 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12110
c19d1205 12111 if (inst.operands[1].isreg)
b99bd4ef 12112 {
fdfde340 12113 if (Rn < 8 && Rm < 8)
b99bd4ef 12114 {
c19d1205
ZW
12115 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12116 since a MOV instruction produces unpredictable results. */
12117 if (inst.instruction == T_OPCODE_MOV_I8)
12118 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 12119 else
c19d1205 12120 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 12121
fdfde340
JM
12122 inst.instruction |= Rn;
12123 inst.instruction |= Rm << 3;
b99bd4ef
NC
12124 }
12125 else
12126 {
c19d1205
ZW
12127 if (inst.instruction == T_OPCODE_MOV_I8)
12128 inst.instruction = T_OPCODE_MOV_HR;
12129 else
12130 inst.instruction = T_OPCODE_CMP_HR;
12131 do_t_cpy ();
b99bd4ef
NC
12132 }
12133 }
c19d1205 12134 else
b99bd4ef 12135 {
fdfde340 12136 constraint (Rn > 7,
c19d1205 12137 _("only lo regs allowed with immediate"));
fdfde340 12138 inst.instruction |= Rn << 8;
c19d1205
ZW
12139 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
12140 }
12141}
b99bd4ef 12142
c19d1205
ZW
12143static void
12144do_t_mov16 (void)
12145{
fdfde340 12146 unsigned Rd;
b6895b4f
PB
12147 bfd_vma imm;
12148 bfd_boolean top;
12149
12150 top = (inst.instruction & 0x00800000) != 0;
12151 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
12152 {
33eaf5de 12153 constraint (top, _(":lower16: not allowed in this instruction"));
b6895b4f
PB
12154 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
12155 }
12156 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
12157 {
33eaf5de 12158 constraint (!top, _(":upper16: not allowed in this instruction"));
b6895b4f
PB
12159 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
12160 }
12161
fdfde340
JM
12162 Rd = inst.operands[0].reg;
12163 reject_bad_reg (Rd);
12164
12165 inst.instruction |= Rd << 8;
b6895b4f
PB
12166 if (inst.reloc.type == BFD_RELOC_UNUSED)
12167 {
12168 imm = inst.reloc.exp.X_add_number;
12169 inst.instruction |= (imm & 0xf000) << 4;
12170 inst.instruction |= (imm & 0x0800) << 15;
12171 inst.instruction |= (imm & 0x0700) << 4;
12172 inst.instruction |= (imm & 0x00ff);
12173 }
c19d1205 12174}
b99bd4ef 12175
c19d1205
ZW
12176static void
12177do_t_mvn_tst (void)
12178{
fdfde340 12179 unsigned Rn, Rm;
c921be7d 12180
fdfde340
JM
12181 Rn = inst.operands[0].reg;
12182 Rm = inst.operands[1].reg;
12183
12184 if (inst.instruction == T_MNEM_cmp
12185 || inst.instruction == T_MNEM_cmn)
12186 constraint (Rn == REG_PC, BAD_PC);
12187 else
12188 reject_bad_reg (Rn);
12189 reject_bad_reg (Rm);
12190
c19d1205
ZW
12191 if (unified_syntax)
12192 {
12193 int r0off = (inst.instruction == T_MNEM_mvn
12194 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12195 bfd_boolean narrow;
12196
12197 if (inst.size_req == 4
12198 || inst.instruction > 0xffff
12199 || inst.operands[1].shifted
fdfde340 12200 || Rn > 7 || Rm > 7)
3d388997 12201 narrow = FALSE;
fe8b4cc3
KT
12202 else if (inst.instruction == T_MNEM_cmn
12203 || inst.instruction == T_MNEM_tst)
3d388997
PB
12204 narrow = TRUE;
12205 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12206 narrow = !in_it_block ();
3d388997 12207 else
e07e6e58 12208 narrow = in_it_block ();
3d388997 12209
c19d1205 12210 if (!inst.operands[1].isreg)
b99bd4ef 12211 {
c19d1205
ZW
12212 /* For an immediate, we always generate a 32-bit opcode;
12213 section relaxation will shrink it later if possible. */
12214 if (inst.instruction < 0xffff)
12215 inst.instruction = THUMB_OP32 (inst.instruction);
12216 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12217 inst.instruction |= Rn << r0off;
c19d1205 12218 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12219 }
c19d1205 12220 else
b99bd4ef 12221 {
c19d1205 12222 /* See if we can do this with a 16-bit instruction. */
3d388997 12223 if (narrow)
b99bd4ef 12224 {
c19d1205 12225 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12226 inst.instruction |= Rn;
12227 inst.instruction |= Rm << 3;
b99bd4ef 12228 }
c19d1205 12229 else
b99bd4ef 12230 {
c19d1205
ZW
12231 constraint (inst.operands[1].shifted
12232 && inst.operands[1].immisreg,
12233 _("shift must be constant"));
12234 if (inst.instruction < 0xffff)
12235 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12236 inst.instruction |= Rn << r0off;
c19d1205 12237 encode_thumb32_shifted_operand (1);
b99bd4ef 12238 }
b99bd4ef
NC
12239 }
12240 }
12241 else
12242 {
c19d1205
ZW
12243 constraint (inst.instruction > 0xffff
12244 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12245 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12246 _("unshifted register required"));
fdfde340 12247 constraint (Rn > 7 || Rm > 7,
c19d1205 12248 BAD_HIREG);
b99bd4ef 12249
c19d1205 12250 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12251 inst.instruction |= Rn;
12252 inst.instruction |= Rm << 3;
b99bd4ef 12253 }
b99bd4ef
NC
12254}
12255
b05fe5cf 12256static void
c19d1205 12257do_t_mrs (void)
b05fe5cf 12258{
fdfde340 12259 unsigned Rd;
037e8744
JB
12260
12261 if (do_vfp_nsyn_mrs () == SUCCESS)
12262 return;
12263
90ec0d68
MGD
12264 Rd = inst.operands[0].reg;
12265 reject_bad_reg (Rd);
12266 inst.instruction |= Rd << 8;
12267
12268 if (inst.operands[1].isreg)
62b3e311 12269 {
90ec0d68
MGD
12270 unsigned br = inst.operands[1].reg;
12271 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12272 as_bad (_("bad register for mrs"));
12273
12274 inst.instruction |= br & (0xf << 16);
12275 inst.instruction |= (br & 0x300) >> 4;
12276 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12277 }
12278 else
12279 {
90ec0d68 12280 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12281
d2cd1205 12282 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12283 {
12284 /* PR gas/12698: The constraint is only applied for m_profile.
12285 If the user has specified -march=all, we want to ignore it as
12286 we are building for any CPU type, including non-m variants. */
823d2571
TG
12287 bfd_boolean m_profile =
12288 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12289 constraint ((flags != 0) && m_profile, _("selected processor does "
12290 "not support requested special purpose register"));
12291 }
90ec0d68 12292 else
d2cd1205
JB
12293 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12294 devices). */
12295 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12296 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12297
90ec0d68
MGD
12298 inst.instruction |= (flags & SPSR_BIT) >> 2;
12299 inst.instruction |= inst.operands[1].imm & 0xff;
12300 inst.instruction |= 0xf0000;
12301 }
c19d1205 12302}
b05fe5cf 12303
c19d1205
ZW
12304static void
12305do_t_msr (void)
12306{
62b3e311 12307 int flags;
fdfde340 12308 unsigned Rn;
62b3e311 12309
037e8744
JB
12310 if (do_vfp_nsyn_msr () == SUCCESS)
12311 return;
12312
c19d1205
ZW
12313 constraint (!inst.operands[1].isreg,
12314 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12315
12316 if (inst.operands[0].isreg)
12317 flags = (int)(inst.operands[0].reg);
12318 else
12319 flags = inst.operands[0].imm;
12320
d2cd1205 12321 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12322 {
d2cd1205
JB
12323 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12324
1a43faaf 12325 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12326 If the user has specified -march=all, we want to ignore it as
12327 we are building for any CPU type, including non-m variants. */
823d2571
TG
12328 bfd_boolean m_profile =
12329 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12330 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12331 && (bits & ~(PSR_s | PSR_f)) != 0)
12332 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12333 && bits != PSR_f)) && m_profile,
12334 _("selected processor does not support requested special "
12335 "purpose register"));
62b3e311
PB
12336 }
12337 else
d2cd1205
JB
12338 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12339 "requested special purpose register"));
c921be7d 12340
fdfde340
JM
12341 Rn = inst.operands[1].reg;
12342 reject_bad_reg (Rn);
12343
62b3e311 12344 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12345 inst.instruction |= (flags & 0xf0000) >> 8;
12346 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12347 inst.instruction |= (flags & 0xff);
fdfde340 12348 inst.instruction |= Rn << 16;
c19d1205 12349}
b05fe5cf 12350
c19d1205
ZW
12351static void
12352do_t_mul (void)
12353{
17828f45 12354 bfd_boolean narrow;
fdfde340 12355 unsigned Rd, Rn, Rm;
17828f45 12356
c19d1205
ZW
12357 if (!inst.operands[2].present)
12358 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12359
fdfde340
JM
12360 Rd = inst.operands[0].reg;
12361 Rn = inst.operands[1].reg;
12362 Rm = inst.operands[2].reg;
12363
17828f45 12364 if (unified_syntax)
b05fe5cf 12365 {
17828f45 12366 if (inst.size_req == 4
fdfde340
JM
12367 || (Rd != Rn
12368 && Rd != Rm)
12369 || Rn > 7
12370 || Rm > 7)
17828f45
JM
12371 narrow = FALSE;
12372 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12373 narrow = !in_it_block ();
17828f45 12374 else
e07e6e58 12375 narrow = in_it_block ();
b05fe5cf 12376 }
c19d1205 12377 else
b05fe5cf 12378 {
17828f45 12379 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12380 constraint (Rn > 7 || Rm > 7,
c19d1205 12381 BAD_HIREG);
17828f45
JM
12382 narrow = TRUE;
12383 }
b05fe5cf 12384
17828f45
JM
12385 if (narrow)
12386 {
12387 /* 16-bit MULS/Conditional MUL. */
c19d1205 12388 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12389 inst.instruction |= Rd;
b05fe5cf 12390
fdfde340
JM
12391 if (Rd == Rn)
12392 inst.instruction |= Rm << 3;
12393 else if (Rd == Rm)
12394 inst.instruction |= Rn << 3;
c19d1205
ZW
12395 else
12396 constraint (1, _("dest must overlap one source register"));
12397 }
17828f45
JM
12398 else
12399 {
e07e6e58
NC
12400 constraint (inst.instruction != T_MNEM_mul,
12401 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12402 /* 32-bit MUL. */
12403 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12404 inst.instruction |= Rd << 8;
12405 inst.instruction |= Rn << 16;
12406 inst.instruction |= Rm << 0;
12407
12408 reject_bad_reg (Rd);
12409 reject_bad_reg (Rn);
12410 reject_bad_reg (Rm);
17828f45 12411 }
c19d1205 12412}
b05fe5cf 12413
c19d1205
ZW
12414static void
12415do_t_mull (void)
12416{
fdfde340 12417 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12418
fdfde340
JM
12419 RdLo = inst.operands[0].reg;
12420 RdHi = inst.operands[1].reg;
12421 Rn = inst.operands[2].reg;
12422 Rm = inst.operands[3].reg;
12423
12424 reject_bad_reg (RdLo);
12425 reject_bad_reg (RdHi);
12426 reject_bad_reg (Rn);
12427 reject_bad_reg (Rm);
12428
12429 inst.instruction |= RdLo << 12;
12430 inst.instruction |= RdHi << 8;
12431 inst.instruction |= Rn << 16;
12432 inst.instruction |= Rm;
12433
12434 if (RdLo == RdHi)
c19d1205
ZW
12435 as_tsktsk (_("rdhi and rdlo must be different"));
12436}
b05fe5cf 12437
c19d1205
ZW
12438static void
12439do_t_nop (void)
12440{
e07e6e58
NC
12441 set_it_insn_type (NEUTRAL_IT_INSN);
12442
c19d1205
ZW
12443 if (unified_syntax)
12444 {
12445 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12446 {
c19d1205
ZW
12447 inst.instruction = THUMB_OP32 (inst.instruction);
12448 inst.instruction |= inst.operands[0].imm;
12449 }
12450 else
12451 {
bc2d1808
NC
12452 /* PR9722: Check for Thumb2 availability before
12453 generating a thumb2 nop instruction. */
afa62d5e 12454 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12455 {
12456 inst.instruction = THUMB_OP16 (inst.instruction);
12457 inst.instruction |= inst.operands[0].imm << 4;
12458 }
12459 else
12460 inst.instruction = 0x46c0;
c19d1205
ZW
12461 }
12462 }
12463 else
12464 {
12465 constraint (inst.operands[0].present,
12466 _("Thumb does not support NOP with hints"));
12467 inst.instruction = 0x46c0;
12468 }
12469}
b05fe5cf 12470
c19d1205
ZW
12471static void
12472do_t_neg (void)
12473{
12474 if (unified_syntax)
12475 {
3d388997
PB
12476 bfd_boolean narrow;
12477
12478 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12479 narrow = !in_it_block ();
3d388997 12480 else
e07e6e58 12481 narrow = in_it_block ();
3d388997
PB
12482 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12483 narrow = FALSE;
12484 if (inst.size_req == 4)
12485 narrow = FALSE;
12486
12487 if (!narrow)
c19d1205
ZW
12488 {
12489 inst.instruction = THUMB_OP32 (inst.instruction);
12490 inst.instruction |= inst.operands[0].reg << 8;
12491 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12492 }
12493 else
12494 {
c19d1205
ZW
12495 inst.instruction = THUMB_OP16 (inst.instruction);
12496 inst.instruction |= inst.operands[0].reg;
12497 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12498 }
12499 }
12500 else
12501 {
c19d1205
ZW
12502 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12503 BAD_HIREG);
12504 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12505
12506 inst.instruction = THUMB_OP16 (inst.instruction);
12507 inst.instruction |= inst.operands[0].reg;
12508 inst.instruction |= inst.operands[1].reg << 3;
12509 }
12510}
12511
1c444d06
JM
12512static void
12513do_t_orn (void)
12514{
12515 unsigned Rd, Rn;
12516
12517 Rd = inst.operands[0].reg;
12518 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12519
fdfde340
JM
12520 reject_bad_reg (Rd);
12521 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12522 reject_bad_reg (Rn);
12523
1c444d06
JM
12524 inst.instruction |= Rd << 8;
12525 inst.instruction |= Rn << 16;
12526
12527 if (!inst.operands[2].isreg)
12528 {
12529 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12530 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12531 }
12532 else
12533 {
12534 unsigned Rm;
12535
12536 Rm = inst.operands[2].reg;
fdfde340 12537 reject_bad_reg (Rm);
1c444d06
JM
12538
12539 constraint (inst.operands[2].shifted
12540 && inst.operands[2].immisreg,
12541 _("shift must be constant"));
12542 encode_thumb32_shifted_operand (2);
12543 }
12544}
12545
c19d1205
ZW
12546static void
12547do_t_pkhbt (void)
12548{
fdfde340
JM
12549 unsigned Rd, Rn, Rm;
12550
12551 Rd = inst.operands[0].reg;
12552 Rn = inst.operands[1].reg;
12553 Rm = inst.operands[2].reg;
12554
12555 reject_bad_reg (Rd);
12556 reject_bad_reg (Rn);
12557 reject_bad_reg (Rm);
12558
12559 inst.instruction |= Rd << 8;
12560 inst.instruction |= Rn << 16;
12561 inst.instruction |= Rm;
c19d1205
ZW
12562 if (inst.operands[3].present)
12563 {
12564 unsigned int val = inst.reloc.exp.X_add_number;
12565 constraint (inst.reloc.exp.X_op != O_constant,
12566 _("expression too complex"));
12567 inst.instruction |= (val & 0x1c) << 10;
12568 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12569 }
c19d1205 12570}
b05fe5cf 12571
c19d1205
ZW
12572static void
12573do_t_pkhtb (void)
12574{
12575 if (!inst.operands[3].present)
1ef52f49
NC
12576 {
12577 unsigned Rtmp;
12578
12579 inst.instruction &= ~0x00000020;
12580
12581 /* PR 10168. Swap the Rm and Rn registers. */
12582 Rtmp = inst.operands[1].reg;
12583 inst.operands[1].reg = inst.operands[2].reg;
12584 inst.operands[2].reg = Rtmp;
12585 }
c19d1205 12586 do_t_pkhbt ();
b05fe5cf
ZW
12587}
12588
c19d1205
ZW
12589static void
12590do_t_pld (void)
12591{
fdfde340
JM
12592 if (inst.operands[0].immisreg)
12593 reject_bad_reg (inst.operands[0].imm);
12594
c19d1205
ZW
12595 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12596}
b05fe5cf 12597
c19d1205
ZW
12598static void
12599do_t_push_pop (void)
b99bd4ef 12600{
e9f89963 12601 unsigned mask;
5f4273c7 12602
c19d1205
ZW
12603 constraint (inst.operands[0].writeback,
12604 _("push/pop do not support {reglist}^"));
12605 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12606 _("expression too complex"));
b99bd4ef 12607
e9f89963 12608 mask = inst.operands[0].imm;
d3bfe16e 12609 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12610 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 12611 else if (inst.size_req != 4
c6025a80 12612 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 12613 ? REG_LR : REG_PC)))
b99bd4ef 12614 {
c19d1205
ZW
12615 inst.instruction = THUMB_OP16 (inst.instruction);
12616 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12617 inst.instruction |= mask & 0xff;
c19d1205
ZW
12618 }
12619 else if (unified_syntax)
12620 {
3c707909 12621 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12622 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12623 }
12624 else
12625 {
12626 inst.error = _("invalid register list to push/pop instruction");
12627 return;
12628 }
c19d1205 12629}
b99bd4ef 12630
c19d1205
ZW
12631static void
12632do_t_rbit (void)
12633{
fdfde340
JM
12634 unsigned Rd, Rm;
12635
12636 Rd = inst.operands[0].reg;
12637 Rm = inst.operands[1].reg;
12638
12639 reject_bad_reg (Rd);
12640 reject_bad_reg (Rm);
12641
12642 inst.instruction |= Rd << 8;
12643 inst.instruction |= Rm << 16;
12644 inst.instruction |= Rm;
c19d1205 12645}
b99bd4ef 12646
c19d1205
ZW
12647static void
12648do_t_rev (void)
12649{
fdfde340
JM
12650 unsigned Rd, Rm;
12651
12652 Rd = inst.operands[0].reg;
12653 Rm = inst.operands[1].reg;
12654
12655 reject_bad_reg (Rd);
12656 reject_bad_reg (Rm);
12657
12658 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12659 && inst.size_req != 4)
12660 {
12661 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12662 inst.instruction |= Rd;
12663 inst.instruction |= Rm << 3;
c19d1205
ZW
12664 }
12665 else if (unified_syntax)
12666 {
12667 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12668 inst.instruction |= Rd << 8;
12669 inst.instruction |= Rm << 16;
12670 inst.instruction |= Rm;
c19d1205
ZW
12671 }
12672 else
12673 inst.error = BAD_HIREG;
12674}
b99bd4ef 12675
1c444d06
JM
12676static void
12677do_t_rrx (void)
12678{
12679 unsigned Rd, Rm;
12680
12681 Rd = inst.operands[0].reg;
12682 Rm = inst.operands[1].reg;
12683
fdfde340
JM
12684 reject_bad_reg (Rd);
12685 reject_bad_reg (Rm);
c921be7d 12686
1c444d06
JM
12687 inst.instruction |= Rd << 8;
12688 inst.instruction |= Rm;
12689}
12690
c19d1205
ZW
12691static void
12692do_t_rsb (void)
12693{
fdfde340 12694 unsigned Rd, Rs;
b99bd4ef 12695
c19d1205
ZW
12696 Rd = inst.operands[0].reg;
12697 Rs = (inst.operands[1].present
12698 ? inst.operands[1].reg /* Rd, Rs, foo */
12699 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12700
fdfde340
JM
12701 reject_bad_reg (Rd);
12702 reject_bad_reg (Rs);
12703 if (inst.operands[2].isreg)
12704 reject_bad_reg (inst.operands[2].reg);
12705
c19d1205
ZW
12706 inst.instruction |= Rd << 8;
12707 inst.instruction |= Rs << 16;
12708 if (!inst.operands[2].isreg)
12709 {
026d3abb
PB
12710 bfd_boolean narrow;
12711
12712 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12713 narrow = !in_it_block ();
026d3abb 12714 else
e07e6e58 12715 narrow = in_it_block ();
026d3abb
PB
12716
12717 if (Rd > 7 || Rs > 7)
12718 narrow = FALSE;
12719
12720 if (inst.size_req == 4 || !unified_syntax)
12721 narrow = FALSE;
12722
12723 if (inst.reloc.exp.X_op != O_constant
12724 || inst.reloc.exp.X_add_number != 0)
12725 narrow = FALSE;
12726
12727 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12728 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12729 if (narrow)
12730 {
12731 inst.reloc.type = BFD_RELOC_UNUSED;
12732 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12733 inst.instruction |= Rs << 3;
12734 inst.instruction |= Rd;
12735 }
12736 else
12737 {
12738 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12739 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12740 }
c19d1205
ZW
12741 }
12742 else
12743 encode_thumb32_shifted_operand (2);
12744}
b99bd4ef 12745
c19d1205
ZW
12746static void
12747do_t_setend (void)
12748{
12e37cbc
MGD
12749 if (warn_on_deprecated
12750 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12751 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12752
e07e6e58 12753 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12754 if (inst.operands[0].imm)
12755 inst.instruction |= 0x8;
12756}
b99bd4ef 12757
c19d1205
ZW
12758static void
12759do_t_shift (void)
12760{
12761 if (!inst.operands[1].present)
12762 inst.operands[1].reg = inst.operands[0].reg;
12763
12764 if (unified_syntax)
12765 {
3d388997
PB
12766 bfd_boolean narrow;
12767 int shift_kind;
12768
12769 switch (inst.instruction)
12770 {
12771 case T_MNEM_asr:
12772 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12773 case T_MNEM_lsl:
12774 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12775 case T_MNEM_lsr:
12776 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12777 case T_MNEM_ror:
12778 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12779 default: abort ();
12780 }
12781
12782 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12783 narrow = !in_it_block ();
3d388997 12784 else
e07e6e58 12785 narrow = in_it_block ();
3d388997
PB
12786 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12787 narrow = FALSE;
12788 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12789 narrow = FALSE;
12790 if (inst.operands[2].isreg
12791 && (inst.operands[1].reg != inst.operands[0].reg
12792 || inst.operands[2].reg > 7))
12793 narrow = FALSE;
12794 if (inst.size_req == 4)
12795 narrow = FALSE;
12796
fdfde340
JM
12797 reject_bad_reg (inst.operands[0].reg);
12798 reject_bad_reg (inst.operands[1].reg);
c921be7d 12799
3d388997 12800 if (!narrow)
c19d1205
ZW
12801 {
12802 if (inst.operands[2].isreg)
b99bd4ef 12803 {
fdfde340 12804 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12805 inst.instruction = THUMB_OP32 (inst.instruction);
12806 inst.instruction |= inst.operands[0].reg << 8;
12807 inst.instruction |= inst.operands[1].reg << 16;
12808 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12809
12810 /* PR 12854: Error on extraneous shifts. */
12811 constraint (inst.operands[2].shifted,
12812 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12813 }
12814 else
12815 {
12816 inst.operands[1].shifted = 1;
3d388997 12817 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12818 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12819 ? T_MNEM_movs : T_MNEM_mov);
12820 inst.instruction |= inst.operands[0].reg << 8;
12821 encode_thumb32_shifted_operand (1);
12822 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12823 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12824 }
12825 }
12826 else
12827 {
c19d1205 12828 if (inst.operands[2].isreg)
b99bd4ef 12829 {
3d388997 12830 switch (shift_kind)
b99bd4ef 12831 {
3d388997
PB
12832 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12833 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12834 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12835 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12836 default: abort ();
b99bd4ef 12837 }
5f4273c7 12838
c19d1205
ZW
12839 inst.instruction |= inst.operands[0].reg;
12840 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12841
12842 /* PR 12854: Error on extraneous shifts. */
12843 constraint (inst.operands[2].shifted,
12844 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12845 }
12846 else
12847 {
3d388997 12848 switch (shift_kind)
b99bd4ef 12849 {
3d388997
PB
12850 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12851 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12852 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12853 default: abort ();
b99bd4ef 12854 }
c19d1205
ZW
12855 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12856 inst.instruction |= inst.operands[0].reg;
12857 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12858 }
12859 }
c19d1205
ZW
12860 }
12861 else
12862 {
12863 constraint (inst.operands[0].reg > 7
12864 || inst.operands[1].reg > 7, BAD_HIREG);
12865 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12866
c19d1205
ZW
12867 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12868 {
12869 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12870 constraint (inst.operands[0].reg != inst.operands[1].reg,
12871 _("source1 and dest must be same register"));
b99bd4ef 12872
c19d1205
ZW
12873 switch (inst.instruction)
12874 {
12875 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12876 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12877 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12878 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12879 default: abort ();
12880 }
5f4273c7 12881
c19d1205
ZW
12882 inst.instruction |= inst.operands[0].reg;
12883 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12884
12885 /* PR 12854: Error on extraneous shifts. */
12886 constraint (inst.operands[2].shifted,
12887 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12888 }
12889 else
b99bd4ef 12890 {
c19d1205
ZW
12891 switch (inst.instruction)
12892 {
12893 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12894 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12895 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12896 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12897 default: abort ();
12898 }
12899 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12900 inst.instruction |= inst.operands[0].reg;
12901 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12902 }
12903 }
b99bd4ef
NC
12904}
12905
12906static void
c19d1205 12907do_t_simd (void)
b99bd4ef 12908{
fdfde340
JM
12909 unsigned Rd, Rn, Rm;
12910
12911 Rd = inst.operands[0].reg;
12912 Rn = inst.operands[1].reg;
12913 Rm = inst.operands[2].reg;
12914
12915 reject_bad_reg (Rd);
12916 reject_bad_reg (Rn);
12917 reject_bad_reg (Rm);
12918
12919 inst.instruction |= Rd << 8;
12920 inst.instruction |= Rn << 16;
12921 inst.instruction |= Rm;
c19d1205 12922}
b99bd4ef 12923
03ee1b7f
NC
12924static void
12925do_t_simd2 (void)
12926{
12927 unsigned Rd, Rn, Rm;
12928
12929 Rd = inst.operands[0].reg;
12930 Rm = inst.operands[1].reg;
12931 Rn = inst.operands[2].reg;
12932
12933 reject_bad_reg (Rd);
12934 reject_bad_reg (Rn);
12935 reject_bad_reg (Rm);
12936
12937 inst.instruction |= Rd << 8;
12938 inst.instruction |= Rn << 16;
12939 inst.instruction |= Rm;
12940}
12941
c19d1205 12942static void
3eb17e6b 12943do_t_smc (void)
c19d1205
ZW
12944{
12945 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
12946 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12947 _("SMC is not permitted on this architecture"));
c19d1205
ZW
12948 constraint (inst.reloc.exp.X_op != O_constant,
12949 _("expression too complex"));
12950 inst.reloc.type = BFD_RELOC_UNUSED;
12951 inst.instruction |= (value & 0xf000) >> 12;
12952 inst.instruction |= (value & 0x0ff0);
12953 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
12954 /* PR gas/15623: SMC instructions must be last in an IT block. */
12955 set_it_insn_type_last ();
c19d1205 12956}
b99bd4ef 12957
90ec0d68
MGD
12958static void
12959do_t_hvc (void)
12960{
12961 unsigned int value = inst.reloc.exp.X_add_number;
12962
12963 inst.reloc.type = BFD_RELOC_UNUSED;
12964 inst.instruction |= (value & 0x0fff);
12965 inst.instruction |= (value & 0xf000) << 4;
12966}
12967
c19d1205 12968static void
3a21c15a 12969do_t_ssat_usat (int bias)
c19d1205 12970{
fdfde340
JM
12971 unsigned Rd, Rn;
12972
12973 Rd = inst.operands[0].reg;
12974 Rn = inst.operands[2].reg;
12975
12976 reject_bad_reg (Rd);
12977 reject_bad_reg (Rn);
12978
12979 inst.instruction |= Rd << 8;
3a21c15a 12980 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 12981 inst.instruction |= Rn << 16;
b99bd4ef 12982
c19d1205 12983 if (inst.operands[3].present)
b99bd4ef 12984 {
3a21c15a
NC
12985 offsetT shift_amount = inst.reloc.exp.X_add_number;
12986
12987 inst.reloc.type = BFD_RELOC_UNUSED;
12988
c19d1205
ZW
12989 constraint (inst.reloc.exp.X_op != O_constant,
12990 _("expression too complex"));
b99bd4ef 12991
3a21c15a 12992 if (shift_amount != 0)
6189168b 12993 {
3a21c15a
NC
12994 constraint (shift_amount > 31,
12995 _("shift expression is too large"));
12996
c19d1205 12997 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
12998 inst.instruction |= 0x00200000; /* sh bit. */
12999
13000 inst.instruction |= (shift_amount & 0x1c) << 10;
13001 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
13002 }
13003 }
b99bd4ef 13004}
c921be7d 13005
3a21c15a
NC
13006static void
13007do_t_ssat (void)
13008{
13009 do_t_ssat_usat (1);
13010}
b99bd4ef 13011
0dd132b6 13012static void
c19d1205 13013do_t_ssat16 (void)
0dd132b6 13014{
fdfde340
JM
13015 unsigned Rd, Rn;
13016
13017 Rd = inst.operands[0].reg;
13018 Rn = inst.operands[2].reg;
13019
13020 reject_bad_reg (Rd);
13021 reject_bad_reg (Rn);
13022
13023 inst.instruction |= Rd << 8;
c19d1205 13024 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 13025 inst.instruction |= Rn << 16;
c19d1205 13026}
0dd132b6 13027
c19d1205
ZW
13028static void
13029do_t_strex (void)
13030{
13031 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
13032 || inst.operands[2].postind || inst.operands[2].writeback
13033 || inst.operands[2].immisreg || inst.operands[2].shifted
13034 || inst.operands[2].negative,
01cfc07f 13035 BAD_ADDR_MODE);
0dd132b6 13036
5be8be5d
DG
13037 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
13038
c19d1205
ZW
13039 inst.instruction |= inst.operands[0].reg << 8;
13040 inst.instruction |= inst.operands[1].reg << 12;
13041 inst.instruction |= inst.operands[2].reg << 16;
13042 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
13043}
13044
b99bd4ef 13045static void
c19d1205 13046do_t_strexd (void)
b99bd4ef 13047{
c19d1205
ZW
13048 if (!inst.operands[2].present)
13049 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 13050
c19d1205
ZW
13051 constraint (inst.operands[0].reg == inst.operands[1].reg
13052 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 13053 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 13054 BAD_OVERLAP);
b99bd4ef 13055
c19d1205
ZW
13056 inst.instruction |= inst.operands[0].reg;
13057 inst.instruction |= inst.operands[1].reg << 12;
13058 inst.instruction |= inst.operands[2].reg << 8;
13059 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
13060}
13061
13062static void
c19d1205 13063do_t_sxtah (void)
b99bd4ef 13064{
fdfde340
JM
13065 unsigned Rd, Rn, Rm;
13066
13067 Rd = inst.operands[0].reg;
13068 Rn = inst.operands[1].reg;
13069 Rm = inst.operands[2].reg;
13070
13071 reject_bad_reg (Rd);
13072 reject_bad_reg (Rn);
13073 reject_bad_reg (Rm);
13074
13075 inst.instruction |= Rd << 8;
13076 inst.instruction |= Rn << 16;
13077 inst.instruction |= Rm;
c19d1205
ZW
13078 inst.instruction |= inst.operands[3].imm << 4;
13079}
b99bd4ef 13080
c19d1205
ZW
13081static void
13082do_t_sxth (void)
13083{
fdfde340
JM
13084 unsigned Rd, Rm;
13085
13086 Rd = inst.operands[0].reg;
13087 Rm = inst.operands[1].reg;
13088
13089 reject_bad_reg (Rd);
13090 reject_bad_reg (Rm);
c921be7d
NC
13091
13092 if (inst.instruction <= 0xffff
13093 && inst.size_req != 4
fdfde340 13094 && Rd <= 7 && Rm <= 7
c19d1205 13095 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 13096 {
c19d1205 13097 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13098 inst.instruction |= Rd;
13099 inst.instruction |= Rm << 3;
b99bd4ef 13100 }
c19d1205 13101 else if (unified_syntax)
b99bd4ef 13102 {
c19d1205
ZW
13103 if (inst.instruction <= 0xffff)
13104 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13105 inst.instruction |= Rd << 8;
13106 inst.instruction |= Rm;
c19d1205 13107 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 13108 }
c19d1205 13109 else
b99bd4ef 13110 {
c19d1205
ZW
13111 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13112 _("Thumb encoding does not support rotation"));
13113 constraint (1, BAD_HIREG);
b99bd4ef 13114 }
c19d1205 13115}
b99bd4ef 13116
c19d1205
ZW
13117static void
13118do_t_swi (void)
13119{
b2a5fbdc
MGD
13120 /* We have to do the following check manually as ARM_EXT_OS only applies
13121 to ARM_EXT_V6M. */
13122 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
13123 {
ac7f631b 13124 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
2b0f3761 13125 /* This only applies to the v6m however, not later architectures. */
ac7f631b 13126 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
13127 as_bad (_("SVC is not permitted on this architecture"));
13128 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
13129 }
13130
c19d1205
ZW
13131 inst.reloc.type = BFD_RELOC_ARM_SWI;
13132}
b99bd4ef 13133
92e90b6e
PB
13134static void
13135do_t_tb (void)
13136{
fdfde340 13137 unsigned Rn, Rm;
92e90b6e
PB
13138 int half;
13139
13140 half = (inst.instruction & 0x10) != 0;
e07e6e58 13141 set_it_insn_type_last ();
dfa9f0d5
PB
13142 constraint (inst.operands[0].immisreg,
13143 _("instruction requires register index"));
fdfde340
JM
13144
13145 Rn = inst.operands[0].reg;
13146 Rm = inst.operands[0].imm;
c921be7d 13147
5c8ed6a4
JW
13148 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13149 constraint (Rn == REG_SP, BAD_SP);
fdfde340
JM
13150 reject_bad_reg (Rm);
13151
92e90b6e
PB
13152 constraint (!half && inst.operands[0].shifted,
13153 _("instruction does not allow shifted index"));
fdfde340 13154 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
13155}
13156
74db7efb
NC
13157static void
13158do_t_udf (void)
13159{
13160 if (!inst.operands[0].present)
13161 inst.operands[0].imm = 0;
13162
13163 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13164 {
13165 constraint (inst.size_req == 2,
13166 _("immediate value out of range"));
13167 inst.instruction = THUMB_OP32 (inst.instruction);
13168 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13169 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13170 }
13171 else
13172 {
13173 inst.instruction = THUMB_OP16 (inst.instruction);
13174 inst.instruction |= inst.operands[0].imm;
13175 }
13176
13177 set_it_insn_type (NEUTRAL_IT_INSN);
13178}
13179
13180
c19d1205
ZW
13181static void
13182do_t_usat (void)
13183{
3a21c15a 13184 do_t_ssat_usat (0);
b99bd4ef
NC
13185}
13186
13187static void
c19d1205 13188do_t_usat16 (void)
b99bd4ef 13189{
fdfde340
JM
13190 unsigned Rd, Rn;
13191
13192 Rd = inst.operands[0].reg;
13193 Rn = inst.operands[2].reg;
13194
13195 reject_bad_reg (Rd);
13196 reject_bad_reg (Rn);
13197
13198 inst.instruction |= Rd << 8;
c19d1205 13199 inst.instruction |= inst.operands[1].imm;
fdfde340 13200 inst.instruction |= Rn << 16;
b99bd4ef 13201}
c19d1205 13202
5287ad62 13203/* Neon instruction encoder helpers. */
5f4273c7 13204
5287ad62 13205/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13206
5287ad62
JB
13207/* An "invalid" code for the following tables. */
13208#define N_INV -1u
13209
13210struct neon_tab_entry
b99bd4ef 13211{
5287ad62
JB
13212 unsigned integer;
13213 unsigned float_or_poly;
13214 unsigned scalar_or_imm;
13215};
5f4273c7 13216
5287ad62
JB
13217/* Map overloaded Neon opcodes to their respective encodings. */
13218#define NEON_ENC_TAB \
13219 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13220 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13221 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13222 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13223 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13224 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13225 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13226 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13227 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13228 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13229 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13230 /* Register variants of the following two instructions are encoded as
e07e6e58 13231 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13232 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13233 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13234 X(vfma, N_INV, 0x0000c10, N_INV), \
13235 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13236 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13237 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13238 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13239 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13240 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13241 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13242 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13243 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13244 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13245 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13246 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13247 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13248 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13249 X(vshl, 0x0000400, N_INV, 0x0800510), \
13250 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13251 X(vand, 0x0000110, N_INV, 0x0800030), \
13252 X(vbic, 0x0100110, N_INV, 0x0800030), \
13253 X(veor, 0x1000110, N_INV, N_INV), \
13254 X(vorn, 0x0300110, N_INV, 0x0800010), \
13255 X(vorr, 0x0200110, N_INV, 0x0800010), \
13256 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13257 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13258 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13259 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13260 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13261 X(vst1, 0x0000000, 0x0800000, N_INV), \
13262 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13263 X(vst2, 0x0000100, 0x0800100, N_INV), \
13264 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13265 X(vst3, 0x0000200, 0x0800200, N_INV), \
13266 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13267 X(vst4, 0x0000300, 0x0800300, N_INV), \
13268 X(vmovn, 0x1b20200, N_INV, N_INV), \
13269 X(vtrn, 0x1b20080, N_INV, N_INV), \
13270 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13271 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13272 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13273 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13274 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13275 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13276 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13277 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13278 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13279 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13280 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13281 X(vseleq, 0xe000a00, N_INV, N_INV), \
13282 X(vselvs, 0xe100a00, N_INV, N_INV), \
13283 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13284 X(vselgt, 0xe300a00, N_INV, N_INV), \
13285 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13286 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13287 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13288 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13289 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13290 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13291 X(sha3op, 0x2000c00, N_INV, N_INV), \
13292 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13293 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13294
13295enum neon_opc
13296{
13297#define X(OPC,I,F,S) N_MNEM_##OPC
13298NEON_ENC_TAB
13299#undef X
13300};
b99bd4ef 13301
5287ad62
JB
13302static const struct neon_tab_entry neon_enc_tab[] =
13303{
13304#define X(OPC,I,F,S) { (I), (F), (S) }
13305NEON_ENC_TAB
13306#undef X
13307};
b99bd4ef 13308
88714cb8
DG
13309/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13310#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13311#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13312#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13313#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13314#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13315#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13316#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13317#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13318#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13319#define NEON_ENC_SINGLE_(X) \
037e8744 13320 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13321#define NEON_ENC_DOUBLE_(X) \
037e8744 13322 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13323#define NEON_ENC_FPV8_(X) \
13324 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13325
88714cb8
DG
13326#define NEON_ENCODE(type, inst) \
13327 do \
13328 { \
13329 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13330 inst.is_neon = 1; \
13331 } \
13332 while (0)
13333
13334#define check_neon_suffixes \
13335 do \
13336 { \
13337 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13338 { \
13339 as_bad (_("invalid neon suffix for non neon instruction")); \
13340 return; \
13341 } \
13342 } \
13343 while (0)
13344
037e8744
JB
13345/* Define shapes for instruction operands. The following mnemonic characters
13346 are used in this table:
5287ad62 13347
037e8744 13348 F - VFP S<n> register
5287ad62
JB
13349 D - Neon D<n> register
13350 Q - Neon Q<n> register
13351 I - Immediate
13352 S - Scalar
13353 R - ARM register
13354 L - D<n> register list
5f4273c7 13355
037e8744
JB
13356 This table is used to generate various data:
13357 - enumerations of the form NS_DDR to be used as arguments to
13358 neon_select_shape.
13359 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13360 - a table used to drive neon_select_shape. */
b99bd4ef 13361
037e8744
JB
13362#define NEON_SHAPE_DEF \
13363 X(3, (D, D, D), DOUBLE), \
13364 X(3, (Q, Q, Q), QUAD), \
13365 X(3, (D, D, I), DOUBLE), \
13366 X(3, (Q, Q, I), QUAD), \
13367 X(3, (D, D, S), DOUBLE), \
13368 X(3, (Q, Q, S), QUAD), \
13369 X(2, (D, D), DOUBLE), \
13370 X(2, (Q, Q), QUAD), \
13371 X(2, (D, S), DOUBLE), \
13372 X(2, (Q, S), QUAD), \
13373 X(2, (D, R), DOUBLE), \
13374 X(2, (Q, R), QUAD), \
13375 X(2, (D, I), DOUBLE), \
13376 X(2, (Q, I), QUAD), \
13377 X(3, (D, L, D), DOUBLE), \
13378 X(2, (D, Q), MIXED), \
13379 X(2, (Q, D), MIXED), \
13380 X(3, (D, Q, I), MIXED), \
13381 X(3, (Q, D, I), MIXED), \
13382 X(3, (Q, D, D), MIXED), \
13383 X(3, (D, Q, Q), MIXED), \
13384 X(3, (Q, Q, D), MIXED), \
13385 X(3, (Q, D, S), MIXED), \
13386 X(3, (D, Q, S), MIXED), \
13387 X(4, (D, D, D, I), DOUBLE), \
13388 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
13389 X(4, (D, D, S, I), DOUBLE), \
13390 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
13391 X(2, (F, F), SINGLE), \
13392 X(3, (F, F, F), SINGLE), \
13393 X(2, (F, I), SINGLE), \
13394 X(2, (F, D), MIXED), \
13395 X(2, (D, F), MIXED), \
13396 X(3, (F, F, I), MIXED), \
13397 X(4, (R, R, F, F), SINGLE), \
13398 X(4, (F, F, R, R), SINGLE), \
13399 X(3, (D, R, R), DOUBLE), \
13400 X(3, (R, R, D), DOUBLE), \
13401 X(2, (S, R), SINGLE), \
13402 X(2, (R, S), SINGLE), \
13403 X(2, (F, R), SINGLE), \
d54af2d0
RL
13404 X(2, (R, F), SINGLE), \
13405/* Half float shape supported so far. */\
13406 X (2, (H, D), MIXED), \
13407 X (2, (D, H), MIXED), \
13408 X (2, (H, F), MIXED), \
13409 X (2, (F, H), MIXED), \
13410 X (2, (H, H), HALF), \
13411 X (2, (H, R), HALF), \
13412 X (2, (R, H), HALF), \
13413 X (2, (H, I), HALF), \
13414 X (3, (H, H, H), HALF), \
13415 X (3, (H, F, I), MIXED), \
13416 X (3, (F, H, I), MIXED)
037e8744
JB
13417
13418#define S2(A,B) NS_##A##B
13419#define S3(A,B,C) NS_##A##B##C
13420#define S4(A,B,C,D) NS_##A##B##C##D
13421
13422#define X(N, L, C) S##N L
13423
5287ad62
JB
13424enum neon_shape
13425{
037e8744
JB
13426 NEON_SHAPE_DEF,
13427 NS_NULL
5287ad62 13428};
b99bd4ef 13429
037e8744
JB
13430#undef X
13431#undef S2
13432#undef S3
13433#undef S4
13434
13435enum neon_shape_class
13436{
d54af2d0 13437 SC_HALF,
037e8744
JB
13438 SC_SINGLE,
13439 SC_DOUBLE,
13440 SC_QUAD,
13441 SC_MIXED
13442};
13443
13444#define X(N, L, C) SC_##C
13445
13446static enum neon_shape_class neon_shape_class[] =
13447{
13448 NEON_SHAPE_DEF
13449};
13450
13451#undef X
13452
13453enum neon_shape_el
13454{
d54af2d0 13455 SE_H,
037e8744
JB
13456 SE_F,
13457 SE_D,
13458 SE_Q,
13459 SE_I,
13460 SE_S,
13461 SE_R,
13462 SE_L
13463};
13464
13465/* Register widths of above. */
13466static unsigned neon_shape_el_size[] =
13467{
d54af2d0 13468 16,
037e8744
JB
13469 32,
13470 64,
13471 128,
13472 0,
13473 32,
13474 32,
13475 0
13476};
13477
13478struct neon_shape_info
13479{
13480 unsigned els;
13481 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13482};
13483
13484#define S2(A,B) { SE_##A, SE_##B }
13485#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13486#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13487
13488#define X(N, L, C) { N, S##N L }
13489
13490static struct neon_shape_info neon_shape_tab[] =
13491{
13492 NEON_SHAPE_DEF
13493};
13494
13495#undef X
13496#undef S2
13497#undef S3
13498#undef S4
13499
5287ad62
JB
13500/* Bit masks used in type checking given instructions.
13501 'N_EQK' means the type must be the same as (or based on in some way) the key
13502 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13503 set, various other bits can be set as well in order to modify the meaning of
13504 the type constraint. */
13505
13506enum neon_type_mask
13507{
8e79c3df
CM
13508 N_S8 = 0x0000001,
13509 N_S16 = 0x0000002,
13510 N_S32 = 0x0000004,
13511 N_S64 = 0x0000008,
13512 N_U8 = 0x0000010,
13513 N_U16 = 0x0000020,
13514 N_U32 = 0x0000040,
13515 N_U64 = 0x0000080,
13516 N_I8 = 0x0000100,
13517 N_I16 = 0x0000200,
13518 N_I32 = 0x0000400,
13519 N_I64 = 0x0000800,
13520 N_8 = 0x0001000,
13521 N_16 = 0x0002000,
13522 N_32 = 0x0004000,
13523 N_64 = 0x0008000,
13524 N_P8 = 0x0010000,
13525 N_P16 = 0x0020000,
13526 N_F16 = 0x0040000,
13527 N_F32 = 0x0080000,
13528 N_F64 = 0x0100000,
4f51b4bd 13529 N_P64 = 0x0200000,
c921be7d
NC
13530 N_KEY = 0x1000000, /* Key element (main type specifier). */
13531 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13532 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13533 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13534 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13535 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13536 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13537 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13538 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13539 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13540 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13541 N_UTYP = 0,
4f51b4bd 13542 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13543};
13544
dcbf9037
JB
13545#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13546
5287ad62
JB
13547#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13548#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13549#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
13550#define N_S_32 (N_S8 | N_S16 | N_S32)
13551#define N_F_16_32 (N_F16 | N_F32)
13552#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 13553#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 13554#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 13555#define N_F_ALL (N_F16 | N_F32 | N_F64)
5287ad62
JB
13556
13557/* Pass this as the first type argument to neon_check_type to ignore types
13558 altogether. */
13559#define N_IGNORE_TYPE (N_KEY | N_EQK)
13560
037e8744
JB
13561/* Select a "shape" for the current instruction (describing register types or
13562 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13563 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13564 function of operand parsing, so this function doesn't need to be called.
13565 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13566
13567static enum neon_shape
037e8744 13568neon_select_shape (enum neon_shape shape, ...)
5287ad62 13569{
037e8744
JB
13570 va_list ap;
13571 enum neon_shape first_shape = shape;
5287ad62
JB
13572
13573 /* Fix missing optional operands. FIXME: we don't know at this point how
13574 many arguments we should have, so this makes the assumption that we have
13575 > 1. This is true of all current Neon opcodes, I think, but may not be
13576 true in the future. */
13577 if (!inst.operands[1].present)
13578 inst.operands[1] = inst.operands[0];
13579
037e8744 13580 va_start (ap, shape);
5f4273c7 13581
21d799b5 13582 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13583 {
13584 unsigned j;
13585 int matches = 1;
13586
13587 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13588 {
13589 if (!inst.operands[j].present)
13590 {
13591 matches = 0;
13592 break;
13593 }
13594
13595 switch (neon_shape_tab[shape].el[j])
13596 {
d54af2d0
RL
13597 /* If a .f16, .16, .u16, .s16 type specifier is given over
13598 a VFP single precision register operand, it's essentially
13599 means only half of the register is used.
13600
13601 If the type specifier is given after the mnemonics, the
13602 information is stored in inst.vectype. If the type specifier
13603 is given after register operand, the information is stored
13604 in inst.operands[].vectype.
13605
13606 When there is only one type specifier, and all the register
13607 operands are the same type of hardware register, the type
13608 specifier applies to all register operands.
13609
13610 If no type specifier is given, the shape is inferred from
13611 operand information.
13612
13613 for example:
13614 vadd.f16 s0, s1, s2: NS_HHH
13615 vabs.f16 s0, s1: NS_HH
13616 vmov.f16 s0, r1: NS_HR
13617 vmov.f16 r0, s1: NS_RH
13618 vcvt.f16 r0, s1: NS_RH
13619 vcvt.f16.s32 s2, s2, #29: NS_HFI
13620 vcvt.f16.s32 s2, s2: NS_HF
13621 */
13622 case SE_H:
13623 if (!(inst.operands[j].isreg
13624 && inst.operands[j].isvec
13625 && inst.operands[j].issingle
13626 && !inst.operands[j].isquad
13627 && ((inst.vectype.elems == 1
13628 && inst.vectype.el[0].size == 16)
13629 || (inst.vectype.elems > 1
13630 && inst.vectype.el[j].size == 16)
13631 || (inst.vectype.elems == 0
13632 && inst.operands[j].vectype.type != NT_invtype
13633 && inst.operands[j].vectype.size == 16))))
13634 matches = 0;
13635 break;
13636
477330fc
RM
13637 case SE_F:
13638 if (!(inst.operands[j].isreg
13639 && inst.operands[j].isvec
13640 && inst.operands[j].issingle
d54af2d0
RL
13641 && !inst.operands[j].isquad
13642 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13643 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13644 || (inst.vectype.elems == 0
13645 && (inst.operands[j].vectype.size == 32
13646 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
13647 matches = 0;
13648 break;
13649
13650 case SE_D:
13651 if (!(inst.operands[j].isreg
13652 && inst.operands[j].isvec
13653 && !inst.operands[j].isquad
13654 && !inst.operands[j].issingle))
13655 matches = 0;
13656 break;
13657
13658 case SE_R:
13659 if (!(inst.operands[j].isreg
13660 && !inst.operands[j].isvec))
13661 matches = 0;
13662 break;
13663
13664 case SE_Q:
13665 if (!(inst.operands[j].isreg
13666 && inst.operands[j].isvec
13667 && inst.operands[j].isquad
13668 && !inst.operands[j].issingle))
13669 matches = 0;
13670 break;
13671
13672 case SE_I:
13673 if (!(!inst.operands[j].isreg
13674 && !inst.operands[j].isscalar))
13675 matches = 0;
13676 break;
13677
13678 case SE_S:
13679 if (!(!inst.operands[j].isreg
13680 && inst.operands[j].isscalar))
13681 matches = 0;
13682 break;
13683
13684 case SE_L:
13685 break;
13686 }
3fde54a2
JZ
13687 if (!matches)
13688 break;
477330fc 13689 }
ad6cec43
MGD
13690 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13691 /* We've matched all the entries in the shape table, and we don't
13692 have any left over operands which have not been matched. */
477330fc 13693 break;
037e8744 13694 }
5f4273c7 13695
037e8744 13696 va_end (ap);
5287ad62 13697
037e8744
JB
13698 if (shape == NS_NULL && first_shape != NS_NULL)
13699 first_error (_("invalid instruction shape"));
5287ad62 13700
037e8744
JB
13701 return shape;
13702}
5287ad62 13703
037e8744
JB
13704/* True if SHAPE is predominantly a quadword operation (most of the time, this
13705 means the Q bit should be set). */
13706
13707static int
13708neon_quad (enum neon_shape shape)
13709{
13710 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13711}
037e8744 13712
5287ad62
JB
13713static void
13714neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13715 unsigned *g_size)
5287ad62
JB
13716{
13717 /* Allow modification to be made to types which are constrained to be
13718 based on the key element, based on bits set alongside N_EQK. */
13719 if ((typebits & N_EQK) != 0)
13720 {
13721 if ((typebits & N_HLF) != 0)
13722 *g_size /= 2;
13723 else if ((typebits & N_DBL) != 0)
13724 *g_size *= 2;
13725 if ((typebits & N_SGN) != 0)
13726 *g_type = NT_signed;
13727 else if ((typebits & N_UNS) != 0)
477330fc 13728 *g_type = NT_unsigned;
5287ad62 13729 else if ((typebits & N_INT) != 0)
477330fc 13730 *g_type = NT_integer;
5287ad62 13731 else if ((typebits & N_FLT) != 0)
477330fc 13732 *g_type = NT_float;
dcbf9037 13733 else if ((typebits & N_SIZ) != 0)
477330fc 13734 *g_type = NT_untyped;
5287ad62
JB
13735 }
13736}
5f4273c7 13737
5287ad62
JB
13738/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13739 operand type, i.e. the single type specified in a Neon instruction when it
13740 is the only one given. */
13741
13742static struct neon_type_el
13743neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13744{
13745 struct neon_type_el dest = *key;
5f4273c7 13746
9c2799c2 13747 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13748
5287ad62
JB
13749 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13750
13751 return dest;
13752}
13753
13754/* Convert Neon type and size into compact bitmask representation. */
13755
13756static enum neon_type_mask
13757type_chk_of_el_type (enum neon_el_type type, unsigned size)
13758{
13759 switch (type)
13760 {
13761 case NT_untyped:
13762 switch (size)
477330fc
RM
13763 {
13764 case 8: return N_8;
13765 case 16: return N_16;
13766 case 32: return N_32;
13767 case 64: return N_64;
13768 default: ;
13769 }
5287ad62
JB
13770 break;
13771
13772 case NT_integer:
13773 switch (size)
477330fc
RM
13774 {
13775 case 8: return N_I8;
13776 case 16: return N_I16;
13777 case 32: return N_I32;
13778 case 64: return N_I64;
13779 default: ;
13780 }
5287ad62
JB
13781 break;
13782
13783 case NT_float:
037e8744 13784 switch (size)
477330fc 13785 {
8e79c3df 13786 case 16: return N_F16;
477330fc
RM
13787 case 32: return N_F32;
13788 case 64: return N_F64;
13789 default: ;
13790 }
5287ad62
JB
13791 break;
13792
13793 case NT_poly:
13794 switch (size)
477330fc
RM
13795 {
13796 case 8: return N_P8;
13797 case 16: return N_P16;
4f51b4bd 13798 case 64: return N_P64;
477330fc
RM
13799 default: ;
13800 }
5287ad62
JB
13801 break;
13802
13803 case NT_signed:
13804 switch (size)
477330fc
RM
13805 {
13806 case 8: return N_S8;
13807 case 16: return N_S16;
13808 case 32: return N_S32;
13809 case 64: return N_S64;
13810 default: ;
13811 }
5287ad62
JB
13812 break;
13813
13814 case NT_unsigned:
13815 switch (size)
477330fc
RM
13816 {
13817 case 8: return N_U8;
13818 case 16: return N_U16;
13819 case 32: return N_U32;
13820 case 64: return N_U64;
13821 default: ;
13822 }
5287ad62
JB
13823 break;
13824
13825 default: ;
13826 }
5f4273c7 13827
5287ad62
JB
13828 return N_UTYP;
13829}
13830
13831/* Convert compact Neon bitmask type representation to a type and size. Only
13832 handles the case where a single bit is set in the mask. */
13833
dcbf9037 13834static int
5287ad62 13835el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13836 enum neon_type_mask mask)
5287ad62 13837{
dcbf9037
JB
13838 if ((mask & N_EQK) != 0)
13839 return FAIL;
13840
5287ad62
JB
13841 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13842 *size = 8;
c70a8987 13843 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13844 *size = 16;
dcbf9037 13845 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13846 *size = 32;
4f51b4bd 13847 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13848 *size = 64;
dcbf9037
JB
13849 else
13850 return FAIL;
13851
5287ad62
JB
13852 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13853 *type = NT_signed;
dcbf9037 13854 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13855 *type = NT_unsigned;
dcbf9037 13856 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13857 *type = NT_integer;
dcbf9037 13858 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13859 *type = NT_untyped;
4f51b4bd 13860 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13861 *type = NT_poly;
d54af2d0 13862 else if ((mask & (N_F_ALL)) != 0)
5287ad62 13863 *type = NT_float;
dcbf9037
JB
13864 else
13865 return FAIL;
5f4273c7 13866
dcbf9037 13867 return SUCCESS;
5287ad62
JB
13868}
13869
13870/* Modify a bitmask of allowed types. This is only needed for type
13871 relaxation. */
13872
13873static unsigned
13874modify_types_allowed (unsigned allowed, unsigned mods)
13875{
13876 unsigned size;
13877 enum neon_el_type type;
13878 unsigned destmask;
13879 int i;
5f4273c7 13880
5287ad62 13881 destmask = 0;
5f4273c7 13882
5287ad62
JB
13883 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13884 {
21d799b5 13885 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13886 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13887 {
13888 neon_modify_type_size (mods, &type, &size);
13889 destmask |= type_chk_of_el_type (type, size);
13890 }
5287ad62 13891 }
5f4273c7 13892
5287ad62
JB
13893 return destmask;
13894}
13895
13896/* Check type and return type classification.
13897 The manual states (paraphrase): If one datatype is given, it indicates the
13898 type given in:
13899 - the second operand, if there is one
13900 - the operand, if there is no second operand
13901 - the result, if there are no operands.
13902 This isn't quite good enough though, so we use a concept of a "key" datatype
13903 which is set on a per-instruction basis, which is the one which matters when
13904 only one data type is written.
13905 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13906 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13907
13908static struct neon_type_el
13909neon_check_type (unsigned els, enum neon_shape ns, ...)
13910{
13911 va_list ap;
13912 unsigned i, pass, key_el = 0;
13913 unsigned types[NEON_MAX_TYPE_ELS];
13914 enum neon_el_type k_type = NT_invtype;
13915 unsigned k_size = -1u;
13916 struct neon_type_el badtype = {NT_invtype, -1};
13917 unsigned key_allowed = 0;
13918
13919 /* Optional registers in Neon instructions are always (not) in operand 1.
13920 Fill in the missing operand here, if it was omitted. */
13921 if (els > 1 && !inst.operands[1].present)
13922 inst.operands[1] = inst.operands[0];
13923
13924 /* Suck up all the varargs. */
13925 va_start (ap, ns);
13926 for (i = 0; i < els; i++)
13927 {
13928 unsigned thisarg = va_arg (ap, unsigned);
13929 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
13930 {
13931 va_end (ap);
13932 return badtype;
13933 }
5287ad62
JB
13934 types[i] = thisarg;
13935 if ((thisarg & N_KEY) != 0)
477330fc 13936 key_el = i;
5287ad62
JB
13937 }
13938 va_end (ap);
13939
dcbf9037
JB
13940 if (inst.vectype.elems > 0)
13941 for (i = 0; i < els; i++)
13942 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
13943 {
13944 first_error (_("types specified in both the mnemonic and operands"));
13945 return badtype;
13946 }
dcbf9037 13947
5287ad62
JB
13948 /* Duplicate inst.vectype elements here as necessary.
13949 FIXME: No idea if this is exactly the same as the ARM assembler,
13950 particularly when an insn takes one register and one non-register
13951 operand. */
13952 if (inst.vectype.elems == 1 && els > 1)
13953 {
13954 unsigned j;
13955 inst.vectype.elems = els;
13956 inst.vectype.el[key_el] = inst.vectype.el[0];
13957 for (j = 0; j < els; j++)
477330fc
RM
13958 if (j != key_el)
13959 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13960 types[j]);
dcbf9037
JB
13961 }
13962 else if (inst.vectype.elems == 0 && els > 0)
13963 {
13964 unsigned j;
13965 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
13966 after each operand. We allow some flexibility here; as long as the
13967 "key" operand has a type, we can infer the others. */
dcbf9037 13968 for (j = 0; j < els; j++)
477330fc
RM
13969 if (inst.operands[j].vectype.type != NT_invtype)
13970 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
13971
13972 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
13973 {
13974 for (j = 0; j < els; j++)
13975 if (inst.operands[j].vectype.type == NT_invtype)
13976 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13977 types[j]);
13978 }
dcbf9037 13979 else
477330fc
RM
13980 {
13981 first_error (_("operand types can't be inferred"));
13982 return badtype;
13983 }
5287ad62
JB
13984 }
13985 else if (inst.vectype.elems != els)
13986 {
dcbf9037 13987 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
13988 return badtype;
13989 }
13990
13991 for (pass = 0; pass < 2; pass++)
13992 {
13993 for (i = 0; i < els; i++)
477330fc
RM
13994 {
13995 unsigned thisarg = types[i];
13996 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
13997 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
13998 enum neon_el_type g_type = inst.vectype.el[i].type;
13999 unsigned g_size = inst.vectype.el[i].size;
14000
14001 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 14002 integer types if sign-specific variants are unavailable. */
477330fc 14003 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
14004 && (types_allowed & N_SU_ALL) == 0)
14005 g_type = NT_integer;
14006
477330fc 14007 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
14008 them. Some instructions only care about signs for some element
14009 sizes, so handle that properly. */
477330fc 14010 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
14011 && ((g_size == 8 && (types_allowed & N_8) != 0)
14012 || (g_size == 16 && (types_allowed & N_16) != 0)
14013 || (g_size == 32 && (types_allowed & N_32) != 0)
14014 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
14015 g_type = NT_untyped;
14016
477330fc
RM
14017 if (pass == 0)
14018 {
14019 if ((thisarg & N_KEY) != 0)
14020 {
14021 k_type = g_type;
14022 k_size = g_size;
14023 key_allowed = thisarg & ~N_KEY;
cc933301
JW
14024
14025 /* Check architecture constraint on FP16 extension. */
14026 if (k_size == 16
14027 && k_type == NT_float
14028 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14029 {
14030 inst.error = _(BAD_FP16);
14031 return badtype;
14032 }
477330fc
RM
14033 }
14034 }
14035 else
14036 {
14037 if ((thisarg & N_VFP) != 0)
14038 {
14039 enum neon_shape_el regshape;
14040 unsigned regwidth, match;
99b253c5
NC
14041
14042 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
14043 if (ns == NS_NULL)
14044 {
14045 first_error (_("invalid instruction shape"));
14046 return badtype;
14047 }
477330fc
RM
14048 regshape = neon_shape_tab[ns].el[i];
14049 regwidth = neon_shape_el_size[regshape];
14050
14051 /* In VFP mode, operands must match register widths. If we
14052 have a key operand, use its width, else use the width of
14053 the current operand. */
14054 if (k_size != -1u)
14055 match = k_size;
14056 else
14057 match = g_size;
14058
9db2f6b4
RL
14059 /* FP16 will use a single precision register. */
14060 if (regwidth == 32 && match == 16)
14061 {
14062 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14063 match = regwidth;
14064 else
14065 {
14066 inst.error = _(BAD_FP16);
14067 return badtype;
14068 }
14069 }
14070
477330fc
RM
14071 if (regwidth != match)
14072 {
14073 first_error (_("operand size must match register width"));
14074 return badtype;
14075 }
14076 }
14077
14078 if ((thisarg & N_EQK) == 0)
14079 {
14080 unsigned given_type = type_chk_of_el_type (g_type, g_size);
14081
14082 if ((given_type & types_allowed) == 0)
14083 {
14084 first_error (_("bad type in Neon instruction"));
14085 return badtype;
14086 }
14087 }
14088 else
14089 {
14090 enum neon_el_type mod_k_type = k_type;
14091 unsigned mod_k_size = k_size;
14092 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
14093 if (g_type != mod_k_type || g_size != mod_k_size)
14094 {
14095 first_error (_("inconsistent types in Neon instruction"));
14096 return badtype;
14097 }
14098 }
14099 }
14100 }
5287ad62
JB
14101 }
14102
14103 return inst.vectype.el[key_el];
14104}
14105
037e8744 14106/* Neon-style VFP instruction forwarding. */
5287ad62 14107
037e8744
JB
14108/* Thumb VFP instructions have 0xE in the condition field. */
14109
14110static void
14111do_vfp_cond_or_thumb (void)
5287ad62 14112{
88714cb8
DG
14113 inst.is_neon = 1;
14114
5287ad62 14115 if (thumb_mode)
037e8744 14116 inst.instruction |= 0xe0000000;
5287ad62 14117 else
037e8744 14118 inst.instruction |= inst.cond << 28;
5287ad62
JB
14119}
14120
037e8744
JB
14121/* Look up and encode a simple mnemonic, for use as a helper function for the
14122 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14123 etc. It is assumed that operand parsing has already been done, and that the
14124 operands are in the form expected by the given opcode (this isn't necessarily
14125 the same as the form in which they were parsed, hence some massaging must
14126 take place before this function is called).
14127 Checks current arch version against that in the looked-up opcode. */
5287ad62 14128
037e8744
JB
14129static void
14130do_vfp_nsyn_opcode (const char *opname)
5287ad62 14131{
037e8744 14132 const struct asm_opcode *opcode;
5f4273c7 14133
21d799b5 14134 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 14135
037e8744
JB
14136 if (!opcode)
14137 abort ();
5287ad62 14138
037e8744 14139 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
14140 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14141 _(BAD_FPU));
5287ad62 14142
88714cb8
DG
14143 inst.is_neon = 1;
14144
037e8744
JB
14145 if (thumb_mode)
14146 {
14147 inst.instruction = opcode->tvalue;
14148 opcode->tencode ();
14149 }
14150 else
14151 {
14152 inst.instruction = (inst.cond << 28) | opcode->avalue;
14153 opcode->aencode ();
14154 }
14155}
5287ad62
JB
14156
14157static void
037e8744 14158do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 14159{
037e8744
JB
14160 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14161
9db2f6b4 14162 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14163 {
14164 if (is_add)
477330fc 14165 do_vfp_nsyn_opcode ("fadds");
037e8744 14166 else
477330fc 14167 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
14168
14169 /* ARMv8.2 fp16 instruction. */
14170 if (rs == NS_HHH)
14171 do_scalar_fp16_v82_encode ();
037e8744
JB
14172 }
14173 else
14174 {
14175 if (is_add)
477330fc 14176 do_vfp_nsyn_opcode ("faddd");
037e8744 14177 else
477330fc 14178 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
14179 }
14180}
14181
14182/* Check operand types to see if this is a VFP instruction, and if so call
14183 PFN (). */
14184
14185static int
14186try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14187{
14188 enum neon_shape rs;
14189 struct neon_type_el et;
14190
14191 switch (args)
14192 {
14193 case 2:
9db2f6b4
RL
14194 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14195 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 14196 break;
5f4273c7 14197
037e8744 14198 case 3:
9db2f6b4
RL
14199 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14200 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14201 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
14202 break;
14203
14204 default:
14205 abort ();
14206 }
14207
14208 if (et.type != NT_invtype)
14209 {
14210 pfn (rs);
14211 return SUCCESS;
14212 }
037e8744 14213
99b253c5 14214 inst.error = NULL;
037e8744
JB
14215 return FAIL;
14216}
14217
14218static void
14219do_vfp_nsyn_mla_mls (enum neon_shape rs)
14220{
14221 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 14222
9db2f6b4 14223 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14224 {
14225 if (is_mla)
477330fc 14226 do_vfp_nsyn_opcode ("fmacs");
037e8744 14227 else
477330fc 14228 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
14229
14230 /* ARMv8.2 fp16 instruction. */
14231 if (rs == NS_HHH)
14232 do_scalar_fp16_v82_encode ();
037e8744
JB
14233 }
14234 else
14235 {
14236 if (is_mla)
477330fc 14237 do_vfp_nsyn_opcode ("fmacd");
037e8744 14238 else
477330fc 14239 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
14240 }
14241}
14242
62f3b8c8
PB
14243static void
14244do_vfp_nsyn_fma_fms (enum neon_shape rs)
14245{
14246 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14247
9db2f6b4 14248 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
14249 {
14250 if (is_fma)
477330fc 14251 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 14252 else
477330fc 14253 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
14254
14255 /* ARMv8.2 fp16 instruction. */
14256 if (rs == NS_HHH)
14257 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
14258 }
14259 else
14260 {
14261 if (is_fma)
477330fc 14262 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14263 else
477330fc 14264 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14265 }
14266}
14267
037e8744
JB
14268static void
14269do_vfp_nsyn_mul (enum neon_shape rs)
14270{
9db2f6b4
RL
14271 if (rs == NS_FFF || rs == NS_HHH)
14272 {
14273 do_vfp_nsyn_opcode ("fmuls");
14274
14275 /* ARMv8.2 fp16 instruction. */
14276 if (rs == NS_HHH)
14277 do_scalar_fp16_v82_encode ();
14278 }
037e8744
JB
14279 else
14280 do_vfp_nsyn_opcode ("fmuld");
14281}
14282
14283static void
14284do_vfp_nsyn_abs_neg (enum neon_shape rs)
14285{
14286 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 14287 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 14288
9db2f6b4 14289 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
14290 {
14291 if (is_neg)
477330fc 14292 do_vfp_nsyn_opcode ("fnegs");
037e8744 14293 else
477330fc 14294 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
14295
14296 /* ARMv8.2 fp16 instruction. */
14297 if (rs == NS_HH)
14298 do_scalar_fp16_v82_encode ();
037e8744
JB
14299 }
14300 else
14301 {
14302 if (is_neg)
477330fc 14303 do_vfp_nsyn_opcode ("fnegd");
037e8744 14304 else
477330fc 14305 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14306 }
14307}
14308
14309/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14310 insns belong to Neon, and are handled elsewhere. */
14311
14312static void
14313do_vfp_nsyn_ldm_stm (int is_dbmode)
14314{
14315 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14316 if (is_ldm)
14317 {
14318 if (is_dbmode)
477330fc 14319 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14320 else
477330fc 14321 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14322 }
14323 else
14324 {
14325 if (is_dbmode)
477330fc 14326 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14327 else
477330fc 14328 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14329 }
14330}
14331
037e8744
JB
14332static void
14333do_vfp_nsyn_sqrt (void)
14334{
9db2f6b4
RL
14335 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14336 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14337
9db2f6b4
RL
14338 if (rs == NS_FF || rs == NS_HH)
14339 {
14340 do_vfp_nsyn_opcode ("fsqrts");
14341
14342 /* ARMv8.2 fp16 instruction. */
14343 if (rs == NS_HH)
14344 do_scalar_fp16_v82_encode ();
14345 }
037e8744
JB
14346 else
14347 do_vfp_nsyn_opcode ("fsqrtd");
14348}
14349
14350static void
14351do_vfp_nsyn_div (void)
14352{
9db2f6b4 14353 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14354 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14355 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14356
9db2f6b4
RL
14357 if (rs == NS_FFF || rs == NS_HHH)
14358 {
14359 do_vfp_nsyn_opcode ("fdivs");
14360
14361 /* ARMv8.2 fp16 instruction. */
14362 if (rs == NS_HHH)
14363 do_scalar_fp16_v82_encode ();
14364 }
037e8744
JB
14365 else
14366 do_vfp_nsyn_opcode ("fdivd");
14367}
14368
14369static void
14370do_vfp_nsyn_nmul (void)
14371{
9db2f6b4 14372 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14373 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14374 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14375
9db2f6b4 14376 if (rs == NS_FFF || rs == NS_HHH)
037e8744 14377 {
88714cb8 14378 NEON_ENCODE (SINGLE, inst);
037e8744 14379 do_vfp_sp_dyadic ();
9db2f6b4
RL
14380
14381 /* ARMv8.2 fp16 instruction. */
14382 if (rs == NS_HHH)
14383 do_scalar_fp16_v82_encode ();
037e8744
JB
14384 }
14385 else
14386 {
88714cb8 14387 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14388 do_vfp_dp_rd_rn_rm ();
14389 }
14390 do_vfp_cond_or_thumb ();
9db2f6b4 14391
037e8744
JB
14392}
14393
14394static void
14395do_vfp_nsyn_cmp (void)
14396{
9db2f6b4 14397 enum neon_shape rs;
037e8744
JB
14398 if (inst.operands[1].isreg)
14399 {
9db2f6b4
RL
14400 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14401 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14402
9db2f6b4 14403 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
14404 {
14405 NEON_ENCODE (SINGLE, inst);
14406 do_vfp_sp_monadic ();
14407 }
037e8744 14408 else
477330fc
RM
14409 {
14410 NEON_ENCODE (DOUBLE, inst);
14411 do_vfp_dp_rd_rm ();
14412 }
037e8744
JB
14413 }
14414 else
14415 {
9db2f6b4
RL
14416 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14417 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
14418
14419 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14420 {
14421 case N_MNEM_vcmp:
14422 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14423 break;
14424 case N_MNEM_vcmpe:
14425 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14426 break;
14427 default:
14428 abort ();
14429 }
5f4273c7 14430
9db2f6b4 14431 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
14432 {
14433 NEON_ENCODE (SINGLE, inst);
14434 do_vfp_sp_compare_z ();
14435 }
037e8744 14436 else
477330fc
RM
14437 {
14438 NEON_ENCODE (DOUBLE, inst);
14439 do_vfp_dp_rd ();
14440 }
037e8744
JB
14441 }
14442 do_vfp_cond_or_thumb ();
9db2f6b4
RL
14443
14444 /* ARMv8.2 fp16 instruction. */
14445 if (rs == NS_HI || rs == NS_HH)
14446 do_scalar_fp16_v82_encode ();
037e8744
JB
14447}
14448
14449static void
14450nsyn_insert_sp (void)
14451{
14452 inst.operands[1] = inst.operands[0];
14453 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14454 inst.operands[0].reg = REG_SP;
037e8744
JB
14455 inst.operands[0].isreg = 1;
14456 inst.operands[0].writeback = 1;
14457 inst.operands[0].present = 1;
14458}
14459
14460static void
14461do_vfp_nsyn_push (void)
14462{
14463 nsyn_insert_sp ();
b126985e
NC
14464
14465 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14466 _("register list must contain at least 1 and at most 16 "
14467 "registers"));
14468
037e8744
JB
14469 if (inst.operands[1].issingle)
14470 do_vfp_nsyn_opcode ("fstmdbs");
14471 else
14472 do_vfp_nsyn_opcode ("fstmdbd");
14473}
14474
14475static void
14476do_vfp_nsyn_pop (void)
14477{
14478 nsyn_insert_sp ();
b126985e
NC
14479
14480 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14481 _("register list must contain at least 1 and at most 16 "
14482 "registers"));
14483
037e8744 14484 if (inst.operands[1].issingle)
22b5b651 14485 do_vfp_nsyn_opcode ("fldmias");
037e8744 14486 else
22b5b651 14487 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14488}
14489
14490/* Fix up Neon data-processing instructions, ORing in the correct bits for
14491 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14492
88714cb8
DG
14493static void
14494neon_dp_fixup (struct arm_it* insn)
037e8744 14495{
88714cb8
DG
14496 unsigned int i = insn->instruction;
14497 insn->is_neon = 1;
14498
037e8744
JB
14499 if (thumb_mode)
14500 {
14501 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14502 if (i & (1 << 24))
477330fc 14503 i |= 1 << 28;
5f4273c7 14504
037e8744 14505 i &= ~(1 << 24);
5f4273c7 14506
037e8744
JB
14507 i |= 0xef000000;
14508 }
14509 else
14510 i |= 0xf2000000;
5f4273c7 14511
88714cb8 14512 insn->instruction = i;
037e8744
JB
14513}
14514
14515/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14516 (0, 1, 2, 3). */
14517
14518static unsigned
14519neon_logbits (unsigned x)
14520{
14521 return ffs (x) - 4;
14522}
14523
14524#define LOW4(R) ((R) & 0xf)
14525#define HI1(R) (((R) >> 4) & 1)
14526
14527/* Encode insns with bit pattern:
14528
14529 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14530 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14531
037e8744
JB
14532 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14533 different meaning for some instruction. */
14534
14535static void
14536neon_three_same (int isquad, int ubit, int size)
14537{
14538 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14539 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14540 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14541 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14542 inst.instruction |= LOW4 (inst.operands[2].reg);
14543 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14544 inst.instruction |= (isquad != 0) << 6;
14545 inst.instruction |= (ubit != 0) << 24;
14546 if (size != -1)
14547 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14548
88714cb8 14549 neon_dp_fixup (&inst);
037e8744
JB
14550}
14551
14552/* Encode instructions of the form:
14553
14554 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14555 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14556
14557 Don't write size if SIZE == -1. */
14558
14559static void
14560neon_two_same (int qbit, int ubit, int size)
14561{
14562 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14563 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14564 inst.instruction |= LOW4 (inst.operands[1].reg);
14565 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14566 inst.instruction |= (qbit != 0) << 6;
14567 inst.instruction |= (ubit != 0) << 24;
14568
14569 if (size != -1)
14570 inst.instruction |= neon_logbits (size) << 18;
14571
88714cb8 14572 neon_dp_fixup (&inst);
5287ad62
JB
14573}
14574
14575/* Neon instruction encoders, in approximate order of appearance. */
14576
14577static void
14578do_neon_dyadic_i_su (void)
14579{
037e8744 14580 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14581 struct neon_type_el et = neon_check_type (3, rs,
14582 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14583 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14584}
14585
14586static void
14587do_neon_dyadic_i64_su (void)
14588{
037e8744 14589 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14590 struct neon_type_el et = neon_check_type (3, rs,
14591 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14592 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14593}
14594
14595static void
14596neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14597 unsigned immbits)
5287ad62
JB
14598{
14599 unsigned size = et.size >> 3;
14600 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14601 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14602 inst.instruction |= LOW4 (inst.operands[1].reg);
14603 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14604 inst.instruction |= (isquad != 0) << 6;
14605 inst.instruction |= immbits << 16;
14606 inst.instruction |= (size >> 3) << 7;
14607 inst.instruction |= (size & 0x7) << 19;
14608 if (write_ubit)
14609 inst.instruction |= (uval != 0) << 24;
14610
88714cb8 14611 neon_dp_fixup (&inst);
5287ad62
JB
14612}
14613
14614static void
14615do_neon_shl_imm (void)
14616{
14617 if (!inst.operands[2].isreg)
14618 {
037e8744 14619 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14620 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14621 int imm = inst.operands[2].imm;
14622
14623 constraint (imm < 0 || (unsigned)imm >= et.size,
14624 _("immediate out of range for shift"));
88714cb8 14625 NEON_ENCODE (IMMED, inst);
cb3b1e65 14626 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14627 }
14628 else
14629 {
037e8744 14630 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14631 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14632 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14633 unsigned int tmp;
14634
14635 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14636 vshl.xx Dd, Dm, Dn
14637 whereas other 3-register operations encoded by neon_three_same have
14638 syntax like:
14639 vadd.xx Dd, Dn, Dm
14640 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14641 here. */
627907b7
JB
14642 tmp = inst.operands[2].reg;
14643 inst.operands[2].reg = inst.operands[1].reg;
14644 inst.operands[1].reg = tmp;
88714cb8 14645 NEON_ENCODE (INTEGER, inst);
037e8744 14646 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14647 }
14648}
14649
14650static void
14651do_neon_qshl_imm (void)
14652{
14653 if (!inst.operands[2].isreg)
14654 {
037e8744 14655 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14656 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14657 int imm = inst.operands[2].imm;
627907b7 14658
cb3b1e65
JB
14659 constraint (imm < 0 || (unsigned)imm >= et.size,
14660 _("immediate out of range for shift"));
88714cb8 14661 NEON_ENCODE (IMMED, inst);
cb3b1e65 14662 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14663 }
14664 else
14665 {
037e8744 14666 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14667 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14668 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14669 unsigned int tmp;
14670
14671 /* See note in do_neon_shl_imm. */
14672 tmp = inst.operands[2].reg;
14673 inst.operands[2].reg = inst.operands[1].reg;
14674 inst.operands[1].reg = tmp;
88714cb8 14675 NEON_ENCODE (INTEGER, inst);
037e8744 14676 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14677 }
14678}
14679
627907b7
JB
14680static void
14681do_neon_rshl (void)
14682{
14683 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14684 struct neon_type_el et = neon_check_type (3, rs,
14685 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14686 unsigned int tmp;
14687
14688 tmp = inst.operands[2].reg;
14689 inst.operands[2].reg = inst.operands[1].reg;
14690 inst.operands[1].reg = tmp;
14691 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14692}
14693
5287ad62
JB
14694static int
14695neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14696{
036dc3f7
PB
14697 /* Handle .I8 pseudo-instructions. */
14698 if (size == 8)
5287ad62 14699 {
5287ad62 14700 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14701 FIXME is this the intended semantics? There doesn't seem much point in
14702 accepting .I8 if so. */
5287ad62
JB
14703 immediate |= immediate << 8;
14704 size = 16;
036dc3f7
PB
14705 }
14706
14707 if (size >= 32)
14708 {
14709 if (immediate == (immediate & 0x000000ff))
14710 {
14711 *immbits = immediate;
14712 return 0x1;
14713 }
14714 else if (immediate == (immediate & 0x0000ff00))
14715 {
14716 *immbits = immediate >> 8;
14717 return 0x3;
14718 }
14719 else if (immediate == (immediate & 0x00ff0000))
14720 {
14721 *immbits = immediate >> 16;
14722 return 0x5;
14723 }
14724 else if (immediate == (immediate & 0xff000000))
14725 {
14726 *immbits = immediate >> 24;
14727 return 0x7;
14728 }
14729 if ((immediate & 0xffff) != (immediate >> 16))
14730 goto bad_immediate;
14731 immediate &= 0xffff;
5287ad62
JB
14732 }
14733
14734 if (immediate == (immediate & 0x000000ff))
14735 {
14736 *immbits = immediate;
036dc3f7 14737 return 0x9;
5287ad62
JB
14738 }
14739 else if (immediate == (immediate & 0x0000ff00))
14740 {
14741 *immbits = immediate >> 8;
036dc3f7 14742 return 0xb;
5287ad62
JB
14743 }
14744
14745 bad_immediate:
dcbf9037 14746 first_error (_("immediate value out of range"));
5287ad62
JB
14747 return FAIL;
14748}
14749
5287ad62
JB
14750static void
14751do_neon_logic (void)
14752{
14753 if (inst.operands[2].present && inst.operands[2].isreg)
14754 {
037e8744 14755 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14756 neon_check_type (3, rs, N_IGNORE_TYPE);
14757 /* U bit and size field were set as part of the bitmask. */
88714cb8 14758 NEON_ENCODE (INTEGER, inst);
037e8744 14759 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14760 }
14761 else
14762 {
4316f0d2
DG
14763 const int three_ops_form = (inst.operands[2].present
14764 && !inst.operands[2].isreg);
14765 const int immoperand = (three_ops_form ? 2 : 1);
14766 enum neon_shape rs = (three_ops_form
14767 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14768 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14769 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14770 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14771 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14772 unsigned immbits;
14773 int cmode;
5f4273c7 14774
5287ad62 14775 if (et.type == NT_invtype)
477330fc 14776 return;
5f4273c7 14777
4316f0d2
DG
14778 if (three_ops_form)
14779 constraint (inst.operands[0].reg != inst.operands[1].reg,
14780 _("first and second operands shall be the same register"));
14781
88714cb8 14782 NEON_ENCODE (IMMED, inst);
5287ad62 14783
4316f0d2 14784 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14785 if (et.size == 64)
14786 {
14787 /* .i64 is a pseudo-op, so the immediate must be a repeating
14788 pattern. */
4316f0d2
DG
14789 if (immbits != (inst.operands[immoperand].regisimm ?
14790 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14791 {
14792 /* Set immbits to an invalid constant. */
14793 immbits = 0xdeadbeef;
14794 }
14795 }
14796
5287ad62 14797 switch (opcode)
477330fc
RM
14798 {
14799 case N_MNEM_vbic:
14800 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14801 break;
14802
14803 case N_MNEM_vorr:
14804 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14805 break;
14806
14807 case N_MNEM_vand:
14808 /* Pseudo-instruction for VBIC. */
14809 neon_invert_size (&immbits, 0, et.size);
14810 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14811 break;
14812
14813 case N_MNEM_vorn:
14814 /* Pseudo-instruction for VORR. */
14815 neon_invert_size (&immbits, 0, et.size);
14816 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14817 break;
14818
14819 default:
14820 abort ();
14821 }
5287ad62
JB
14822
14823 if (cmode == FAIL)
477330fc 14824 return;
5287ad62 14825
037e8744 14826 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14827 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14828 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14829 inst.instruction |= cmode << 8;
14830 neon_write_immbits (immbits);
5f4273c7 14831
88714cb8 14832 neon_dp_fixup (&inst);
5287ad62
JB
14833 }
14834}
14835
14836static void
14837do_neon_bitfield (void)
14838{
037e8744 14839 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14840 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14841 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14842}
14843
14844static void
dcbf9037 14845neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14846 unsigned destbits)
5287ad62 14847{
037e8744 14848 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14849 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14850 types | N_KEY);
5287ad62
JB
14851 if (et.type == NT_float)
14852 {
88714cb8 14853 NEON_ENCODE (FLOAT, inst);
cc933301 14854 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
14855 }
14856 else
14857 {
88714cb8 14858 NEON_ENCODE (INTEGER, inst);
037e8744 14859 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14860 }
14861}
14862
14863static void
14864do_neon_dyadic_if_su (void)
14865{
dcbf9037 14866 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14867}
14868
14869static void
14870do_neon_dyadic_if_su_d (void)
14871{
14872 /* This version only allow D registers, but that constraint is enforced during
14873 operand parsing so we don't need to do anything extra here. */
dcbf9037 14874 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14875}
14876
5287ad62
JB
14877static void
14878do_neon_dyadic_if_i_d (void)
14879{
428e3f1f
PB
14880 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14881 affected if we specify unsigned args. */
14882 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14883}
14884
037e8744
JB
14885enum vfp_or_neon_is_neon_bits
14886{
14887 NEON_CHECK_CC = 1,
73924fbc
MGD
14888 NEON_CHECK_ARCH = 2,
14889 NEON_CHECK_ARCH8 = 4
037e8744
JB
14890};
14891
14892/* Call this function if an instruction which may have belonged to the VFP or
14893 Neon instruction sets, but turned out to be a Neon instruction (due to the
14894 operand types involved, etc.). We have to check and/or fix-up a couple of
14895 things:
14896
14897 - Make sure the user hasn't attempted to make a Neon instruction
14898 conditional.
14899 - Alter the value in the condition code field if necessary.
14900 - Make sure that the arch supports Neon instructions.
14901
14902 Which of these operations take place depends on bits from enum
14903 vfp_or_neon_is_neon_bits.
14904
14905 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14906 current instruction's condition is COND_ALWAYS, the condition field is
14907 changed to inst.uncond_value. This is necessary because instructions shared
14908 between VFP and Neon may be conditional for the VFP variants only, and the
14909 unconditional Neon version must have, e.g., 0xF in the condition field. */
14910
14911static int
14912vfp_or_neon_is_neon (unsigned check)
14913{
14914 /* Conditions are always legal in Thumb mode (IT blocks). */
14915 if (!thumb_mode && (check & NEON_CHECK_CC))
14916 {
14917 if (inst.cond != COND_ALWAYS)
477330fc
RM
14918 {
14919 first_error (_(BAD_COND));
14920 return FAIL;
14921 }
037e8744 14922 if (inst.uncond_value != -1)
477330fc 14923 inst.instruction |= inst.uncond_value << 28;
037e8744 14924 }
5f4273c7 14925
037e8744 14926 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14927 && !mark_feature_used (&fpu_neon_ext_v1))
14928 {
14929 first_error (_(BAD_FPU));
14930 return FAIL;
14931 }
14932
14933 if ((check & NEON_CHECK_ARCH8)
14934 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
14935 {
14936 first_error (_(BAD_FPU));
14937 return FAIL;
14938 }
5f4273c7 14939
037e8744
JB
14940 return SUCCESS;
14941}
14942
5287ad62
JB
14943static void
14944do_neon_addsub_if_i (void)
14945{
037e8744
JB
14946 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14947 return;
14948
14949 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14950 return;
14951
5287ad62
JB
14952 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14953 affected if we specify unsigned args. */
dcbf9037 14954 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
14955}
14956
14957/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14958 result to be:
14959 V<op> A,B (A is operand 0, B is operand 2)
14960 to mean:
14961 V<op> A,B,A
14962 not:
14963 V<op> A,B,B
14964 so handle that case specially. */
14965
14966static void
14967neon_exchange_operands (void)
14968{
5287ad62
JB
14969 if (inst.operands[1].present)
14970 {
e1fa0163
NC
14971 void *scratch = xmalloc (sizeof (inst.operands[0]));
14972
5287ad62
JB
14973 /* Swap operands[1] and operands[2]. */
14974 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14975 inst.operands[1] = inst.operands[2];
14976 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 14977 free (scratch);
5287ad62
JB
14978 }
14979 else
14980 {
14981 inst.operands[1] = inst.operands[2];
14982 inst.operands[2] = inst.operands[0];
14983 }
14984}
14985
14986static void
14987neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14988{
14989 if (inst.operands[2].isreg)
14990 {
14991 if (invert)
477330fc 14992 neon_exchange_operands ();
dcbf9037 14993 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
14994 }
14995 else
14996 {
037e8744 14997 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 14998 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14999 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 15000
88714cb8 15001 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15002 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15003 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15004 inst.instruction |= LOW4 (inst.operands[1].reg);
15005 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15006 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15007 inst.instruction |= (et.type == NT_float) << 10;
15008 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15009
88714cb8 15010 neon_dp_fixup (&inst);
5287ad62
JB
15011 }
15012}
15013
15014static void
15015do_neon_cmp (void)
15016{
cc933301 15017 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
15018}
15019
15020static void
15021do_neon_cmp_inv (void)
15022{
cc933301 15023 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
15024}
15025
15026static void
15027do_neon_ceq (void)
15028{
15029 neon_compare (N_IF_32, N_IF_32, FALSE);
15030}
15031
15032/* For multiply instructions, we have the possibility of 16-bit or 32-bit
15033 scalars, which are encoded in 5 bits, M : Rm.
15034 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
15035 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
15036 index in M. */
15037
15038static unsigned
15039neon_scalar_for_mul (unsigned scalar, unsigned elsize)
15040{
dcbf9037
JB
15041 unsigned regno = NEON_SCALAR_REG (scalar);
15042 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
15043
15044 switch (elsize)
15045 {
15046 case 16:
15047 if (regno > 7 || elno > 3)
477330fc 15048 goto bad_scalar;
5287ad62 15049 return regno | (elno << 3);
5f4273c7 15050
5287ad62
JB
15051 case 32:
15052 if (regno > 15 || elno > 1)
477330fc 15053 goto bad_scalar;
5287ad62
JB
15054 return regno | (elno << 4);
15055
15056 default:
15057 bad_scalar:
dcbf9037 15058 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
15059 }
15060
15061 return 0;
15062}
15063
15064/* Encode multiply / multiply-accumulate scalar instructions. */
15065
15066static void
15067neon_mul_mac (struct neon_type_el et, int ubit)
15068{
dcbf9037
JB
15069 unsigned scalar;
15070
15071 /* Give a more helpful error message if we have an invalid type. */
15072 if (et.type == NT_invtype)
15073 return;
5f4273c7 15074
dcbf9037 15075 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
15076 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15077 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15078 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15079 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15080 inst.instruction |= LOW4 (scalar);
15081 inst.instruction |= HI1 (scalar) << 5;
15082 inst.instruction |= (et.type == NT_float) << 8;
15083 inst.instruction |= neon_logbits (et.size) << 20;
15084 inst.instruction |= (ubit != 0) << 24;
15085
88714cb8 15086 neon_dp_fixup (&inst);
5287ad62
JB
15087}
15088
15089static void
15090do_neon_mac_maybe_scalar (void)
15091{
037e8744
JB
15092 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
15093 return;
15094
15095 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15096 return;
15097
5287ad62
JB
15098 if (inst.operands[2].isscalar)
15099 {
037e8744 15100 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15101 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 15102 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 15103 NEON_ENCODE (SCALAR, inst);
037e8744 15104 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15105 }
15106 else
428e3f1f
PB
15107 {
15108 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15109 affected if we specify unsigned args. */
15110 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15111 }
5287ad62
JB
15112}
15113
62f3b8c8
PB
15114static void
15115do_neon_fmac (void)
15116{
15117 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15118 return;
15119
15120 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15121 return;
15122
15123 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15124}
15125
5287ad62
JB
15126static void
15127do_neon_tst (void)
15128{
037e8744 15129 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15130 struct neon_type_el et = neon_check_type (3, rs,
15131 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 15132 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15133}
15134
15135/* VMUL with 3 registers allows the P8 type. The scalar version supports the
15136 same types as the MAC equivalents. The polynomial type for this instruction
15137 is encoded the same as the integer type. */
15138
15139static void
15140do_neon_mul (void)
15141{
037e8744
JB
15142 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
15143 return;
15144
15145 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15146 return;
15147
5287ad62
JB
15148 if (inst.operands[2].isscalar)
15149 do_neon_mac_maybe_scalar ();
15150 else
cc933301 15151 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
5287ad62
JB
15152}
15153
15154static void
15155do_neon_qdmulh (void)
15156{
15157 if (inst.operands[2].isscalar)
15158 {
037e8744 15159 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15160 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15161 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15162 NEON_ENCODE (SCALAR, inst);
037e8744 15163 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15164 }
15165 else
15166 {
037e8744 15167 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15168 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15169 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15170 NEON_ENCODE (INTEGER, inst);
5287ad62 15171 /* The U bit (rounding) comes from bit mask. */
037e8744 15172 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15173 }
15174}
15175
643afb90
MW
15176static void
15177do_neon_qrdmlah (void)
15178{
15179 /* Check we're on the correct architecture. */
15180 if (!mark_feature_used (&fpu_neon_ext_armv8))
15181 inst.error =
15182 _("instruction form not available on this architecture.");
15183 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15184 {
15185 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15186 record_feature_use (&fpu_neon_ext_v8_1);
15187 }
15188
15189 if (inst.operands[2].isscalar)
15190 {
15191 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15192 struct neon_type_el et = neon_check_type (3, rs,
15193 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15194 NEON_ENCODE (SCALAR, inst);
15195 neon_mul_mac (et, neon_quad (rs));
15196 }
15197 else
15198 {
15199 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15200 struct neon_type_el et = neon_check_type (3, rs,
15201 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15202 NEON_ENCODE (INTEGER, inst);
15203 /* The U bit (rounding) comes from bit mask. */
15204 neon_three_same (neon_quad (rs), 0, et.size);
15205 }
15206}
15207
5287ad62
JB
15208static void
15209do_neon_fcmp_absolute (void)
15210{
037e8744 15211 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15212 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15213 N_F_16_32 | N_KEY);
5287ad62 15214 /* Size field comes from bit mask. */
cc933301 15215 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15216}
15217
15218static void
15219do_neon_fcmp_absolute_inv (void)
15220{
15221 neon_exchange_operands ();
15222 do_neon_fcmp_absolute ();
15223}
15224
15225static void
15226do_neon_step (void)
15227{
037e8744 15228 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15229 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15230 N_F_16_32 | N_KEY);
15231 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15232}
15233
15234static void
15235do_neon_abs_neg (void)
15236{
037e8744
JB
15237 enum neon_shape rs;
15238 struct neon_type_el et;
5f4273c7 15239
037e8744
JB
15240 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15241 return;
15242
15243 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15244 return;
15245
15246 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 15247 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 15248
5287ad62
JB
15249 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15250 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15251 inst.instruction |= LOW4 (inst.operands[1].reg);
15252 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15253 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15254 inst.instruction |= (et.type == NT_float) << 10;
15255 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15256
88714cb8 15257 neon_dp_fixup (&inst);
5287ad62
JB
15258}
15259
15260static void
15261do_neon_sli (void)
15262{
037e8744 15263 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15264 struct neon_type_el et = neon_check_type (2, rs,
15265 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15266 int imm = inst.operands[2].imm;
15267 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15268 _("immediate out of range for insert"));
037e8744 15269 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15270}
15271
15272static void
15273do_neon_sri (void)
15274{
037e8744 15275 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15276 struct neon_type_el et = neon_check_type (2, rs,
15277 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15278 int imm = inst.operands[2].imm;
15279 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15280 _("immediate out of range for insert"));
037e8744 15281 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15282}
15283
15284static void
15285do_neon_qshlu_imm (void)
15286{
037e8744 15287 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15288 struct neon_type_el et = neon_check_type (2, rs,
15289 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15290 int imm = inst.operands[2].imm;
15291 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15292 _("immediate out of range for shift"));
5287ad62
JB
15293 /* Only encodes the 'U present' variant of the instruction.
15294 In this case, signed types have OP (bit 8) set to 0.
15295 Unsigned types have OP set to 1. */
15296 inst.instruction |= (et.type == NT_unsigned) << 8;
15297 /* The rest of the bits are the same as other immediate shifts. */
037e8744 15298 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15299}
15300
15301static void
15302do_neon_qmovn (void)
15303{
15304 struct neon_type_el et = neon_check_type (2, NS_DQ,
15305 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15306 /* Saturating move where operands can be signed or unsigned, and the
15307 destination has the same signedness. */
88714cb8 15308 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15309 if (et.type == NT_unsigned)
15310 inst.instruction |= 0xc0;
15311 else
15312 inst.instruction |= 0x80;
15313 neon_two_same (0, 1, et.size / 2);
15314}
15315
15316static void
15317do_neon_qmovun (void)
15318{
15319 struct neon_type_el et = neon_check_type (2, NS_DQ,
15320 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15321 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 15322 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15323 neon_two_same (0, 1, et.size / 2);
15324}
15325
15326static void
15327do_neon_rshift_sat_narrow (void)
15328{
15329 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15330 or unsigned. If operands are unsigned, results must also be unsigned. */
15331 struct neon_type_el et = neon_check_type (2, NS_DQI,
15332 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15333 int imm = inst.operands[2].imm;
15334 /* This gets the bounds check, size encoding and immediate bits calculation
15335 right. */
15336 et.size /= 2;
5f4273c7 15337
5287ad62
JB
15338 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15339 VQMOVN.I<size> <Dd>, <Qm>. */
15340 if (imm == 0)
15341 {
15342 inst.operands[2].present = 0;
15343 inst.instruction = N_MNEM_vqmovn;
15344 do_neon_qmovn ();
15345 return;
15346 }
5f4273c7 15347
5287ad62 15348 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15349 _("immediate out of range"));
5287ad62
JB
15350 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15351}
15352
15353static void
15354do_neon_rshift_sat_narrow_u (void)
15355{
15356 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15357 or unsigned. If operands are unsigned, results must also be unsigned. */
15358 struct neon_type_el et = neon_check_type (2, NS_DQI,
15359 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15360 int imm = inst.operands[2].imm;
15361 /* This gets the bounds check, size encoding and immediate bits calculation
15362 right. */
15363 et.size /= 2;
15364
15365 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15366 VQMOVUN.I<size> <Dd>, <Qm>. */
15367 if (imm == 0)
15368 {
15369 inst.operands[2].present = 0;
15370 inst.instruction = N_MNEM_vqmovun;
15371 do_neon_qmovun ();
15372 return;
15373 }
15374
15375 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15376 _("immediate out of range"));
5287ad62
JB
15377 /* FIXME: The manual is kind of unclear about what value U should have in
15378 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15379 must be 1. */
15380 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15381}
15382
15383static void
15384do_neon_movn (void)
15385{
15386 struct neon_type_el et = neon_check_type (2, NS_DQ,
15387 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15388 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15389 neon_two_same (0, 1, et.size / 2);
15390}
15391
15392static void
15393do_neon_rshift_narrow (void)
15394{
15395 struct neon_type_el et = neon_check_type (2, NS_DQI,
15396 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15397 int imm = inst.operands[2].imm;
15398 /* This gets the bounds check, size encoding and immediate bits calculation
15399 right. */
15400 et.size /= 2;
5f4273c7 15401
5287ad62
JB
15402 /* If immediate is zero then we are a pseudo-instruction for
15403 VMOVN.I<size> <Dd>, <Qm> */
15404 if (imm == 0)
15405 {
15406 inst.operands[2].present = 0;
15407 inst.instruction = N_MNEM_vmovn;
15408 do_neon_movn ();
15409 return;
15410 }
5f4273c7 15411
5287ad62 15412 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15413 _("immediate out of range for narrowing operation"));
5287ad62
JB
15414 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15415}
15416
15417static void
15418do_neon_shll (void)
15419{
15420 /* FIXME: Type checking when lengthening. */
15421 struct neon_type_el et = neon_check_type (2, NS_QDI,
15422 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15423 unsigned imm = inst.operands[2].imm;
15424
15425 if (imm == et.size)
15426 {
15427 /* Maximum shift variant. */
88714cb8 15428 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15429 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15430 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15431 inst.instruction |= LOW4 (inst.operands[1].reg);
15432 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15433 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15434
88714cb8 15435 neon_dp_fixup (&inst);
5287ad62
JB
15436 }
15437 else
15438 {
15439 /* A more-specific type check for non-max versions. */
15440 et = neon_check_type (2, NS_QDI,
477330fc 15441 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15442 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15443 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15444 }
15445}
15446
037e8744 15447/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15448 the current instruction is. */
15449
6b9a8b67
MGD
15450#define CVT_FLAVOUR_VAR \
15451 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15452 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15453 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15454 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15455 /* Half-precision conversions. */ \
cc933301
JW
15456 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15457 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15458 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
15459 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
15460 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15461 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
15462 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15463 Compared with single/double precision variants, only the co-processor \
15464 field is different, so the encoding flow is reused here. */ \
15465 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15466 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15467 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15468 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
15469 /* VFP instructions. */ \
15470 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15471 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15472 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15473 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15474 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15475 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15476 /* VFP instructions with bitshift. */ \
15477 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15478 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15479 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15480 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15481 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15482 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15483 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15484 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15485
15486#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15487 neon_cvt_flavour_##C,
15488
15489/* The different types of conversions we can do. */
15490enum neon_cvt_flavour
15491{
15492 CVT_FLAVOUR_VAR
15493 neon_cvt_flavour_invalid,
15494 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15495};
15496
15497#undef CVT_VAR
15498
15499static enum neon_cvt_flavour
15500get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15501{
6b9a8b67
MGD
15502#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15503 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15504 if (et.type != NT_invtype) \
15505 { \
15506 inst.error = NULL; \
15507 return (neon_cvt_flavour_##C); \
5287ad62 15508 }
6b9a8b67 15509
5287ad62 15510 struct neon_type_el et;
037e8744 15511 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15512 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15513 /* The instruction versions which take an immediate take one register
15514 argument, which is extended to the width of the full register. Thus the
15515 "source" and "destination" registers must have the same width. Hack that
15516 here by making the size equal to the key (wider, in this case) operand. */
15517 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15518
6b9a8b67
MGD
15519 CVT_FLAVOUR_VAR;
15520
15521 return neon_cvt_flavour_invalid;
5287ad62
JB
15522#undef CVT_VAR
15523}
15524
7e8e6784
MGD
15525enum neon_cvt_mode
15526{
15527 neon_cvt_mode_a,
15528 neon_cvt_mode_n,
15529 neon_cvt_mode_p,
15530 neon_cvt_mode_m,
15531 neon_cvt_mode_z,
30bdf752
MGD
15532 neon_cvt_mode_x,
15533 neon_cvt_mode_r
7e8e6784
MGD
15534};
15535
037e8744
JB
15536/* Neon-syntax VFP conversions. */
15537
5287ad62 15538static void
6b9a8b67 15539do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15540{
037e8744 15541 const char *opname = 0;
5f4273c7 15542
d54af2d0
RL
15543 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15544 || rs == NS_FHI || rs == NS_HFI)
5287ad62 15545 {
037e8744
JB
15546 /* Conversions with immediate bitshift. */
15547 const char *enc[] =
477330fc 15548 {
6b9a8b67
MGD
15549#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15550 CVT_FLAVOUR_VAR
15551 NULL
15552#undef CVT_VAR
477330fc 15553 };
037e8744 15554
6b9a8b67 15555 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15556 {
15557 opname = enc[flavour];
15558 constraint (inst.operands[0].reg != inst.operands[1].reg,
15559 _("operands 0 and 1 must be the same register"));
15560 inst.operands[1] = inst.operands[2];
15561 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15562 }
5287ad62
JB
15563 }
15564 else
15565 {
037e8744
JB
15566 /* Conversions without bitshift. */
15567 const char *enc[] =
477330fc 15568 {
6b9a8b67
MGD
15569#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15570 CVT_FLAVOUR_VAR
15571 NULL
15572#undef CVT_VAR
477330fc 15573 };
037e8744 15574
6b9a8b67 15575 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15576 opname = enc[flavour];
037e8744
JB
15577 }
15578
15579 if (opname)
15580 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
15581
15582 /* ARMv8.2 fp16 VCVT instruction. */
15583 if (flavour == neon_cvt_flavour_s32_f16
15584 || flavour == neon_cvt_flavour_u32_f16
15585 || flavour == neon_cvt_flavour_f16_u32
15586 || flavour == neon_cvt_flavour_f16_s32)
15587 do_scalar_fp16_v82_encode ();
037e8744
JB
15588}
15589
15590static void
15591do_vfp_nsyn_cvtz (void)
15592{
d54af2d0 15593 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 15594 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15595 const char *enc[] =
15596 {
6b9a8b67
MGD
15597#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15598 CVT_FLAVOUR_VAR
15599 NULL
15600#undef CVT_VAR
037e8744
JB
15601 };
15602
6b9a8b67 15603 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15604 do_vfp_nsyn_opcode (enc[flavour]);
15605}
f31fef98 15606
037e8744 15607static void
bacebabc 15608do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15609 enum neon_cvt_mode mode)
15610{
15611 int sz, op;
15612 int rm;
15613
a715796b
TG
15614 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15615 D register operands. */
15616 if (flavour == neon_cvt_flavour_s32_f64
15617 || flavour == neon_cvt_flavour_u32_f64)
15618 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15619 _(BAD_FPU));
15620
9db2f6b4
RL
15621 if (flavour == neon_cvt_flavour_s32_f16
15622 || flavour == neon_cvt_flavour_u32_f16)
15623 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15624 _(BAD_FP16));
15625
7e8e6784
MGD
15626 set_it_insn_type (OUTSIDE_IT_INSN);
15627
15628 switch (flavour)
15629 {
15630 case neon_cvt_flavour_s32_f64:
15631 sz = 1;
827f64ff 15632 op = 1;
7e8e6784
MGD
15633 break;
15634 case neon_cvt_flavour_s32_f32:
15635 sz = 0;
15636 op = 1;
15637 break;
9db2f6b4
RL
15638 case neon_cvt_flavour_s32_f16:
15639 sz = 0;
15640 op = 1;
15641 break;
7e8e6784
MGD
15642 case neon_cvt_flavour_u32_f64:
15643 sz = 1;
15644 op = 0;
15645 break;
15646 case neon_cvt_flavour_u32_f32:
15647 sz = 0;
15648 op = 0;
15649 break;
9db2f6b4
RL
15650 case neon_cvt_flavour_u32_f16:
15651 sz = 0;
15652 op = 0;
15653 break;
7e8e6784
MGD
15654 default:
15655 first_error (_("invalid instruction shape"));
15656 return;
15657 }
15658
15659 switch (mode)
15660 {
15661 case neon_cvt_mode_a: rm = 0; break;
15662 case neon_cvt_mode_n: rm = 1; break;
15663 case neon_cvt_mode_p: rm = 2; break;
15664 case neon_cvt_mode_m: rm = 3; break;
15665 default: first_error (_("invalid rounding mode")); return;
15666 }
15667
15668 NEON_ENCODE (FPV8, inst);
15669 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15670 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15671 inst.instruction |= sz << 8;
9db2f6b4
RL
15672
15673 /* ARMv8.2 fp16 VCVT instruction. */
15674 if (flavour == neon_cvt_flavour_s32_f16
15675 ||flavour == neon_cvt_flavour_u32_f16)
15676 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
15677 inst.instruction |= op << 7;
15678 inst.instruction |= rm << 16;
15679 inst.instruction |= 0xf0000000;
15680 inst.is_neon = TRUE;
15681}
15682
15683static void
15684do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15685{
15686 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
15687 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
15688 NS_FH, NS_HF, NS_FHI, NS_HFI,
15689 NS_NULL);
6b9a8b67 15690 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15691
cc933301
JW
15692 if (flavour == neon_cvt_flavour_invalid)
15693 return;
15694
e3e535bc 15695 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15696 if (mode == neon_cvt_mode_z
e3e535bc 15697 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
15698 && (flavour == neon_cvt_flavour_s16_f16
15699 || flavour == neon_cvt_flavour_u16_f16
15700 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
15701 || flavour == neon_cvt_flavour_u32_f32
15702 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15703 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15704 && (rs == NS_FD || rs == NS_FF))
15705 {
15706 do_vfp_nsyn_cvtz ();
15707 return;
15708 }
15709
9db2f6b4
RL
15710 /* ARMv8.2 fp16 VCVT conversions. */
15711 if (mode == neon_cvt_mode_z
15712 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
15713 && (flavour == neon_cvt_flavour_s32_f16
15714 || flavour == neon_cvt_flavour_u32_f16)
15715 && (rs == NS_FH))
15716 {
15717 do_vfp_nsyn_cvtz ();
15718 do_scalar_fp16_v82_encode ();
15719 return;
15720 }
15721
037e8744 15722 /* VFP rather than Neon conversions. */
6b9a8b67 15723 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15724 {
7e8e6784
MGD
15725 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15726 do_vfp_nsyn_cvt (rs, flavour);
15727 else
15728 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15729
037e8744
JB
15730 return;
15731 }
15732
15733 switch (rs)
15734 {
15735 case NS_DDI:
15736 case NS_QQI:
15737 {
477330fc 15738 unsigned immbits;
cc933301
JW
15739 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
15740 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 15741
477330fc
RM
15742 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15743 return;
037e8744 15744
477330fc
RM
15745 /* Fixed-point conversion with #0 immediate is encoded as an
15746 integer conversion. */
15747 if (inst.operands[2].present && inst.operands[2].imm == 0)
15748 goto int_encode;
477330fc
RM
15749 NEON_ENCODE (IMMED, inst);
15750 if (flavour != neon_cvt_flavour_invalid)
15751 inst.instruction |= enctab[flavour];
15752 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15753 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15754 inst.instruction |= LOW4 (inst.operands[1].reg);
15755 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15756 inst.instruction |= neon_quad (rs) << 6;
15757 inst.instruction |= 1 << 21;
cc933301
JW
15758 if (flavour < neon_cvt_flavour_s16_f16)
15759 {
15760 inst.instruction |= 1 << 21;
15761 immbits = 32 - inst.operands[2].imm;
15762 inst.instruction |= immbits << 16;
15763 }
15764 else
15765 {
15766 inst.instruction |= 3 << 20;
15767 immbits = 16 - inst.operands[2].imm;
15768 inst.instruction |= immbits << 16;
15769 inst.instruction &= ~(1 << 9);
15770 }
477330fc
RM
15771
15772 neon_dp_fixup (&inst);
037e8744
JB
15773 }
15774 break;
15775
15776 case NS_DD:
15777 case NS_QQ:
7e8e6784
MGD
15778 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15779 {
15780 NEON_ENCODE (FLOAT, inst);
15781 set_it_insn_type (OUTSIDE_IT_INSN);
15782
15783 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15784 return;
15785
15786 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15787 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15788 inst.instruction |= LOW4 (inst.operands[1].reg);
15789 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15790 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15791 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
15792 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 15793 inst.instruction |= mode << 8;
cc933301
JW
15794 if (flavour == neon_cvt_flavour_u16_f16
15795 || flavour == neon_cvt_flavour_s16_f16)
15796 /* Mask off the original size bits and reencode them. */
15797 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
15798
7e8e6784
MGD
15799 if (thumb_mode)
15800 inst.instruction |= 0xfc000000;
15801 else
15802 inst.instruction |= 0xf0000000;
15803 }
15804 else
15805 {
037e8744 15806 int_encode:
7e8e6784 15807 {
cc933301
JW
15808 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
15809 0x100, 0x180, 0x0, 0x080};
037e8744 15810
7e8e6784 15811 NEON_ENCODE (INTEGER, inst);
037e8744 15812
7e8e6784
MGD
15813 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15814 return;
037e8744 15815
7e8e6784
MGD
15816 if (flavour != neon_cvt_flavour_invalid)
15817 inst.instruction |= enctab[flavour];
037e8744 15818
7e8e6784
MGD
15819 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15820 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15821 inst.instruction |= LOW4 (inst.operands[1].reg);
15822 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15823 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15824 if (flavour >= neon_cvt_flavour_s16_f16
15825 && flavour <= neon_cvt_flavour_f16_u16)
15826 /* Half precision. */
15827 inst.instruction |= 1 << 18;
15828 else
15829 inst.instruction |= 2 << 18;
037e8744 15830
7e8e6784
MGD
15831 neon_dp_fixup (&inst);
15832 }
15833 }
15834 break;
037e8744 15835
8e79c3df
CM
15836 /* Half-precision conversions for Advanced SIMD -- neon. */
15837 case NS_QD:
15838 case NS_DQ:
15839
15840 if ((rs == NS_DQ)
15841 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15842 {
15843 as_bad (_("operand size must match register width"));
15844 break;
15845 }
15846
15847 if ((rs == NS_QD)
15848 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15849 {
15850 as_bad (_("operand size must match register width"));
15851 break;
15852 }
15853
15854 if (rs == NS_DQ)
477330fc 15855 inst.instruction = 0x3b60600;
8e79c3df
CM
15856 else
15857 inst.instruction = 0x3b60700;
15858
15859 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15860 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15861 inst.instruction |= LOW4 (inst.operands[1].reg);
15862 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15863 neon_dp_fixup (&inst);
8e79c3df
CM
15864 break;
15865
037e8744
JB
15866 default:
15867 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15868 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15869 do_vfp_nsyn_cvt (rs, flavour);
15870 else
15871 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15872 }
5287ad62
JB
15873}
15874
e3e535bc
NC
15875static void
15876do_neon_cvtr (void)
15877{
7e8e6784 15878 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15879}
15880
15881static void
15882do_neon_cvt (void)
15883{
7e8e6784
MGD
15884 do_neon_cvt_1 (neon_cvt_mode_z);
15885}
15886
15887static void
15888do_neon_cvta (void)
15889{
15890 do_neon_cvt_1 (neon_cvt_mode_a);
15891}
15892
15893static void
15894do_neon_cvtn (void)
15895{
15896 do_neon_cvt_1 (neon_cvt_mode_n);
15897}
15898
15899static void
15900do_neon_cvtp (void)
15901{
15902 do_neon_cvt_1 (neon_cvt_mode_p);
15903}
15904
15905static void
15906do_neon_cvtm (void)
15907{
15908 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15909}
15910
8e79c3df 15911static void
c70a8987 15912do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15913{
c70a8987
MGD
15914 if (is_double)
15915 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15916
c70a8987
MGD
15917 encode_arm_vfp_reg (inst.operands[0].reg,
15918 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15919 encode_arm_vfp_reg (inst.operands[1].reg,
15920 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15921 inst.instruction |= to ? 0x10000 : 0;
15922 inst.instruction |= t ? 0x80 : 0;
15923 inst.instruction |= is_double ? 0x100 : 0;
15924 do_vfp_cond_or_thumb ();
15925}
8e79c3df 15926
c70a8987
MGD
15927static void
15928do_neon_cvttb_1 (bfd_boolean t)
15929{
d54af2d0
RL
15930 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
15931 NS_DF, NS_DH, NS_NULL);
8e79c3df 15932
c70a8987
MGD
15933 if (rs == NS_NULL)
15934 return;
15935 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
15936 {
15937 inst.error = NULL;
15938 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
15939 }
15940 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
15941 {
15942 inst.error = NULL;
15943 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
15944 }
15945 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
15946 {
a715796b
TG
15947 /* The VCVTB and VCVTT instructions with D-register operands
15948 don't work for SP only targets. */
15949 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15950 _(BAD_FPU));
15951
c70a8987
MGD
15952 inst.error = NULL;
15953 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
15954 }
15955 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
15956 {
a715796b
TG
15957 /* The VCVTB and VCVTT instructions with D-register operands
15958 don't work for SP only targets. */
15959 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15960 _(BAD_FPU));
15961
c70a8987
MGD
15962 inst.error = NULL;
15963 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
15964 }
15965 else
15966 return;
15967}
15968
15969static void
15970do_neon_cvtb (void)
15971{
15972 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
15973}
15974
15975
15976static void
15977do_neon_cvtt (void)
15978{
c70a8987 15979 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
15980}
15981
5287ad62
JB
15982static void
15983neon_move_immediate (void)
15984{
037e8744
JB
15985 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
15986 struct neon_type_el et = neon_check_type (2, rs,
15987 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 15988 unsigned immlo, immhi = 0, immbits;
c96612cc 15989 int op, cmode, float_p;
5287ad62 15990
037e8744 15991 constraint (et.type == NT_invtype,
477330fc 15992 _("operand size must be specified for immediate VMOV"));
037e8744 15993
5287ad62
JB
15994 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
15995 op = (inst.instruction & (1 << 5)) != 0;
15996
15997 immlo = inst.operands[1].imm;
15998 if (inst.operands[1].regisimm)
15999 immhi = inst.operands[1].reg;
16000
16001 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 16002 _("immediate has bits set outside the operand size"));
5287ad62 16003
c96612cc
JB
16004 float_p = inst.operands[1].immisfloat;
16005
16006 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 16007 et.size, et.type)) == FAIL)
5287ad62
JB
16008 {
16009 /* Invert relevant bits only. */
16010 neon_invert_size (&immlo, &immhi, et.size);
16011 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
16012 with one or the other; those cases are caught by
16013 neon_cmode_for_move_imm. */
5287ad62 16014 op = !op;
c96612cc
JB
16015 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
16016 &op, et.size, et.type)) == FAIL)
477330fc
RM
16017 {
16018 first_error (_("immediate out of range"));
16019 return;
16020 }
5287ad62
JB
16021 }
16022
16023 inst.instruction &= ~(1 << 5);
16024 inst.instruction |= op << 5;
16025
16026 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16027 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 16028 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16029 inst.instruction |= cmode << 8;
16030
16031 neon_write_immbits (immbits);
16032}
16033
16034static void
16035do_neon_mvn (void)
16036{
16037 if (inst.operands[1].isreg)
16038 {
037e8744 16039 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 16040
88714cb8 16041 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16042 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16043 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16044 inst.instruction |= LOW4 (inst.operands[1].reg);
16045 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 16046 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16047 }
16048 else
16049 {
88714cb8 16050 NEON_ENCODE (IMMED, inst);
5287ad62
JB
16051 neon_move_immediate ();
16052 }
16053
88714cb8 16054 neon_dp_fixup (&inst);
5287ad62
JB
16055}
16056
16057/* Encode instructions of form:
16058
16059 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 16060 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
16061
16062static void
16063neon_mixed_length (struct neon_type_el et, unsigned size)
16064{
16065 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16066 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16067 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16068 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16069 inst.instruction |= LOW4 (inst.operands[2].reg);
16070 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16071 inst.instruction |= (et.type == NT_unsigned) << 24;
16072 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16073
88714cb8 16074 neon_dp_fixup (&inst);
5287ad62
JB
16075}
16076
16077static void
16078do_neon_dyadic_long (void)
16079{
16080 /* FIXME: Type checking for lengthening op. */
16081 struct neon_type_el et = neon_check_type (3, NS_QDD,
16082 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
16083 neon_mixed_length (et, et.size);
16084}
16085
16086static void
16087do_neon_abal (void)
16088{
16089 struct neon_type_el et = neon_check_type (3, NS_QDD,
16090 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16091 neon_mixed_length (et, et.size);
16092}
16093
16094static void
16095neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16096{
16097 if (inst.operands[2].isscalar)
16098 {
dcbf9037 16099 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 16100 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 16101 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16102 neon_mul_mac (et, et.type == NT_unsigned);
16103 }
16104 else
16105 {
16106 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16107 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 16108 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16109 neon_mixed_length (et, et.size);
16110 }
16111}
16112
16113static void
16114do_neon_mac_maybe_scalar_long (void)
16115{
16116 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16117}
16118
16119static void
16120do_neon_dyadic_wide (void)
16121{
16122 struct neon_type_el et = neon_check_type (3, NS_QQD,
16123 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
16124 neon_mixed_length (et, et.size);
16125}
16126
16127static void
16128do_neon_dyadic_narrow (void)
16129{
16130 struct neon_type_el et = neon_check_type (3, NS_QDD,
16131 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
16132 /* Operand sign is unimportant, and the U bit is part of the opcode,
16133 so force the operand type to integer. */
16134 et.type = NT_integer;
5287ad62
JB
16135 neon_mixed_length (et, et.size / 2);
16136}
16137
16138static void
16139do_neon_mul_sat_scalar_long (void)
16140{
16141 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
16142}
16143
16144static void
16145do_neon_vmull (void)
16146{
16147 if (inst.operands[2].isscalar)
16148 do_neon_mac_maybe_scalar_long ();
16149 else
16150 {
16151 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16152 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 16153
5287ad62 16154 if (et.type == NT_poly)
477330fc 16155 NEON_ENCODE (POLY, inst);
5287ad62 16156 else
477330fc 16157 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
16158
16159 /* For polynomial encoding the U bit must be zero, and the size must
16160 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
16161 obviously, as 0b10). */
16162 if (et.size == 64)
16163 {
16164 /* Check we're on the correct architecture. */
16165 if (!mark_feature_used (&fpu_crypto_ext_armv8))
16166 inst.error =
16167 _("Instruction form not available on this architecture.");
16168
16169 et.size = 32;
16170 }
16171
5287ad62
JB
16172 neon_mixed_length (et, et.size);
16173 }
16174}
16175
16176static void
16177do_neon_ext (void)
16178{
037e8744 16179 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
16180 struct neon_type_el et = neon_check_type (3, rs,
16181 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16182 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
16183
16184 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
16185 _("shift out of range"));
5287ad62
JB
16186 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16187 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16188 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16189 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16190 inst.instruction |= LOW4 (inst.operands[2].reg);
16191 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 16192 inst.instruction |= neon_quad (rs) << 6;
5287ad62 16193 inst.instruction |= imm << 8;
5f4273c7 16194
88714cb8 16195 neon_dp_fixup (&inst);
5287ad62
JB
16196}
16197
16198static void
16199do_neon_rev (void)
16200{
037e8744 16201 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16202 struct neon_type_el et = neon_check_type (2, rs,
16203 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16204 unsigned op = (inst.instruction >> 7) & 3;
16205 /* N (width of reversed regions) is encoded as part of the bitmask. We
16206 extract it here to check the elements to be reversed are smaller.
16207 Otherwise we'd get a reserved instruction. */
16208 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 16209 gas_assert (elsize != 0);
5287ad62 16210 constraint (et.size >= elsize,
477330fc 16211 _("elements must be smaller than reversal region"));
037e8744 16212 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16213}
16214
16215static void
16216do_neon_dup (void)
16217{
16218 if (inst.operands[1].isscalar)
16219 {
037e8744 16220 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 16221 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16222 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 16223 unsigned sizebits = et.size >> 3;
dcbf9037 16224 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 16225 int logsize = neon_logbits (et.size);
dcbf9037 16226 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
16227
16228 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 16229 return;
037e8744 16230
88714cb8 16231 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16232 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16233 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16234 inst.instruction |= LOW4 (dm);
16235 inst.instruction |= HI1 (dm) << 5;
037e8744 16236 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16237 inst.instruction |= x << 17;
16238 inst.instruction |= sizebits << 16;
5f4273c7 16239
88714cb8 16240 neon_dp_fixup (&inst);
5287ad62
JB
16241 }
16242 else
16243 {
037e8744
JB
16244 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16245 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16246 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 16247 /* Duplicate ARM register to lanes of vector. */
88714cb8 16248 NEON_ENCODE (ARMREG, inst);
5287ad62 16249 switch (et.size)
477330fc
RM
16250 {
16251 case 8: inst.instruction |= 0x400000; break;
16252 case 16: inst.instruction |= 0x000020; break;
16253 case 32: inst.instruction |= 0x000000; break;
16254 default: break;
16255 }
5287ad62
JB
16256 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16257 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16258 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 16259 inst.instruction |= neon_quad (rs) << 21;
5287ad62 16260 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 16261 variants, except for the condition field. */
037e8744 16262 do_vfp_cond_or_thumb ();
5287ad62
JB
16263 }
16264}
16265
16266/* VMOV has particularly many variations. It can be one of:
16267 0. VMOV<c><q> <Qd>, <Qm>
16268 1. VMOV<c><q> <Dd>, <Dm>
16269 (Register operations, which are VORR with Rm = Rn.)
16270 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16271 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16272 (Immediate loads.)
16273 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16274 (ARM register to scalar.)
16275 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16276 (Two ARM registers to vector.)
16277 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16278 (Scalar to ARM register.)
16279 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16280 (Vector to two ARM registers.)
037e8744
JB
16281 8. VMOV.F32 <Sd>, <Sm>
16282 9. VMOV.F64 <Dd>, <Dm>
16283 (VFP register moves.)
16284 10. VMOV.F32 <Sd>, #imm
16285 11. VMOV.F64 <Dd>, #imm
16286 (VFP float immediate load.)
16287 12. VMOV <Rd>, <Sm>
16288 (VFP single to ARM reg.)
16289 13. VMOV <Sd>, <Rm>
16290 (ARM reg to VFP single.)
16291 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16292 (Two ARM regs to two VFP singles.)
16293 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16294 (Two VFP singles to two ARM regs.)
5f4273c7 16295
037e8744
JB
16296 These cases can be disambiguated using neon_select_shape, except cases 1/9
16297 and 3/11 which depend on the operand type too.
5f4273c7 16298
5287ad62 16299 All the encoded bits are hardcoded by this function.
5f4273c7 16300
b7fc2769
JB
16301 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16302 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 16303
5287ad62 16304 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 16305 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
16306
16307static void
16308do_neon_mov (void)
16309{
037e8744 16310 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
16311 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16312 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16313 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
16314 struct neon_type_el et;
16315 const char *ldconst = 0;
5287ad62 16316
037e8744 16317 switch (rs)
5287ad62 16318 {
037e8744
JB
16319 case NS_DD: /* case 1/9. */
16320 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16321 /* It is not an error here if no type is given. */
16322 inst.error = NULL;
16323 if (et.type == NT_float && et.size == 64)
477330fc
RM
16324 {
16325 do_vfp_nsyn_opcode ("fcpyd");
16326 break;
16327 }
037e8744 16328 /* fall through. */
5287ad62 16329
037e8744
JB
16330 case NS_QQ: /* case 0/1. */
16331 {
477330fc
RM
16332 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16333 return;
16334 /* The architecture manual I have doesn't explicitly state which
16335 value the U bit should have for register->register moves, but
16336 the equivalent VORR instruction has U = 0, so do that. */
16337 inst.instruction = 0x0200110;
16338 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16339 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16340 inst.instruction |= LOW4 (inst.operands[1].reg);
16341 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16342 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16343 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16344 inst.instruction |= neon_quad (rs) << 6;
16345
16346 neon_dp_fixup (&inst);
037e8744
JB
16347 }
16348 break;
5f4273c7 16349
037e8744
JB
16350 case NS_DI: /* case 3/11. */
16351 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16352 inst.error = NULL;
16353 if (et.type == NT_float && et.size == 64)
477330fc
RM
16354 {
16355 /* case 11 (fconstd). */
16356 ldconst = "fconstd";
16357 goto encode_fconstd;
16358 }
037e8744
JB
16359 /* fall through. */
16360
16361 case NS_QI: /* case 2/3. */
16362 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 16363 return;
037e8744
JB
16364 inst.instruction = 0x0800010;
16365 neon_move_immediate ();
88714cb8 16366 neon_dp_fixup (&inst);
5287ad62 16367 break;
5f4273c7 16368
037e8744
JB
16369 case NS_SR: /* case 4. */
16370 {
477330fc
RM
16371 unsigned bcdebits = 0;
16372 int logsize;
16373 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16374 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 16375
05ac0ffb
JB
16376 /* .<size> is optional here, defaulting to .32. */
16377 if (inst.vectype.elems == 0
16378 && inst.operands[0].vectype.type == NT_invtype
16379 && inst.operands[1].vectype.type == NT_invtype)
16380 {
16381 inst.vectype.el[0].type = NT_untyped;
16382 inst.vectype.el[0].size = 32;
16383 inst.vectype.elems = 1;
16384 }
16385
477330fc
RM
16386 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16387 logsize = neon_logbits (et.size);
16388
16389 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16390 _(BAD_FPU));
16391 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16392 && et.size != 32, _(BAD_FPU));
16393 constraint (et.type == NT_invtype, _("bad type for scalar"));
16394 constraint (x >= 64 / et.size, _("scalar index out of range"));
16395
16396 switch (et.size)
16397 {
16398 case 8: bcdebits = 0x8; break;
16399 case 16: bcdebits = 0x1; break;
16400 case 32: bcdebits = 0x0; break;
16401 default: ;
16402 }
16403
16404 bcdebits |= x << logsize;
16405
16406 inst.instruction = 0xe000b10;
16407 do_vfp_cond_or_thumb ();
16408 inst.instruction |= LOW4 (dn) << 16;
16409 inst.instruction |= HI1 (dn) << 7;
16410 inst.instruction |= inst.operands[1].reg << 12;
16411 inst.instruction |= (bcdebits & 3) << 5;
16412 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
16413 }
16414 break;
5f4273c7 16415
037e8744 16416 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 16417 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16418 _(BAD_FPU));
b7fc2769 16419
037e8744
JB
16420 inst.instruction = 0xc400b10;
16421 do_vfp_cond_or_thumb ();
16422 inst.instruction |= LOW4 (inst.operands[0].reg);
16423 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16424 inst.instruction |= inst.operands[1].reg << 12;
16425 inst.instruction |= inst.operands[2].reg << 16;
16426 break;
5f4273c7 16427
037e8744
JB
16428 case NS_RS: /* case 6. */
16429 {
477330fc
RM
16430 unsigned logsize;
16431 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16432 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16433 unsigned abcdebits = 0;
037e8744 16434
05ac0ffb
JB
16435 /* .<dt> is optional here, defaulting to .32. */
16436 if (inst.vectype.elems == 0
16437 && inst.operands[0].vectype.type == NT_invtype
16438 && inst.operands[1].vectype.type == NT_invtype)
16439 {
16440 inst.vectype.el[0].type = NT_untyped;
16441 inst.vectype.el[0].size = 32;
16442 inst.vectype.elems = 1;
16443 }
16444
91d6fa6a
NC
16445 et = neon_check_type (2, NS_NULL,
16446 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
16447 logsize = neon_logbits (et.size);
16448
16449 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16450 _(BAD_FPU));
16451 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16452 && et.size != 32, _(BAD_FPU));
16453 constraint (et.type == NT_invtype, _("bad type for scalar"));
16454 constraint (x >= 64 / et.size, _("scalar index out of range"));
16455
16456 switch (et.size)
16457 {
16458 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16459 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16460 case 32: abcdebits = 0x00; break;
16461 default: ;
16462 }
16463
16464 abcdebits |= x << logsize;
16465 inst.instruction = 0xe100b10;
16466 do_vfp_cond_or_thumb ();
16467 inst.instruction |= LOW4 (dn) << 16;
16468 inst.instruction |= HI1 (dn) << 7;
16469 inst.instruction |= inst.operands[0].reg << 12;
16470 inst.instruction |= (abcdebits & 3) << 5;
16471 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16472 }
16473 break;
5f4273c7 16474
037e8744
JB
16475 case NS_RRD: /* case 7 (fmrrd). */
16476 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16477 _(BAD_FPU));
037e8744
JB
16478
16479 inst.instruction = 0xc500b10;
16480 do_vfp_cond_or_thumb ();
16481 inst.instruction |= inst.operands[0].reg << 12;
16482 inst.instruction |= inst.operands[1].reg << 16;
16483 inst.instruction |= LOW4 (inst.operands[2].reg);
16484 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16485 break;
5f4273c7 16486
037e8744
JB
16487 case NS_FF: /* case 8 (fcpys). */
16488 do_vfp_nsyn_opcode ("fcpys");
16489 break;
5f4273c7 16490
9db2f6b4 16491 case NS_HI:
037e8744
JB
16492 case NS_FI: /* case 10 (fconsts). */
16493 ldconst = "fconsts";
16494 encode_fconstd:
16495 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16496 {
16497 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16498 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
16499
16500 /* ARMv8.2 fp16 vmov.f16 instruction. */
16501 if (rs == NS_HI)
16502 do_scalar_fp16_v82_encode ();
477330fc 16503 }
5287ad62 16504 else
477330fc 16505 first_error (_("immediate out of range"));
037e8744 16506 break;
5f4273c7 16507
9db2f6b4 16508 case NS_RH:
037e8744
JB
16509 case NS_RF: /* case 12 (fmrs). */
16510 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
16511 /* ARMv8.2 fp16 vmov.f16 instruction. */
16512 if (rs == NS_RH)
16513 do_scalar_fp16_v82_encode ();
037e8744 16514 break;
5f4273c7 16515
9db2f6b4 16516 case NS_HR:
037e8744
JB
16517 case NS_FR: /* case 13 (fmsr). */
16518 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
16519 /* ARMv8.2 fp16 vmov.f16 instruction. */
16520 if (rs == NS_HR)
16521 do_scalar_fp16_v82_encode ();
037e8744 16522 break;
5f4273c7 16523
037e8744
JB
16524 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16525 (one of which is a list), but we have parsed four. Do some fiddling to
16526 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16527 expect. */
16528 case NS_RRFF: /* case 14 (fmrrs). */
16529 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16530 _("VFP registers must be adjacent"));
037e8744
JB
16531 inst.operands[2].imm = 2;
16532 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16533 do_vfp_nsyn_opcode ("fmrrs");
16534 break;
5f4273c7 16535
037e8744
JB
16536 case NS_FFRR: /* case 15 (fmsrr). */
16537 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16538 _("VFP registers must be adjacent"));
037e8744
JB
16539 inst.operands[1] = inst.operands[2];
16540 inst.operands[2] = inst.operands[3];
16541 inst.operands[0].imm = 2;
16542 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16543 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16544 break;
5f4273c7 16545
4c261dff
NC
16546 case NS_NULL:
16547 /* neon_select_shape has determined that the instruction
16548 shape is wrong and has already set the error message. */
16549 break;
16550
5287ad62
JB
16551 default:
16552 abort ();
16553 }
16554}
16555
16556static void
16557do_neon_rshift_round_imm (void)
16558{
037e8744 16559 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16560 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16561 int imm = inst.operands[2].imm;
16562
16563 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16564 if (imm == 0)
16565 {
16566 inst.operands[2].present = 0;
16567 do_neon_mov ();
16568 return;
16569 }
16570
16571 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16572 _("immediate out of range for shift"));
037e8744 16573 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16574 et.size - imm);
5287ad62
JB
16575}
16576
9db2f6b4
RL
16577static void
16578do_neon_movhf (void)
16579{
16580 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
16581 constraint (rs != NS_HH, _("invalid suffix"));
16582
16583 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16584 _(BAD_FPU));
16585
16586 do_vfp_sp_monadic ();
16587
16588 inst.is_neon = 1;
16589 inst.instruction |= 0xf0000000;
16590}
16591
5287ad62
JB
16592static void
16593do_neon_movl (void)
16594{
16595 struct neon_type_el et = neon_check_type (2, NS_QD,
16596 N_EQK | N_DBL, N_SU_32 | N_KEY);
16597 unsigned sizebits = et.size >> 3;
16598 inst.instruction |= sizebits << 19;
16599 neon_two_same (0, et.type == NT_unsigned, -1);
16600}
16601
16602static void
16603do_neon_trn (void)
16604{
037e8744 16605 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16606 struct neon_type_el et = neon_check_type (2, rs,
16607 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16608 NEON_ENCODE (INTEGER, inst);
037e8744 16609 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16610}
16611
16612static void
16613do_neon_zip_uzp (void)
16614{
037e8744 16615 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16616 struct neon_type_el et = neon_check_type (2, rs,
16617 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16618 if (rs == NS_DD && et.size == 32)
16619 {
16620 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16621 inst.instruction = N_MNEM_vtrn;
16622 do_neon_trn ();
16623 return;
16624 }
037e8744 16625 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16626}
16627
16628static void
16629do_neon_sat_abs_neg (void)
16630{
037e8744 16631 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16632 struct neon_type_el et = neon_check_type (2, rs,
16633 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16634 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16635}
16636
16637static void
16638do_neon_pair_long (void)
16639{
037e8744 16640 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16641 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16642 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16643 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16644 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16645}
16646
16647static void
16648do_neon_recip_est (void)
16649{
037e8744 16650 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 16651 struct neon_type_el et = neon_check_type (2, rs,
cc933301 16652 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 16653 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16654 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16655}
16656
16657static void
16658do_neon_cls (void)
16659{
037e8744 16660 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16661 struct neon_type_el et = neon_check_type (2, rs,
16662 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16663 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16664}
16665
16666static void
16667do_neon_clz (void)
16668{
037e8744 16669 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16670 struct neon_type_el et = neon_check_type (2, rs,
16671 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16672 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16673}
16674
16675static void
16676do_neon_cnt (void)
16677{
037e8744 16678 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16679 struct neon_type_el et = neon_check_type (2, rs,
16680 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16681 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16682}
16683
16684static void
16685do_neon_swp (void)
16686{
037e8744
JB
16687 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16688 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16689}
16690
16691static void
16692do_neon_tbl_tbx (void)
16693{
16694 unsigned listlenbits;
dcbf9037 16695 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16696
5287ad62
JB
16697 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16698 {
dcbf9037 16699 first_error (_("bad list length for table lookup"));
5287ad62
JB
16700 return;
16701 }
5f4273c7 16702
5287ad62
JB
16703 listlenbits = inst.operands[1].imm - 1;
16704 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16705 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16706 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16707 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16708 inst.instruction |= LOW4 (inst.operands[2].reg);
16709 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16710 inst.instruction |= listlenbits << 8;
5f4273c7 16711
88714cb8 16712 neon_dp_fixup (&inst);
5287ad62
JB
16713}
16714
16715static void
16716do_neon_ldm_stm (void)
16717{
16718 /* P, U and L bits are part of bitmask. */
16719 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16720 unsigned offsetbits = inst.operands[1].imm * 2;
16721
037e8744
JB
16722 if (inst.operands[1].issingle)
16723 {
16724 do_vfp_nsyn_ldm_stm (is_dbmode);
16725 return;
16726 }
16727
5287ad62 16728 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16729 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16730
16731 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16732 _("register list must contain at least 1 and at most 16 "
16733 "registers"));
5287ad62
JB
16734
16735 inst.instruction |= inst.operands[0].reg << 16;
16736 inst.instruction |= inst.operands[0].writeback << 21;
16737 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16738 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16739
16740 inst.instruction |= offsetbits;
5f4273c7 16741
037e8744 16742 do_vfp_cond_or_thumb ();
5287ad62
JB
16743}
16744
16745static void
16746do_neon_ldr_str (void)
16747{
5287ad62 16748 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16749
6844b2c2
MGD
16750 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16751 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16752 if (!is_ldr
6844b2c2 16753 && inst.operands[1].reg == REG_PC
ba86b375 16754 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16755 {
94dcf8bf 16756 if (thumb_mode)
6844b2c2 16757 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 16758 else if (warn_on_deprecated)
5c3696f8 16759 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
16760 }
16761
037e8744
JB
16762 if (inst.operands[0].issingle)
16763 {
cd2f129f 16764 if (is_ldr)
477330fc 16765 do_vfp_nsyn_opcode ("flds");
cd2f129f 16766 else
477330fc 16767 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
16768
16769 /* ARMv8.2 vldr.16/vstr.16 instruction. */
16770 if (inst.vectype.el[0].size == 16)
16771 do_scalar_fp16_v82_encode ();
5287ad62
JB
16772 }
16773 else
5287ad62 16774 {
cd2f129f 16775 if (is_ldr)
477330fc 16776 do_vfp_nsyn_opcode ("fldd");
5287ad62 16777 else
477330fc 16778 do_vfp_nsyn_opcode ("fstd");
5287ad62 16779 }
5287ad62
JB
16780}
16781
16782/* "interleave" version also handles non-interleaving register VLD1/VST1
16783 instructions. */
16784
16785static void
16786do_neon_ld_st_interleave (void)
16787{
037e8744 16788 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 16789 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
16790 unsigned alignbits = 0;
16791 unsigned idx;
16792 /* The bits in this table go:
16793 0: register stride of one (0) or two (1)
16794 1,2: register list length, minus one (1, 2, 3, 4).
16795 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
16796 We use -1 for invalid entries. */
16797 const int typetable[] =
16798 {
16799 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
16800 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
16801 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
16802 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
16803 };
16804 int typebits;
16805
dcbf9037
JB
16806 if (et.type == NT_invtype)
16807 return;
16808
5287ad62
JB
16809 if (inst.operands[1].immisalign)
16810 switch (inst.operands[1].imm >> 8)
16811 {
16812 case 64: alignbits = 1; break;
16813 case 128:
477330fc 16814 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 16815 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
16816 goto bad_alignment;
16817 alignbits = 2;
16818 break;
5287ad62 16819 case 256:
477330fc
RM
16820 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
16821 goto bad_alignment;
16822 alignbits = 3;
16823 break;
5287ad62
JB
16824 default:
16825 bad_alignment:
477330fc
RM
16826 first_error (_("bad alignment"));
16827 return;
5287ad62
JB
16828 }
16829
16830 inst.instruction |= alignbits << 4;
16831 inst.instruction |= neon_logbits (et.size) << 6;
16832
16833 /* Bits [4:6] of the immediate in a list specifier encode register stride
16834 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
16835 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
16836 up the right value for "type" in a table based on this value and the given
16837 list style, then stick it back. */
16838 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 16839 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
16840
16841 typebits = typetable[idx];
5f4273c7 16842
5287ad62 16843 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
16844 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
16845 _("bad element type for instruction"));
5287ad62
JB
16846
16847 inst.instruction &= ~0xf00;
16848 inst.instruction |= typebits << 8;
16849}
16850
16851/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
16852 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
16853 otherwise. The variable arguments are a list of pairs of legal (size, align)
16854 values, terminated with -1. */
16855
16856static int
aa8a0863 16857neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
16858{
16859 va_list ap;
16860 int result = FAIL, thissize, thisalign;
5f4273c7 16861
5287ad62
JB
16862 if (!inst.operands[1].immisalign)
16863 {
aa8a0863 16864 *do_alignment = 0;
5287ad62
JB
16865 return SUCCESS;
16866 }
5f4273c7 16867
aa8a0863 16868 va_start (ap, do_alignment);
5287ad62
JB
16869
16870 do
16871 {
16872 thissize = va_arg (ap, int);
16873 if (thissize == -1)
477330fc 16874 break;
5287ad62
JB
16875 thisalign = va_arg (ap, int);
16876
16877 if (size == thissize && align == thisalign)
477330fc 16878 result = SUCCESS;
5287ad62
JB
16879 }
16880 while (result != SUCCESS);
16881
16882 va_end (ap);
16883
16884 if (result == SUCCESS)
aa8a0863 16885 *do_alignment = 1;
5287ad62 16886 else
dcbf9037 16887 first_error (_("unsupported alignment for instruction"));
5f4273c7 16888
5287ad62
JB
16889 return result;
16890}
16891
16892static void
16893do_neon_ld_st_lane (void)
16894{
037e8744 16895 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16896 int align_good, do_alignment = 0;
5287ad62
JB
16897 int logsize = neon_logbits (et.size);
16898 int align = inst.operands[1].imm >> 8;
16899 int n = (inst.instruction >> 8) & 3;
16900 int max_el = 64 / et.size;
5f4273c7 16901
dcbf9037
JB
16902 if (et.type == NT_invtype)
16903 return;
5f4273c7 16904
5287ad62 16905 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 16906 _("bad list length"));
5287ad62 16907 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 16908 _("scalar index out of range"));
5287ad62 16909 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
16910 && et.size == 8,
16911 _("stride of 2 unavailable when element size is 8"));
5f4273c7 16912
5287ad62
JB
16913 switch (n)
16914 {
16915 case 0: /* VLD1 / VST1. */
aa8a0863 16916 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 16917 32, 32, -1);
5287ad62 16918 if (align_good == FAIL)
477330fc 16919 return;
aa8a0863 16920 if (do_alignment)
477330fc
RM
16921 {
16922 unsigned alignbits = 0;
16923 switch (et.size)
16924 {
16925 case 16: alignbits = 0x1; break;
16926 case 32: alignbits = 0x3; break;
16927 default: ;
16928 }
16929 inst.instruction |= alignbits << 4;
16930 }
5287ad62
JB
16931 break;
16932
16933 case 1: /* VLD2 / VST2. */
aa8a0863
TS
16934 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
16935 16, 32, 32, 64, -1);
5287ad62 16936 if (align_good == FAIL)
477330fc 16937 return;
aa8a0863 16938 if (do_alignment)
477330fc 16939 inst.instruction |= 1 << 4;
5287ad62
JB
16940 break;
16941
16942 case 2: /* VLD3 / VST3. */
16943 constraint (inst.operands[1].immisalign,
477330fc 16944 _("can't use alignment with this instruction"));
5287ad62
JB
16945 break;
16946
16947 case 3: /* VLD4 / VST4. */
aa8a0863 16948 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 16949 16, 64, 32, 64, 32, 128, -1);
5287ad62 16950 if (align_good == FAIL)
477330fc 16951 return;
aa8a0863 16952 if (do_alignment)
477330fc
RM
16953 {
16954 unsigned alignbits = 0;
16955 switch (et.size)
16956 {
16957 case 8: alignbits = 0x1; break;
16958 case 16: alignbits = 0x1; break;
16959 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
16960 default: ;
16961 }
16962 inst.instruction |= alignbits << 4;
16963 }
5287ad62
JB
16964 break;
16965
16966 default: ;
16967 }
16968
16969 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
16970 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16971 inst.instruction |= 1 << (4 + logsize);
5f4273c7 16972
5287ad62
JB
16973 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
16974 inst.instruction |= logsize << 10;
16975}
16976
16977/* Encode single n-element structure to all lanes VLD<n> instructions. */
16978
16979static void
16980do_neon_ld_dup (void)
16981{
037e8744 16982 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16983 int align_good, do_alignment = 0;
5287ad62 16984
dcbf9037
JB
16985 if (et.type == NT_invtype)
16986 return;
16987
5287ad62
JB
16988 switch ((inst.instruction >> 8) & 3)
16989 {
16990 case 0: /* VLD1. */
9c2799c2 16991 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 16992 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 16993 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 16994 if (align_good == FAIL)
477330fc 16995 return;
5287ad62 16996 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
16997 {
16998 case 1: break;
16999 case 2: inst.instruction |= 1 << 5; break;
17000 default: first_error (_("bad list length")); return;
17001 }
5287ad62
JB
17002 inst.instruction |= neon_logbits (et.size) << 6;
17003 break;
17004
17005 case 1: /* VLD2. */
17006 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
17007 &do_alignment, 8, 16, 16, 32, 32, 64,
17008 -1);
5287ad62 17009 if (align_good == FAIL)
477330fc 17010 return;
5287ad62 17011 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 17012 _("bad list length"));
5287ad62 17013 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17014 inst.instruction |= 1 << 5;
5287ad62
JB
17015 inst.instruction |= neon_logbits (et.size) << 6;
17016 break;
17017
17018 case 2: /* VLD3. */
17019 constraint (inst.operands[1].immisalign,
477330fc 17020 _("can't use alignment with this instruction"));
5287ad62 17021 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 17022 _("bad list length"));
5287ad62 17023 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 17024 inst.instruction |= 1 << 5;
5287ad62
JB
17025 inst.instruction |= neon_logbits (et.size) << 6;
17026 break;
17027
17028 case 3: /* VLD4. */
17029 {
477330fc 17030 int align = inst.operands[1].imm >> 8;
aa8a0863 17031 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
17032 16, 64, 32, 64, 32, 128, -1);
17033 if (align_good == FAIL)
17034 return;
17035 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
17036 _("bad list length"));
17037 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17038 inst.instruction |= 1 << 5;
17039 if (et.size == 32 && align == 128)
17040 inst.instruction |= 0x3 << 6;
17041 else
17042 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
17043 }
17044 break;
17045
17046 default: ;
17047 }
17048
aa8a0863 17049 inst.instruction |= do_alignment << 4;
5287ad62
JB
17050}
17051
17052/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
17053 apart from bits [11:4]. */
17054
17055static void
17056do_neon_ldx_stx (void)
17057{
b1a769ed
DG
17058 if (inst.operands[1].isreg)
17059 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
17060
5287ad62
JB
17061 switch (NEON_LANE (inst.operands[0].imm))
17062 {
17063 case NEON_INTERLEAVE_LANES:
88714cb8 17064 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
17065 do_neon_ld_st_interleave ();
17066 break;
5f4273c7 17067
5287ad62 17068 case NEON_ALL_LANES:
88714cb8 17069 NEON_ENCODE (DUP, inst);
2d51fb74
JB
17070 if (inst.instruction == N_INV)
17071 {
17072 first_error ("only loads support such operands");
17073 break;
17074 }
5287ad62
JB
17075 do_neon_ld_dup ();
17076 break;
5f4273c7 17077
5287ad62 17078 default:
88714cb8 17079 NEON_ENCODE (LANE, inst);
5287ad62
JB
17080 do_neon_ld_st_lane ();
17081 }
17082
17083 /* L bit comes from bit mask. */
17084 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17085 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17086 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 17087
5287ad62
JB
17088 if (inst.operands[1].postind)
17089 {
17090 int postreg = inst.operands[1].imm & 0xf;
17091 constraint (!inst.operands[1].immisreg,
477330fc 17092 _("post-index must be a register"));
5287ad62 17093 constraint (postreg == 0xd || postreg == 0xf,
477330fc 17094 _("bad register for post-index"));
5287ad62
JB
17095 inst.instruction |= postreg;
17096 }
4f2374c7 17097 else
5287ad62 17098 {
4f2374c7
WN
17099 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17100 constraint (inst.reloc.exp.X_op != O_constant
17101 || inst.reloc.exp.X_add_number != 0,
17102 BAD_ADDR_MODE);
17103
17104 if (inst.operands[1].writeback)
17105 {
17106 inst.instruction |= 0xd;
17107 }
17108 else
17109 inst.instruction |= 0xf;
5287ad62 17110 }
5f4273c7 17111
5287ad62
JB
17112 if (thumb_mode)
17113 inst.instruction |= 0xf9000000;
17114 else
17115 inst.instruction |= 0xf4000000;
17116}
33399f07
MGD
17117
17118/* FP v8. */
17119static void
17120do_vfp_nsyn_fpv8 (enum neon_shape rs)
17121{
a715796b
TG
17122 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17123 D register operands. */
17124 if (neon_shape_class[rs] == SC_DOUBLE)
17125 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17126 _(BAD_FPU));
17127
33399f07
MGD
17128 NEON_ENCODE (FPV8, inst);
17129
9db2f6b4
RL
17130 if (rs == NS_FFF || rs == NS_HHH)
17131 {
17132 do_vfp_sp_dyadic ();
17133
17134 /* ARMv8.2 fp16 instruction. */
17135 if (rs == NS_HHH)
17136 do_scalar_fp16_v82_encode ();
17137 }
33399f07
MGD
17138 else
17139 do_vfp_dp_rd_rn_rm ();
17140
17141 if (rs == NS_DDD)
17142 inst.instruction |= 0x100;
17143
17144 inst.instruction |= 0xf0000000;
17145}
17146
17147static void
17148do_vsel (void)
17149{
17150 set_it_insn_type (OUTSIDE_IT_INSN);
17151
17152 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
17153 first_error (_("invalid instruction shape"));
17154}
17155
73924fbc
MGD
17156static void
17157do_vmaxnm (void)
17158{
17159 set_it_insn_type (OUTSIDE_IT_INSN);
17160
17161 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
17162 return;
17163
17164 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17165 return;
17166
cc933301 17167 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
17168}
17169
30bdf752
MGD
17170static void
17171do_vrint_1 (enum neon_cvt_mode mode)
17172{
9db2f6b4 17173 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
17174 struct neon_type_el et;
17175
17176 if (rs == NS_NULL)
17177 return;
17178
a715796b
TG
17179 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17180 D register operands. */
17181 if (neon_shape_class[rs] == SC_DOUBLE)
17182 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17183 _(BAD_FPU));
17184
9db2f6b4
RL
17185 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
17186 | N_VFP);
30bdf752
MGD
17187 if (et.type != NT_invtype)
17188 {
17189 /* VFP encodings. */
17190 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
17191 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
17192 set_it_insn_type (OUTSIDE_IT_INSN);
17193
17194 NEON_ENCODE (FPV8, inst);
9db2f6b4 17195 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
17196 do_vfp_sp_monadic ();
17197 else
17198 do_vfp_dp_rd_rm ();
17199
17200 switch (mode)
17201 {
17202 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
17203 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
17204 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
17205 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
17206 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
17207 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
17208 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
17209 default: abort ();
17210 }
17211
17212 inst.instruction |= (rs == NS_DD) << 8;
17213 do_vfp_cond_or_thumb ();
9db2f6b4
RL
17214
17215 /* ARMv8.2 fp16 vrint instruction. */
17216 if (rs == NS_HH)
17217 do_scalar_fp16_v82_encode ();
30bdf752
MGD
17218 }
17219 else
17220 {
17221 /* Neon encodings (or something broken...). */
17222 inst.error = NULL;
cc933301 17223 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
17224
17225 if (et.type == NT_invtype)
17226 return;
17227
17228 set_it_insn_type (OUTSIDE_IT_INSN);
17229 NEON_ENCODE (FLOAT, inst);
17230
17231 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17232 return;
17233
17234 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17235 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17236 inst.instruction |= LOW4 (inst.operands[1].reg);
17237 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17238 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
17239 /* Mask off the original size bits and reencode them. */
17240 inst.instruction = ((inst.instruction & 0xfff3ffff)
17241 | neon_logbits (et.size) << 18);
17242
30bdf752
MGD
17243 switch (mode)
17244 {
17245 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17246 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17247 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17248 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17249 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17250 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17251 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17252 default: abort ();
17253 }
17254
17255 if (thumb_mode)
17256 inst.instruction |= 0xfc000000;
17257 else
17258 inst.instruction |= 0xf0000000;
17259 }
17260}
17261
17262static void
17263do_vrintx (void)
17264{
17265 do_vrint_1 (neon_cvt_mode_x);
17266}
17267
17268static void
17269do_vrintz (void)
17270{
17271 do_vrint_1 (neon_cvt_mode_z);
17272}
17273
17274static void
17275do_vrintr (void)
17276{
17277 do_vrint_1 (neon_cvt_mode_r);
17278}
17279
17280static void
17281do_vrinta (void)
17282{
17283 do_vrint_1 (neon_cvt_mode_a);
17284}
17285
17286static void
17287do_vrintn (void)
17288{
17289 do_vrint_1 (neon_cvt_mode_n);
17290}
17291
17292static void
17293do_vrintp (void)
17294{
17295 do_vrint_1 (neon_cvt_mode_p);
17296}
17297
17298static void
17299do_vrintm (void)
17300{
17301 do_vrint_1 (neon_cvt_mode_m);
17302}
17303
c28eeff2
SN
17304static unsigned
17305neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
17306{
17307 unsigned regno = NEON_SCALAR_REG (opnd);
17308 unsigned elno = NEON_SCALAR_INDEX (opnd);
17309
17310 if (elsize == 16 && elno < 2 && regno < 16)
17311 return regno | (elno << 4);
17312 else if (elsize == 32 && elno == 0)
17313 return regno;
17314
17315 first_error (_("scalar out of range"));
17316 return 0;
17317}
17318
17319static void
17320do_vcmla (void)
17321{
17322 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17323 _(BAD_FPU));
17324 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17325 unsigned rot = inst.reloc.exp.X_add_number;
17326 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
17327 _("immediate out of range"));
17328 rot /= 90;
17329 if (inst.operands[2].isscalar)
17330 {
17331 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
17332 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17333 N_KEY | N_F16 | N_F32).size;
17334 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
17335 inst.is_neon = 1;
17336 inst.instruction = 0xfe000800;
17337 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17338 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17339 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17340 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17341 inst.instruction |= LOW4 (m);
17342 inst.instruction |= HI1 (m) << 5;
17343 inst.instruction |= neon_quad (rs) << 6;
17344 inst.instruction |= rot << 20;
17345 inst.instruction |= (size == 32) << 23;
17346 }
17347 else
17348 {
17349 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17350 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17351 N_KEY | N_F16 | N_F32).size;
17352 neon_three_same (neon_quad (rs), 0, -1);
17353 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17354 inst.instruction |= 0xfc200800;
17355 inst.instruction |= rot << 23;
17356 inst.instruction |= (size == 32) << 20;
17357 }
17358}
17359
17360static void
17361do_vcadd (void)
17362{
17363 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17364 _(BAD_FPU));
17365 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17366 unsigned rot = inst.reloc.exp.X_add_number;
17367 constraint (rot != 90 && rot != 270, _("immediate out of range"));
17368 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17369 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17370 N_KEY | N_F16 | N_F32).size;
17371 neon_three_same (neon_quad (rs), 0, -1);
17372 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17373 inst.instruction |= 0xfc800800;
17374 inst.instruction |= (rot == 270) << 24;
17375 inst.instruction |= (size == 32) << 20;
17376}
17377
91ff7894
MGD
17378/* Crypto v1 instructions. */
17379static void
17380do_crypto_2op_1 (unsigned elttype, int op)
17381{
17382 set_it_insn_type (OUTSIDE_IT_INSN);
17383
17384 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17385 == NT_invtype)
17386 return;
17387
17388 inst.error = NULL;
17389
17390 NEON_ENCODE (INTEGER, inst);
17391 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17392 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17393 inst.instruction |= LOW4 (inst.operands[1].reg);
17394 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17395 if (op != -1)
17396 inst.instruction |= op << 6;
17397
17398 if (thumb_mode)
17399 inst.instruction |= 0xfc000000;
17400 else
17401 inst.instruction |= 0xf0000000;
17402}
17403
48adcd8e
MGD
17404static void
17405do_crypto_3op_1 (int u, int op)
17406{
17407 set_it_insn_type (OUTSIDE_IT_INSN);
17408
17409 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17410 N_32 | N_UNT | N_KEY).type == NT_invtype)
17411 return;
17412
17413 inst.error = NULL;
17414
17415 NEON_ENCODE (INTEGER, inst);
17416 neon_three_same (1, u, 8 << op);
17417}
17418
91ff7894
MGD
17419static void
17420do_aese (void)
17421{
17422 do_crypto_2op_1 (N_8, 0);
17423}
17424
17425static void
17426do_aesd (void)
17427{
17428 do_crypto_2op_1 (N_8, 1);
17429}
17430
17431static void
17432do_aesmc (void)
17433{
17434 do_crypto_2op_1 (N_8, 2);
17435}
17436
17437static void
17438do_aesimc (void)
17439{
17440 do_crypto_2op_1 (N_8, 3);
17441}
17442
48adcd8e
MGD
17443static void
17444do_sha1c (void)
17445{
17446 do_crypto_3op_1 (0, 0);
17447}
17448
17449static void
17450do_sha1p (void)
17451{
17452 do_crypto_3op_1 (0, 1);
17453}
17454
17455static void
17456do_sha1m (void)
17457{
17458 do_crypto_3op_1 (0, 2);
17459}
17460
17461static void
17462do_sha1su0 (void)
17463{
17464 do_crypto_3op_1 (0, 3);
17465}
91ff7894 17466
48adcd8e
MGD
17467static void
17468do_sha256h (void)
17469{
17470 do_crypto_3op_1 (1, 0);
17471}
17472
17473static void
17474do_sha256h2 (void)
17475{
17476 do_crypto_3op_1 (1, 1);
17477}
17478
17479static void
17480do_sha256su1 (void)
17481{
17482 do_crypto_3op_1 (1, 2);
17483}
3c9017d2
MGD
17484
17485static void
17486do_sha1h (void)
17487{
17488 do_crypto_2op_1 (N_32, -1);
17489}
17490
17491static void
17492do_sha1su1 (void)
17493{
17494 do_crypto_2op_1 (N_32, 0);
17495}
17496
17497static void
17498do_sha256su0 (void)
17499{
17500 do_crypto_2op_1 (N_32, 1);
17501}
dd5181d5
KT
17502
17503static void
17504do_crc32_1 (unsigned int poly, unsigned int sz)
17505{
17506 unsigned int Rd = inst.operands[0].reg;
17507 unsigned int Rn = inst.operands[1].reg;
17508 unsigned int Rm = inst.operands[2].reg;
17509
17510 set_it_insn_type (OUTSIDE_IT_INSN);
17511 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
17512 inst.instruction |= LOW4 (Rn) << 16;
17513 inst.instruction |= LOW4 (Rm);
17514 inst.instruction |= sz << (thumb_mode ? 4 : 21);
17515 inst.instruction |= poly << (thumb_mode ? 20 : 9);
17516
17517 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
17518 as_warn (UNPRED_REG ("r15"));
17519 if (thumb_mode && (Rd == REG_SP || Rn == REG_SP || Rm == REG_SP))
17520 as_warn (UNPRED_REG ("r13"));
17521}
17522
17523static void
17524do_crc32b (void)
17525{
17526 do_crc32_1 (0, 0);
17527}
17528
17529static void
17530do_crc32h (void)
17531{
17532 do_crc32_1 (0, 1);
17533}
17534
17535static void
17536do_crc32w (void)
17537{
17538 do_crc32_1 (0, 2);
17539}
17540
17541static void
17542do_crc32cb (void)
17543{
17544 do_crc32_1 (1, 0);
17545}
17546
17547static void
17548do_crc32ch (void)
17549{
17550 do_crc32_1 (1, 1);
17551}
17552
17553static void
17554do_crc32cw (void)
17555{
17556 do_crc32_1 (1, 2);
17557}
17558
49e8a725
SN
17559static void
17560do_vjcvt (void)
17561{
17562 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17563 _(BAD_FPU));
17564 neon_check_type (2, NS_FD, N_S32, N_F64);
17565 do_vfp_sp_dp_cvt ();
17566 do_vfp_cond_or_thumb ();
17567}
17568
5287ad62
JB
17569\f
17570/* Overall per-instruction processing. */
17571
17572/* We need to be able to fix up arbitrary expressions in some statements.
17573 This is so that we can handle symbols that are an arbitrary distance from
17574 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17575 which returns part of an address in a form which will be valid for
17576 a data instruction. We do this by pushing the expression into a symbol
17577 in the expr_section, and creating a fix for that. */
17578
17579static void
17580fix_new_arm (fragS * frag,
17581 int where,
17582 short int size,
17583 expressionS * exp,
17584 int pc_rel,
17585 int reloc)
17586{
17587 fixS * new_fix;
17588
17589 switch (exp->X_op)
17590 {
17591 case O_constant:
6e7ce2cd
PB
17592 if (pc_rel)
17593 {
17594 /* Create an absolute valued symbol, so we have something to
477330fc
RM
17595 refer to in the object file. Unfortunately for us, gas's
17596 generic expression parsing will already have folded out
17597 any use of .set foo/.type foo %function that may have
17598 been used to set type information of the target location,
17599 that's being specified symbolically. We have to presume
17600 the user knows what they are doing. */
6e7ce2cd
PB
17601 char name[16 + 8];
17602 symbolS *symbol;
17603
17604 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17605
17606 symbol = symbol_find_or_make (name);
17607 S_SET_SEGMENT (symbol, absolute_section);
17608 symbol_set_frag (symbol, &zero_address_frag);
17609 S_SET_VALUE (symbol, exp->X_add_number);
17610 exp->X_op = O_symbol;
17611 exp->X_add_symbol = symbol;
17612 exp->X_add_number = 0;
17613 }
17614 /* FALLTHROUGH */
5287ad62
JB
17615 case O_symbol:
17616 case O_add:
17617 case O_subtract:
21d799b5 17618 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 17619 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17620 break;
17621
17622 default:
21d799b5 17623 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 17624 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17625 break;
17626 }
17627
17628 /* Mark whether the fix is to a THUMB instruction, or an ARM
17629 instruction. */
17630 new_fix->tc_fix_data = thumb_mode;
17631}
17632
17633/* Create a frg for an instruction requiring relaxation. */
17634static void
17635output_relax_insn (void)
17636{
17637 char * to;
17638 symbolS *sym;
0110f2b8
PB
17639 int offset;
17640
6e1cb1a6
PB
17641 /* The size of the instruction is unknown, so tie the debug info to the
17642 start of the instruction. */
17643 dwarf2_emit_insn (0);
6e1cb1a6 17644
0110f2b8
PB
17645 switch (inst.reloc.exp.X_op)
17646 {
17647 case O_symbol:
17648 sym = inst.reloc.exp.X_add_symbol;
17649 offset = inst.reloc.exp.X_add_number;
17650 break;
17651 case O_constant:
17652 sym = NULL;
17653 offset = inst.reloc.exp.X_add_number;
17654 break;
17655 default:
17656 sym = make_expr_symbol (&inst.reloc.exp);
17657 offset = 0;
17658 break;
17659 }
17660 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17661 inst.relax, sym, offset, NULL/*offset, opcode*/);
17662 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
17663}
17664
17665/* Write a 32-bit thumb instruction to buf. */
17666static void
17667put_thumb32_insn (char * buf, unsigned long insn)
17668{
17669 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17670 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17671}
17672
b99bd4ef 17673static void
c19d1205 17674output_inst (const char * str)
b99bd4ef 17675{
c19d1205 17676 char * to = NULL;
b99bd4ef 17677
c19d1205 17678 if (inst.error)
b99bd4ef 17679 {
c19d1205 17680 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
17681 return;
17682 }
5f4273c7
NC
17683 if (inst.relax)
17684 {
17685 output_relax_insn ();
0110f2b8 17686 return;
5f4273c7 17687 }
c19d1205
ZW
17688 if (inst.size == 0)
17689 return;
b99bd4ef 17690
c19d1205 17691 to = frag_more (inst.size);
8dc2430f
NC
17692 /* PR 9814: Record the thumb mode into the current frag so that we know
17693 what type of NOP padding to use, if necessary. We override any previous
17694 setting so that if the mode has changed then the NOPS that we use will
17695 match the encoding of the last instruction in the frag. */
cd000bff 17696 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
17697
17698 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 17699 {
9c2799c2 17700 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 17701 put_thumb32_insn (to, inst.instruction);
b99bd4ef 17702 }
c19d1205 17703 else if (inst.size > INSN_SIZE)
b99bd4ef 17704 {
9c2799c2 17705 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
17706 md_number_to_chars (to, inst.instruction, INSN_SIZE);
17707 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 17708 }
c19d1205
ZW
17709 else
17710 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 17711
c19d1205
ZW
17712 if (inst.reloc.type != BFD_RELOC_UNUSED)
17713 fix_new_arm (frag_now, to - frag_now->fr_literal,
17714 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
17715 inst.reloc.type);
b99bd4ef 17716
c19d1205 17717 dwarf2_emit_insn (inst.size);
c19d1205 17718}
b99bd4ef 17719
e07e6e58
NC
17720static char *
17721output_it_inst (int cond, int mask, char * to)
17722{
17723 unsigned long instruction = 0xbf00;
17724
17725 mask &= 0xf;
17726 instruction |= mask;
17727 instruction |= cond << 4;
17728
17729 if (to == NULL)
17730 {
17731 to = frag_more (2);
17732#ifdef OBJ_ELF
17733 dwarf2_emit_insn (2);
17734#endif
17735 }
17736
17737 md_number_to_chars (to, instruction, 2);
17738
17739 return to;
17740}
17741
c19d1205
ZW
17742/* Tag values used in struct asm_opcode's tag field. */
17743enum opcode_tag
17744{
17745 OT_unconditional, /* Instruction cannot be conditionalized.
17746 The ARM condition field is still 0xE. */
17747 OT_unconditionalF, /* Instruction cannot be conditionalized
17748 and carries 0xF in its ARM condition field. */
17749 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 17750 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
17751 suffix, others place 0xF where the condition field
17752 would be. */
c19d1205
ZW
17753 OT_cinfix3, /* Instruction takes a conditional infix,
17754 beginning at character index 3. (In
17755 unified mode, it becomes a suffix.) */
088fa78e
KH
17756 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
17757 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
17758 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
17759 character index 3, even in unified mode. Used for
17760 legacy instructions where suffix and infix forms
17761 may be ambiguous. */
c19d1205 17762 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 17763 suffix or an infix at character index 3. */
c19d1205
ZW
17764 OT_odd_infix_unc, /* This is the unconditional variant of an
17765 instruction that takes a conditional infix
17766 at an unusual position. In unified mode,
17767 this variant will accept a suffix. */
17768 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
17769 are the conditional variants of instructions that
17770 take conditional infixes in unusual positions.
17771 The infix appears at character index
17772 (tag - OT_odd_infix_0). These are not accepted
17773 in unified mode. */
17774};
b99bd4ef 17775
c19d1205
ZW
17776/* Subroutine of md_assemble, responsible for looking up the primary
17777 opcode from the mnemonic the user wrote. STR points to the
17778 beginning of the mnemonic.
17779
17780 This is not simply a hash table lookup, because of conditional
17781 variants. Most instructions have conditional variants, which are
17782 expressed with a _conditional affix_ to the mnemonic. If we were
17783 to encode each conditional variant as a literal string in the opcode
17784 table, it would have approximately 20,000 entries.
17785
17786 Most mnemonics take this affix as a suffix, and in unified syntax,
17787 'most' is upgraded to 'all'. However, in the divided syntax, some
17788 instructions take the affix as an infix, notably the s-variants of
17789 the arithmetic instructions. Of those instructions, all but six
17790 have the infix appear after the third character of the mnemonic.
17791
17792 Accordingly, the algorithm for looking up primary opcodes given
17793 an identifier is:
17794
17795 1. Look up the identifier in the opcode table.
17796 If we find a match, go to step U.
17797
17798 2. Look up the last two characters of the identifier in the
17799 conditions table. If we find a match, look up the first N-2
17800 characters of the identifier in the opcode table. If we
17801 find a match, go to step CE.
17802
17803 3. Look up the fourth and fifth characters of the identifier in
17804 the conditions table. If we find a match, extract those
17805 characters from the identifier, and look up the remaining
17806 characters in the opcode table. If we find a match, go
17807 to step CM.
17808
17809 4. Fail.
17810
17811 U. Examine the tag field of the opcode structure, in case this is
17812 one of the six instructions with its conditional infix in an
17813 unusual place. If it is, the tag tells us where to find the
17814 infix; look it up in the conditions table and set inst.cond
17815 accordingly. Otherwise, this is an unconditional instruction.
17816 Again set inst.cond accordingly. Return the opcode structure.
17817
17818 CE. Examine the tag field to make sure this is an instruction that
17819 should receive a conditional suffix. If it is not, fail.
17820 Otherwise, set inst.cond from the suffix we already looked up,
17821 and return the opcode structure.
17822
17823 CM. Examine the tag field to make sure this is an instruction that
17824 should receive a conditional infix after the third character.
17825 If it is not, fail. Otherwise, undo the edits to the current
17826 line of input and proceed as for case CE. */
17827
17828static const struct asm_opcode *
17829opcode_lookup (char **str)
17830{
17831 char *end, *base;
17832 char *affix;
17833 const struct asm_opcode *opcode;
17834 const struct asm_cond *cond;
e3cb604e 17835 char save[2];
c19d1205
ZW
17836
17837 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 17838 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 17839 for (base = end = *str; *end != '\0'; end++)
721a8186 17840 if (*end == ' ' || *end == '.')
c19d1205 17841 break;
b99bd4ef 17842
c19d1205 17843 if (end == base)
c921be7d 17844 return NULL;
b99bd4ef 17845
5287ad62 17846 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 17847 if (end[0] == '.')
b99bd4ef 17848 {
5287ad62 17849 int offset = 2;
5f4273c7 17850
267d2029 17851 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 17852 use. */
267d2029 17853 if (unified_syntax && end[1] == 'w')
c19d1205 17854 inst.size_req = 4;
267d2029 17855 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
17856 inst.size_req = 2;
17857 else
477330fc 17858 offset = 0;
5287ad62
JB
17859
17860 inst.vectype.elems = 0;
17861
17862 *str = end + offset;
b99bd4ef 17863
5f4273c7 17864 if (end[offset] == '.')
5287ad62 17865 {
267d2029 17866 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
17867 non-unified ARM syntax mode). */
17868 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 17869 return NULL;
477330fc 17870 }
5287ad62 17871 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 17872 return NULL;
b99bd4ef 17873 }
c19d1205
ZW
17874 else
17875 *str = end;
b99bd4ef 17876
c19d1205 17877 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 17878 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17879 end - base);
c19d1205 17880 if (opcode)
b99bd4ef 17881 {
c19d1205
ZW
17882 /* step U */
17883 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 17884 {
c19d1205
ZW
17885 inst.cond = COND_ALWAYS;
17886 return opcode;
b99bd4ef 17887 }
b99bd4ef 17888
278df34e 17889 if (warn_on_deprecated && unified_syntax)
5c3696f8 17890 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 17891 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 17892 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 17893 gas_assert (cond);
b99bd4ef 17894
c19d1205
ZW
17895 inst.cond = cond->value;
17896 return opcode;
17897 }
b99bd4ef 17898
c19d1205
ZW
17899 /* Cannot have a conditional suffix on a mnemonic of less than two
17900 characters. */
17901 if (end - base < 3)
c921be7d 17902 return NULL;
b99bd4ef 17903
c19d1205
ZW
17904 /* Look for suffixed mnemonic. */
17905 affix = end - 2;
21d799b5
NC
17906 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
17907 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17908 affix - base);
c19d1205
ZW
17909 if (opcode && cond)
17910 {
17911 /* step CE */
17912 switch (opcode->tag)
17913 {
e3cb604e
PB
17914 case OT_cinfix3_legacy:
17915 /* Ignore conditional suffixes matched on infix only mnemonics. */
17916 break;
17917
c19d1205 17918 case OT_cinfix3:
088fa78e 17919 case OT_cinfix3_deprecated:
c19d1205
ZW
17920 case OT_odd_infix_unc:
17921 if (!unified_syntax)
e3cb604e 17922 return 0;
1a0670f3 17923 /* Fall through. */
c19d1205
ZW
17924
17925 case OT_csuffix:
477330fc 17926 case OT_csuffixF:
c19d1205
ZW
17927 case OT_csuf_or_in3:
17928 inst.cond = cond->value;
17929 return opcode;
17930
17931 case OT_unconditional:
17932 case OT_unconditionalF:
dfa9f0d5 17933 if (thumb_mode)
c921be7d 17934 inst.cond = cond->value;
dfa9f0d5
PB
17935 else
17936 {
c921be7d 17937 /* Delayed diagnostic. */
dfa9f0d5
PB
17938 inst.error = BAD_COND;
17939 inst.cond = COND_ALWAYS;
17940 }
c19d1205 17941 return opcode;
b99bd4ef 17942
c19d1205 17943 default:
c921be7d 17944 return NULL;
c19d1205
ZW
17945 }
17946 }
b99bd4ef 17947
c19d1205
ZW
17948 /* Cannot have a usual-position infix on a mnemonic of less than
17949 six characters (five would be a suffix). */
17950 if (end - base < 6)
c921be7d 17951 return NULL;
b99bd4ef 17952
c19d1205
ZW
17953 /* Look for infixed mnemonic in the usual position. */
17954 affix = base + 3;
21d799b5 17955 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 17956 if (!cond)
c921be7d 17957 return NULL;
e3cb604e
PB
17958
17959 memcpy (save, affix, 2);
17960 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 17961 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17962 (end - base) - 2);
e3cb604e
PB
17963 memmove (affix + 2, affix, (end - affix) - 2);
17964 memcpy (affix, save, 2);
17965
088fa78e
KH
17966 if (opcode
17967 && (opcode->tag == OT_cinfix3
17968 || opcode->tag == OT_cinfix3_deprecated
17969 || opcode->tag == OT_csuf_or_in3
17970 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 17971 {
c921be7d 17972 /* Step CM. */
278df34e 17973 if (warn_on_deprecated && unified_syntax
088fa78e
KH
17974 && (opcode->tag == OT_cinfix3
17975 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 17976 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
17977
17978 inst.cond = cond->value;
17979 return opcode;
b99bd4ef
NC
17980 }
17981
c921be7d 17982 return NULL;
b99bd4ef
NC
17983}
17984
e07e6e58
NC
17985/* This function generates an initial IT instruction, leaving its block
17986 virtually open for the new instructions. Eventually,
17987 the mask will be updated by now_it_add_mask () each time
17988 a new instruction needs to be included in the IT block.
17989 Finally, the block is closed with close_automatic_it_block ().
17990 The block closure can be requested either from md_assemble (),
17991 a tencode (), or due to a label hook. */
17992
17993static void
17994new_automatic_it_block (int cond)
17995{
17996 now_it.state = AUTOMATIC_IT_BLOCK;
17997 now_it.mask = 0x18;
17998 now_it.cc = cond;
17999 now_it.block_length = 1;
cd000bff 18000 mapping_state (MAP_THUMB);
e07e6e58 18001 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
18002 now_it.warn_deprecated = FALSE;
18003 now_it.insn_cond = TRUE;
e07e6e58
NC
18004}
18005
18006/* Close an automatic IT block.
18007 See comments in new_automatic_it_block (). */
18008
18009static void
18010close_automatic_it_block (void)
18011{
18012 now_it.mask = 0x10;
18013 now_it.block_length = 0;
18014}
18015
18016/* Update the mask of the current automatically-generated IT
18017 instruction. See comments in new_automatic_it_block (). */
18018
18019static void
18020now_it_add_mask (int cond)
18021{
18022#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
18023#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 18024 | ((bitvalue) << (nbit)))
e07e6e58 18025 const int resulting_bit = (cond & 1);
c921be7d 18026
e07e6e58
NC
18027 now_it.mask &= 0xf;
18028 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18029 resulting_bit,
18030 (5 - now_it.block_length));
e07e6e58 18031 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18032 1,
18033 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
18034 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
18035
18036#undef CLEAR_BIT
18037#undef SET_BIT_VALUE
e07e6e58
NC
18038}
18039
18040/* The IT blocks handling machinery is accessed through the these functions:
18041 it_fsm_pre_encode () from md_assemble ()
18042 set_it_insn_type () optional, from the tencode functions
18043 set_it_insn_type_last () ditto
18044 in_it_block () ditto
18045 it_fsm_post_encode () from md_assemble ()
33eaf5de 18046 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
18047
18048 Rationale:
18049 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
18050 initializing the IT insn type with a generic initial value depending
18051 on the inst.condition.
e07e6e58 18052 2) During the tencode function, two things may happen:
477330fc
RM
18053 a) The tencode function overrides the IT insn type by
18054 calling either set_it_insn_type (type) or set_it_insn_type_last ().
18055 b) The tencode function queries the IT block state by
18056 calling in_it_block () (i.e. to determine narrow/not narrow mode).
18057
18058 Both set_it_insn_type and in_it_block run the internal FSM state
18059 handling function (handle_it_state), because: a) setting the IT insn
18060 type may incur in an invalid state (exiting the function),
18061 and b) querying the state requires the FSM to be updated.
18062 Specifically we want to avoid creating an IT block for conditional
18063 branches, so it_fsm_pre_encode is actually a guess and we can't
18064 determine whether an IT block is required until the tencode () routine
18065 has decided what type of instruction this actually it.
18066 Because of this, if set_it_insn_type and in_it_block have to be used,
18067 set_it_insn_type has to be called first.
18068
18069 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
18070 determines the insn IT type depending on the inst.cond code.
18071 When a tencode () routine encodes an instruction that can be
18072 either outside an IT block, or, in the case of being inside, has to be
18073 the last one, set_it_insn_type_last () will determine the proper
18074 IT instruction type based on the inst.cond code. Otherwise,
18075 set_it_insn_type can be called for overriding that logic or
18076 for covering other cases.
18077
18078 Calling handle_it_state () may not transition the IT block state to
2b0f3761 18079 OUTSIDE_IT_BLOCK immediately, since the (current) state could be
477330fc
RM
18080 still queried. Instead, if the FSM determines that the state should
18081 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
18082 after the tencode () function: that's what it_fsm_post_encode () does.
18083
18084 Since in_it_block () calls the state handling function to get an
18085 updated state, an error may occur (due to invalid insns combination).
18086 In that case, inst.error is set.
18087 Therefore, inst.error has to be checked after the execution of
18088 the tencode () routine.
e07e6e58
NC
18089
18090 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
18091 any pending state change (if any) that didn't take place in
18092 handle_it_state () as explained above. */
e07e6e58
NC
18093
18094static void
18095it_fsm_pre_encode (void)
18096{
18097 if (inst.cond != COND_ALWAYS)
18098 inst.it_insn_type = INSIDE_IT_INSN;
18099 else
18100 inst.it_insn_type = OUTSIDE_IT_INSN;
18101
18102 now_it.state_handled = 0;
18103}
18104
18105/* IT state FSM handling function. */
18106
18107static int
18108handle_it_state (void)
18109{
18110 now_it.state_handled = 1;
5a01bb1d 18111 now_it.insn_cond = FALSE;
e07e6e58
NC
18112
18113 switch (now_it.state)
18114 {
18115 case OUTSIDE_IT_BLOCK:
18116 switch (inst.it_insn_type)
18117 {
18118 case OUTSIDE_IT_INSN:
18119 break;
18120
18121 case INSIDE_IT_INSN:
18122 case INSIDE_IT_LAST_INSN:
18123 if (thumb_mode == 0)
18124 {
c921be7d 18125 if (unified_syntax
e07e6e58
NC
18126 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
18127 as_tsktsk (_("Warning: conditional outside an IT block"\
18128 " for Thumb."));
18129 }
18130 else
18131 {
18132 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
fc289b0a 18133 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
e07e6e58
NC
18134 {
18135 /* Automatically generate the IT instruction. */
18136 new_automatic_it_block (inst.cond);
18137 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
18138 close_automatic_it_block ();
18139 }
18140 else
18141 {
18142 inst.error = BAD_OUT_IT;
18143 return FAIL;
18144 }
18145 }
18146 break;
18147
18148 case IF_INSIDE_IT_LAST_INSN:
18149 case NEUTRAL_IT_INSN:
18150 break;
18151
18152 case IT_INSN:
18153 now_it.state = MANUAL_IT_BLOCK;
18154 now_it.block_length = 0;
18155 break;
18156 }
18157 break;
18158
18159 case AUTOMATIC_IT_BLOCK:
18160 /* Three things may happen now:
18161 a) We should increment current it block size;
18162 b) We should close current it block (closing insn or 4 insns);
18163 c) We should close current it block and start a new one (due
18164 to incompatible conditions or
18165 4 insns-length block reached). */
18166
18167 switch (inst.it_insn_type)
18168 {
18169 case OUTSIDE_IT_INSN:
2b0f3761 18170 /* The closure of the block shall happen immediately,
e07e6e58
NC
18171 so any in_it_block () call reports the block as closed. */
18172 force_automatic_it_block_close ();
18173 break;
18174
18175 case INSIDE_IT_INSN:
18176 case INSIDE_IT_LAST_INSN:
18177 case IF_INSIDE_IT_LAST_INSN:
18178 now_it.block_length++;
18179
18180 if (now_it.block_length > 4
18181 || !now_it_compatible (inst.cond))
18182 {
18183 force_automatic_it_block_close ();
18184 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
18185 new_automatic_it_block (inst.cond);
18186 }
18187 else
18188 {
5a01bb1d 18189 now_it.insn_cond = TRUE;
e07e6e58
NC
18190 now_it_add_mask (inst.cond);
18191 }
18192
18193 if (now_it.state == AUTOMATIC_IT_BLOCK
18194 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
18195 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
18196 close_automatic_it_block ();
18197 break;
18198
18199 case NEUTRAL_IT_INSN:
18200 now_it.block_length++;
5a01bb1d 18201 now_it.insn_cond = TRUE;
e07e6e58
NC
18202
18203 if (now_it.block_length > 4)
18204 force_automatic_it_block_close ();
18205 else
18206 now_it_add_mask (now_it.cc & 1);
18207 break;
18208
18209 case IT_INSN:
18210 close_automatic_it_block ();
18211 now_it.state = MANUAL_IT_BLOCK;
18212 break;
18213 }
18214 break;
18215
18216 case MANUAL_IT_BLOCK:
18217 {
18218 /* Check conditional suffixes. */
18219 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
18220 int is_last;
18221 now_it.mask <<= 1;
18222 now_it.mask &= 0x1f;
18223 is_last = (now_it.mask == 0x10);
5a01bb1d 18224 now_it.insn_cond = TRUE;
e07e6e58
NC
18225
18226 switch (inst.it_insn_type)
18227 {
18228 case OUTSIDE_IT_INSN:
18229 inst.error = BAD_NOT_IT;
18230 return FAIL;
18231
18232 case INSIDE_IT_INSN:
18233 if (cond != inst.cond)
18234 {
18235 inst.error = BAD_IT_COND;
18236 return FAIL;
18237 }
18238 break;
18239
18240 case INSIDE_IT_LAST_INSN:
18241 case IF_INSIDE_IT_LAST_INSN:
18242 if (cond != inst.cond)
18243 {
18244 inst.error = BAD_IT_COND;
18245 return FAIL;
18246 }
18247 if (!is_last)
18248 {
18249 inst.error = BAD_BRANCH;
18250 return FAIL;
18251 }
18252 break;
18253
18254 case NEUTRAL_IT_INSN:
18255 /* The BKPT instruction is unconditional even in an IT block. */
18256 break;
18257
18258 case IT_INSN:
18259 inst.error = BAD_IT_IT;
18260 return FAIL;
18261 }
18262 }
18263 break;
18264 }
18265
18266 return SUCCESS;
18267}
18268
5a01bb1d
MGD
18269struct depr_insn_mask
18270{
18271 unsigned long pattern;
18272 unsigned long mask;
18273 const char* description;
18274};
18275
18276/* List of 16-bit instruction patterns deprecated in an IT block in
18277 ARMv8. */
18278static const struct depr_insn_mask depr_it_insns[] = {
18279 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
18280 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
18281 { 0xa000, 0xb800, N_("ADR") },
18282 { 0x4800, 0xf800, N_("Literal loads") },
18283 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
18284 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
18285 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
18286 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
18287 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
18288 { 0, 0, NULL }
18289};
18290
e07e6e58
NC
18291static void
18292it_fsm_post_encode (void)
18293{
18294 int is_last;
18295
18296 if (!now_it.state_handled)
18297 handle_it_state ();
18298
5a01bb1d
MGD
18299 if (now_it.insn_cond
18300 && !now_it.warn_deprecated
18301 && warn_on_deprecated
18302 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
18303 {
18304 if (inst.instruction >= 0x10000)
18305 {
5c3696f8 18306 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
5a01bb1d
MGD
18307 "deprecated in ARMv8"));
18308 now_it.warn_deprecated = TRUE;
18309 }
18310 else
18311 {
18312 const struct depr_insn_mask *p = depr_it_insns;
18313
18314 while (p->mask != 0)
18315 {
18316 if ((inst.instruction & p->mask) == p->pattern)
18317 {
5c3696f8 18318 as_tsktsk (_("IT blocks containing 16-bit Thumb instructions "
5a01bb1d
MGD
18319 "of the following class are deprecated in ARMv8: "
18320 "%s"), p->description);
18321 now_it.warn_deprecated = TRUE;
18322 break;
18323 }
18324
18325 ++p;
18326 }
18327 }
18328
18329 if (now_it.block_length > 1)
18330 {
5c3696f8 18331 as_tsktsk (_("IT blocks containing more than one conditional "
0a8897c7 18332 "instruction are deprecated in ARMv8"));
5a01bb1d
MGD
18333 now_it.warn_deprecated = TRUE;
18334 }
18335 }
18336
e07e6e58
NC
18337 is_last = (now_it.mask == 0x10);
18338 if (is_last)
18339 {
18340 now_it.state = OUTSIDE_IT_BLOCK;
18341 now_it.mask = 0;
18342 }
18343}
18344
18345static void
18346force_automatic_it_block_close (void)
18347{
18348 if (now_it.state == AUTOMATIC_IT_BLOCK)
18349 {
18350 close_automatic_it_block ();
18351 now_it.state = OUTSIDE_IT_BLOCK;
18352 now_it.mask = 0;
18353 }
18354}
18355
18356static int
18357in_it_block (void)
18358{
18359 if (!now_it.state_handled)
18360 handle_it_state ();
18361
18362 return now_it.state != OUTSIDE_IT_BLOCK;
18363}
18364
ff8646ee
TP
18365/* Whether OPCODE only has T32 encoding. Since this function is only used by
18366 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18367 here, hence the "known" in the function name. */
fc289b0a
TP
18368
18369static bfd_boolean
ff8646ee 18370known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
18371{
18372 /* Original Thumb-1 wide instruction. */
18373 if (opcode->tencode == do_t_blx
18374 || opcode->tencode == do_t_branch23
18375 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18376 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18377 return TRUE;
18378
16a1fa25
TP
18379 /* Wide-only instruction added to ARMv8-M Baseline. */
18380 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
18381 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18382 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18383 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18384 return TRUE;
18385
18386 return FALSE;
18387}
18388
18389/* Whether wide instruction variant can be used if available for a valid OPCODE
18390 in ARCH. */
18391
18392static bfd_boolean
18393t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18394{
18395 if (known_t32_only_insn (opcode))
18396 return TRUE;
18397
18398 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18399 of variant T3 of B.W is checked in do_t_branch. */
18400 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18401 && opcode->tencode == do_t_branch)
18402 return TRUE;
18403
bada4342
JW
18404 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
18405 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18406 && opcode->tencode == do_t_mov_cmp
18407 /* Make sure CMP instruction is not affected. */
18408 && opcode->aencode == do_mov)
18409 return TRUE;
18410
ff8646ee
TP
18411 /* Wide instruction variants of all instructions with narrow *and* wide
18412 variants become available with ARMv6t2. Other opcodes are either
18413 narrow-only or wide-only and are thus available if OPCODE is valid. */
18414 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18415 return TRUE;
18416
18417 /* OPCODE with narrow only instruction variant or wide variant not
18418 available. */
fc289b0a
TP
18419 return FALSE;
18420}
18421
c19d1205
ZW
18422void
18423md_assemble (char *str)
b99bd4ef 18424{
c19d1205
ZW
18425 char *p = str;
18426 const struct asm_opcode * opcode;
b99bd4ef 18427
c19d1205
ZW
18428 /* Align the previous label if needed. */
18429 if (last_label_seen != NULL)
b99bd4ef 18430 {
c19d1205
ZW
18431 symbol_set_frag (last_label_seen, frag_now);
18432 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18433 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
18434 }
18435
c19d1205
ZW
18436 memset (&inst, '\0', sizeof (inst));
18437 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 18438
c19d1205
ZW
18439 opcode = opcode_lookup (&p);
18440 if (!opcode)
b99bd4ef 18441 {
c19d1205 18442 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 18443 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 18444 if (! create_register_alias (str, p)
477330fc 18445 && ! create_neon_reg_alias (str, p))
c19d1205 18446 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 18447
b99bd4ef
NC
18448 return;
18449 }
18450
278df34e 18451 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 18452 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 18453
037e8744
JB
18454 /* The value which unconditional instructions should have in place of the
18455 condition field. */
18456 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
18457
c19d1205 18458 if (thumb_mode)
b99bd4ef 18459 {
e74cfd16 18460 arm_feature_set variant;
8f06b2d8
PB
18461
18462 variant = cpu_variant;
18463 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
18464 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
18465 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 18466 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
18467 if (!opcode->tvariant
18468 || (thumb_mode == 1
18469 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 18470 {
84b52b66 18471 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
18472 return;
18473 }
c19d1205
ZW
18474 if (inst.cond != COND_ALWAYS && !unified_syntax
18475 && opcode->tencode != do_t_branch)
b99bd4ef 18476 {
c19d1205 18477 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
18478 return;
18479 }
18480
fc289b0a
TP
18481 /* Two things are addressed here:
18482 1) Implicit require narrow instructions on Thumb-1.
18483 This avoids relaxation accidentally introducing Thumb-2
18484 instructions.
18485 2) Reject wide instructions in non Thumb-2 cores.
18486
18487 Only instructions with narrow and wide variants need to be handled
18488 but selecting all non wide-only instructions is easier. */
18489 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 18490 && !t32_insn_ok (variant, opcode))
076d447c 18491 {
fc289b0a
TP
18492 if (inst.size_req == 0)
18493 inst.size_req = 2;
18494 else if (inst.size_req == 4)
752d5da4 18495 {
ff8646ee
TP
18496 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
18497 as_bad (_("selected processor does not support 32bit wide "
18498 "variant of instruction `%s'"), str);
18499 else
18500 as_bad (_("selected processor does not support `%s' in "
18501 "Thumb-2 mode"), str);
fc289b0a 18502 return;
752d5da4 18503 }
076d447c
PB
18504 }
18505
c19d1205
ZW
18506 inst.instruction = opcode->tvalue;
18507
5be8be5d 18508 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
18509 {
18510 /* Prepare the it_insn_type for those encodings that don't set
18511 it. */
18512 it_fsm_pre_encode ();
c19d1205 18513
477330fc 18514 opcode->tencode ();
e07e6e58 18515
477330fc
RM
18516 it_fsm_post_encode ();
18517 }
e27ec89e 18518
0110f2b8 18519 if (!(inst.error || inst.relax))
b99bd4ef 18520 {
9c2799c2 18521 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
18522 inst.size = (inst.instruction > 0xffff ? 4 : 2);
18523 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 18524 {
c19d1205 18525 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
18526 return;
18527 }
18528 }
076d447c
PB
18529
18530 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 18531 instruction. */
9c2799c2 18532 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 18533
e74cfd16
PB
18534 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18535 *opcode->tvariant);
ee065d83 18536 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
18537 set those bits when Thumb-2 32-bit instructions are seen. The impact
18538 of relaxable instructions will be considered later after we finish all
18539 relaxation. */
ff8646ee
TP
18540 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
18541 variant = arm_arch_none;
18542 else
18543 variant = cpu_variant;
18544 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
18545 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18546 arm_ext_v6t2);
cd000bff 18547
88714cb8
DG
18548 check_neon_suffixes;
18549
cd000bff 18550 if (!inst.error)
c877a2f2
NC
18551 {
18552 mapping_state (MAP_THUMB);
18553 }
c19d1205 18554 }
3e9e4fcf 18555 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 18556 {
845b51d6
PB
18557 bfd_boolean is_bx;
18558
18559 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
18560 is_bx = (opcode->aencode == do_bx);
18561
c19d1205 18562 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
18563 if (!(is_bx && fix_v4bx)
18564 && !(opcode->avariant &&
18565 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 18566 {
84b52b66 18567 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 18568 return;
b99bd4ef 18569 }
c19d1205 18570 if (inst.size_req)
b99bd4ef 18571 {
c19d1205
ZW
18572 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
18573 return;
b99bd4ef
NC
18574 }
18575
c19d1205
ZW
18576 inst.instruction = opcode->avalue;
18577 if (opcode->tag == OT_unconditionalF)
eff0bc54 18578 inst.instruction |= 0xFU << 28;
c19d1205
ZW
18579 else
18580 inst.instruction |= inst.cond << 28;
18581 inst.size = INSN_SIZE;
5be8be5d 18582 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
18583 {
18584 it_fsm_pre_encode ();
18585 opcode->aencode ();
18586 it_fsm_post_encode ();
18587 }
ee065d83 18588 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 18589 on a hypothetical non-thumb v5 core. */
845b51d6 18590 if (is_bx)
e74cfd16 18591 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 18592 else
e74cfd16
PB
18593 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
18594 *opcode->avariant);
88714cb8
DG
18595
18596 check_neon_suffixes;
18597
cd000bff 18598 if (!inst.error)
c877a2f2
NC
18599 {
18600 mapping_state (MAP_ARM);
18601 }
b99bd4ef 18602 }
3e9e4fcf
JB
18603 else
18604 {
18605 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
18606 "-- `%s'"), str);
18607 return;
18608 }
c19d1205
ZW
18609 output_inst (str);
18610}
b99bd4ef 18611
e07e6e58
NC
18612static void
18613check_it_blocks_finished (void)
18614{
18615#ifdef OBJ_ELF
18616 asection *sect;
18617
18618 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
18619 if (seg_info (sect)->tc_segment_info_data.current_it.state
18620 == MANUAL_IT_BLOCK)
18621 {
18622 as_warn (_("section '%s' finished with an open IT block."),
18623 sect->name);
18624 }
18625#else
18626 if (now_it.state == MANUAL_IT_BLOCK)
18627 as_warn (_("file finished with an open IT block."));
18628#endif
18629}
18630
c19d1205
ZW
18631/* Various frobbings of labels and their addresses. */
18632
18633void
18634arm_start_line_hook (void)
18635{
18636 last_label_seen = NULL;
b99bd4ef
NC
18637}
18638
c19d1205
ZW
18639void
18640arm_frob_label (symbolS * sym)
b99bd4ef 18641{
c19d1205 18642 last_label_seen = sym;
b99bd4ef 18643
c19d1205 18644 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 18645
c19d1205
ZW
18646#if defined OBJ_COFF || defined OBJ_ELF
18647 ARM_SET_INTERWORK (sym, support_interwork);
18648#endif
b99bd4ef 18649
e07e6e58
NC
18650 force_automatic_it_block_close ();
18651
5f4273c7 18652 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
18653 as Thumb functions. This is because these labels, whilst
18654 they exist inside Thumb code, are not the entry points for
18655 possible ARM->Thumb calls. Also, these labels can be used
18656 as part of a computed goto or switch statement. eg gcc
18657 can generate code that looks like this:
b99bd4ef 18658
c19d1205
ZW
18659 ldr r2, [pc, .Laaa]
18660 lsl r3, r3, #2
18661 ldr r2, [r3, r2]
18662 mov pc, r2
b99bd4ef 18663
c19d1205
ZW
18664 .Lbbb: .word .Lxxx
18665 .Lccc: .word .Lyyy
18666 ..etc...
18667 .Laaa: .word Lbbb
b99bd4ef 18668
c19d1205
ZW
18669 The first instruction loads the address of the jump table.
18670 The second instruction converts a table index into a byte offset.
18671 The third instruction gets the jump address out of the table.
18672 The fourth instruction performs the jump.
b99bd4ef 18673
c19d1205
ZW
18674 If the address stored at .Laaa is that of a symbol which has the
18675 Thumb_Func bit set, then the linker will arrange for this address
18676 to have the bottom bit set, which in turn would mean that the
18677 address computation performed by the third instruction would end
18678 up with the bottom bit set. Since the ARM is capable of unaligned
18679 word loads, the instruction would then load the incorrect address
18680 out of the jump table, and chaos would ensue. */
18681 if (label_is_thumb_function_name
18682 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18683 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 18684 {
c19d1205
ZW
18685 /* When the address of a Thumb function is taken the bottom
18686 bit of that address should be set. This will allow
18687 interworking between Arm and Thumb functions to work
18688 correctly. */
b99bd4ef 18689
c19d1205 18690 THUMB_SET_FUNC (sym, 1);
b99bd4ef 18691
c19d1205 18692 label_is_thumb_function_name = FALSE;
b99bd4ef 18693 }
07a53e5c 18694
07a53e5c 18695 dwarf2_emit_label (sym);
b99bd4ef
NC
18696}
18697
c921be7d 18698bfd_boolean
c19d1205 18699arm_data_in_code (void)
b99bd4ef 18700{
c19d1205 18701 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 18702 {
c19d1205
ZW
18703 *input_line_pointer = '/';
18704 input_line_pointer += 5;
18705 *input_line_pointer = 0;
c921be7d 18706 return TRUE;
b99bd4ef
NC
18707 }
18708
c921be7d 18709 return FALSE;
b99bd4ef
NC
18710}
18711
c19d1205
ZW
18712char *
18713arm_canonicalize_symbol_name (char * name)
b99bd4ef 18714{
c19d1205 18715 int len;
b99bd4ef 18716
c19d1205
ZW
18717 if (thumb_mode && (len = strlen (name)) > 5
18718 && streq (name + len - 5, "/data"))
18719 *(name + len - 5) = 0;
b99bd4ef 18720
c19d1205 18721 return name;
b99bd4ef 18722}
c19d1205
ZW
18723\f
18724/* Table of all register names defined by default. The user can
18725 define additional names with .req. Note that all register names
18726 should appear in both upper and lowercase variants. Some registers
18727 also have mixed-case names. */
b99bd4ef 18728
dcbf9037 18729#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 18730#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 18731#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
18732#define REGSET(p,t) \
18733 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
18734 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
18735 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
18736 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
18737#define REGSETH(p,t) \
18738 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
18739 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
18740 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
18741 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
18742#define REGSET2(p,t) \
18743 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
18744 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
18745 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
18746 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
18747#define SPLRBANK(base,bank,t) \
18748 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
18749 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
18750 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
18751 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
18752 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
18753 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 18754
c19d1205 18755static const struct reg_entry reg_names[] =
7ed4c4c5 18756{
c19d1205
ZW
18757 /* ARM integer registers. */
18758 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 18759
c19d1205
ZW
18760 /* ATPCS synonyms. */
18761 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
18762 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
18763 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 18764
c19d1205
ZW
18765 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
18766 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
18767 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 18768
c19d1205
ZW
18769 /* Well-known aliases. */
18770 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
18771 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
18772
18773 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
18774 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
18775
18776 /* Coprocessor numbers. */
18777 REGSET(p, CP), REGSET(P, CP),
18778
18779 /* Coprocessor register numbers. The "cr" variants are for backward
18780 compatibility. */
18781 REGSET(c, CN), REGSET(C, CN),
18782 REGSET(cr, CN), REGSET(CR, CN),
18783
90ec0d68
MGD
18784 /* ARM banked registers. */
18785 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
18786 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
18787 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
18788 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
18789 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
18790 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
18791 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
18792
18793 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
18794 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
18795 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
18796 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
18797 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 18798 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
18799 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
18800 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
18801
18802 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
18803 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
18804 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
18805 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
18806 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
18807 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
18808 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 18809 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
18810 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
18811
c19d1205
ZW
18812 /* FPA registers. */
18813 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
18814 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
18815
18816 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
18817 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
18818
18819 /* VFP SP registers. */
5287ad62
JB
18820 REGSET(s,VFS), REGSET(S,VFS),
18821 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
18822
18823 /* VFP DP Registers. */
5287ad62
JB
18824 REGSET(d,VFD), REGSET(D,VFD),
18825 /* Extra Neon DP registers. */
18826 REGSETH(d,VFD), REGSETH(D,VFD),
18827
18828 /* Neon QP registers. */
18829 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
18830
18831 /* VFP control registers. */
18832 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
18833 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
18834 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
18835 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
18836 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
18837 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
18838
18839 /* Maverick DSP coprocessor registers. */
18840 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
18841 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
18842
18843 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
18844 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
18845 REGDEF(dspsc,0,DSPSC),
18846
18847 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
18848 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
18849 REGDEF(DSPSC,0,DSPSC),
18850
18851 /* iWMMXt data registers - p0, c0-15. */
18852 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
18853
18854 /* iWMMXt control registers - p1, c0-3. */
18855 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
18856 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
18857 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
18858 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
18859
18860 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
18861 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
18862 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
18863 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
18864 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
18865
18866 /* XScale accumulator registers. */
18867 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
18868};
18869#undef REGDEF
18870#undef REGNUM
18871#undef REGSET
7ed4c4c5 18872
c19d1205
ZW
18873/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
18874 within psr_required_here. */
18875static const struct asm_psr psrs[] =
18876{
18877 /* Backward compatibility notation. Note that "all" is no longer
18878 truly all possible PSR bits. */
18879 {"all", PSR_c | PSR_f},
18880 {"flg", PSR_f},
18881 {"ctl", PSR_c},
18882
18883 /* Individual flags. */
18884 {"f", PSR_f},
18885 {"c", PSR_c},
18886 {"x", PSR_x},
18887 {"s", PSR_s},
59b42a0d 18888
c19d1205
ZW
18889 /* Combinations of flags. */
18890 {"fs", PSR_f | PSR_s},
18891 {"fx", PSR_f | PSR_x},
18892 {"fc", PSR_f | PSR_c},
18893 {"sf", PSR_s | PSR_f},
18894 {"sx", PSR_s | PSR_x},
18895 {"sc", PSR_s | PSR_c},
18896 {"xf", PSR_x | PSR_f},
18897 {"xs", PSR_x | PSR_s},
18898 {"xc", PSR_x | PSR_c},
18899 {"cf", PSR_c | PSR_f},
18900 {"cs", PSR_c | PSR_s},
18901 {"cx", PSR_c | PSR_x},
18902 {"fsx", PSR_f | PSR_s | PSR_x},
18903 {"fsc", PSR_f | PSR_s | PSR_c},
18904 {"fxs", PSR_f | PSR_x | PSR_s},
18905 {"fxc", PSR_f | PSR_x | PSR_c},
18906 {"fcs", PSR_f | PSR_c | PSR_s},
18907 {"fcx", PSR_f | PSR_c | PSR_x},
18908 {"sfx", PSR_s | PSR_f | PSR_x},
18909 {"sfc", PSR_s | PSR_f | PSR_c},
18910 {"sxf", PSR_s | PSR_x | PSR_f},
18911 {"sxc", PSR_s | PSR_x | PSR_c},
18912 {"scf", PSR_s | PSR_c | PSR_f},
18913 {"scx", PSR_s | PSR_c | PSR_x},
18914 {"xfs", PSR_x | PSR_f | PSR_s},
18915 {"xfc", PSR_x | PSR_f | PSR_c},
18916 {"xsf", PSR_x | PSR_s | PSR_f},
18917 {"xsc", PSR_x | PSR_s | PSR_c},
18918 {"xcf", PSR_x | PSR_c | PSR_f},
18919 {"xcs", PSR_x | PSR_c | PSR_s},
18920 {"cfs", PSR_c | PSR_f | PSR_s},
18921 {"cfx", PSR_c | PSR_f | PSR_x},
18922 {"csf", PSR_c | PSR_s | PSR_f},
18923 {"csx", PSR_c | PSR_s | PSR_x},
18924 {"cxf", PSR_c | PSR_x | PSR_f},
18925 {"cxs", PSR_c | PSR_x | PSR_s},
18926 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
18927 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
18928 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
18929 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
18930 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
18931 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
18932 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
18933 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
18934 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
18935 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
18936 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
18937 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
18938 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
18939 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
18940 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
18941 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
18942 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
18943 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
18944 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
18945 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
18946 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
18947 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
18948 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
18949 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
18950};
18951
62b3e311
PB
18952/* Table of V7M psr names. */
18953static const struct asm_psr v7m_psrs[] =
18954{
1a336194
TP
18955 {"apsr", 0x0 }, {"APSR", 0x0 },
18956 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
18957 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
18958 {"psr", 0x3 }, {"PSR", 0x3 },
18959 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
18960 {"ipsr", 0x5 }, {"IPSR", 0x5 },
18961 {"epsr", 0x6 }, {"EPSR", 0x6 },
18962 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
18963 {"msp", 0x8 }, {"MSP", 0x8 },
18964 {"psp", 0x9 }, {"PSP", 0x9 },
18965 {"msplim", 0xa }, {"MSPLIM", 0xa },
18966 {"psplim", 0xb }, {"PSPLIM", 0xb },
18967 {"primask", 0x10}, {"PRIMASK", 0x10},
18968 {"basepri", 0x11}, {"BASEPRI", 0x11},
18969 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
18970 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
18971 {"control", 0x14}, {"CONTROL", 0x14},
18972 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
18973 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
18974 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
18975 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
18976 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
18977 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
18978 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
18979 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
18980 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
18981};
18982
c19d1205
ZW
18983/* Table of all shift-in-operand names. */
18984static const struct asm_shift_name shift_names [] =
b99bd4ef 18985{
c19d1205
ZW
18986 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
18987 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
18988 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
18989 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
18990 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
18991 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
18992};
b99bd4ef 18993
c19d1205
ZW
18994/* Table of all explicit relocation names. */
18995#ifdef OBJ_ELF
18996static struct reloc_entry reloc_names[] =
18997{
18998 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
18999 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
19000 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
19001 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
19002 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
19003 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
19004 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
19005 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
19006 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
19007 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 19008 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
19009 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
19010 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 19011 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 19012 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 19013 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 19014 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
477330fc 19015 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
19016};
19017#endif
b99bd4ef 19018
c19d1205
ZW
19019/* Table of all conditional affixes. 0xF is not defined as a condition code. */
19020static const struct asm_cond conds[] =
19021{
19022 {"eq", 0x0},
19023 {"ne", 0x1},
19024 {"cs", 0x2}, {"hs", 0x2},
19025 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
19026 {"mi", 0x4},
19027 {"pl", 0x5},
19028 {"vs", 0x6},
19029 {"vc", 0x7},
19030 {"hi", 0x8},
19031 {"ls", 0x9},
19032 {"ge", 0xa},
19033 {"lt", 0xb},
19034 {"gt", 0xc},
19035 {"le", 0xd},
19036 {"al", 0xe}
19037};
bfae80f2 19038
e797f7e0 19039#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
19040 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
19041 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 19042
62b3e311
PB
19043static struct asm_barrier_opt barrier_opt_names[] =
19044{
e797f7e0
MGD
19045 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
19046 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
19047 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
19048 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
19049 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
19050 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
19051 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
19052 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
19053 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
19054 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
19055 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
19056 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
19057 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
19058 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
19059 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
19060 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
19061};
19062
e797f7e0
MGD
19063#undef UL_BARRIER
19064
c19d1205
ZW
19065/* Table of ARM-format instructions. */
19066
19067/* Macros for gluing together operand strings. N.B. In all cases
19068 other than OPS0, the trailing OP_stop comes from default
19069 zero-initialization of the unspecified elements of the array. */
19070#define OPS0() { OP_stop, }
19071#define OPS1(a) { OP_##a, }
19072#define OPS2(a,b) { OP_##a,OP_##b, }
19073#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
19074#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
19075#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
19076#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
19077
5be8be5d
DG
19078/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
19079 This is useful when mixing operands for ARM and THUMB, i.e. using the
19080 MIX_ARM_THUMB_OPERANDS macro.
19081 In order to use these macros, prefix the number of operands with _
19082 e.g. _3. */
19083#define OPS_1(a) { a, }
19084#define OPS_2(a,b) { a,b, }
19085#define OPS_3(a,b,c) { a,b,c, }
19086#define OPS_4(a,b,c,d) { a,b,c,d, }
19087#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
19088#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
19089
c19d1205
ZW
19090/* These macros abstract out the exact format of the mnemonic table and
19091 save some repeated characters. */
19092
19093/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
19094#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19095 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 19096 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19097
19098/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
19099 a T_MNEM_xyz enumerator. */
19100#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19101 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19102#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19103 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
19104
19105/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
19106 infix after the third character. */
19107#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 19108 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 19109 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 19110#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 19111 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 19112 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19113#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19114 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 19115#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19116 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19117#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19118 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 19119#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19120 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 19121
c19d1205 19122/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
19123 field is still 0xE. Many of the Thumb variants can be executed
19124 conditionally, so this is checked separately. */
c19d1205 19125#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19126 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19127 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19128
dd5181d5
KT
19129/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
19130 Used by mnemonics that have very minimal differences in the encoding for
19131 ARM and Thumb variants and can be handled in a common function. */
19132#define TUEc(mnem, op, top, nops, ops, en) \
19133 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
19134 THUMB_VARIANT, do_##en, do_##en }
19135
c19d1205
ZW
19136/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
19137 condition code field. */
19138#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 19139 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19140 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19141
19142/* ARM-only variants of all the above. */
6a86118a 19143#define CE(mnem, op, nops, ops, ae) \
21d799b5 19144 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
19145
19146#define C3(mnem, op, nops, ops, ae) \
19147 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19148
e3cb604e
PB
19149/* Legacy mnemonics that always have conditional infix after the third
19150 character. */
19151#define CL(mnem, op, nops, ops, ae) \
21d799b5 19152 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19153 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19154
8f06b2d8
PB
19155/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
19156#define cCE(mnem, op, nops, ops, ae) \
21d799b5 19157 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19158
e3cb604e
PB
19159/* Legacy coprocessor instructions where conditional infix and conditional
19160 suffix are ambiguous. For consistency this includes all FPA instructions,
19161 not just the potentially ambiguous ones. */
19162#define cCL(mnem, op, nops, ops, ae) \
21d799b5 19163 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19164 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
19165
19166/* Coprocessor, takes either a suffix or a position-3 infix
19167 (for an FPA corner case). */
19168#define C3E(mnem, op, nops, ops, ae) \
21d799b5 19169 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 19170 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19171
6a86118a 19172#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
19173 { m1 #m2 m3, OPS##nops ops, \
19174 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
19175 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19176
19177#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
19178 xCM_ (m1, , m2, op, nops, ops, ae), \
19179 xCM_ (m1, eq, m2, op, nops, ops, ae), \
19180 xCM_ (m1, ne, m2, op, nops, ops, ae), \
19181 xCM_ (m1, cs, m2, op, nops, ops, ae), \
19182 xCM_ (m1, hs, m2, op, nops, ops, ae), \
19183 xCM_ (m1, cc, m2, op, nops, ops, ae), \
19184 xCM_ (m1, ul, m2, op, nops, ops, ae), \
19185 xCM_ (m1, lo, m2, op, nops, ops, ae), \
19186 xCM_ (m1, mi, m2, op, nops, ops, ae), \
19187 xCM_ (m1, pl, m2, op, nops, ops, ae), \
19188 xCM_ (m1, vs, m2, op, nops, ops, ae), \
19189 xCM_ (m1, vc, m2, op, nops, ops, ae), \
19190 xCM_ (m1, hi, m2, op, nops, ops, ae), \
19191 xCM_ (m1, ls, m2, op, nops, ops, ae), \
19192 xCM_ (m1, ge, m2, op, nops, ops, ae), \
19193 xCM_ (m1, lt, m2, op, nops, ops, ae), \
19194 xCM_ (m1, gt, m2, op, nops, ops, ae), \
19195 xCM_ (m1, le, m2, op, nops, ops, ae), \
19196 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
19197
19198#define UE(mnem, op, nops, ops, ae) \
19199 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19200
19201#define UF(mnem, op, nops, ops, ae) \
19202 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19203
5287ad62
JB
19204/* Neon data-processing. ARM versions are unconditional with cond=0xf.
19205 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
19206 use the same encoding function for each. */
19207#define NUF(mnem, op, nops, ops, enc) \
19208 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
19209 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19210
19211/* Neon data processing, version which indirects through neon_enc_tab for
19212 the various overloaded versions of opcodes. */
19213#define nUF(mnem, op, nops, ops, enc) \
21d799b5 19214 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19215 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19216
19217/* Neon insn with conditional suffix for the ARM version, non-overloaded
19218 version. */
037e8744
JB
19219#define NCE_tag(mnem, op, nops, ops, enc, tag) \
19220 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
19221 THUMB_VARIANT, do_##enc, do_##enc }
19222
037e8744 19223#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 19224 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19225
19226#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 19227 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19228
5287ad62 19229/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 19230#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 19231 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19232 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19233
037e8744 19234#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 19235 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19236
19237#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 19238 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19239
c19d1205
ZW
19240#define do_0 0
19241
c19d1205 19242static const struct asm_opcode insns[] =
bfae80f2 19243{
74db7efb
NC
19244#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
19245#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
19246 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
19247 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
19248 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
19249 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
19250 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
19251 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
19252 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
19253 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
19254 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
19255 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
19256 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
19257 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
19258 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
19259 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
19260 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
19261 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
19262
19263 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
19264 for setting PSR flag bits. They are obsolete in V6 and do not
19265 have Thumb equivalents. */
21d799b5
NC
19266 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19267 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19268 CL("tstp", 110f000, 2, (RR, SH), cmp),
19269 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19270 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19271 CL("cmpp", 150f000, 2, (RR, SH), cmp),
19272 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19273 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19274 CL("cmnp", 170f000, 2, (RR, SH), cmp),
19275
19276 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 19277 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
19278 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
19279 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
19280
19281 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
19282 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19283 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
19284 OP_RRnpc),
19285 OP_ADDRGLDR),ldst, t_ldst),
19286 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
19287
19288 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19289 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19290 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19291 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19292 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19293 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19294
19295 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
19296 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
19297 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
19298 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 19299
c19d1205 19300 /* Pseudo ops. */
21d799b5 19301 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 19302 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 19303 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 19304 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
19305
19306 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
19307 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
19308 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
19309 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
19310 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
19311 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
19312 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
19313 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
19314 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
19315 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
19316 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
19317 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
19318 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 19319
16a4cf17 19320 /* These may simplify to neg. */
21d799b5
NC
19321 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
19322 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 19323
c921be7d
NC
19324#undef THUMB_VARIANT
19325#define THUMB_VARIANT & arm_ext_v6
19326
21d799b5 19327 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
19328
19329 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
19330#undef THUMB_VARIANT
19331#define THUMB_VARIANT & arm_ext_v6t2
19332
21d799b5
NC
19333 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19334 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19335 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 19336
5be8be5d
DG
19337 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19338 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19339 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19340 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 19341
21d799b5
NC
19342 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19343 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 19344
21d799b5
NC
19345 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19346 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
19347
19348 /* V1 instructions with no Thumb analogue at all. */
21d799b5 19349 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
19350 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19351
19352 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19353 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19354 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19355 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19356 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19357 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19358 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19359 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19360
c921be7d
NC
19361#undef ARM_VARIANT
19362#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19363#undef THUMB_VARIANT
19364#define THUMB_VARIANT & arm_ext_v4t
19365
21d799b5
NC
19366 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19367 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 19368
c921be7d
NC
19369#undef THUMB_VARIANT
19370#define THUMB_VARIANT & arm_ext_v6t2
19371
21d799b5 19372 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
19373 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19374
19375 /* Generic coprocessor instructions. */
21d799b5
NC
19376 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19377 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19378 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19379 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19380 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19381 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 19382 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19383
c921be7d
NC
19384#undef ARM_VARIANT
19385#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19386
21d799b5 19387 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
19388 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19389
c921be7d
NC
19390#undef ARM_VARIANT
19391#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19392#undef THUMB_VARIANT
19393#define THUMB_VARIANT & arm_ext_msr
19394
d2cd1205
JB
19395 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19396 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 19397
c921be7d
NC
19398#undef ARM_VARIANT
19399#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19400#undef THUMB_VARIANT
19401#define THUMB_VARIANT & arm_ext_v6t2
19402
21d799b5
NC
19403 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19404 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19405 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19406 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19407 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19408 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19409 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19410 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 19411
c921be7d
NC
19412#undef ARM_VARIANT
19413#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
19414#undef THUMB_VARIANT
19415#define THUMB_VARIANT & arm_ext_v4t
19416
5be8be5d
DG
19417 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19418 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19419 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19420 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
19421 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19422 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 19423
c921be7d
NC
19424#undef ARM_VARIANT
19425#define ARM_VARIANT & arm_ext_v4t_5
19426
c19d1205
ZW
19427 /* ARM Architecture 4T. */
19428 /* Note: bx (and blx) are required on V5, even if the processor does
19429 not support Thumb. */
21d799b5 19430 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 19431
c921be7d
NC
19432#undef ARM_VARIANT
19433#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
19434#undef THUMB_VARIANT
19435#define THUMB_VARIANT & arm_ext_v5t
19436
c19d1205
ZW
19437 /* Note: blx has 2 variants; the .value coded here is for
19438 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
19439 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
19440 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 19441
c921be7d
NC
19442#undef THUMB_VARIANT
19443#define THUMB_VARIANT & arm_ext_v6t2
19444
21d799b5
NC
19445 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
19446 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19447 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19448 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19449 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19450 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19451 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19452 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19453
c921be7d 19454#undef ARM_VARIANT
74db7efb
NC
19455#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
19456#undef THUMB_VARIANT
19457#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 19458
21d799b5
NC
19459 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19460 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19461 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19462 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19463
21d799b5
NC
19464 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19465 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19466
21d799b5
NC
19467 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19468 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19469 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19470 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 19471
21d799b5
NC
19472 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19473 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19474 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19475 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19476
21d799b5
NC
19477 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19478 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19479
03ee1b7f
NC
19480 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19481 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19482 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19483 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 19484
c921be7d 19485#undef ARM_VARIANT
74db7efb
NC
19486#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
19487#undef THUMB_VARIANT
19488#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19489
21d799b5 19490 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
19491 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
19492 ldrd, t_ldstd),
19493 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
19494 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 19495
21d799b5
NC
19496 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19497 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 19498
c921be7d
NC
19499#undef ARM_VARIANT
19500#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
19501
21d799b5 19502 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 19503
c921be7d
NC
19504#undef ARM_VARIANT
19505#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
19506#undef THUMB_VARIANT
19507#define THUMB_VARIANT & arm_ext_v6
19508
21d799b5
NC
19509 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
19510 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
19511 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19512 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19513 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19514 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19515 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19516 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19517 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19518 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 19519
c921be7d 19520#undef THUMB_VARIANT
ff8646ee 19521#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 19522
5be8be5d
DG
19523 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
19524 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19525 strex, t_strex),
ff8646ee
TP
19526#undef THUMB_VARIANT
19527#define THUMB_VARIANT & arm_ext_v6t2
19528
21d799b5
NC
19529 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19530 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 19531
21d799b5
NC
19532 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
19533 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 19534
9e3c6df6 19535/* ARM V6 not included in V7M. */
c921be7d
NC
19536#undef THUMB_VARIANT
19537#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 19538 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 19539 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
19540 UF(rfeib, 9900a00, 1, (RRw), rfe),
19541 UF(rfeda, 8100a00, 1, (RRw), rfe),
19542 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19543 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
19544 UF(rfefa, 8100a00, 1, (RRw), rfe),
19545 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19546 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 19547 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
19548 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19549 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 19550 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 19551 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 19552 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 19553 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 19554 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 19555 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 19556 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 19557
9e3c6df6
PB
19558/* ARM V6 not included in V7M (eg. integer SIMD). */
19559#undef THUMB_VARIANT
19560#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
19561 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
19562 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
19563 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19564 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19565 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19566 /* Old name for QASX. */
74db7efb 19567 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19568 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19569 /* Old name for QSAX. */
74db7efb 19570 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19571 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19572 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19573 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19574 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19575 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19576 /* Old name for SASX. */
74db7efb 19577 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19578 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19579 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19580 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19581 /* Old name for SHASX. */
21d799b5 19582 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19583 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19584 /* Old name for SHSAX. */
21d799b5
NC
19585 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19586 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19587 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19588 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19589 /* Old name for SSAX. */
74db7efb 19590 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19591 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19592 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19593 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19594 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19595 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19596 /* Old name for UASX. */
74db7efb 19597 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19598 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19599 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19600 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19601 /* Old name for UHASX. */
21d799b5
NC
19602 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19603 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19604 /* Old name for UHSAX. */
21d799b5
NC
19605 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19606 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19607 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19608 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19609 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19610 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19611 /* Old name for UQASX. */
21d799b5
NC
19612 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19613 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19614 /* Old name for UQSAX. */
21d799b5
NC
19615 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19616 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19617 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19618 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19619 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19620 /* Old name for USAX. */
74db7efb 19621 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19622 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19623 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19624 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19625 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19626 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19627 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19628 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19629 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19630 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19631 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19632 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19633 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19634 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19635 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19636 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19637 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19638 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19639 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19640 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19641 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19642 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19643 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19644 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19645 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19646 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19647 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19648 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19649 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
19650 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
19651 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
19652 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19653 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19654 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 19655
c921be7d
NC
19656#undef ARM_VARIANT
19657#define ARM_VARIANT & arm_ext_v6k
19658#undef THUMB_VARIANT
19659#define THUMB_VARIANT & arm_ext_v6k
19660
21d799b5
NC
19661 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
19662 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
19663 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
19664 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 19665
c921be7d
NC
19666#undef THUMB_VARIANT
19667#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
19668 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
19669 ldrexd, t_ldrexd),
19670 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
19671 RRnpcb), strexd, t_strexd),
ebdca51a 19672
c921be7d 19673#undef THUMB_VARIANT
ff8646ee 19674#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
19675 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
19676 rd_rn, rd_rn),
19677 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
19678 rd_rn, rd_rn),
19679 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19680 strex, t_strexbh),
5be8be5d 19681 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19682 strex, t_strexbh),
21d799b5 19683 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 19684
c921be7d 19685#undef ARM_VARIANT
f4c65163 19686#define ARM_VARIANT & arm_ext_sec
74db7efb 19687#undef THUMB_VARIANT
f4c65163 19688#define THUMB_VARIANT & arm_ext_sec
c921be7d 19689
21d799b5 19690 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 19691
90ec0d68
MGD
19692#undef ARM_VARIANT
19693#define ARM_VARIANT & arm_ext_virt
19694#undef THUMB_VARIANT
19695#define THUMB_VARIANT & arm_ext_virt
19696
19697 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
19698 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
19699
ddfded2f
MW
19700#undef ARM_VARIANT
19701#define ARM_VARIANT & arm_ext_pan
19702#undef THUMB_VARIANT
19703#define THUMB_VARIANT & arm_ext_pan
19704
19705 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
19706
c921be7d 19707#undef ARM_VARIANT
74db7efb 19708#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
19709#undef THUMB_VARIANT
19710#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19711
21d799b5
NC
19712 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
19713 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
19714 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
19715 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 19716
21d799b5 19717 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 19718 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 19719
5be8be5d
DG
19720 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19721 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19722 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19723 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 19724
ff8646ee
TP
19725#undef THUMB_VARIANT
19726#define THUMB_VARIANT & arm_ext_v6t2_v8m
19727 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
19728 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
19729
bf3eeda7 19730 /* Thumb-only instructions. */
74db7efb 19731#undef ARM_VARIANT
bf3eeda7
NS
19732#define ARM_VARIANT NULL
19733 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
19734 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
19735
19736 /* ARM does not really have an IT instruction, so always allow it.
19737 The opcode is copied from Thumb in order to allow warnings in
19738 -mimplicit-it=[never | arm] modes. */
19739#undef ARM_VARIANT
19740#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
19741#undef THUMB_VARIANT
19742#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19743
21d799b5
NC
19744 TUE("it", bf08, bf08, 1, (COND), it, t_it),
19745 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
19746 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
19747 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
19748 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
19749 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
19750 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
19751 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
19752 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
19753 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
19754 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
19755 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
19756 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
19757 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
19758 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 19759 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
19760 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
19761 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 19762
92e90b6e 19763 /* Thumb2 only instructions. */
c921be7d
NC
19764#undef ARM_VARIANT
19765#define ARM_VARIANT NULL
92e90b6e 19766
21d799b5
NC
19767 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19768 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19769 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
19770 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
19771 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
19772 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 19773
eea54501
MGD
19774 /* Hardware division instructions. */
19775#undef ARM_VARIANT
19776#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
19777#undef THUMB_VARIANT
19778#define THUMB_VARIANT & arm_ext_div
19779
eea54501
MGD
19780 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
19781 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 19782
7e806470 19783 /* ARM V6M/V7 instructions. */
c921be7d
NC
19784#undef ARM_VARIANT
19785#define ARM_VARIANT & arm_ext_barrier
19786#undef THUMB_VARIANT
19787#define THUMB_VARIANT & arm_ext_barrier
19788
ccb84d65
JB
19789 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
19790 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
19791 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 19792
62b3e311 19793 /* ARM V7 instructions. */
c921be7d
NC
19794#undef ARM_VARIANT
19795#define ARM_VARIANT & arm_ext_v7
19796#undef THUMB_VARIANT
19797#define THUMB_VARIANT & arm_ext_v7
19798
21d799b5
NC
19799 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
19800 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 19801
74db7efb 19802#undef ARM_VARIANT
60e5ef9f 19803#define ARM_VARIANT & arm_ext_mp
74db7efb 19804#undef THUMB_VARIANT
60e5ef9f
MGD
19805#define THUMB_VARIANT & arm_ext_mp
19806
19807 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
19808
53c4b28b
MGD
19809 /* AArchv8 instructions. */
19810#undef ARM_VARIANT
19811#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
19812
19813/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 19814#undef THUMB_VARIANT
4ed7ed8d 19815#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 19816
4ed7ed8d
TP
19817 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19818 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19819 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19820 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19821 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19822 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 19823 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
19824 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
19825 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19826 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
19827 stlex, t_stlex),
4b8c8c02
RE
19828 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
19829 stlex, t_stlex),
19830 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
19831 stlex, t_stlex),
4ed7ed8d
TP
19832#undef THUMB_VARIANT
19833#define THUMB_VARIANT & arm_ext_v8
53c4b28b 19834
4ed7ed8d
TP
19835 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
19836 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
19837 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
19838 ldrexd, t_ldrexd),
19839 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
19840 strexd, t_strexd),
8884b720 19841 /* ARMv8 T32 only. */
74db7efb 19842#undef ARM_VARIANT
b79f7053
MGD
19843#define ARM_VARIANT NULL
19844 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
19845 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
19846 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
19847
33399f07
MGD
19848 /* FP for ARMv8. */
19849#undef ARM_VARIANT
a715796b 19850#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 19851#undef THUMB_VARIANT
a715796b 19852#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
19853
19854 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
19855 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
19856 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
19857 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
19858 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
19859 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
19860 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
19861 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
19862 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
19863 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
19864 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
19865 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
19866 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
19867 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
19868 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
19869 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
19870 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 19871
91ff7894
MGD
19872 /* Crypto v1 extensions. */
19873#undef ARM_VARIANT
19874#define ARM_VARIANT & fpu_crypto_ext_armv8
19875#undef THUMB_VARIANT
19876#define THUMB_VARIANT & fpu_crypto_ext_armv8
19877
19878 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
19879 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
19880 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
19881 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
19882 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
19883 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
19884 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
19885 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
19886 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
19887 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
19888 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
19889 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
19890 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
19891 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 19892
dd5181d5 19893#undef ARM_VARIANT
74db7efb 19894#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
19895#undef THUMB_VARIANT
19896#define THUMB_VARIANT & crc_ext_armv8
19897 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
19898 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
19899 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
19900 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
19901 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
19902 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
19903
105bde57
MW
19904 /* ARMv8.2 RAS extension. */
19905#undef ARM_VARIANT
4d1464f2 19906#define ARM_VARIANT & arm_ext_ras
105bde57 19907#undef THUMB_VARIANT
4d1464f2 19908#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
19909 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
19910
49e8a725
SN
19911#undef ARM_VARIANT
19912#define ARM_VARIANT & arm_ext_v8_3
19913#undef THUMB_VARIANT
19914#define THUMB_VARIANT & arm_ext_v8_3
19915 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
c28eeff2
SN
19916 NUF (vcmla, 0, 4, (RNDQ, RNDQ, RNDQ_RNSC, EXPi), vcmla),
19917 NUF (vcadd, 0, 4, (RNDQ, RNDQ, RNDQ, EXPi), vcadd),
49e8a725 19918
c921be7d
NC
19919#undef ARM_VARIANT
19920#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
19921#undef THUMB_VARIANT
19922#define THUMB_VARIANT NULL
c921be7d 19923
21d799b5
NC
19924 cCE("wfs", e200110, 1, (RR), rd),
19925 cCE("rfs", e300110, 1, (RR), rd),
19926 cCE("wfc", e400110, 1, (RR), rd),
19927 cCE("rfc", e500110, 1, (RR), rd),
19928
19929 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
19930 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
19931 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
19932 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
19933
19934 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
19935 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
19936 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
19937 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
19938
19939 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
19940 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
19941 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
19942 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
19943 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
19944 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
19945 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
19946 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
19947 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
19948 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
19949 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
19950 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
19951
19952 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
19953 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
19954 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
19955 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
19956 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
19957 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
19958 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
19959 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
19960 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
19961 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
19962 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
19963 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
19964
19965 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
19966 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
19967 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
19968 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
19969 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
19970 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
19971 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
19972 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
19973 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
19974 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
19975 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
19976 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
19977
19978 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
19979 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
19980 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
19981 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
19982 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
19983 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
19984 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
19985 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
19986 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
19987 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
19988 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
19989 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
19990
19991 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
19992 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
19993 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
19994 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
19995 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
19996 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
19997 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
19998 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
19999 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
20000 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
20001 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
20002 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
20003
20004 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
20005 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
20006 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
20007 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
20008 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
20009 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
20010 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
20011 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
20012 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
20013 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
20014 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
20015 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
20016
20017 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
20018 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
20019 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
20020 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
20021 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
20022 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
20023 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
20024 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
20025 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
20026 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
20027 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
20028 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
20029
20030 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
20031 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
20032 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
20033 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
20034 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
20035 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
20036 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
20037 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
20038 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
20039 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
20040 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
20041 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
20042
20043 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
20044 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
20045 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
20046 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
20047 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
20048 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
20049 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
20050 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
20051 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
20052 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
20053 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
20054 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
20055
20056 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
20057 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
20058 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
20059 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
20060 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
20061 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
20062 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
20063 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
20064 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
20065 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
20066 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
20067 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
20068
20069 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
20070 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
20071 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
20072 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
20073 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
20074 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
20075 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
20076 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
20077 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
20078 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
20079 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
20080 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
20081
20082 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
20083 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
20084 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
20085 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
20086 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
20087 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
20088 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
20089 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
20090 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
20091 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
20092 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
20093 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
20094
20095 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
20096 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
20097 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
20098 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
20099 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
20100 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
20101 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
20102 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
20103 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
20104 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
20105 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
20106 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
20107
20108 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
20109 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
20110 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
20111 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
20112 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
20113 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
20114 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
20115 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
20116 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
20117 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
20118 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
20119 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
20120
20121 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
20122 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
20123 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
20124 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
20125 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
20126 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
20127 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
20128 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
20129 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
20130 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
20131 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
20132 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
20133
20134 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
20135 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
20136 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
20137 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
20138 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
20139 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
20140 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
20141 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
20142 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
20143 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
20144 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
20145 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
20146
20147 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
20148 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
20149 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
20150 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
20151 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
20152 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20153 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20154 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20155 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
20156 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
20157 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
20158 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
20159
20160 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
20161 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
20162 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
20163 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
20164 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
20165 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20166 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20167 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20168 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
20169 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
20170 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
20171 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
20172
20173 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
20174 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
20175 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
20176 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
20177 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
20178 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20179 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20180 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20181 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
20182 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
20183 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
20184 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
20185
20186 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
20187 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
20188 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
20189 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
20190 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
20191 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20192 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20193 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20194 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
20195 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
20196 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
20197 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
20198
20199 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
20200 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
20201 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
20202 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
20203 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
20204 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20205 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20206 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20207 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
20208 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
20209 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
20210 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
20211
20212 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
20213 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
20214 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
20215 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
20216 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
20217 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20218 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20219 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20220 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
20221 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
20222 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
20223 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
20224
20225 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
20226 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
20227 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
20228 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
20229 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
20230 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20231 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20232 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20233 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
20234 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
20235 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
20236 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
20237
20238 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
20239 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
20240 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
20241 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
20242 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
20243 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20244 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20245 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20246 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
20247 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
20248 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
20249 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
20250
20251 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
20252 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
20253 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
20254 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
20255 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
20256 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20257 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20258 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20259 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
20260 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
20261 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
20262 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
20263
20264 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
20265 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
20266 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
20267 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
20268 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
20269 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20270 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20271 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20272 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
20273 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
20274 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
20275 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
20276
20277 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20278 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20279 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20280 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20281 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20282 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20283 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20284 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20285 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20286 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20287 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20288 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20289
20290 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20291 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20292 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20293 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20294 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20295 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20296 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20297 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20298 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20299 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20300 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20301 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20302
20303 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20304 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20305 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20306 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20307 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20308 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20309 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20310 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20311 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20312 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20313 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20314 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20315
20316 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
20317 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
20318 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
20319 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
20320
20321 cCL("flts", e000110, 2, (RF, RR), rn_rd),
20322 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
20323 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
20324 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
20325 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
20326 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
20327 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
20328 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
20329 cCL("flte", e080110, 2, (RF, RR), rn_rd),
20330 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
20331 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20332 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 20333
c19d1205
ZW
20334 /* The implementation of the FIX instruction is broken on some
20335 assemblers, in that it accepts a precision specifier as well as a
20336 rounding specifier, despite the fact that this is meaningless.
20337 To be more compatible, we accept it as well, though of course it
20338 does not set any bits. */
21d799b5
NC
20339 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20340 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20341 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20342 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20343 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20344 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20345 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20346 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20347 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20348 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20349 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20350 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20351 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 20352
c19d1205 20353 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
20354#undef ARM_VARIANT
20355#define ARM_VARIANT & fpu_fpa_ext_v2
20356
21d799b5
NC
20357 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20358 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20359 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20360 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20361 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20362 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 20363
c921be7d
NC
20364#undef ARM_VARIANT
20365#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20366
c19d1205 20367 /* Moves and type conversions. */
21d799b5
NC
20368 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20369 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20370 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20371 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
20372 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20373 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
20374 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20375 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20376 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
20377 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20378 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
20379 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20380 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
20381 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
20382
20383 /* Memory operations. */
21d799b5
NC
20384 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20385 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
20386 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20387 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20388 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20389 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20390 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20391 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20392 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20393 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20394 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20395 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20396 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20397 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20398 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20399 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20400 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20401 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 20402
c19d1205 20403 /* Monadic operations. */
21d799b5
NC
20404 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
20405 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
20406 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
20407
20408 /* Dyadic operations. */
21d799b5
NC
20409 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20410 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20411 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20412 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20413 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20414 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20415 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20416 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20417 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 20418
c19d1205 20419 /* Comparisons. */
21d799b5
NC
20420 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
20421 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
20422 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
20423 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 20424
62f3b8c8
PB
20425 /* Double precision load/store are still present on single precision
20426 implementations. */
20427 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20428 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
20429 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20430 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20431 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20432 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20433 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20434 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20435 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20436 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 20437
c921be7d
NC
20438#undef ARM_VARIANT
20439#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
20440
c19d1205 20441 /* Moves and type conversions. */
21d799b5
NC
20442 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20443 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20444 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20445 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
20446 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
20447 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
20448 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
20449 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20450 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
20451 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20452 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20453 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20454 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 20455
c19d1205 20456 /* Monadic operations. */
21d799b5
NC
20457 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20458 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20459 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
20460
20461 /* Dyadic operations. */
21d799b5
NC
20462 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20463 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20464 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20465 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20466 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20467 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20468 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20469 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20470 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 20471
c19d1205 20472 /* Comparisons. */
21d799b5
NC
20473 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20474 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
20475 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20476 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 20477
c921be7d
NC
20478#undef ARM_VARIANT
20479#define ARM_VARIANT & fpu_vfp_ext_v2
20480
21d799b5
NC
20481 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
20482 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
20483 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
20484 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 20485
037e8744
JB
20486/* Instructions which may belong to either the Neon or VFP instruction sets.
20487 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
20488#undef ARM_VARIANT
20489#define ARM_VARIANT & fpu_vfp_ext_v1xd
20490#undef THUMB_VARIANT
20491#define THUMB_VARIANT & fpu_vfp_ext_v1xd
20492
037e8744
JB
20493 /* These mnemonics are unique to VFP. */
20494 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
20495 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
20496 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20497 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20498 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
20499 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20500 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
20501 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
20502 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
20503 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
20504
20505 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
20506 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
20507 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20508 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 20509
21d799b5
NC
20510 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20511 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
20512
20513 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20514 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20515
55881a11
MGD
20516 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20517 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20518 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20519 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20520 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20521 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
20522 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20523 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 20524
5f1af56b 20525 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 20526 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
20527 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
20528 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 20529
037e8744
JB
20530
20531 /* NOTE: All VMOV encoding is special-cased! */
20532 NCE(vmov, 0, 1, (VMOV), neon_mov),
20533 NCE(vmovq, 0, 1, (VMOV), neon_mov),
20534
9db2f6b4
RL
20535#undef ARM_VARIANT
20536#define ARM_VARIANT & arm_ext_fp16
20537#undef THUMB_VARIANT
20538#define THUMB_VARIANT & arm_ext_fp16
20539 /* New instructions added from v8.2, allowing the extraction and insertion of
20540 the upper 16 bits of a 32-bit vector register. */
20541 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
20542 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
20543
c921be7d
NC
20544#undef THUMB_VARIANT
20545#define THUMB_VARIANT & fpu_neon_ext_v1
20546#undef ARM_VARIANT
20547#define ARM_VARIANT & fpu_neon_ext_v1
20548
5287ad62
JB
20549 /* Data processing with three registers of the same length. */
20550 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
20551 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
20552 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
20553 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20554 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20555 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20556 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20557 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20558 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20559 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
20560 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20561 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20562 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20563 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
20564 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20565 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20566 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20567 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
20568 /* If not immediate, fall back to neon_dyadic_i64_su.
20569 shl_imm should accept I8 I16 I32 I64,
20570 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
20571 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
20572 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
20573 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
20574 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 20575 /* Logic ops, types optional & ignored. */
4316f0d2
DG
20576 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20577 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20578 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20579 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20580 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20581 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20582 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20583 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20584 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
20585 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
20586 /* Bitfield ops, untyped. */
20587 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20588 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20589 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20590 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20591 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20592 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 20593 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5
NC
20594 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20595 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20596 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20597 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20598 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20599 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
20600 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
20601 back to neon_dyadic_if_su. */
21d799b5
NC
20602 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20603 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20604 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20605 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20606 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20607 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
20608 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20609 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 20610 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
20611 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
20612 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 20613 /* As above, D registers only. */
21d799b5
NC
20614 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
20615 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 20616 /* Int and float variants, signedness unimportant. */
21d799b5
NC
20617 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20618 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20619 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 20620 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
20621 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
20622 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
20623 /* vtst takes sizes 8, 16, 32. */
20624 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
20625 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
20626 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 20627 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 20628 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
20629 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20630 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
20631 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20632 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
20633 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20634 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
20635 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20636 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
20637 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20638 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
20639 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20640 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
20641 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20642 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
20643 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20644 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 20645 /* ARM v8.1 extension. */
643afb90
MW
20646 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20647 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
20648 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20649 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
20650
20651 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 20652 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
20653 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
20654
20655 /* Data processing with two registers and a shift amount. */
20656 /* Right shifts, and variants with rounding.
20657 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
20658 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20659 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20660 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20661 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20662 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20663 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20664 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20665 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20666 /* Shift and insert. Sizes accepted 8 16 32 64. */
20667 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
20668 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
20669 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
20670 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
20671 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
20672 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
20673 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
20674 /* Right shift immediate, saturating & narrowing, with rounding variants.
20675 Types accepted S16 S32 S64 U16 U32 U64. */
20676 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20677 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20678 /* As above, unsigned. Types accepted S16 S32 S64. */
20679 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20680 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20681 /* Right shift narrowing. Types accepted I16 I32 I64. */
20682 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20683 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20684 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 20685 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 20686 /* CVT with optional immediate for fixed-point variant. */
21d799b5 20687 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 20688
4316f0d2
DG
20689 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
20690 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
20691
20692 /* Data processing, three registers of different lengths. */
20693 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
20694 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
20695 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
20696 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
20697 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
20698 /* If not scalar, fall back to neon_dyadic_long.
20699 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
20700 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
20701 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
20702 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
20703 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20704 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20705 /* Dyadic, narrowing insns. Types I16 I32 I64. */
20706 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20707 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20708 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20709 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20710 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
20711 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20712 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20713 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
20714 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
20715 S16 S32 U16 U32. */
21d799b5 20716 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
20717
20718 /* Extract. Size 8. */
3b8d421e
PB
20719 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
20720 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
20721
20722 /* Two registers, miscellaneous. */
20723 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
20724 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
20725 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
20726 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
20727 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
20728 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
20729 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
20730 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
20731 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
20732 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
20733 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
20734 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
20735 /* VMOVN. Types I16 I32 I64. */
21d799b5 20736 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 20737 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 20738 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 20739 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 20740 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
20741 /* VZIP / VUZP. Sizes 8 16 32. */
20742 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
20743 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
20744 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
20745 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
20746 /* VQABS / VQNEG. Types S8 S16 S32. */
20747 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20748 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
20749 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20750 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
20751 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
20752 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
20753 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
20754 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
20755 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 20756 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
20757 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
20758 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
20759 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
20760 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
20761 /* VCLS. Types S8 S16 S32. */
20762 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
20763 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
20764 /* VCLZ. Types I8 I16 I32. */
20765 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
20766 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
20767 /* VCNT. Size 8. */
20768 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
20769 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
20770 /* Two address, untyped. */
20771 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
20772 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
20773 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
20774 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
20775 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
20776
20777 /* Table lookup. Size 8. */
20778 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20779 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20780
c921be7d
NC
20781#undef THUMB_VARIANT
20782#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
20783#undef ARM_VARIANT
20784#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
20785
5287ad62 20786 /* Neon element/structure load/store. */
21d799b5
NC
20787 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20788 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20789 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20790 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20791 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20792 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20793 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
20794 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 20795
c921be7d 20796#undef THUMB_VARIANT
74db7efb
NC
20797#define THUMB_VARIANT & fpu_vfp_ext_v3xd
20798#undef ARM_VARIANT
20799#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
20800 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
20801 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20802 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20803 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20804 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20805 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20806 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20807 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20808 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20809
74db7efb 20810#undef THUMB_VARIANT
c921be7d
NC
20811#define THUMB_VARIANT & fpu_vfp_ext_v3
20812#undef ARM_VARIANT
20813#define ARM_VARIANT & fpu_vfp_ext_v3
20814
21d799b5 20815 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 20816 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20817 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20818 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20819 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20820 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20821 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20822 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20823 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 20824
74db7efb
NC
20825#undef ARM_VARIANT
20826#define ARM_VARIANT & fpu_vfp_ext_fma
20827#undef THUMB_VARIANT
20828#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
20829 /* Mnemonics shared by Neon and VFP. These are included in the
20830 VFP FMA variant; NEON and VFP FMA always includes the NEON
20831 FMA instructions. */
20832 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20833 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20834 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
20835 the v form should always be used. */
20836 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20837 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20838 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20839 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20840 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20841 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20842
5287ad62 20843#undef THUMB_VARIANT
c921be7d
NC
20844#undef ARM_VARIANT
20845#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
20846
21d799b5
NC
20847 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20848 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20849 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20850 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20851 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20852 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20853 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
20854 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 20855
c921be7d
NC
20856#undef ARM_VARIANT
20857#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
20858
21d799b5
NC
20859 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
20860 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
20861 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
20862 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
20863 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
20864 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
20865 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
20866 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
20867 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
20868 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20869 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20870 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20871 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20872 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20873 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
20874 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20875 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20876 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20877 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
20878 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
20879 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20880 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20881 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20882 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20883 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20884 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
20885 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
20886 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
20887 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
20888 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
20889 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
20890 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
20891 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
20892 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
20893 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
20894 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
20895 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
20896 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20897 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20898 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20899 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20900 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20901 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20902 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20903 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20904 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20905 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
20906 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20907 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20908 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20909 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20910 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20911 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20912 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20913 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20914 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20915 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20916 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20917 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20918 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20919 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20920 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20921 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20922 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20923 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20924 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20925 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20926 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20927 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20928 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20929 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20930 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20931 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20932 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20933 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20934 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20935 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20936 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20937 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20938 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20939 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20940 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20941 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20942 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20943 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20944 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20945 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20946 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20947 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
20948 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20949 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20950 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20951 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20952 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20953 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20954 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20955 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20956 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20957 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20958 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20959 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20960 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20961 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20962 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20963 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20964 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20965 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20966 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20967 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20968 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20969 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
20970 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20971 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20972 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20973 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20974 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20975 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20976 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20977 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20978 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20979 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20980 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20981 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20982 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20983 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20984 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20985 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20986 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20987 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20988 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20989 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20990 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20991 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20992 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20993 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20994 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20995 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20996 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20997 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20998 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20999 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21000 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21001 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
21002 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
21003 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
21004 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
21005 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
21006 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
21007 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21008 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21009 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21010 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
21011 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
21012 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
21013 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
21014 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
21015 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
21016 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21017 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21018 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21019 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21020 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 21021
c921be7d
NC
21022#undef ARM_VARIANT
21023#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
21024
21d799b5
NC
21025 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
21026 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
21027 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
21028 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
21029 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
21030 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
21031 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21032 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21033 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21034 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21035 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21036 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21037 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21038 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21039 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21040 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21041 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21042 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21043 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21044 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21045 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
21046 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21047 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21048 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21049 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21050 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21051 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21052 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21053 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21054 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21055 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21056 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21057 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21058 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21059 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21060 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21061 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21062 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21063 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21064 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21065 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21066 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21067 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21068 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21069 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21070 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21071 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21072 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21073 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21074 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21075 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21076 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21077 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21078 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21079 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21080 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21081 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 21082
c921be7d
NC
21083#undef ARM_VARIANT
21084#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
21085
21d799b5
NC
21086 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21087 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21088 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21089 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21090 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21091 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21092 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21093 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21094 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
21095 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
21096 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
21097 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
21098 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
21099 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
21100 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
21101 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
21102 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
21103 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
21104 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
21105 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
21106 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
21107 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
21108 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
21109 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
21110 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
21111 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
21112 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
21113 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
21114 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
21115 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
21116 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
21117 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
21118 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
21119 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
21120 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
21121 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
21122 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
21123 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
21124 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
21125 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
21126 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
21127 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
21128 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
21129 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
21130 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
21131 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
21132 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
21133 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
21134 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
21135 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
21136 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
21137 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
21138 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
21139 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
21140 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
21141 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
21142 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
21143 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
21144 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
21145 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
21146 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
21147 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
21148 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
21149 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
21150 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21151 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21152 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21153 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21154 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21155 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21156 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21157 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
21158 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21159 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
21160 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
21161 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 21162
16a1fa25 21163 /* ARMv8-M instructions. */
4ed7ed8d
TP
21164#undef ARM_VARIANT
21165#define ARM_VARIANT NULL
21166#undef THUMB_VARIANT
21167#define THUMB_VARIANT & arm_ext_v8m
16a1fa25
TP
21168 TUE("sg", 0, e97fe97f, 0, (), 0, noargs),
21169 TUE("blxns", 0, 4784, 1, (RRnpc), 0, t_blx),
21170 TUE("bxns", 0, 4704, 1, (RRnpc), 0, t_bx),
4ed7ed8d
TP
21171 TUE("tt", 0, e840f000, 2, (RRnpc, RRnpc), 0, tt),
21172 TUE("ttt", 0, e840f040, 2, (RRnpc, RRnpc), 0, tt),
16a1fa25
TP
21173 TUE("tta", 0, e840f080, 2, (RRnpc, RRnpc), 0, tt),
21174 TUE("ttat", 0, e840f0c0, 2, (RRnpc, RRnpc), 0, tt),
21175
21176 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
21177 instructions behave as nop if no VFP is present. */
21178#undef THUMB_VARIANT
21179#define THUMB_VARIANT & arm_ext_v8m_main
21180 TUEc("vlldm", 0, ec300a00, 1, (RRnpc), rn),
21181 TUEc("vlstm", 0, ec200a00, 1, (RRnpc), rn),
c19d1205
ZW
21182};
21183#undef ARM_VARIANT
21184#undef THUMB_VARIANT
21185#undef TCE
c19d1205
ZW
21186#undef TUE
21187#undef TUF
21188#undef TCC
8f06b2d8 21189#undef cCE
e3cb604e
PB
21190#undef cCL
21191#undef C3E
c19d1205
ZW
21192#undef CE
21193#undef CM
21194#undef UE
21195#undef UF
21196#undef UT
5287ad62
JB
21197#undef NUF
21198#undef nUF
21199#undef NCE
21200#undef nCE
c19d1205
ZW
21201#undef OPS0
21202#undef OPS1
21203#undef OPS2
21204#undef OPS3
21205#undef OPS4
21206#undef OPS5
21207#undef OPS6
21208#undef do_0
21209\f
21210/* MD interface: bits in the object file. */
bfae80f2 21211
c19d1205
ZW
21212/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
21213 for use in the a.out file, and stores them in the array pointed to by buf.
21214 This knows about the endian-ness of the target machine and does
21215 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
21216 2 (short) and 4 (long) Floating numbers are put out as a series of
21217 LITTLENUMS (shorts, here at least). */
b99bd4ef 21218
c19d1205
ZW
21219void
21220md_number_to_chars (char * buf, valueT val, int n)
21221{
21222 if (target_big_endian)
21223 number_to_chars_bigendian (buf, val, n);
21224 else
21225 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
21226}
21227
c19d1205
ZW
21228static valueT
21229md_chars_to_number (char * buf, int n)
bfae80f2 21230{
c19d1205
ZW
21231 valueT result = 0;
21232 unsigned char * where = (unsigned char *) buf;
bfae80f2 21233
c19d1205 21234 if (target_big_endian)
b99bd4ef 21235 {
c19d1205
ZW
21236 while (n--)
21237 {
21238 result <<= 8;
21239 result |= (*where++ & 255);
21240 }
b99bd4ef 21241 }
c19d1205 21242 else
b99bd4ef 21243 {
c19d1205
ZW
21244 while (n--)
21245 {
21246 result <<= 8;
21247 result |= (where[n] & 255);
21248 }
bfae80f2 21249 }
b99bd4ef 21250
c19d1205 21251 return result;
bfae80f2 21252}
b99bd4ef 21253
c19d1205 21254/* MD interface: Sections. */
b99bd4ef 21255
fa94de6b
RM
21256/* Calculate the maximum variable size (i.e., excluding fr_fix)
21257 that an rs_machine_dependent frag may reach. */
21258
21259unsigned int
21260arm_frag_max_var (fragS *fragp)
21261{
21262 /* We only use rs_machine_dependent for variable-size Thumb instructions,
21263 which are either THUMB_SIZE (2) or INSN_SIZE (4).
21264
21265 Note that we generate relaxable instructions even for cases that don't
21266 really need it, like an immediate that's a trivial constant. So we're
21267 overestimating the instruction size for some of those cases. Rather
21268 than putting more intelligence here, it would probably be better to
21269 avoid generating a relaxation frag in the first place when it can be
21270 determined up front that a short instruction will suffice. */
21271
21272 gas_assert (fragp->fr_type == rs_machine_dependent);
21273 return INSN_SIZE;
21274}
21275
0110f2b8
PB
21276/* Estimate the size of a frag before relaxing. Assume everything fits in
21277 2 bytes. */
21278
c19d1205 21279int
0110f2b8 21280md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
21281 segT segtype ATTRIBUTE_UNUSED)
21282{
0110f2b8
PB
21283 fragp->fr_var = 2;
21284 return 2;
21285}
21286
21287/* Convert a machine dependent frag. */
21288
21289void
21290md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
21291{
21292 unsigned long insn;
21293 unsigned long old_op;
21294 char *buf;
21295 expressionS exp;
21296 fixS *fixp;
21297 int reloc_type;
21298 int pc_rel;
21299 int opcode;
21300
21301 buf = fragp->fr_literal + fragp->fr_fix;
21302
21303 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
21304 if (fragp->fr_symbol)
21305 {
0110f2b8
PB
21306 exp.X_op = O_symbol;
21307 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
21308 }
21309 else
21310 {
0110f2b8 21311 exp.X_op = O_constant;
5f4273c7 21312 }
0110f2b8
PB
21313 exp.X_add_number = fragp->fr_offset;
21314 opcode = fragp->fr_subtype;
21315 switch (opcode)
21316 {
21317 case T_MNEM_ldr_pc:
21318 case T_MNEM_ldr_pc2:
21319 case T_MNEM_ldr_sp:
21320 case T_MNEM_str_sp:
21321 case T_MNEM_ldr:
21322 case T_MNEM_ldrb:
21323 case T_MNEM_ldrh:
21324 case T_MNEM_str:
21325 case T_MNEM_strb:
21326 case T_MNEM_strh:
21327 if (fragp->fr_var == 4)
21328 {
5f4273c7 21329 insn = THUMB_OP32 (opcode);
0110f2b8
PB
21330 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
21331 {
21332 insn |= (old_op & 0x700) << 4;
21333 }
21334 else
21335 {
21336 insn |= (old_op & 7) << 12;
21337 insn |= (old_op & 0x38) << 13;
21338 }
21339 insn |= 0x00000c00;
21340 put_thumb32_insn (buf, insn);
21341 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
21342 }
21343 else
21344 {
21345 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
21346 }
21347 pc_rel = (opcode == T_MNEM_ldr_pc2);
21348 break;
21349 case T_MNEM_adr:
21350 if (fragp->fr_var == 4)
21351 {
21352 insn = THUMB_OP32 (opcode);
21353 insn |= (old_op & 0xf0) << 4;
21354 put_thumb32_insn (buf, insn);
21355 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
21356 }
21357 else
21358 {
21359 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21360 exp.X_add_number -= 4;
21361 }
21362 pc_rel = 1;
21363 break;
21364 case T_MNEM_mov:
21365 case T_MNEM_movs:
21366 case T_MNEM_cmp:
21367 case T_MNEM_cmn:
21368 if (fragp->fr_var == 4)
21369 {
21370 int r0off = (opcode == T_MNEM_mov
21371 || opcode == T_MNEM_movs) ? 0 : 8;
21372 insn = THUMB_OP32 (opcode);
21373 insn = (insn & 0xe1ffffff) | 0x10000000;
21374 insn |= (old_op & 0x700) << r0off;
21375 put_thumb32_insn (buf, insn);
21376 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21377 }
21378 else
21379 {
21380 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
21381 }
21382 pc_rel = 0;
21383 break;
21384 case T_MNEM_b:
21385 if (fragp->fr_var == 4)
21386 {
21387 insn = THUMB_OP32(opcode);
21388 put_thumb32_insn (buf, insn);
21389 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
21390 }
21391 else
21392 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
21393 pc_rel = 1;
21394 break;
21395 case T_MNEM_bcond:
21396 if (fragp->fr_var == 4)
21397 {
21398 insn = THUMB_OP32(opcode);
21399 insn |= (old_op & 0xf00) << 14;
21400 put_thumb32_insn (buf, insn);
21401 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
21402 }
21403 else
21404 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
21405 pc_rel = 1;
21406 break;
21407 case T_MNEM_add_sp:
21408 case T_MNEM_add_pc:
21409 case T_MNEM_inc_sp:
21410 case T_MNEM_dec_sp:
21411 if (fragp->fr_var == 4)
21412 {
21413 /* ??? Choose between add and addw. */
21414 insn = THUMB_OP32 (opcode);
21415 insn |= (old_op & 0xf0) << 4;
21416 put_thumb32_insn (buf, insn);
16805f35
PB
21417 if (opcode == T_MNEM_add_pc)
21418 reloc_type = BFD_RELOC_ARM_T32_IMM12;
21419 else
21420 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
21421 }
21422 else
21423 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21424 pc_rel = 0;
21425 break;
21426
21427 case T_MNEM_addi:
21428 case T_MNEM_addis:
21429 case T_MNEM_subi:
21430 case T_MNEM_subis:
21431 if (fragp->fr_var == 4)
21432 {
21433 insn = THUMB_OP32 (opcode);
21434 insn |= (old_op & 0xf0) << 4;
21435 insn |= (old_op & 0xf) << 16;
21436 put_thumb32_insn (buf, insn);
16805f35
PB
21437 if (insn & (1 << 20))
21438 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21439 else
21440 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
21441 }
21442 else
21443 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21444 pc_rel = 0;
21445 break;
21446 default:
5f4273c7 21447 abort ();
0110f2b8
PB
21448 }
21449 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 21450 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
21451 fixp->fx_file = fragp->fr_file;
21452 fixp->fx_line = fragp->fr_line;
21453 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
21454
21455 /* Set whether we use thumb-2 ISA based on final relaxation results. */
21456 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
21457 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
21458 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
21459}
21460
21461/* Return the size of a relaxable immediate operand instruction.
21462 SHIFT and SIZE specify the form of the allowable immediate. */
21463static int
21464relax_immediate (fragS *fragp, int size, int shift)
21465{
21466 offsetT offset;
21467 offsetT mask;
21468 offsetT low;
21469
21470 /* ??? Should be able to do better than this. */
21471 if (fragp->fr_symbol)
21472 return 4;
21473
21474 low = (1 << shift) - 1;
21475 mask = (1 << (shift + size)) - (1 << shift);
21476 offset = fragp->fr_offset;
21477 /* Force misaligned offsets to 32-bit variant. */
21478 if (offset & low)
5e77afaa 21479 return 4;
0110f2b8
PB
21480 if (offset & ~mask)
21481 return 4;
21482 return 2;
21483}
21484
5e77afaa
PB
21485/* Get the address of a symbol during relaxation. */
21486static addressT
5f4273c7 21487relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
21488{
21489 fragS *sym_frag;
21490 addressT addr;
21491 symbolS *sym;
21492
21493 sym = fragp->fr_symbol;
21494 sym_frag = symbol_get_frag (sym);
21495 know (S_GET_SEGMENT (sym) != absolute_section
21496 || sym_frag == &zero_address_frag);
21497 addr = S_GET_VALUE (sym) + fragp->fr_offset;
21498
21499 /* If frag has yet to be reached on this pass, assume it will
21500 move by STRETCH just as we did. If this is not so, it will
21501 be because some frag between grows, and that will force
21502 another pass. */
21503
21504 if (stretch != 0
21505 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
21506 {
21507 fragS *f;
21508
21509 /* Adjust stretch for any alignment frag. Note that if have
21510 been expanding the earlier code, the symbol may be
21511 defined in what appears to be an earlier frag. FIXME:
21512 This doesn't handle the fr_subtype field, which specifies
21513 a maximum number of bytes to skip when doing an
21514 alignment. */
21515 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
21516 {
21517 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
21518 {
21519 if (stretch < 0)
21520 stretch = - ((- stretch)
21521 & ~ ((1 << (int) f->fr_offset) - 1));
21522 else
21523 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
21524 if (stretch == 0)
21525 break;
21526 }
21527 }
21528 if (f != NULL)
21529 addr += stretch;
21530 }
5e77afaa
PB
21531
21532 return addr;
21533}
21534
0110f2b8
PB
21535/* Return the size of a relaxable adr pseudo-instruction or PC-relative
21536 load. */
21537static int
5e77afaa 21538relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
21539{
21540 addressT addr;
21541 offsetT val;
21542
21543 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
21544 if (fragp->fr_symbol == NULL
21545 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21546 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21547 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21548 return 4;
21549
5f4273c7 21550 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21551 addr = fragp->fr_address + fragp->fr_fix;
21552 addr = (addr + 4) & ~3;
5e77afaa 21553 /* Force misaligned targets to 32-bit variant. */
0110f2b8 21554 if (val & 3)
5e77afaa 21555 return 4;
0110f2b8
PB
21556 val -= addr;
21557 if (val < 0 || val > 1020)
21558 return 4;
21559 return 2;
21560}
21561
21562/* Return the size of a relaxable add/sub immediate instruction. */
21563static int
21564relax_addsub (fragS *fragp, asection *sec)
21565{
21566 char *buf;
21567 int op;
21568
21569 buf = fragp->fr_literal + fragp->fr_fix;
21570 op = bfd_get_16(sec->owner, buf);
21571 if ((op & 0xf) == ((op >> 4) & 0xf))
21572 return relax_immediate (fragp, 8, 0);
21573 else
21574 return relax_immediate (fragp, 3, 0);
21575}
21576
e83a675f
RE
21577/* Return TRUE iff the definition of symbol S could be pre-empted
21578 (overridden) at link or load time. */
21579static bfd_boolean
21580symbol_preemptible (symbolS *s)
21581{
21582 /* Weak symbols can always be pre-empted. */
21583 if (S_IS_WEAK (s))
21584 return TRUE;
21585
21586 /* Non-global symbols cannot be pre-empted. */
21587 if (! S_IS_EXTERNAL (s))
21588 return FALSE;
21589
21590#ifdef OBJ_ELF
21591 /* In ELF, a global symbol can be marked protected, or private. In that
21592 case it can't be pre-empted (other definitions in the same link unit
21593 would violate the ODR). */
21594 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
21595 return FALSE;
21596#endif
21597
21598 /* Other global symbols might be pre-empted. */
21599 return TRUE;
21600}
0110f2b8
PB
21601
21602/* Return the size of a relaxable branch instruction. BITS is the
21603 size of the offset field in the narrow instruction. */
21604
21605static int
5e77afaa 21606relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
21607{
21608 addressT addr;
21609 offsetT val;
21610 offsetT limit;
21611
21612 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 21613 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21614 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21615 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21616 return 4;
21617
267bf995 21618#ifdef OBJ_ELF
e83a675f 21619 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
21620 if (S_IS_DEFINED (fragp->fr_symbol)
21621 && ARM_IS_FUNC (fragp->fr_symbol))
21622 return 4;
e83a675f 21623#endif
0d9b4b55 21624
e83a675f 21625 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 21626 return 4;
267bf995 21627
5f4273c7 21628 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21629 addr = fragp->fr_address + fragp->fr_fix + 4;
21630 val -= addr;
21631
21632 /* Offset is a signed value *2 */
21633 limit = 1 << bits;
21634 if (val >= limit || val < -limit)
21635 return 4;
21636 return 2;
21637}
21638
21639
21640/* Relax a machine dependent frag. This returns the amount by which
21641 the current size of the frag should change. */
21642
21643int
5e77afaa 21644arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
21645{
21646 int oldsize;
21647 int newsize;
21648
21649 oldsize = fragp->fr_var;
21650 switch (fragp->fr_subtype)
21651 {
21652 case T_MNEM_ldr_pc2:
5f4273c7 21653 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21654 break;
21655 case T_MNEM_ldr_pc:
21656 case T_MNEM_ldr_sp:
21657 case T_MNEM_str_sp:
5f4273c7 21658 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
21659 break;
21660 case T_MNEM_ldr:
21661 case T_MNEM_str:
5f4273c7 21662 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
21663 break;
21664 case T_MNEM_ldrh:
21665 case T_MNEM_strh:
5f4273c7 21666 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
21667 break;
21668 case T_MNEM_ldrb:
21669 case T_MNEM_strb:
5f4273c7 21670 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
21671 break;
21672 case T_MNEM_adr:
5f4273c7 21673 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21674 break;
21675 case T_MNEM_mov:
21676 case T_MNEM_movs:
21677 case T_MNEM_cmp:
21678 case T_MNEM_cmn:
5f4273c7 21679 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
21680 break;
21681 case T_MNEM_b:
5f4273c7 21682 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
21683 break;
21684 case T_MNEM_bcond:
5f4273c7 21685 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
21686 break;
21687 case T_MNEM_add_sp:
21688 case T_MNEM_add_pc:
21689 newsize = relax_immediate (fragp, 8, 2);
21690 break;
21691 case T_MNEM_inc_sp:
21692 case T_MNEM_dec_sp:
21693 newsize = relax_immediate (fragp, 7, 2);
21694 break;
21695 case T_MNEM_addi:
21696 case T_MNEM_addis:
21697 case T_MNEM_subi:
21698 case T_MNEM_subis:
21699 newsize = relax_addsub (fragp, sec);
21700 break;
21701 default:
5f4273c7 21702 abort ();
0110f2b8 21703 }
5e77afaa
PB
21704
21705 fragp->fr_var = newsize;
21706 /* Freeze wide instructions that are at or before the same location as
21707 in the previous pass. This avoids infinite loops.
5f4273c7
NC
21708 Don't freeze them unconditionally because targets may be artificially
21709 misaligned by the expansion of preceding frags. */
5e77afaa 21710 if (stretch <= 0 && newsize > 2)
0110f2b8 21711 {
0110f2b8 21712 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 21713 frag_wane (fragp);
0110f2b8 21714 }
5e77afaa 21715
0110f2b8 21716 return newsize - oldsize;
c19d1205 21717}
b99bd4ef 21718
c19d1205 21719/* Round up a section size to the appropriate boundary. */
b99bd4ef 21720
c19d1205
ZW
21721valueT
21722md_section_align (segT segment ATTRIBUTE_UNUSED,
21723 valueT size)
21724{
f0927246
NC
21725#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
21726 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
21727 {
21728 /* For a.out, force the section size to be aligned. If we don't do
21729 this, BFD will align it for us, but it will not write out the
21730 final bytes of the section. This may be a bug in BFD, but it is
21731 easier to fix it here since that is how the other a.out targets
21732 work. */
21733 int align;
21734
21735 align = bfd_get_section_alignment (stdoutput, segment);
8d3842cd 21736 size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
f0927246 21737 }
c19d1205 21738#endif
f0927246 21739
6844c0cc 21740 return size;
bfae80f2 21741}
b99bd4ef 21742
c19d1205
ZW
21743/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
21744 of an rs_align_code fragment. */
21745
21746void
21747arm_handle_align (fragS * fragP)
bfae80f2 21748{
d9235011 21749 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
21750 {
21751 { /* ARMv1 */
21752 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
21753 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
21754 },
21755 { /* ARMv6k */
21756 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
21757 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
21758 },
21759 };
d9235011 21760 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
21761 {
21762 { /* Thumb-1 */
21763 {0xc0, 0x46}, /* LE */
21764 {0x46, 0xc0}, /* BE */
21765 },
21766 { /* Thumb-2 */
21767 {0x00, 0xbf}, /* LE */
21768 {0xbf, 0x00} /* BE */
21769 }
21770 };
d9235011 21771 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
21772 { /* Wide Thumb-2 */
21773 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
21774 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
21775 };
c921be7d 21776
e7495e45 21777 unsigned bytes, fix, noop_size;
c19d1205 21778 char * p;
d9235011
TS
21779 const unsigned char * noop;
21780 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
21781#ifdef OBJ_ELF
21782 enum mstate state;
21783#endif
bfae80f2 21784
c19d1205 21785 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
21786 return;
21787
c19d1205
ZW
21788 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
21789 p = fragP->fr_literal + fragP->fr_fix;
21790 fix = 0;
bfae80f2 21791
c19d1205
ZW
21792 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
21793 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 21794
cd000bff 21795 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 21796
cd000bff 21797 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 21798 {
7f78eb34
JW
21799 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21800 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
21801 {
21802 narrow_noop = thumb_noop[1][target_big_endian];
21803 noop = wide_thumb_noop[target_big_endian];
21804 }
c19d1205 21805 else
e7495e45
NS
21806 noop = thumb_noop[0][target_big_endian];
21807 noop_size = 2;
cd000bff
DJ
21808#ifdef OBJ_ELF
21809 state = MAP_THUMB;
21810#endif
7ed4c4c5
NC
21811 }
21812 else
21813 {
7f78eb34
JW
21814 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21815 ? selected_cpu : arm_arch_none,
21816 arm_ext_v6k) != 0]
e7495e45
NS
21817 [target_big_endian];
21818 noop_size = 4;
cd000bff
DJ
21819#ifdef OBJ_ELF
21820 state = MAP_ARM;
21821#endif
7ed4c4c5 21822 }
c921be7d 21823
e7495e45 21824 fragP->fr_var = noop_size;
c921be7d 21825
c19d1205 21826 if (bytes & (noop_size - 1))
7ed4c4c5 21827 {
c19d1205 21828 fix = bytes & (noop_size - 1);
cd000bff
DJ
21829#ifdef OBJ_ELF
21830 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
21831#endif
c19d1205
ZW
21832 memset (p, 0, fix);
21833 p += fix;
21834 bytes -= fix;
a737bd4d 21835 }
a737bd4d 21836
e7495e45
NS
21837 if (narrow_noop)
21838 {
21839 if (bytes & noop_size)
21840 {
21841 /* Insert a narrow noop. */
21842 memcpy (p, narrow_noop, noop_size);
21843 p += noop_size;
21844 bytes -= noop_size;
21845 fix += noop_size;
21846 }
21847
21848 /* Use wide noops for the remainder */
21849 noop_size = 4;
21850 }
21851
c19d1205 21852 while (bytes >= noop_size)
a737bd4d 21853 {
c19d1205
ZW
21854 memcpy (p, noop, noop_size);
21855 p += noop_size;
21856 bytes -= noop_size;
21857 fix += noop_size;
a737bd4d
NC
21858 }
21859
c19d1205 21860 fragP->fr_fix += fix;
a737bd4d
NC
21861}
21862
c19d1205
ZW
21863/* Called from md_do_align. Used to create an alignment
21864 frag in a code section. */
21865
21866void
21867arm_frag_align_code (int n, int max)
bfae80f2 21868{
c19d1205 21869 char * p;
7ed4c4c5 21870
c19d1205 21871 /* We assume that there will never be a requirement
6ec8e702 21872 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 21873 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
21874 {
21875 char err_msg[128];
21876
fa94de6b 21877 sprintf (err_msg,
477330fc
RM
21878 _("alignments greater than %d bytes not supported in .text sections."),
21879 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 21880 as_fatal ("%s", err_msg);
6ec8e702 21881 }
bfae80f2 21882
c19d1205
ZW
21883 p = frag_var (rs_align_code,
21884 MAX_MEM_FOR_RS_ALIGN_CODE,
21885 1,
21886 (relax_substateT) max,
21887 (symbolS *) NULL,
21888 (offsetT) n,
21889 (char *) NULL);
21890 *p = 0;
21891}
bfae80f2 21892
8dc2430f
NC
21893/* Perform target specific initialisation of a frag.
21894 Note - despite the name this initialisation is not done when the frag
21895 is created, but only when its type is assigned. A frag can be created
21896 and used a long time before its type is set, so beware of assuming that
33eaf5de 21897 this initialisation is performed first. */
bfae80f2 21898
cd000bff
DJ
21899#ifndef OBJ_ELF
21900void
21901arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
21902{
21903 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 21904 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
21905}
21906
21907#else /* OBJ_ELF is defined. */
c19d1205 21908void
cd000bff 21909arm_init_frag (fragS * fragP, int max_chars)
c19d1205 21910{
b968d18a
JW
21911 int frag_thumb_mode;
21912
8dc2430f
NC
21913 /* If the current ARM vs THUMB mode has not already
21914 been recorded into this frag then do so now. */
cd000bff 21915 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
21916 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
21917
21918 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 21919
f9c1b181
RL
21920 /* Record a mapping symbol for alignment frags. We will delete this
21921 later if the alignment ends up empty. */
21922 switch (fragP->fr_type)
21923 {
21924 case rs_align:
21925 case rs_align_test:
21926 case rs_fill:
21927 mapping_state_2 (MAP_DATA, max_chars);
21928 break;
21929 case rs_align_code:
b968d18a 21930 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
21931 break;
21932 default:
21933 break;
cd000bff 21934 }
bfae80f2
RE
21935}
21936
c19d1205
ZW
21937/* When we change sections we need to issue a new mapping symbol. */
21938
21939void
21940arm_elf_change_section (void)
bfae80f2 21941{
c19d1205
ZW
21942 /* Link an unlinked unwind index table section to the .text section. */
21943 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
21944 && elf_linked_to_section (now_seg) == NULL)
21945 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
21946}
21947
c19d1205
ZW
21948int
21949arm_elf_section_type (const char * str, size_t len)
e45d0630 21950{
c19d1205
ZW
21951 if (len == 5 && strncmp (str, "exidx", 5) == 0)
21952 return SHT_ARM_EXIDX;
e45d0630 21953
c19d1205
ZW
21954 return -1;
21955}
21956\f
21957/* Code to deal with unwinding tables. */
e45d0630 21958
c19d1205 21959static void add_unwind_adjustsp (offsetT);
e45d0630 21960
5f4273c7 21961/* Generate any deferred unwind frame offset. */
e45d0630 21962
bfae80f2 21963static void
c19d1205 21964flush_pending_unwind (void)
bfae80f2 21965{
c19d1205 21966 offsetT offset;
bfae80f2 21967
c19d1205
ZW
21968 offset = unwind.pending_offset;
21969 unwind.pending_offset = 0;
21970 if (offset != 0)
21971 add_unwind_adjustsp (offset);
bfae80f2
RE
21972}
21973
c19d1205
ZW
21974/* Add an opcode to this list for this function. Two-byte opcodes should
21975 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
21976 order. */
21977
bfae80f2 21978static void
c19d1205 21979add_unwind_opcode (valueT op, int length)
bfae80f2 21980{
c19d1205
ZW
21981 /* Add any deferred stack adjustment. */
21982 if (unwind.pending_offset)
21983 flush_pending_unwind ();
bfae80f2 21984
c19d1205 21985 unwind.sp_restored = 0;
bfae80f2 21986
c19d1205 21987 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 21988 {
c19d1205
ZW
21989 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
21990 if (unwind.opcodes)
325801bd
TS
21991 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
21992 unwind.opcode_alloc);
c19d1205 21993 else
325801bd 21994 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 21995 }
c19d1205 21996 while (length > 0)
bfae80f2 21997 {
c19d1205
ZW
21998 length--;
21999 unwind.opcodes[unwind.opcode_count] = op & 0xff;
22000 op >>= 8;
22001 unwind.opcode_count++;
bfae80f2 22002 }
bfae80f2
RE
22003}
22004
c19d1205
ZW
22005/* Add unwind opcodes to adjust the stack pointer. */
22006
bfae80f2 22007static void
c19d1205 22008add_unwind_adjustsp (offsetT offset)
bfae80f2 22009{
c19d1205 22010 valueT op;
bfae80f2 22011
c19d1205 22012 if (offset > 0x200)
bfae80f2 22013 {
c19d1205
ZW
22014 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
22015 char bytes[5];
22016 int n;
22017 valueT o;
bfae80f2 22018
c19d1205
ZW
22019 /* Long form: 0xb2, uleb128. */
22020 /* This might not fit in a word so add the individual bytes,
22021 remembering the list is built in reverse order. */
22022 o = (valueT) ((offset - 0x204) >> 2);
22023 if (o == 0)
22024 add_unwind_opcode (0, 1);
bfae80f2 22025
c19d1205
ZW
22026 /* Calculate the uleb128 encoding of the offset. */
22027 n = 0;
22028 while (o)
22029 {
22030 bytes[n] = o & 0x7f;
22031 o >>= 7;
22032 if (o)
22033 bytes[n] |= 0x80;
22034 n++;
22035 }
22036 /* Add the insn. */
22037 for (; n; n--)
22038 add_unwind_opcode (bytes[n - 1], 1);
22039 add_unwind_opcode (0xb2, 1);
22040 }
22041 else if (offset > 0x100)
bfae80f2 22042 {
c19d1205
ZW
22043 /* Two short opcodes. */
22044 add_unwind_opcode (0x3f, 1);
22045 op = (offset - 0x104) >> 2;
22046 add_unwind_opcode (op, 1);
bfae80f2 22047 }
c19d1205
ZW
22048 else if (offset > 0)
22049 {
22050 /* Short opcode. */
22051 op = (offset - 4) >> 2;
22052 add_unwind_opcode (op, 1);
22053 }
22054 else if (offset < 0)
bfae80f2 22055 {
c19d1205
ZW
22056 offset = -offset;
22057 while (offset > 0x100)
bfae80f2 22058 {
c19d1205
ZW
22059 add_unwind_opcode (0x7f, 1);
22060 offset -= 0x100;
bfae80f2 22061 }
c19d1205
ZW
22062 op = ((offset - 4) >> 2) | 0x40;
22063 add_unwind_opcode (op, 1);
bfae80f2 22064 }
bfae80f2
RE
22065}
22066
c19d1205
ZW
22067/* Finish the list of unwind opcodes for this function. */
22068static void
22069finish_unwind_opcodes (void)
bfae80f2 22070{
c19d1205 22071 valueT op;
bfae80f2 22072
c19d1205 22073 if (unwind.fp_used)
bfae80f2 22074 {
708587a4 22075 /* Adjust sp as necessary. */
c19d1205
ZW
22076 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
22077 flush_pending_unwind ();
bfae80f2 22078
c19d1205
ZW
22079 /* After restoring sp from the frame pointer. */
22080 op = 0x90 | unwind.fp_reg;
22081 add_unwind_opcode (op, 1);
22082 }
22083 else
22084 flush_pending_unwind ();
bfae80f2
RE
22085}
22086
bfae80f2 22087
c19d1205
ZW
22088/* Start an exception table entry. If idx is nonzero this is an index table
22089 entry. */
bfae80f2
RE
22090
22091static void
c19d1205 22092start_unwind_section (const segT text_seg, int idx)
bfae80f2 22093{
c19d1205
ZW
22094 const char * text_name;
22095 const char * prefix;
22096 const char * prefix_once;
22097 const char * group_name;
c19d1205 22098 char * sec_name;
c19d1205
ZW
22099 int type;
22100 int flags;
22101 int linkonce;
bfae80f2 22102
c19d1205 22103 if (idx)
bfae80f2 22104 {
c19d1205
ZW
22105 prefix = ELF_STRING_ARM_unwind;
22106 prefix_once = ELF_STRING_ARM_unwind_once;
22107 type = SHT_ARM_EXIDX;
bfae80f2 22108 }
c19d1205 22109 else
bfae80f2 22110 {
c19d1205
ZW
22111 prefix = ELF_STRING_ARM_unwind_info;
22112 prefix_once = ELF_STRING_ARM_unwind_info_once;
22113 type = SHT_PROGBITS;
bfae80f2
RE
22114 }
22115
c19d1205
ZW
22116 text_name = segment_name (text_seg);
22117 if (streq (text_name, ".text"))
22118 text_name = "";
22119
22120 if (strncmp (text_name, ".gnu.linkonce.t.",
22121 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 22122 {
c19d1205
ZW
22123 prefix = prefix_once;
22124 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
22125 }
22126
29a2809e 22127 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 22128
c19d1205
ZW
22129 flags = SHF_ALLOC;
22130 linkonce = 0;
22131 group_name = 0;
bfae80f2 22132
c19d1205
ZW
22133 /* Handle COMDAT group. */
22134 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 22135 {
c19d1205
ZW
22136 group_name = elf_group_name (text_seg);
22137 if (group_name == NULL)
22138 {
bd3ba5d1 22139 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
22140 segment_name (text_seg));
22141 ignore_rest_of_line ();
22142 return;
22143 }
22144 flags |= SHF_GROUP;
22145 linkonce = 1;
bfae80f2
RE
22146 }
22147
a91e1603
L
22148 obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
22149 linkonce, 0);
bfae80f2 22150
5f4273c7 22151 /* Set the section link for index tables. */
c19d1205
ZW
22152 if (idx)
22153 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
22154}
22155
bfae80f2 22156
c19d1205
ZW
22157/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
22158 personality routine data. Returns zero, or the index table value for
cad0da33 22159 an inline entry. */
c19d1205
ZW
22160
22161static valueT
22162create_unwind_entry (int have_data)
bfae80f2 22163{
c19d1205
ZW
22164 int size;
22165 addressT where;
22166 char *ptr;
22167 /* The current word of data. */
22168 valueT data;
22169 /* The number of bytes left in this word. */
22170 int n;
bfae80f2 22171
c19d1205 22172 finish_unwind_opcodes ();
bfae80f2 22173
c19d1205
ZW
22174 /* Remember the current text section. */
22175 unwind.saved_seg = now_seg;
22176 unwind.saved_subseg = now_subseg;
bfae80f2 22177
c19d1205 22178 start_unwind_section (now_seg, 0);
bfae80f2 22179
c19d1205 22180 if (unwind.personality_routine == NULL)
bfae80f2 22181 {
c19d1205
ZW
22182 if (unwind.personality_index == -2)
22183 {
22184 if (have_data)
5f4273c7 22185 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
22186 return 1; /* EXIDX_CANTUNWIND. */
22187 }
bfae80f2 22188
c19d1205
ZW
22189 /* Use a default personality routine if none is specified. */
22190 if (unwind.personality_index == -1)
22191 {
22192 if (unwind.opcode_count > 3)
22193 unwind.personality_index = 1;
22194 else
22195 unwind.personality_index = 0;
22196 }
bfae80f2 22197
c19d1205
ZW
22198 /* Space for the personality routine entry. */
22199 if (unwind.personality_index == 0)
22200 {
22201 if (unwind.opcode_count > 3)
22202 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 22203
c19d1205
ZW
22204 if (!have_data)
22205 {
22206 /* All the data is inline in the index table. */
22207 data = 0x80;
22208 n = 3;
22209 while (unwind.opcode_count > 0)
22210 {
22211 unwind.opcode_count--;
22212 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22213 n--;
22214 }
bfae80f2 22215
c19d1205
ZW
22216 /* Pad with "finish" opcodes. */
22217 while (n--)
22218 data = (data << 8) | 0xb0;
bfae80f2 22219
c19d1205
ZW
22220 return data;
22221 }
22222 size = 0;
22223 }
22224 else
22225 /* We get two opcodes "free" in the first word. */
22226 size = unwind.opcode_count - 2;
22227 }
22228 else
5011093d 22229 {
cad0da33
NC
22230 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
22231 if (unwind.personality_index != -1)
22232 {
22233 as_bad (_("attempt to recreate an unwind entry"));
22234 return 1;
22235 }
5011093d
NC
22236
22237 /* An extra byte is required for the opcode count. */
22238 size = unwind.opcode_count + 1;
22239 }
bfae80f2 22240
c19d1205
ZW
22241 size = (size + 3) >> 2;
22242 if (size > 0xff)
22243 as_bad (_("too many unwind opcodes"));
bfae80f2 22244
c19d1205
ZW
22245 frag_align (2, 0, 0);
22246 record_alignment (now_seg, 2);
22247 unwind.table_entry = expr_build_dot ();
22248
22249 /* Allocate the table entry. */
22250 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
22251 /* PR 13449: Zero the table entries in case some of them are not used. */
22252 memset (ptr, 0, (size << 2) + 4);
c19d1205 22253 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 22254
c19d1205 22255 switch (unwind.personality_index)
bfae80f2 22256 {
c19d1205
ZW
22257 case -1:
22258 /* ??? Should this be a PLT generating relocation? */
22259 /* Custom personality routine. */
22260 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
22261 BFD_RELOC_ARM_PREL31);
bfae80f2 22262
c19d1205
ZW
22263 where += 4;
22264 ptr += 4;
bfae80f2 22265
c19d1205 22266 /* Set the first byte to the number of additional words. */
5011093d 22267 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
22268 n = 3;
22269 break;
bfae80f2 22270
c19d1205
ZW
22271 /* ABI defined personality routines. */
22272 case 0:
22273 /* Three opcodes bytes are packed into the first word. */
22274 data = 0x80;
22275 n = 3;
22276 break;
bfae80f2 22277
c19d1205
ZW
22278 case 1:
22279 case 2:
22280 /* The size and first two opcode bytes go in the first word. */
22281 data = ((0x80 + unwind.personality_index) << 8) | size;
22282 n = 2;
22283 break;
bfae80f2 22284
c19d1205
ZW
22285 default:
22286 /* Should never happen. */
22287 abort ();
22288 }
bfae80f2 22289
c19d1205
ZW
22290 /* Pack the opcodes into words (MSB first), reversing the list at the same
22291 time. */
22292 while (unwind.opcode_count > 0)
22293 {
22294 if (n == 0)
22295 {
22296 md_number_to_chars (ptr, data, 4);
22297 ptr += 4;
22298 n = 4;
22299 data = 0;
22300 }
22301 unwind.opcode_count--;
22302 n--;
22303 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22304 }
22305
22306 /* Finish off the last word. */
22307 if (n < 4)
22308 {
22309 /* Pad with "finish" opcodes. */
22310 while (n--)
22311 data = (data << 8) | 0xb0;
22312
22313 md_number_to_chars (ptr, data, 4);
22314 }
22315
22316 if (!have_data)
22317 {
22318 /* Add an empty descriptor if there is no user-specified data. */
22319 ptr = frag_more (4);
22320 md_number_to_chars (ptr, 0, 4);
22321 }
22322
22323 return 0;
bfae80f2
RE
22324}
22325
f0927246
NC
22326
22327/* Initialize the DWARF-2 unwind information for this procedure. */
22328
22329void
22330tc_arm_frame_initial_instructions (void)
22331{
22332 cfi_add_CFA_def_cfa (REG_SP, 0);
22333}
22334#endif /* OBJ_ELF */
22335
c19d1205
ZW
22336/* Convert REGNAME to a DWARF-2 register number. */
22337
22338int
1df69f4f 22339tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 22340{
1df69f4f 22341 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
22342 if (reg != FAIL)
22343 return reg;
c19d1205 22344
1f5afe1c
NC
22345 /* PR 16694: Allow VFP registers as well. */
22346 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22347 if (reg != FAIL)
22348 return 64 + reg;
c19d1205 22349
1f5afe1c
NC
22350 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
22351 if (reg != FAIL)
22352 return reg + 256;
22353
22354 return -1;
bfae80f2
RE
22355}
22356
f0927246 22357#ifdef TE_PE
c19d1205 22358void
f0927246 22359tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 22360{
91d6fa6a 22361 expressionS exp;
bfae80f2 22362
91d6fa6a
NC
22363 exp.X_op = O_secrel;
22364 exp.X_add_symbol = symbol;
22365 exp.X_add_number = 0;
22366 emit_expr (&exp, size);
f0927246
NC
22367}
22368#endif
bfae80f2 22369
c19d1205 22370/* MD interface: Symbol and relocation handling. */
bfae80f2 22371
2fc8bdac
ZW
22372/* Return the address within the segment that a PC-relative fixup is
22373 relative to. For ARM, PC-relative fixups applied to instructions
22374 are generally relative to the location of the fixup plus 8 bytes.
22375 Thumb branches are offset by 4, and Thumb loads relative to PC
22376 require special handling. */
bfae80f2 22377
c19d1205 22378long
2fc8bdac 22379md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 22380{
2fc8bdac
ZW
22381 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
22382
22383 /* If this is pc-relative and we are going to emit a relocation
22384 then we just want to put out any pipeline compensation that the linker
53baae48
NC
22385 will need. Otherwise we want to use the calculated base.
22386 For WinCE we skip the bias for externals as well, since this
22387 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 22388 if (fixP->fx_pcrel
2fc8bdac 22389 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
22390 || (arm_force_relocation (fixP)
22391#ifdef TE_WINCE
22392 && !S_IS_EXTERNAL (fixP->fx_addsy)
22393#endif
22394 )))
2fc8bdac 22395 base = 0;
bfae80f2 22396
267bf995 22397
c19d1205 22398 switch (fixP->fx_r_type)
bfae80f2 22399 {
2fc8bdac
ZW
22400 /* PC relative addressing on the Thumb is slightly odd as the
22401 bottom two bits of the PC are forced to zero for the
22402 calculation. This happens *after* application of the
22403 pipeline offset. However, Thumb adrl already adjusts for
22404 this, so we need not do it again. */
c19d1205 22405 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 22406 return base & ~3;
c19d1205
ZW
22407
22408 case BFD_RELOC_ARM_THUMB_OFFSET:
22409 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 22410 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 22411 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 22412 return (base + 4) & ~3;
c19d1205 22413
2fc8bdac
ZW
22414 /* Thumb branches are simply offset by +4. */
22415 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22416 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22417 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22418 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 22419 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 22420 return base + 4;
bfae80f2 22421
267bf995 22422 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
22423 if (fixP->fx_addsy
22424 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22425 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 22426 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
22427 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22428 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
22429 return base + 4;
22430
00adf2d4
JB
22431 /* BLX is like branches above, but forces the low two bits of PC to
22432 zero. */
486499d0
CL
22433 case BFD_RELOC_THUMB_PCREL_BLX:
22434 if (fixP->fx_addsy
22435 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22436 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22437 && THUMB_IS_FUNC (fixP->fx_addsy)
22438 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22439 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
22440 return (base + 4) & ~3;
22441
2fc8bdac
ZW
22442 /* ARM mode branches are offset by +8. However, the Windows CE
22443 loader expects the relocation not to take this into account. */
267bf995 22444 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
22445 if (fixP->fx_addsy
22446 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22447 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22448 && ARM_IS_FUNC (fixP->fx_addsy)
22449 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22450 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22451 return base + 8;
267bf995 22452
486499d0
CL
22453 case BFD_RELOC_ARM_PCREL_CALL:
22454 if (fixP->fx_addsy
22455 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22456 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22457 && THUMB_IS_FUNC (fixP->fx_addsy)
22458 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22459 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22460 return base + 8;
267bf995 22461
2fc8bdac 22462 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 22463 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 22464 case BFD_RELOC_ARM_PLT32:
c19d1205 22465#ifdef TE_WINCE
5f4273c7 22466 /* When handling fixups immediately, because we have already
477330fc 22467 discovered the value of a symbol, or the address of the frag involved
53baae48 22468 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
22469 see fixup_segment() in write.c
22470 The S_IS_EXTERNAL test handles the case of global symbols.
22471 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
22472 if (fixP->fx_pcrel
22473 && fixP->fx_addsy != NULL
22474 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22475 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
22476 return base + 8;
2fc8bdac 22477 return base;
c19d1205 22478#else
2fc8bdac 22479 return base + 8;
c19d1205 22480#endif
2fc8bdac 22481
267bf995 22482
2fc8bdac
ZW
22483 /* ARM mode loads relative to PC are also offset by +8. Unlike
22484 branches, the Windows CE loader *does* expect the relocation
22485 to take this into account. */
22486 case BFD_RELOC_ARM_OFFSET_IMM:
22487 case BFD_RELOC_ARM_OFFSET_IMM8:
22488 case BFD_RELOC_ARM_HWLITERAL:
22489 case BFD_RELOC_ARM_LITERAL:
22490 case BFD_RELOC_ARM_CP_OFF_IMM:
22491 return base + 8;
22492
22493
22494 /* Other PC-relative relocations are un-offset. */
22495 default:
22496 return base;
22497 }
bfae80f2
RE
22498}
22499
8b2d793c
NC
22500static bfd_boolean flag_warn_syms = TRUE;
22501
ae8714c2
NC
22502bfd_boolean
22503arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 22504{
8b2d793c
NC
22505 /* PR 18347 - Warn if the user attempts to create a symbol with the same
22506 name as an ARM instruction. Whilst strictly speaking it is allowed, it
22507 does mean that the resulting code might be very confusing to the reader.
22508 Also this warning can be triggered if the user omits an operand before
22509 an immediate address, eg:
22510
22511 LDR =foo
22512
22513 GAS treats this as an assignment of the value of the symbol foo to a
22514 symbol LDR, and so (without this code) it will not issue any kind of
22515 warning or error message.
22516
22517 Note - ARM instructions are case-insensitive but the strings in the hash
22518 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
22519 lower case too. */
22520 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
22521 {
22522 char * nbuf = strdup (name);
22523 char * p;
22524
22525 for (p = nbuf; *p; p++)
22526 *p = TOLOWER (*p);
22527 if (hash_find (arm_ops_hsh, nbuf) != NULL)
22528 {
22529 static struct hash_control * already_warned = NULL;
22530
22531 if (already_warned == NULL)
22532 already_warned = hash_new ();
22533 /* Only warn about the symbol once. To keep the code
22534 simple we let hash_insert do the lookup for us. */
22535 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 22536 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
22537 }
22538 else
22539 free (nbuf);
22540 }
3739860c 22541
ae8714c2
NC
22542 return FALSE;
22543}
22544
22545/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
22546 Otherwise we have no need to default values of symbols. */
22547
22548symbolS *
22549md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
22550{
22551#ifdef OBJ_ELF
22552 if (name[0] == '_' && name[1] == 'G'
22553 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
22554 {
22555 if (!GOT_symbol)
22556 {
22557 if (symbol_find (name))
22558 as_bad (_("GOT already in the symbol table"));
22559
22560 GOT_symbol = symbol_new (name, undefined_section,
22561 (valueT) 0, & zero_address_frag);
22562 }
22563
22564 return GOT_symbol;
22565 }
22566#endif
22567
c921be7d 22568 return NULL;
bfae80f2
RE
22569}
22570
55cf6793 22571/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
22572 computed as two separate immediate values, added together. We
22573 already know that this value cannot be computed by just one ARM
22574 instruction. */
22575
22576static unsigned int
22577validate_immediate_twopart (unsigned int val,
22578 unsigned int * highpart)
bfae80f2 22579{
c19d1205
ZW
22580 unsigned int a;
22581 unsigned int i;
bfae80f2 22582
c19d1205
ZW
22583 for (i = 0; i < 32; i += 2)
22584 if (((a = rotate_left (val, i)) & 0xff) != 0)
22585 {
22586 if (a & 0xff00)
22587 {
22588 if (a & ~ 0xffff)
22589 continue;
22590 * highpart = (a >> 8) | ((i + 24) << 7);
22591 }
22592 else if (a & 0xff0000)
22593 {
22594 if (a & 0xff000000)
22595 continue;
22596 * highpart = (a >> 16) | ((i + 16) << 7);
22597 }
22598 else
22599 {
9c2799c2 22600 gas_assert (a & 0xff000000);
c19d1205
ZW
22601 * highpart = (a >> 24) | ((i + 8) << 7);
22602 }
bfae80f2 22603
c19d1205
ZW
22604 return (a & 0xff) | (i << 7);
22605 }
bfae80f2 22606
c19d1205 22607 return FAIL;
bfae80f2
RE
22608}
22609
c19d1205
ZW
22610static int
22611validate_offset_imm (unsigned int val, int hwse)
22612{
22613 if ((hwse && val > 255) || val > 4095)
22614 return FAIL;
22615 return val;
22616}
bfae80f2 22617
55cf6793 22618/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
22619 negative immediate constant by altering the instruction. A bit of
22620 a hack really.
22621 MOV <-> MVN
22622 AND <-> BIC
22623 ADC <-> SBC
22624 by inverting the second operand, and
22625 ADD <-> SUB
22626 CMP <-> CMN
22627 by negating the second operand. */
bfae80f2 22628
c19d1205
ZW
22629static int
22630negate_data_op (unsigned long * instruction,
22631 unsigned long value)
bfae80f2 22632{
c19d1205
ZW
22633 int op, new_inst;
22634 unsigned long negated, inverted;
bfae80f2 22635
c19d1205
ZW
22636 negated = encode_arm_immediate (-value);
22637 inverted = encode_arm_immediate (~value);
bfae80f2 22638
c19d1205
ZW
22639 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
22640 switch (op)
bfae80f2 22641 {
c19d1205
ZW
22642 /* First negates. */
22643 case OPCODE_SUB: /* ADD <-> SUB */
22644 new_inst = OPCODE_ADD;
22645 value = negated;
22646 break;
bfae80f2 22647
c19d1205
ZW
22648 case OPCODE_ADD:
22649 new_inst = OPCODE_SUB;
22650 value = negated;
22651 break;
bfae80f2 22652
c19d1205
ZW
22653 case OPCODE_CMP: /* CMP <-> CMN */
22654 new_inst = OPCODE_CMN;
22655 value = negated;
22656 break;
bfae80f2 22657
c19d1205
ZW
22658 case OPCODE_CMN:
22659 new_inst = OPCODE_CMP;
22660 value = negated;
22661 break;
bfae80f2 22662
c19d1205
ZW
22663 /* Now Inverted ops. */
22664 case OPCODE_MOV: /* MOV <-> MVN */
22665 new_inst = OPCODE_MVN;
22666 value = inverted;
22667 break;
bfae80f2 22668
c19d1205
ZW
22669 case OPCODE_MVN:
22670 new_inst = OPCODE_MOV;
22671 value = inverted;
22672 break;
bfae80f2 22673
c19d1205
ZW
22674 case OPCODE_AND: /* AND <-> BIC */
22675 new_inst = OPCODE_BIC;
22676 value = inverted;
22677 break;
bfae80f2 22678
c19d1205
ZW
22679 case OPCODE_BIC:
22680 new_inst = OPCODE_AND;
22681 value = inverted;
22682 break;
bfae80f2 22683
c19d1205
ZW
22684 case OPCODE_ADC: /* ADC <-> SBC */
22685 new_inst = OPCODE_SBC;
22686 value = inverted;
22687 break;
bfae80f2 22688
c19d1205
ZW
22689 case OPCODE_SBC:
22690 new_inst = OPCODE_ADC;
22691 value = inverted;
22692 break;
bfae80f2 22693
c19d1205
ZW
22694 /* We cannot do anything. */
22695 default:
22696 return FAIL;
b99bd4ef
NC
22697 }
22698
c19d1205
ZW
22699 if (value == (unsigned) FAIL)
22700 return FAIL;
22701
22702 *instruction &= OPCODE_MASK;
22703 *instruction |= new_inst << DATA_OP_SHIFT;
22704 return value;
b99bd4ef
NC
22705}
22706
ef8d22e6
PB
22707/* Like negate_data_op, but for Thumb-2. */
22708
22709static unsigned int
16dd5e42 22710thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
22711{
22712 int op, new_inst;
22713 int rd;
16dd5e42 22714 unsigned int negated, inverted;
ef8d22e6
PB
22715
22716 negated = encode_thumb32_immediate (-value);
22717 inverted = encode_thumb32_immediate (~value);
22718
22719 rd = (*instruction >> 8) & 0xf;
22720 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
22721 switch (op)
22722 {
22723 /* ADD <-> SUB. Includes CMP <-> CMN. */
22724 case T2_OPCODE_SUB:
22725 new_inst = T2_OPCODE_ADD;
22726 value = negated;
22727 break;
22728
22729 case T2_OPCODE_ADD:
22730 new_inst = T2_OPCODE_SUB;
22731 value = negated;
22732 break;
22733
22734 /* ORR <-> ORN. Includes MOV <-> MVN. */
22735 case T2_OPCODE_ORR:
22736 new_inst = T2_OPCODE_ORN;
22737 value = inverted;
22738 break;
22739
22740 case T2_OPCODE_ORN:
22741 new_inst = T2_OPCODE_ORR;
22742 value = inverted;
22743 break;
22744
22745 /* AND <-> BIC. TST has no inverted equivalent. */
22746 case T2_OPCODE_AND:
22747 new_inst = T2_OPCODE_BIC;
22748 if (rd == 15)
22749 value = FAIL;
22750 else
22751 value = inverted;
22752 break;
22753
22754 case T2_OPCODE_BIC:
22755 new_inst = T2_OPCODE_AND;
22756 value = inverted;
22757 break;
22758
22759 /* ADC <-> SBC */
22760 case T2_OPCODE_ADC:
22761 new_inst = T2_OPCODE_SBC;
22762 value = inverted;
22763 break;
22764
22765 case T2_OPCODE_SBC:
22766 new_inst = T2_OPCODE_ADC;
22767 value = inverted;
22768 break;
22769
22770 /* We cannot do anything. */
22771 default:
22772 return FAIL;
22773 }
22774
16dd5e42 22775 if (value == (unsigned int)FAIL)
ef8d22e6
PB
22776 return FAIL;
22777
22778 *instruction &= T2_OPCODE_MASK;
22779 *instruction |= new_inst << T2_DATA_OP_SHIFT;
22780 return value;
22781}
22782
8f06b2d8
PB
22783/* Read a 32-bit thumb instruction from buf. */
22784static unsigned long
22785get_thumb32_insn (char * buf)
22786{
22787 unsigned long insn;
22788 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
22789 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22790
22791 return insn;
22792}
22793
a8bc6c78
PB
22794
22795/* We usually want to set the low bit on the address of thumb function
22796 symbols. In particular .word foo - . should have the low bit set.
22797 Generic code tries to fold the difference of two symbols to
22798 a constant. Prevent this and force a relocation when the first symbols
22799 is a thumb function. */
c921be7d
NC
22800
22801bfd_boolean
a8bc6c78
PB
22802arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
22803{
22804 if (op == O_subtract
22805 && l->X_op == O_symbol
22806 && r->X_op == O_symbol
22807 && THUMB_IS_FUNC (l->X_add_symbol))
22808 {
22809 l->X_op = O_subtract;
22810 l->X_op_symbol = r->X_add_symbol;
22811 l->X_add_number -= r->X_add_number;
c921be7d 22812 return TRUE;
a8bc6c78 22813 }
c921be7d 22814
a8bc6c78 22815 /* Process as normal. */
c921be7d 22816 return FALSE;
a8bc6c78
PB
22817}
22818
4a42ebbc
RR
22819/* Encode Thumb2 unconditional branches and calls. The encoding
22820 for the 2 are identical for the immediate values. */
22821
22822static void
22823encode_thumb2_b_bl_offset (char * buf, offsetT value)
22824{
22825#define T2I1I2MASK ((1 << 13) | (1 << 11))
22826 offsetT newval;
22827 offsetT newval2;
22828 addressT S, I1, I2, lo, hi;
22829
22830 S = (value >> 24) & 0x01;
22831 I1 = (value >> 23) & 0x01;
22832 I2 = (value >> 22) & 0x01;
22833 hi = (value >> 12) & 0x3ff;
fa94de6b 22834 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
22835 newval = md_chars_to_number (buf, THUMB_SIZE);
22836 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22837 newval |= (S << 10) | hi;
22838 newval2 &= ~T2I1I2MASK;
22839 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
22840 md_number_to_chars (buf, newval, THUMB_SIZE);
22841 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22842}
22843
c19d1205 22844void
55cf6793 22845md_apply_fix (fixS * fixP,
c19d1205
ZW
22846 valueT * valP,
22847 segT seg)
22848{
22849 offsetT value = * valP;
22850 offsetT newval;
22851 unsigned int newimm;
22852 unsigned long temp;
22853 int sign;
22854 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 22855
9c2799c2 22856 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 22857
c19d1205 22858 /* Note whether this will delete the relocation. */
4962c51a 22859
c19d1205
ZW
22860 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
22861 fixP->fx_done = 1;
b99bd4ef 22862
adbaf948 22863 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 22864 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
22865 for emit_reloc. */
22866 value &= 0xffffffff;
22867 value ^= 0x80000000;
5f4273c7 22868 value -= 0x80000000;
adbaf948
ZW
22869
22870 *valP = value;
c19d1205 22871 fixP->fx_addnumber = value;
b99bd4ef 22872
adbaf948
ZW
22873 /* Same treatment for fixP->fx_offset. */
22874 fixP->fx_offset &= 0xffffffff;
22875 fixP->fx_offset ^= 0x80000000;
22876 fixP->fx_offset -= 0x80000000;
22877
c19d1205 22878 switch (fixP->fx_r_type)
b99bd4ef 22879 {
c19d1205
ZW
22880 case BFD_RELOC_NONE:
22881 /* This will need to go in the object file. */
22882 fixP->fx_done = 0;
22883 break;
b99bd4ef 22884
c19d1205
ZW
22885 case BFD_RELOC_ARM_IMMEDIATE:
22886 /* We claim that this fixup has been processed here,
22887 even if in fact we generate an error because we do
22888 not have a reloc for it, so tc_gen_reloc will reject it. */
22889 fixP->fx_done = 1;
b99bd4ef 22890
77db8e2e 22891 if (fixP->fx_addsy)
b99bd4ef 22892 {
77db8e2e 22893 const char *msg = 0;
b99bd4ef 22894
77db8e2e
NC
22895 if (! S_IS_DEFINED (fixP->fx_addsy))
22896 msg = _("undefined symbol %s used as an immediate value");
22897 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22898 msg = _("symbol %s is in a different section");
22899 else if (S_IS_WEAK (fixP->fx_addsy))
22900 msg = _("symbol %s is weak and may be overridden later");
22901
22902 if (msg)
22903 {
22904 as_bad_where (fixP->fx_file, fixP->fx_line,
22905 msg, S_GET_NAME (fixP->fx_addsy));
22906 break;
22907 }
42e5fcbf
AS
22908 }
22909
c19d1205
ZW
22910 temp = md_chars_to_number (buf, INSN_SIZE);
22911
5e73442d
SL
22912 /* If the offset is negative, we should use encoding A2 for ADR. */
22913 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
22914 newimm = negate_data_op (&temp, value);
22915 else
22916 {
22917 newimm = encode_arm_immediate (value);
22918
22919 /* If the instruction will fail, see if we can fix things up by
22920 changing the opcode. */
22921 if (newimm == (unsigned int) FAIL)
22922 newimm = negate_data_op (&temp, value);
bada4342
JW
22923 /* MOV accepts both ARM modified immediate (A1 encoding) and
22924 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
22925 When disassembling, MOV is preferred when there is no encoding
22926 overlap. */
22927 if (newimm == (unsigned int) FAIL
22928 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
22929 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
22930 && !((temp >> SBIT_SHIFT) & 0x1)
22931 && value >= 0 && value <= 0xffff)
22932 {
22933 /* Clear bits[23:20] to change encoding from A1 to A2. */
22934 temp &= 0xff0fffff;
22935 /* Encoding high 4bits imm. Code below will encode the remaining
22936 low 12bits. */
22937 temp |= (value & 0x0000f000) << 4;
22938 newimm = value & 0x00000fff;
22939 }
5e73442d
SL
22940 }
22941
22942 if (newimm == (unsigned int) FAIL)
b99bd4ef 22943 {
c19d1205
ZW
22944 as_bad_where (fixP->fx_file, fixP->fx_line,
22945 _("invalid constant (%lx) after fixup"),
22946 (unsigned long) value);
22947 break;
b99bd4ef 22948 }
b99bd4ef 22949
c19d1205
ZW
22950 newimm |= (temp & 0xfffff000);
22951 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
22952 break;
b99bd4ef 22953
c19d1205
ZW
22954 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22955 {
22956 unsigned int highpart = 0;
22957 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 22958
77db8e2e 22959 if (fixP->fx_addsy)
42e5fcbf 22960 {
77db8e2e 22961 const char *msg = 0;
42e5fcbf 22962
77db8e2e
NC
22963 if (! S_IS_DEFINED (fixP->fx_addsy))
22964 msg = _("undefined symbol %s used as an immediate value");
22965 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22966 msg = _("symbol %s is in a different section");
22967 else if (S_IS_WEAK (fixP->fx_addsy))
22968 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 22969
77db8e2e
NC
22970 if (msg)
22971 {
22972 as_bad_where (fixP->fx_file, fixP->fx_line,
22973 msg, S_GET_NAME (fixP->fx_addsy));
22974 break;
22975 }
22976 }
fa94de6b 22977
c19d1205
ZW
22978 newimm = encode_arm_immediate (value);
22979 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 22980
c19d1205
ZW
22981 /* If the instruction will fail, see if we can fix things up by
22982 changing the opcode. */
22983 if (newimm == (unsigned int) FAIL
22984 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
22985 {
22986 /* No ? OK - try using two ADD instructions to generate
22987 the value. */
22988 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 22989
c19d1205
ZW
22990 /* Yes - then make sure that the second instruction is
22991 also an add. */
22992 if (newimm != (unsigned int) FAIL)
22993 newinsn = temp;
22994 /* Still No ? Try using a negated value. */
22995 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
22996 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
22997 /* Otherwise - give up. */
22998 else
22999 {
23000 as_bad_where (fixP->fx_file, fixP->fx_line,
23001 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
23002 (long) value);
23003 break;
23004 }
b99bd4ef 23005
c19d1205
ZW
23006 /* Replace the first operand in the 2nd instruction (which
23007 is the PC) with the destination register. We have
23008 already added in the PC in the first instruction and we
23009 do not want to do it again. */
23010 newinsn &= ~ 0xf0000;
23011 newinsn |= ((newinsn & 0x0f000) << 4);
23012 }
b99bd4ef 23013
c19d1205
ZW
23014 newimm |= (temp & 0xfffff000);
23015 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 23016
c19d1205
ZW
23017 highpart |= (newinsn & 0xfffff000);
23018 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
23019 }
23020 break;
b99bd4ef 23021
c19d1205 23022 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
23023 if (!fixP->fx_done && seg->use_rela_p)
23024 value = 0;
1a0670f3 23025 /* Fall through. */
00a97672 23026
c19d1205 23027 case BFD_RELOC_ARM_LITERAL:
26d97720 23028 sign = value > 0;
b99bd4ef 23029
c19d1205
ZW
23030 if (value < 0)
23031 value = - value;
b99bd4ef 23032
c19d1205 23033 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 23034 {
c19d1205
ZW
23035 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
23036 as_bad_where (fixP->fx_file, fixP->fx_line,
23037 _("invalid literal constant: pool needs to be closer"));
23038 else
23039 as_bad_where (fixP->fx_file, fixP->fx_line,
23040 _("bad immediate value for offset (%ld)"),
23041 (long) value);
23042 break;
f03698e6
RE
23043 }
23044
c19d1205 23045 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23046 if (value == 0)
23047 newval &= 0xfffff000;
23048 else
23049 {
23050 newval &= 0xff7ff000;
23051 newval |= value | (sign ? INDEX_UP : 0);
23052 }
c19d1205
ZW
23053 md_number_to_chars (buf, newval, INSN_SIZE);
23054 break;
b99bd4ef 23055
c19d1205
ZW
23056 case BFD_RELOC_ARM_OFFSET_IMM8:
23057 case BFD_RELOC_ARM_HWLITERAL:
26d97720 23058 sign = value > 0;
b99bd4ef 23059
c19d1205
ZW
23060 if (value < 0)
23061 value = - value;
b99bd4ef 23062
c19d1205 23063 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 23064 {
c19d1205
ZW
23065 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
23066 as_bad_where (fixP->fx_file, fixP->fx_line,
23067 _("invalid literal constant: pool needs to be closer"));
23068 else
427d0db6
RM
23069 as_bad_where (fixP->fx_file, fixP->fx_line,
23070 _("bad immediate value for 8-bit offset (%ld)"),
23071 (long) value);
c19d1205 23072 break;
b99bd4ef
NC
23073 }
23074
c19d1205 23075 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23076 if (value == 0)
23077 newval &= 0xfffff0f0;
23078 else
23079 {
23080 newval &= 0xff7ff0f0;
23081 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
23082 }
c19d1205
ZW
23083 md_number_to_chars (buf, newval, INSN_SIZE);
23084 break;
b99bd4ef 23085
c19d1205
ZW
23086 case BFD_RELOC_ARM_T32_OFFSET_U8:
23087 if (value < 0 || value > 1020 || value % 4 != 0)
23088 as_bad_where (fixP->fx_file, fixP->fx_line,
23089 _("bad immediate value for offset (%ld)"), (long) value);
23090 value /= 4;
b99bd4ef 23091
c19d1205 23092 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
23093 newval |= value;
23094 md_number_to_chars (buf+2, newval, THUMB_SIZE);
23095 break;
b99bd4ef 23096
c19d1205
ZW
23097 case BFD_RELOC_ARM_T32_OFFSET_IMM:
23098 /* This is a complicated relocation used for all varieties of Thumb32
23099 load/store instruction with immediate offset:
23100
23101 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 23102 *4, optional writeback(W)
c19d1205
ZW
23103 (doubleword load/store)
23104
23105 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
23106 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
23107 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
23108 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
23109 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
23110
23111 Uppercase letters indicate bits that are already encoded at
23112 this point. Lowercase letters are our problem. For the
23113 second block of instructions, the secondary opcode nybble
23114 (bits 8..11) is present, and bit 23 is zero, even if this is
23115 a PC-relative operation. */
23116 newval = md_chars_to_number (buf, THUMB_SIZE);
23117 newval <<= 16;
23118 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 23119
c19d1205 23120 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 23121 {
c19d1205
ZW
23122 /* Doubleword load/store: 8-bit offset, scaled by 4. */
23123 if (value >= 0)
23124 newval |= (1 << 23);
23125 else
23126 value = -value;
23127 if (value % 4 != 0)
23128 {
23129 as_bad_where (fixP->fx_file, fixP->fx_line,
23130 _("offset not a multiple of 4"));
23131 break;
23132 }
23133 value /= 4;
216d22bc 23134 if (value > 0xff)
c19d1205
ZW
23135 {
23136 as_bad_where (fixP->fx_file, fixP->fx_line,
23137 _("offset out of range"));
23138 break;
23139 }
23140 newval &= ~0xff;
b99bd4ef 23141 }
c19d1205 23142 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 23143 {
c19d1205
ZW
23144 /* PC-relative, 12-bit offset. */
23145 if (value >= 0)
23146 newval |= (1 << 23);
23147 else
23148 value = -value;
216d22bc 23149 if (value > 0xfff)
c19d1205
ZW
23150 {
23151 as_bad_where (fixP->fx_file, fixP->fx_line,
23152 _("offset out of range"));
23153 break;
23154 }
23155 newval &= ~0xfff;
b99bd4ef 23156 }
c19d1205 23157 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 23158 {
c19d1205
ZW
23159 /* Writeback: 8-bit, +/- offset. */
23160 if (value >= 0)
23161 newval |= (1 << 9);
23162 else
23163 value = -value;
216d22bc 23164 if (value > 0xff)
c19d1205
ZW
23165 {
23166 as_bad_where (fixP->fx_file, fixP->fx_line,
23167 _("offset out of range"));
23168 break;
23169 }
23170 newval &= ~0xff;
b99bd4ef 23171 }
c19d1205 23172 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 23173 {
c19d1205 23174 /* T-instruction: positive 8-bit offset. */
216d22bc 23175 if (value < 0 || value > 0xff)
b99bd4ef 23176 {
c19d1205
ZW
23177 as_bad_where (fixP->fx_file, fixP->fx_line,
23178 _("offset out of range"));
23179 break;
b99bd4ef 23180 }
c19d1205
ZW
23181 newval &= ~0xff;
23182 newval |= value;
b99bd4ef
NC
23183 }
23184 else
b99bd4ef 23185 {
c19d1205
ZW
23186 /* Positive 12-bit or negative 8-bit offset. */
23187 int limit;
23188 if (value >= 0)
b99bd4ef 23189 {
c19d1205
ZW
23190 newval |= (1 << 23);
23191 limit = 0xfff;
23192 }
23193 else
23194 {
23195 value = -value;
23196 limit = 0xff;
23197 }
23198 if (value > limit)
23199 {
23200 as_bad_where (fixP->fx_file, fixP->fx_line,
23201 _("offset out of range"));
23202 break;
b99bd4ef 23203 }
c19d1205 23204 newval &= ~limit;
b99bd4ef 23205 }
b99bd4ef 23206
c19d1205
ZW
23207 newval |= value;
23208 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
23209 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
23210 break;
404ff6b5 23211
c19d1205
ZW
23212 case BFD_RELOC_ARM_SHIFT_IMM:
23213 newval = md_chars_to_number (buf, INSN_SIZE);
23214 if (((unsigned long) value) > 32
23215 || (value == 32
23216 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
23217 {
23218 as_bad_where (fixP->fx_file, fixP->fx_line,
23219 _("shift expression is too large"));
23220 break;
23221 }
404ff6b5 23222
c19d1205
ZW
23223 if (value == 0)
23224 /* Shifts of zero must be done as lsl. */
23225 newval &= ~0x60;
23226 else if (value == 32)
23227 value = 0;
23228 newval &= 0xfffff07f;
23229 newval |= (value & 0x1f) << 7;
23230 md_number_to_chars (buf, newval, INSN_SIZE);
23231 break;
404ff6b5 23232
c19d1205 23233 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 23234 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 23235 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 23236 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
23237 /* We claim that this fixup has been processed here,
23238 even if in fact we generate an error because we do
23239 not have a reloc for it, so tc_gen_reloc will reject it. */
23240 fixP->fx_done = 1;
404ff6b5 23241
c19d1205
ZW
23242 if (fixP->fx_addsy
23243 && ! S_IS_DEFINED (fixP->fx_addsy))
23244 {
23245 as_bad_where (fixP->fx_file, fixP->fx_line,
23246 _("undefined symbol %s used as an immediate value"),
23247 S_GET_NAME (fixP->fx_addsy));
23248 break;
23249 }
404ff6b5 23250
c19d1205
ZW
23251 newval = md_chars_to_number (buf, THUMB_SIZE);
23252 newval <<= 16;
23253 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 23254
16805f35 23255 newimm = FAIL;
bada4342
JW
23256 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23257 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
23258 Thumb2 modified immediate encoding (T2). */
23259 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 23260 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
23261 {
23262 newimm = encode_thumb32_immediate (value);
23263 if (newimm == (unsigned int) FAIL)
23264 newimm = thumb32_negate_data_op (&newval, value);
23265 }
bada4342 23266 if (newimm == (unsigned int) FAIL)
92e90b6e 23267 {
bada4342 23268 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 23269 {
bada4342
JW
23270 /* Turn add/sum into addw/subw. */
23271 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23272 newval = (newval & 0xfeffffff) | 0x02000000;
23273 /* No flat 12-bit imm encoding for addsw/subsw. */
23274 if ((newval & 0x00100000) == 0)
40f246e3 23275 {
bada4342
JW
23276 /* 12 bit immediate for addw/subw. */
23277 if (value < 0)
23278 {
23279 value = -value;
23280 newval ^= 0x00a00000;
23281 }
23282 if (value > 0xfff)
23283 newimm = (unsigned int) FAIL;
23284 else
23285 newimm = value;
23286 }
23287 }
23288 else
23289 {
23290 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
23291 UINT16 (T3 encoding), MOVW only accepts UINT16. When
23292 disassembling, MOV is preferred when there is no encoding
23293 overlap.
23294 NOTE: MOV is using ORR opcode under Thumb 2 mode. */
23295 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
23296 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
23297 && !((newval >> T2_SBIT_SHIFT) & 0x1)
23298 && value >= 0 && value <=0xffff)
23299 {
23300 /* Toggle bit[25] to change encoding from T2 to T3. */
23301 newval ^= 1 << 25;
23302 /* Clear bits[19:16]. */
23303 newval &= 0xfff0ffff;
23304 /* Encoding high 4bits imm. Code below will encode the
23305 remaining low 12bits. */
23306 newval |= (value & 0x0000f000) << 4;
23307 newimm = value & 0x00000fff;
40f246e3 23308 }
e9f89963 23309 }
92e90b6e 23310 }
cc8a6dd0 23311
c19d1205 23312 if (newimm == (unsigned int)FAIL)
3631a3c8 23313 {
c19d1205
ZW
23314 as_bad_where (fixP->fx_file, fixP->fx_line,
23315 _("invalid constant (%lx) after fixup"),
23316 (unsigned long) value);
23317 break;
3631a3c8
NC
23318 }
23319
c19d1205
ZW
23320 newval |= (newimm & 0x800) << 15;
23321 newval |= (newimm & 0x700) << 4;
23322 newval |= (newimm & 0x0ff);
cc8a6dd0 23323
c19d1205
ZW
23324 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
23325 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
23326 break;
a737bd4d 23327
3eb17e6b 23328 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
23329 if (((unsigned long) value) > 0xffff)
23330 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 23331 _("invalid smc expression"));
2fc8bdac 23332 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23333 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23334 md_number_to_chars (buf, newval, INSN_SIZE);
23335 break;
a737bd4d 23336
90ec0d68
MGD
23337 case BFD_RELOC_ARM_HVC:
23338 if (((unsigned long) value) > 0xffff)
23339 as_bad_where (fixP->fx_file, fixP->fx_line,
23340 _("invalid hvc expression"));
23341 newval = md_chars_to_number (buf, INSN_SIZE);
23342 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23343 md_number_to_chars (buf, newval, INSN_SIZE);
23344 break;
23345
c19d1205 23346 case BFD_RELOC_ARM_SWI:
adbaf948 23347 if (fixP->tc_fix_data != 0)
c19d1205
ZW
23348 {
23349 if (((unsigned long) value) > 0xff)
23350 as_bad_where (fixP->fx_file, fixP->fx_line,
23351 _("invalid swi expression"));
2fc8bdac 23352 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
23353 newval |= value;
23354 md_number_to_chars (buf, newval, THUMB_SIZE);
23355 }
23356 else
23357 {
23358 if (((unsigned long) value) > 0x00ffffff)
23359 as_bad_where (fixP->fx_file, fixP->fx_line,
23360 _("invalid swi expression"));
2fc8bdac 23361 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23362 newval |= value;
23363 md_number_to_chars (buf, newval, INSN_SIZE);
23364 }
23365 break;
a737bd4d 23366
c19d1205
ZW
23367 case BFD_RELOC_ARM_MULTI:
23368 if (((unsigned long) value) > 0xffff)
23369 as_bad_where (fixP->fx_file, fixP->fx_line,
23370 _("invalid expression in load/store multiple"));
23371 newval = value | md_chars_to_number (buf, INSN_SIZE);
23372 md_number_to_chars (buf, newval, INSN_SIZE);
23373 break;
a737bd4d 23374
c19d1205 23375#ifdef OBJ_ELF
39b41c9c 23376 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
23377
23378 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23379 && fixP->fx_addsy
34e77a92 23380 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23381 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23382 && THUMB_IS_FUNC (fixP->fx_addsy))
23383 /* Flip the bl to blx. This is a simple flip
23384 bit here because we generate PCREL_CALL for
23385 unconditional bls. */
23386 {
23387 newval = md_chars_to_number (buf, INSN_SIZE);
23388 newval = newval | 0x10000000;
23389 md_number_to_chars (buf, newval, INSN_SIZE);
23390 temp = 1;
23391 fixP->fx_done = 1;
23392 }
39b41c9c
PB
23393 else
23394 temp = 3;
23395 goto arm_branch_common;
23396
23397 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
23398 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23399 && fixP->fx_addsy
34e77a92 23400 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23401 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23402 && THUMB_IS_FUNC (fixP->fx_addsy))
23403 {
23404 /* This would map to a bl<cond>, b<cond>,
23405 b<always> to a Thumb function. We
23406 need to force a relocation for this particular
23407 case. */
23408 newval = md_chars_to_number (buf, INSN_SIZE);
23409 fixP->fx_done = 0;
23410 }
1a0670f3 23411 /* Fall through. */
267bf995 23412
2fc8bdac 23413 case BFD_RELOC_ARM_PLT32:
c19d1205 23414#endif
39b41c9c
PB
23415 case BFD_RELOC_ARM_PCREL_BRANCH:
23416 temp = 3;
23417 goto arm_branch_common;
a737bd4d 23418
39b41c9c 23419 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 23420
39b41c9c 23421 temp = 1;
267bf995
RR
23422 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23423 && fixP->fx_addsy
34e77a92 23424 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23425 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23426 && ARM_IS_FUNC (fixP->fx_addsy))
23427 {
23428 /* Flip the blx to a bl and warn. */
23429 const char *name = S_GET_NAME (fixP->fx_addsy);
23430 newval = 0xeb000000;
23431 as_warn_where (fixP->fx_file, fixP->fx_line,
23432 _("blx to '%s' an ARM ISA state function changed to bl"),
23433 name);
23434 md_number_to_chars (buf, newval, INSN_SIZE);
23435 temp = 3;
23436 fixP->fx_done = 1;
23437 }
23438
23439#ifdef OBJ_ELF
23440 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 23441 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
23442#endif
23443
39b41c9c 23444 arm_branch_common:
c19d1205 23445 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
23446 instruction, in a 24 bit, signed field. Bits 26 through 32 either
23447 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
23448 also be be clear. */
23449 if (value & temp)
c19d1205 23450 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
23451 _("misaligned branch destination"));
23452 if ((value & (offsetT)0xfe000000) != (offsetT)0
23453 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 23454 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23455
2fc8bdac 23456 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23457 {
2fc8bdac
ZW
23458 newval = md_chars_to_number (buf, INSN_SIZE);
23459 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
23460 /* Set the H bit on BLX instructions. */
23461 if (temp == 1)
23462 {
23463 if (value & 2)
23464 newval |= 0x01000000;
23465 else
23466 newval &= ~0x01000000;
23467 }
2fc8bdac 23468 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 23469 }
c19d1205 23470 break;
a737bd4d 23471
25fe350b
MS
23472 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
23473 /* CBZ can only branch forward. */
a737bd4d 23474
738755b0 23475 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
23476 (which, strictly speaking, are prohibited) will be turned into
23477 no-ops.
738755b0
MS
23478
23479 FIXME: It may be better to remove the instruction completely and
23480 perform relaxation. */
23481 if (value == -2)
2fc8bdac
ZW
23482 {
23483 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 23484 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
23485 md_number_to_chars (buf, newval, THUMB_SIZE);
23486 }
738755b0
MS
23487 else
23488 {
23489 if (value & ~0x7e)
08f10d51 23490 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 23491
477330fc 23492 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
23493 {
23494 newval = md_chars_to_number (buf, THUMB_SIZE);
23495 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
23496 md_number_to_chars (buf, newval, THUMB_SIZE);
23497 }
23498 }
c19d1205 23499 break;
a737bd4d 23500
c19d1205 23501 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 23502 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 23503 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23504
2fc8bdac
ZW
23505 if (fixP->fx_done || !seg->use_rela_p)
23506 {
23507 newval = md_chars_to_number (buf, THUMB_SIZE);
23508 newval |= (value & 0x1ff) >> 1;
23509 md_number_to_chars (buf, newval, THUMB_SIZE);
23510 }
c19d1205 23511 break;
a737bd4d 23512
c19d1205 23513 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 23514 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 23515 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23516
2fc8bdac
ZW
23517 if (fixP->fx_done || !seg->use_rela_p)
23518 {
23519 newval = md_chars_to_number (buf, THUMB_SIZE);
23520 newval |= (value & 0xfff) >> 1;
23521 md_number_to_chars (buf, newval, THUMB_SIZE);
23522 }
c19d1205 23523 break;
a737bd4d 23524
c19d1205 23525 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
23526 if (fixP->fx_addsy
23527 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23528 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23529 && ARM_IS_FUNC (fixP->fx_addsy)
23530 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23531 {
23532 /* Force a relocation for a branch 20 bits wide. */
23533 fixP->fx_done = 0;
23534 }
08f10d51 23535 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
23536 as_bad_where (fixP->fx_file, fixP->fx_line,
23537 _("conditional branch out of range"));
404ff6b5 23538
2fc8bdac
ZW
23539 if (fixP->fx_done || !seg->use_rela_p)
23540 {
23541 offsetT newval2;
23542 addressT S, J1, J2, lo, hi;
404ff6b5 23543
2fc8bdac
ZW
23544 S = (value & 0x00100000) >> 20;
23545 J2 = (value & 0x00080000) >> 19;
23546 J1 = (value & 0x00040000) >> 18;
23547 hi = (value & 0x0003f000) >> 12;
23548 lo = (value & 0x00000ffe) >> 1;
6c43fab6 23549
2fc8bdac
ZW
23550 newval = md_chars_to_number (buf, THUMB_SIZE);
23551 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23552 newval |= (S << 10) | hi;
23553 newval2 |= (J1 << 13) | (J2 << 11) | lo;
23554 md_number_to_chars (buf, newval, THUMB_SIZE);
23555 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23556 }
c19d1205 23557 break;
6c43fab6 23558
c19d1205 23559 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
23560 /* If there is a blx from a thumb state function to
23561 another thumb function flip this to a bl and warn
23562 about it. */
23563
23564 if (fixP->fx_addsy
34e77a92 23565 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23566 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23567 && THUMB_IS_FUNC (fixP->fx_addsy))
23568 {
23569 const char *name = S_GET_NAME (fixP->fx_addsy);
23570 as_warn_where (fixP->fx_file, fixP->fx_line,
23571 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
23572 name);
23573 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23574 newval = newval | 0x1000;
23575 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23576 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23577 fixP->fx_done = 1;
23578 }
23579
23580
23581 goto thumb_bl_common;
23582
c19d1205 23583 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
23584 /* A bl from Thumb state ISA to an internal ARM state function
23585 is converted to a blx. */
23586 if (fixP->fx_addsy
23587 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23588 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23589 && ARM_IS_FUNC (fixP->fx_addsy)
23590 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23591 {
23592 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23593 newval = newval & ~0x1000;
23594 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23595 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
23596 fixP->fx_done = 1;
23597 }
23598
23599 thumb_bl_common:
23600
2fc8bdac
ZW
23601 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23602 /* For a BLX instruction, make sure that the relocation is rounded up
23603 to a word boundary. This follows the semantics of the instruction
23604 which specifies that bit 1 of the target address will come from bit
23605 1 of the base address. */
d406f3e4
JB
23606 value = (value + 3) & ~ 3;
23607
23608#ifdef OBJ_ELF
23609 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
23610 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23611 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23612#endif
404ff6b5 23613
2b2f5df9
NC
23614 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
23615 {
fc289b0a 23616 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
23617 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23618 else if ((value & ~0x1ffffff)
23619 && ((value & ~0x1ffffff) != ~0x1ffffff))
23620 as_bad_where (fixP->fx_file, fixP->fx_line,
23621 _("Thumb2 branch out of range"));
23622 }
4a42ebbc
RR
23623
23624 if (fixP->fx_done || !seg->use_rela_p)
23625 encode_thumb2_b_bl_offset (buf, value);
23626
c19d1205 23627 break;
404ff6b5 23628
c19d1205 23629 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
23630 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
23631 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 23632
2fc8bdac 23633 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 23634 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 23635
2fc8bdac 23636 break;
a737bd4d 23637
2fc8bdac
ZW
23638 case BFD_RELOC_8:
23639 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 23640 *buf = value;
c19d1205 23641 break;
a737bd4d 23642
c19d1205 23643 case BFD_RELOC_16:
2fc8bdac 23644 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23645 md_number_to_chars (buf, value, 2);
c19d1205 23646 break;
a737bd4d 23647
c19d1205 23648#ifdef OBJ_ELF
0855e32b
NS
23649 case BFD_RELOC_ARM_TLS_CALL:
23650 case BFD_RELOC_ARM_THM_TLS_CALL:
23651 case BFD_RELOC_ARM_TLS_DESCSEQ:
23652 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 23653 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
23654 case BFD_RELOC_ARM_TLS_GD32:
23655 case BFD_RELOC_ARM_TLS_LE32:
23656 case BFD_RELOC_ARM_TLS_IE32:
23657 case BFD_RELOC_ARM_TLS_LDM32:
23658 case BFD_RELOC_ARM_TLS_LDO32:
23659 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 23660 break;
6c43fab6 23661
c19d1205
ZW
23662 case BFD_RELOC_ARM_GOT32:
23663 case BFD_RELOC_ARM_GOTOFF:
c19d1205 23664 break;
b43420e6
NC
23665
23666 case BFD_RELOC_ARM_GOT_PREL:
23667 if (fixP->fx_done || !seg->use_rela_p)
477330fc 23668 md_number_to_chars (buf, value, 4);
b43420e6
NC
23669 break;
23670
9a6f4e97
NS
23671 case BFD_RELOC_ARM_TARGET2:
23672 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
23673 addend here for REL targets, because it won't be written out
23674 during reloc processing later. */
9a6f4e97
NS
23675 if (fixP->fx_done || !seg->use_rela_p)
23676 md_number_to_chars (buf, fixP->fx_offset, 4);
23677 break;
c19d1205 23678#endif
6c43fab6 23679
c19d1205
ZW
23680 case BFD_RELOC_RVA:
23681 case BFD_RELOC_32:
23682 case BFD_RELOC_ARM_TARGET1:
23683 case BFD_RELOC_ARM_ROSEGREL32:
23684 case BFD_RELOC_ARM_SBREL32:
23685 case BFD_RELOC_32_PCREL:
f0927246
NC
23686#ifdef TE_PE
23687 case BFD_RELOC_32_SECREL:
23688#endif
2fc8bdac 23689 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
23690#ifdef TE_WINCE
23691 /* For WinCE we only do this for pcrel fixups. */
23692 if (fixP->fx_done || fixP->fx_pcrel)
23693#endif
23694 md_number_to_chars (buf, value, 4);
c19d1205 23695 break;
6c43fab6 23696
c19d1205
ZW
23697#ifdef OBJ_ELF
23698 case BFD_RELOC_ARM_PREL31:
2fc8bdac 23699 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
23700 {
23701 newval = md_chars_to_number (buf, 4) & 0x80000000;
23702 if ((value ^ (value >> 1)) & 0x40000000)
23703 {
23704 as_bad_where (fixP->fx_file, fixP->fx_line,
23705 _("rel31 relocation overflow"));
23706 }
23707 newval |= value & 0x7fffffff;
23708 md_number_to_chars (buf, newval, 4);
23709 }
23710 break;
c19d1205 23711#endif
a737bd4d 23712
c19d1205 23713 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 23714 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
9db2f6b4
RL
23715 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
23716 newval = md_chars_to_number (buf, INSN_SIZE);
23717 else
23718 newval = get_thumb32_insn (buf);
23719 if ((newval & 0x0f200f00) == 0x0d000900)
23720 {
23721 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
23722 has permitted values that are multiples of 2, in the range 0
23723 to 510. */
23724 if (value < -510 || value > 510 || (value & 1))
23725 as_bad_where (fixP->fx_file, fixP->fx_line,
23726 _("co-processor offset out of range"));
23727 }
23728 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
23729 as_bad_where (fixP->fx_file, fixP->fx_line,
23730 _("co-processor offset out of range"));
23731 cp_off_common:
26d97720 23732 sign = value > 0;
c19d1205
ZW
23733 if (value < 0)
23734 value = -value;
8f06b2d8
PB
23735 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23736 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23737 newval = md_chars_to_number (buf, INSN_SIZE);
23738 else
23739 newval = get_thumb32_insn (buf);
26d97720
NS
23740 if (value == 0)
23741 newval &= 0xffffff00;
23742 else
23743 {
23744 newval &= 0xff7fff00;
9db2f6b4
RL
23745 if ((newval & 0x0f200f00) == 0x0d000900)
23746 {
23747 /* This is a fp16 vstr/vldr.
23748
23749 It requires the immediate offset in the instruction is shifted
23750 left by 1 to be a half-word offset.
23751
23752 Here, left shift by 1 first, and later right shift by 2
23753 should get the right offset. */
23754 value <<= 1;
23755 }
26d97720
NS
23756 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
23757 }
8f06b2d8
PB
23758 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23759 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23760 md_number_to_chars (buf, newval, INSN_SIZE);
23761 else
23762 put_thumb32_insn (buf, newval);
c19d1205 23763 break;
a737bd4d 23764
c19d1205 23765 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 23766 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
23767 if (value < -255 || value > 255)
23768 as_bad_where (fixP->fx_file, fixP->fx_line,
23769 _("co-processor offset out of range"));
df7849c5 23770 value *= 4;
c19d1205 23771 goto cp_off_common;
6c43fab6 23772
c19d1205
ZW
23773 case BFD_RELOC_ARM_THUMB_OFFSET:
23774 newval = md_chars_to_number (buf, THUMB_SIZE);
23775 /* Exactly what ranges, and where the offset is inserted depends
23776 on the type of instruction, we can establish this from the
23777 top 4 bits. */
23778 switch (newval >> 12)
23779 {
23780 case 4: /* PC load. */
23781 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
23782 forced to zero for these loads; md_pcrel_from has already
23783 compensated for this. */
23784 if (value & 3)
23785 as_bad_where (fixP->fx_file, fixP->fx_line,
23786 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
23787 (((unsigned long) fixP->fx_frag->fr_address
23788 + (unsigned long) fixP->fx_where) & ~3)
23789 + (unsigned long) value);
a737bd4d 23790
c19d1205
ZW
23791 if (value & ~0x3fc)
23792 as_bad_where (fixP->fx_file, fixP->fx_line,
23793 _("invalid offset, value too big (0x%08lX)"),
23794 (long) value);
a737bd4d 23795
c19d1205
ZW
23796 newval |= value >> 2;
23797 break;
a737bd4d 23798
c19d1205
ZW
23799 case 9: /* SP load/store. */
23800 if (value & ~0x3fc)
23801 as_bad_where (fixP->fx_file, fixP->fx_line,
23802 _("invalid offset, value too big (0x%08lX)"),
23803 (long) value);
23804 newval |= value >> 2;
23805 break;
6c43fab6 23806
c19d1205
ZW
23807 case 6: /* Word load/store. */
23808 if (value & ~0x7c)
23809 as_bad_where (fixP->fx_file, fixP->fx_line,
23810 _("invalid offset, value too big (0x%08lX)"),
23811 (long) value);
23812 newval |= value << 4; /* 6 - 2. */
23813 break;
a737bd4d 23814
c19d1205
ZW
23815 case 7: /* Byte load/store. */
23816 if (value & ~0x1f)
23817 as_bad_where (fixP->fx_file, fixP->fx_line,
23818 _("invalid offset, value too big (0x%08lX)"),
23819 (long) value);
23820 newval |= value << 6;
23821 break;
a737bd4d 23822
c19d1205
ZW
23823 case 8: /* Halfword load/store. */
23824 if (value & ~0x3e)
23825 as_bad_where (fixP->fx_file, fixP->fx_line,
23826 _("invalid offset, value too big (0x%08lX)"),
23827 (long) value);
23828 newval |= value << 5; /* 6 - 1. */
23829 break;
a737bd4d 23830
c19d1205
ZW
23831 default:
23832 as_bad_where (fixP->fx_file, fixP->fx_line,
23833 "Unable to process relocation for thumb opcode: %lx",
23834 (unsigned long) newval);
23835 break;
23836 }
23837 md_number_to_chars (buf, newval, THUMB_SIZE);
23838 break;
a737bd4d 23839
c19d1205
ZW
23840 case BFD_RELOC_ARM_THUMB_ADD:
23841 /* This is a complicated relocation, since we use it for all of
23842 the following immediate relocations:
a737bd4d 23843
c19d1205
ZW
23844 3bit ADD/SUB
23845 8bit ADD/SUB
23846 9bit ADD/SUB SP word-aligned
23847 10bit ADD PC/SP word-aligned
a737bd4d 23848
c19d1205
ZW
23849 The type of instruction being processed is encoded in the
23850 instruction field:
a737bd4d 23851
c19d1205
ZW
23852 0x8000 SUB
23853 0x00F0 Rd
23854 0x000F Rs
23855 */
23856 newval = md_chars_to_number (buf, THUMB_SIZE);
23857 {
23858 int rd = (newval >> 4) & 0xf;
23859 int rs = newval & 0xf;
23860 int subtract = !!(newval & 0x8000);
a737bd4d 23861
c19d1205
ZW
23862 /* Check for HI regs, only very restricted cases allowed:
23863 Adjusting SP, and using PC or SP to get an address. */
23864 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
23865 || (rs > 7 && rs != REG_SP && rs != REG_PC))
23866 as_bad_where (fixP->fx_file, fixP->fx_line,
23867 _("invalid Hi register with immediate"));
a737bd4d 23868
c19d1205
ZW
23869 /* If value is negative, choose the opposite instruction. */
23870 if (value < 0)
23871 {
23872 value = -value;
23873 subtract = !subtract;
23874 if (value < 0)
23875 as_bad_where (fixP->fx_file, fixP->fx_line,
23876 _("immediate value out of range"));
23877 }
a737bd4d 23878
c19d1205
ZW
23879 if (rd == REG_SP)
23880 {
75c11999 23881 if (value & ~0x1fc)
c19d1205
ZW
23882 as_bad_where (fixP->fx_file, fixP->fx_line,
23883 _("invalid immediate for stack address calculation"));
23884 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
23885 newval |= value >> 2;
23886 }
23887 else if (rs == REG_PC || rs == REG_SP)
23888 {
c12d2c9d
NC
23889 /* PR gas/18541. If the addition is for a defined symbol
23890 within range of an ADR instruction then accept it. */
23891 if (subtract
23892 && value == 4
23893 && fixP->fx_addsy != NULL)
23894 {
23895 subtract = 0;
23896
23897 if (! S_IS_DEFINED (fixP->fx_addsy)
23898 || S_GET_SEGMENT (fixP->fx_addsy) != seg
23899 || S_IS_WEAK (fixP->fx_addsy))
23900 {
23901 as_bad_where (fixP->fx_file, fixP->fx_line,
23902 _("address calculation needs a strongly defined nearby symbol"));
23903 }
23904 else
23905 {
23906 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
23907
23908 /* Round up to the next 4-byte boundary. */
23909 if (v & 3)
23910 v = (v + 3) & ~ 3;
23911 else
23912 v += 4;
23913 v = S_GET_VALUE (fixP->fx_addsy) - v;
23914
23915 if (v & ~0x3fc)
23916 {
23917 as_bad_where (fixP->fx_file, fixP->fx_line,
23918 _("symbol too far away"));
23919 }
23920 else
23921 {
23922 fixP->fx_done = 1;
23923 value = v;
23924 }
23925 }
23926 }
23927
c19d1205
ZW
23928 if (subtract || value & ~0x3fc)
23929 as_bad_where (fixP->fx_file, fixP->fx_line,
23930 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 23931 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
23932 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
23933 newval |= rd << 8;
23934 newval |= value >> 2;
23935 }
23936 else if (rs == rd)
23937 {
23938 if (value & ~0xff)
23939 as_bad_where (fixP->fx_file, fixP->fx_line,
23940 _("immediate value out of range"));
23941 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
23942 newval |= (rd << 8) | value;
23943 }
23944 else
23945 {
23946 if (value & ~0x7)
23947 as_bad_where (fixP->fx_file, fixP->fx_line,
23948 _("immediate value out of range"));
23949 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
23950 newval |= rd | (rs << 3) | (value << 6);
23951 }
23952 }
23953 md_number_to_chars (buf, newval, THUMB_SIZE);
23954 break;
a737bd4d 23955
c19d1205
ZW
23956 case BFD_RELOC_ARM_THUMB_IMM:
23957 newval = md_chars_to_number (buf, THUMB_SIZE);
23958 if (value < 0 || value > 255)
23959 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 23960 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
23961 (long) value);
23962 newval |= value;
23963 md_number_to_chars (buf, newval, THUMB_SIZE);
23964 break;
a737bd4d 23965
c19d1205
ZW
23966 case BFD_RELOC_ARM_THUMB_SHIFT:
23967 /* 5bit shift value (0..32). LSL cannot take 32. */
23968 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
23969 temp = newval & 0xf800;
23970 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
23971 as_bad_where (fixP->fx_file, fixP->fx_line,
23972 _("invalid shift value: %ld"), (long) value);
23973 /* Shifts of zero must be encoded as LSL. */
23974 if (value == 0)
23975 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
23976 /* Shifts of 32 are encoded as zero. */
23977 else if (value == 32)
23978 value = 0;
23979 newval |= value << 6;
23980 md_number_to_chars (buf, newval, THUMB_SIZE);
23981 break;
a737bd4d 23982
c19d1205
ZW
23983 case BFD_RELOC_VTABLE_INHERIT:
23984 case BFD_RELOC_VTABLE_ENTRY:
23985 fixP->fx_done = 0;
23986 return;
6c43fab6 23987
b6895b4f
PB
23988 case BFD_RELOC_ARM_MOVW:
23989 case BFD_RELOC_ARM_MOVT:
23990 case BFD_RELOC_ARM_THUMB_MOVW:
23991 case BFD_RELOC_ARM_THUMB_MOVT:
23992 if (fixP->fx_done || !seg->use_rela_p)
23993 {
23994 /* REL format relocations are limited to a 16-bit addend. */
23995 if (!fixP->fx_done)
23996 {
39623e12 23997 if (value < -0x8000 || value > 0x7fff)
b6895b4f 23998 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 23999 _("offset out of range"));
b6895b4f
PB
24000 }
24001 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24002 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24003 {
24004 value >>= 16;
24005 }
24006
24007 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24008 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24009 {
24010 newval = get_thumb32_insn (buf);
24011 newval &= 0xfbf08f00;
24012 newval |= (value & 0xf000) << 4;
24013 newval |= (value & 0x0800) << 15;
24014 newval |= (value & 0x0700) << 4;
24015 newval |= (value & 0x00ff);
24016 put_thumb32_insn (buf, newval);
24017 }
24018 else
24019 {
24020 newval = md_chars_to_number (buf, 4);
24021 newval &= 0xfff0f000;
24022 newval |= value & 0x0fff;
24023 newval |= (value & 0xf000) << 4;
24024 md_number_to_chars (buf, newval, 4);
24025 }
24026 }
24027 return;
24028
72d98d16
MG
24029 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24030 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24031 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24032 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
24033 gas_assert (!fixP->fx_done);
24034 {
24035 bfd_vma insn;
24036 bfd_boolean is_mov;
24037 bfd_vma encoded_addend = value;
24038
24039 /* Check that addend can be encoded in instruction. */
24040 if (!seg->use_rela_p && (value < 0 || value > 255))
24041 as_bad_where (fixP->fx_file, fixP->fx_line,
24042 _("the offset 0x%08lX is not representable"),
24043 (unsigned long) encoded_addend);
24044
24045 /* Extract the instruction. */
24046 insn = md_chars_to_number (buf, THUMB_SIZE);
24047 is_mov = (insn & 0xf800) == 0x2000;
24048
24049 /* Encode insn. */
24050 if (is_mov)
24051 {
24052 if (!seg->use_rela_p)
24053 insn |= encoded_addend;
24054 }
24055 else
24056 {
24057 int rd, rs;
24058
24059 /* Extract the instruction. */
24060 /* Encoding is the following
24061 0x8000 SUB
24062 0x00F0 Rd
24063 0x000F Rs
24064 */
24065 /* The following conditions must be true :
24066 - ADD
24067 - Rd == Rs
24068 - Rd <= 7
24069 */
24070 rd = (insn >> 4) & 0xf;
24071 rs = insn & 0xf;
24072 if ((insn & 0x8000) || (rd != rs) || rd > 7)
24073 as_bad_where (fixP->fx_file, fixP->fx_line,
24074 _("Unable to process relocation for thumb opcode: %lx"),
24075 (unsigned long) insn);
24076
24077 /* Encode as ADD immediate8 thumb 1 code. */
24078 insn = 0x3000 | (rd << 8);
24079
24080 /* Place the encoded addend into the first 8 bits of the
24081 instruction. */
24082 if (!seg->use_rela_p)
24083 insn |= encoded_addend;
24084 }
24085
24086 /* Update the instruction. */
24087 md_number_to_chars (buf, insn, THUMB_SIZE);
24088 }
24089 break;
24090
4962c51a
MS
24091 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24092 case BFD_RELOC_ARM_ALU_PC_G0:
24093 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24094 case BFD_RELOC_ARM_ALU_PC_G1:
24095 case BFD_RELOC_ARM_ALU_PC_G2:
24096 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24097 case BFD_RELOC_ARM_ALU_SB_G0:
24098 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24099 case BFD_RELOC_ARM_ALU_SB_G1:
24100 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 24101 gas_assert (!fixP->fx_done);
4962c51a
MS
24102 if (!seg->use_rela_p)
24103 {
477330fc
RM
24104 bfd_vma insn;
24105 bfd_vma encoded_addend;
24106 bfd_vma addend_abs = abs (value);
24107
24108 /* Check that the absolute value of the addend can be
24109 expressed as an 8-bit constant plus a rotation. */
24110 encoded_addend = encode_arm_immediate (addend_abs);
24111 if (encoded_addend == (unsigned int) FAIL)
4962c51a 24112 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24113 _("the offset 0x%08lX is not representable"),
24114 (unsigned long) addend_abs);
24115
24116 /* Extract the instruction. */
24117 insn = md_chars_to_number (buf, INSN_SIZE);
24118
24119 /* If the addend is positive, use an ADD instruction.
24120 Otherwise use a SUB. Take care not to destroy the S bit. */
24121 insn &= 0xff1fffff;
24122 if (value < 0)
24123 insn |= 1 << 22;
24124 else
24125 insn |= 1 << 23;
24126
24127 /* Place the encoded addend into the first 12 bits of the
24128 instruction. */
24129 insn &= 0xfffff000;
24130 insn |= encoded_addend;
24131
24132 /* Update the instruction. */
24133 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
24134 }
24135 break;
24136
24137 case BFD_RELOC_ARM_LDR_PC_G0:
24138 case BFD_RELOC_ARM_LDR_PC_G1:
24139 case BFD_RELOC_ARM_LDR_PC_G2:
24140 case BFD_RELOC_ARM_LDR_SB_G0:
24141 case BFD_RELOC_ARM_LDR_SB_G1:
24142 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 24143 gas_assert (!fixP->fx_done);
4962c51a 24144 if (!seg->use_rela_p)
477330fc
RM
24145 {
24146 bfd_vma insn;
24147 bfd_vma addend_abs = abs (value);
4962c51a 24148
477330fc
RM
24149 /* Check that the absolute value of the addend can be
24150 encoded in 12 bits. */
24151 if (addend_abs >= 0x1000)
4962c51a 24152 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24153 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
24154 (unsigned long) addend_abs);
24155
24156 /* Extract the instruction. */
24157 insn = md_chars_to_number (buf, INSN_SIZE);
24158
24159 /* If the addend is negative, clear bit 23 of the instruction.
24160 Otherwise set it. */
24161 if (value < 0)
24162 insn &= ~(1 << 23);
24163 else
24164 insn |= 1 << 23;
24165
24166 /* Place the absolute value of the addend into the first 12 bits
24167 of the instruction. */
24168 insn &= 0xfffff000;
24169 insn |= addend_abs;
24170
24171 /* Update the instruction. */
24172 md_number_to_chars (buf, insn, INSN_SIZE);
24173 }
4962c51a
MS
24174 break;
24175
24176 case BFD_RELOC_ARM_LDRS_PC_G0:
24177 case BFD_RELOC_ARM_LDRS_PC_G1:
24178 case BFD_RELOC_ARM_LDRS_PC_G2:
24179 case BFD_RELOC_ARM_LDRS_SB_G0:
24180 case BFD_RELOC_ARM_LDRS_SB_G1:
24181 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 24182 gas_assert (!fixP->fx_done);
4962c51a 24183 if (!seg->use_rela_p)
477330fc
RM
24184 {
24185 bfd_vma insn;
24186 bfd_vma addend_abs = abs (value);
4962c51a 24187
477330fc
RM
24188 /* Check that the absolute value of the addend can be
24189 encoded in 8 bits. */
24190 if (addend_abs >= 0x100)
4962c51a 24191 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24192 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
24193 (unsigned long) addend_abs);
24194
24195 /* Extract the instruction. */
24196 insn = md_chars_to_number (buf, INSN_SIZE);
24197
24198 /* If the addend is negative, clear bit 23 of the instruction.
24199 Otherwise set it. */
24200 if (value < 0)
24201 insn &= ~(1 << 23);
24202 else
24203 insn |= 1 << 23;
24204
24205 /* Place the first four bits of the absolute value of the addend
24206 into the first 4 bits of the instruction, and the remaining
24207 four into bits 8 .. 11. */
24208 insn &= 0xfffff0f0;
24209 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
24210
24211 /* Update the instruction. */
24212 md_number_to_chars (buf, insn, INSN_SIZE);
24213 }
4962c51a
MS
24214 break;
24215
24216 case BFD_RELOC_ARM_LDC_PC_G0:
24217 case BFD_RELOC_ARM_LDC_PC_G1:
24218 case BFD_RELOC_ARM_LDC_PC_G2:
24219 case BFD_RELOC_ARM_LDC_SB_G0:
24220 case BFD_RELOC_ARM_LDC_SB_G1:
24221 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 24222 gas_assert (!fixP->fx_done);
4962c51a 24223 if (!seg->use_rela_p)
477330fc
RM
24224 {
24225 bfd_vma insn;
24226 bfd_vma addend_abs = abs (value);
4962c51a 24227
477330fc
RM
24228 /* Check that the absolute value of the addend is a multiple of
24229 four and, when divided by four, fits in 8 bits. */
24230 if (addend_abs & 0x3)
4962c51a 24231 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24232 _("bad offset 0x%08lX (must be word-aligned)"),
24233 (unsigned long) addend_abs);
4962c51a 24234
477330fc 24235 if ((addend_abs >> 2) > 0xff)
4962c51a 24236 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24237 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
24238 (unsigned long) addend_abs);
24239
24240 /* Extract the instruction. */
24241 insn = md_chars_to_number (buf, INSN_SIZE);
24242
24243 /* If the addend is negative, clear bit 23 of the instruction.
24244 Otherwise set it. */
24245 if (value < 0)
24246 insn &= ~(1 << 23);
24247 else
24248 insn |= 1 << 23;
24249
24250 /* Place the addend (divided by four) into the first eight
24251 bits of the instruction. */
24252 insn &= 0xfffffff0;
24253 insn |= addend_abs >> 2;
24254
24255 /* Update the instruction. */
24256 md_number_to_chars (buf, insn, INSN_SIZE);
24257 }
4962c51a
MS
24258 break;
24259
845b51d6
PB
24260 case BFD_RELOC_ARM_V4BX:
24261 /* This will need to go in the object file. */
24262 fixP->fx_done = 0;
24263 break;
24264
c19d1205
ZW
24265 case BFD_RELOC_UNUSED:
24266 default:
24267 as_bad_where (fixP->fx_file, fixP->fx_line,
24268 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
24269 }
6c43fab6
RE
24270}
24271
c19d1205
ZW
24272/* Translate internal representation of relocation info to BFD target
24273 format. */
a737bd4d 24274
c19d1205 24275arelent *
00a97672 24276tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 24277{
c19d1205
ZW
24278 arelent * reloc;
24279 bfd_reloc_code_real_type code;
a737bd4d 24280
325801bd 24281 reloc = XNEW (arelent);
a737bd4d 24282
325801bd 24283 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
24284 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
24285 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 24286
2fc8bdac 24287 if (fixp->fx_pcrel)
00a97672
RS
24288 {
24289 if (section->use_rela_p)
24290 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
24291 else
24292 fixp->fx_offset = reloc->address;
24293 }
c19d1205 24294 reloc->addend = fixp->fx_offset;
a737bd4d 24295
c19d1205 24296 switch (fixp->fx_r_type)
a737bd4d 24297 {
c19d1205
ZW
24298 case BFD_RELOC_8:
24299 if (fixp->fx_pcrel)
24300 {
24301 code = BFD_RELOC_8_PCREL;
24302 break;
24303 }
1a0670f3 24304 /* Fall through. */
a737bd4d 24305
c19d1205
ZW
24306 case BFD_RELOC_16:
24307 if (fixp->fx_pcrel)
24308 {
24309 code = BFD_RELOC_16_PCREL;
24310 break;
24311 }
1a0670f3 24312 /* Fall through. */
6c43fab6 24313
c19d1205
ZW
24314 case BFD_RELOC_32:
24315 if (fixp->fx_pcrel)
24316 {
24317 code = BFD_RELOC_32_PCREL;
24318 break;
24319 }
1a0670f3 24320 /* Fall through. */
a737bd4d 24321
b6895b4f
PB
24322 case BFD_RELOC_ARM_MOVW:
24323 if (fixp->fx_pcrel)
24324 {
24325 code = BFD_RELOC_ARM_MOVW_PCREL;
24326 break;
24327 }
1a0670f3 24328 /* Fall through. */
b6895b4f
PB
24329
24330 case BFD_RELOC_ARM_MOVT:
24331 if (fixp->fx_pcrel)
24332 {
24333 code = BFD_RELOC_ARM_MOVT_PCREL;
24334 break;
24335 }
1a0670f3 24336 /* Fall through. */
b6895b4f
PB
24337
24338 case BFD_RELOC_ARM_THUMB_MOVW:
24339 if (fixp->fx_pcrel)
24340 {
24341 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
24342 break;
24343 }
1a0670f3 24344 /* Fall through. */
b6895b4f
PB
24345
24346 case BFD_RELOC_ARM_THUMB_MOVT:
24347 if (fixp->fx_pcrel)
24348 {
24349 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
24350 break;
24351 }
1a0670f3 24352 /* Fall through. */
b6895b4f 24353
c19d1205
ZW
24354 case BFD_RELOC_NONE:
24355 case BFD_RELOC_ARM_PCREL_BRANCH:
24356 case BFD_RELOC_ARM_PCREL_BLX:
24357 case BFD_RELOC_RVA:
24358 case BFD_RELOC_THUMB_PCREL_BRANCH7:
24359 case BFD_RELOC_THUMB_PCREL_BRANCH9:
24360 case BFD_RELOC_THUMB_PCREL_BRANCH12:
24361 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24362 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24363 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
24364 case BFD_RELOC_VTABLE_ENTRY:
24365 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
24366#ifdef TE_PE
24367 case BFD_RELOC_32_SECREL:
24368#endif
c19d1205
ZW
24369 code = fixp->fx_r_type;
24370 break;
a737bd4d 24371
00adf2d4
JB
24372 case BFD_RELOC_THUMB_PCREL_BLX:
24373#ifdef OBJ_ELF
24374 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
24375 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
24376 else
24377#endif
24378 code = BFD_RELOC_THUMB_PCREL_BLX;
24379 break;
24380
c19d1205
ZW
24381 case BFD_RELOC_ARM_LITERAL:
24382 case BFD_RELOC_ARM_HWLITERAL:
24383 /* If this is called then the a literal has
24384 been referenced across a section boundary. */
24385 as_bad_where (fixp->fx_file, fixp->fx_line,
24386 _("literal referenced across section boundary"));
24387 return NULL;
a737bd4d 24388
c19d1205 24389#ifdef OBJ_ELF
0855e32b
NS
24390 case BFD_RELOC_ARM_TLS_CALL:
24391 case BFD_RELOC_ARM_THM_TLS_CALL:
24392 case BFD_RELOC_ARM_TLS_DESCSEQ:
24393 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
24394 case BFD_RELOC_ARM_GOT32:
24395 case BFD_RELOC_ARM_GOTOFF:
b43420e6 24396 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
24397 case BFD_RELOC_ARM_PLT32:
24398 case BFD_RELOC_ARM_TARGET1:
24399 case BFD_RELOC_ARM_ROSEGREL32:
24400 case BFD_RELOC_ARM_SBREL32:
24401 case BFD_RELOC_ARM_PREL31:
24402 case BFD_RELOC_ARM_TARGET2:
c19d1205 24403 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
24404 case BFD_RELOC_ARM_PCREL_CALL:
24405 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
24406 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24407 case BFD_RELOC_ARM_ALU_PC_G0:
24408 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24409 case BFD_RELOC_ARM_ALU_PC_G1:
24410 case BFD_RELOC_ARM_ALU_PC_G2:
24411 case BFD_RELOC_ARM_LDR_PC_G0:
24412 case BFD_RELOC_ARM_LDR_PC_G1:
24413 case BFD_RELOC_ARM_LDR_PC_G2:
24414 case BFD_RELOC_ARM_LDRS_PC_G0:
24415 case BFD_RELOC_ARM_LDRS_PC_G1:
24416 case BFD_RELOC_ARM_LDRS_PC_G2:
24417 case BFD_RELOC_ARM_LDC_PC_G0:
24418 case BFD_RELOC_ARM_LDC_PC_G1:
24419 case BFD_RELOC_ARM_LDC_PC_G2:
24420 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24421 case BFD_RELOC_ARM_ALU_SB_G0:
24422 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24423 case BFD_RELOC_ARM_ALU_SB_G1:
24424 case BFD_RELOC_ARM_ALU_SB_G2:
24425 case BFD_RELOC_ARM_LDR_SB_G0:
24426 case BFD_RELOC_ARM_LDR_SB_G1:
24427 case BFD_RELOC_ARM_LDR_SB_G2:
24428 case BFD_RELOC_ARM_LDRS_SB_G0:
24429 case BFD_RELOC_ARM_LDRS_SB_G1:
24430 case BFD_RELOC_ARM_LDRS_SB_G2:
24431 case BFD_RELOC_ARM_LDC_SB_G0:
24432 case BFD_RELOC_ARM_LDC_SB_G1:
24433 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 24434 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
24435 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24436 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24437 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24438 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
c19d1205
ZW
24439 code = fixp->fx_r_type;
24440 break;
a737bd4d 24441
0855e32b 24442 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 24443 case BFD_RELOC_ARM_TLS_GD32:
75c11999 24444 case BFD_RELOC_ARM_TLS_LE32:
c19d1205
ZW
24445 case BFD_RELOC_ARM_TLS_IE32:
24446 case BFD_RELOC_ARM_TLS_LDM32:
24447 /* BFD will include the symbol's address in the addend.
24448 But we don't want that, so subtract it out again here. */
24449 if (!S_IS_COMMON (fixp->fx_addsy))
24450 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
24451 code = fixp->fx_r_type;
24452 break;
24453#endif
a737bd4d 24454
c19d1205
ZW
24455 case BFD_RELOC_ARM_IMMEDIATE:
24456 as_bad_where (fixp->fx_file, fixp->fx_line,
24457 _("internal relocation (type: IMMEDIATE) not fixed up"));
24458 return NULL;
a737bd4d 24459
c19d1205
ZW
24460 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24461 as_bad_where (fixp->fx_file, fixp->fx_line,
24462 _("ADRL used for a symbol not defined in the same file"));
24463 return NULL;
a737bd4d 24464
c19d1205 24465 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
24466 if (section->use_rela_p)
24467 {
24468 code = fixp->fx_r_type;
24469 break;
24470 }
24471
c19d1205
ZW
24472 if (fixp->fx_addsy != NULL
24473 && !S_IS_DEFINED (fixp->fx_addsy)
24474 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 24475 {
c19d1205
ZW
24476 as_bad_where (fixp->fx_file, fixp->fx_line,
24477 _("undefined local label `%s'"),
24478 S_GET_NAME (fixp->fx_addsy));
24479 return NULL;
a737bd4d
NC
24480 }
24481
c19d1205
ZW
24482 as_bad_where (fixp->fx_file, fixp->fx_line,
24483 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
24484 return NULL;
a737bd4d 24485
c19d1205
ZW
24486 default:
24487 {
e0471c16 24488 const char * type;
6c43fab6 24489
c19d1205
ZW
24490 switch (fixp->fx_r_type)
24491 {
24492 case BFD_RELOC_NONE: type = "NONE"; break;
24493 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
24494 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 24495 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
24496 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
24497 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
24498 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 24499 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 24500 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
24501 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
24502 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
24503 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
24504 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
24505 default: type = _("<unknown>"); break;
24506 }
24507 as_bad_where (fixp->fx_file, fixp->fx_line,
24508 _("cannot represent %s relocation in this object file format"),
24509 type);
24510 return NULL;
24511 }
a737bd4d 24512 }
6c43fab6 24513
c19d1205
ZW
24514#ifdef OBJ_ELF
24515 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
24516 && GOT_symbol
24517 && fixp->fx_addsy == GOT_symbol)
24518 {
24519 code = BFD_RELOC_ARM_GOTPC;
24520 reloc->addend = fixp->fx_offset = reloc->address;
24521 }
24522#endif
6c43fab6 24523
c19d1205 24524 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 24525
c19d1205
ZW
24526 if (reloc->howto == NULL)
24527 {
24528 as_bad_where (fixp->fx_file, fixp->fx_line,
24529 _("cannot represent %s relocation in this object file format"),
24530 bfd_get_reloc_code_name (code));
24531 return NULL;
24532 }
6c43fab6 24533
c19d1205
ZW
24534 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
24535 vtable entry to be used in the relocation's section offset. */
24536 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
24537 reloc->address = fixp->fx_offset;
6c43fab6 24538
c19d1205 24539 return reloc;
6c43fab6
RE
24540}
24541
c19d1205 24542/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 24543
c19d1205
ZW
24544void
24545cons_fix_new_arm (fragS * frag,
24546 int where,
24547 int size,
62ebcb5c
AM
24548 expressionS * exp,
24549 bfd_reloc_code_real_type reloc)
6c43fab6 24550{
c19d1205 24551 int pcrel = 0;
6c43fab6 24552
c19d1205
ZW
24553 /* Pick a reloc.
24554 FIXME: @@ Should look at CPU word size. */
24555 switch (size)
24556 {
24557 case 1:
62ebcb5c 24558 reloc = BFD_RELOC_8;
c19d1205
ZW
24559 break;
24560 case 2:
62ebcb5c 24561 reloc = BFD_RELOC_16;
c19d1205
ZW
24562 break;
24563 case 4:
24564 default:
62ebcb5c 24565 reloc = BFD_RELOC_32;
c19d1205
ZW
24566 break;
24567 case 8:
62ebcb5c 24568 reloc = BFD_RELOC_64;
c19d1205
ZW
24569 break;
24570 }
6c43fab6 24571
f0927246
NC
24572#ifdef TE_PE
24573 if (exp->X_op == O_secrel)
24574 {
24575 exp->X_op = O_symbol;
62ebcb5c 24576 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
24577 }
24578#endif
24579
62ebcb5c 24580 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 24581}
6c43fab6 24582
4343666d 24583#if defined (OBJ_COFF)
c19d1205
ZW
24584void
24585arm_validate_fix (fixS * fixP)
6c43fab6 24586{
c19d1205
ZW
24587 /* If the destination of the branch is a defined symbol which does not have
24588 the THUMB_FUNC attribute, then we must be calling a function which has
24589 the (interfacearm) attribute. We look for the Thumb entry point to that
24590 function and change the branch to refer to that function instead. */
24591 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
24592 && fixP->fx_addsy != NULL
24593 && S_IS_DEFINED (fixP->fx_addsy)
24594 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 24595 {
c19d1205 24596 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 24597 }
c19d1205
ZW
24598}
24599#endif
6c43fab6 24600
267bf995 24601
c19d1205
ZW
24602int
24603arm_force_relocation (struct fix * fixp)
24604{
24605#if defined (OBJ_COFF) && defined (TE_PE)
24606 if (fixp->fx_r_type == BFD_RELOC_RVA)
24607 return 1;
24608#endif
6c43fab6 24609
267bf995
RR
24610 /* In case we have a call or a branch to a function in ARM ISA mode from
24611 a thumb function or vice-versa force the relocation. These relocations
24612 are cleared off for some cores that might have blx and simple transformations
24613 are possible. */
24614
24615#ifdef OBJ_ELF
24616 switch (fixp->fx_r_type)
24617 {
24618 case BFD_RELOC_ARM_PCREL_JUMP:
24619 case BFD_RELOC_ARM_PCREL_CALL:
24620 case BFD_RELOC_THUMB_PCREL_BLX:
24621 if (THUMB_IS_FUNC (fixp->fx_addsy))
24622 return 1;
24623 break;
24624
24625 case BFD_RELOC_ARM_PCREL_BLX:
24626 case BFD_RELOC_THUMB_PCREL_BRANCH25:
24627 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24628 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24629 if (ARM_IS_FUNC (fixp->fx_addsy))
24630 return 1;
24631 break;
24632
24633 default:
24634 break;
24635 }
24636#endif
24637
b5884301
PB
24638 /* Resolve these relocations even if the symbol is extern or weak.
24639 Technically this is probably wrong due to symbol preemption.
24640 In practice these relocations do not have enough range to be useful
24641 at dynamic link time, and some code (e.g. in the Linux kernel)
24642 expects these references to be resolved. */
c19d1205
ZW
24643 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
24644 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 24645 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 24646 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
24647 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24648 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
24649 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 24650 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
24651 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
24652 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
24653 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
24654 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
24655 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
24656 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 24657 return 0;
a737bd4d 24658
4962c51a
MS
24659 /* Always leave these relocations for the linker. */
24660 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24661 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24662 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
24663 return 1;
24664
f0291e4c
PB
24665 /* Always generate relocations against function symbols. */
24666 if (fixp->fx_r_type == BFD_RELOC_32
24667 && fixp->fx_addsy
24668 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
24669 return 1;
24670
c19d1205 24671 return generic_force_reloc (fixp);
404ff6b5
AH
24672}
24673
0ffdc86c 24674#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
24675/* Relocations against function names must be left unadjusted,
24676 so that the linker can use this information to generate interworking
24677 stubs. The MIPS version of this function
c19d1205
ZW
24678 also prevents relocations that are mips-16 specific, but I do not
24679 know why it does this.
404ff6b5 24680
c19d1205
ZW
24681 FIXME:
24682 There is one other problem that ought to be addressed here, but
24683 which currently is not: Taking the address of a label (rather
24684 than a function) and then later jumping to that address. Such
24685 addresses also ought to have their bottom bit set (assuming that
24686 they reside in Thumb code), but at the moment they will not. */
404ff6b5 24687
c19d1205
ZW
24688bfd_boolean
24689arm_fix_adjustable (fixS * fixP)
404ff6b5 24690{
c19d1205
ZW
24691 if (fixP->fx_addsy == NULL)
24692 return 1;
404ff6b5 24693
e28387c3
PB
24694 /* Preserve relocations against symbols with function type. */
24695 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 24696 return FALSE;
e28387c3 24697
c19d1205
ZW
24698 if (THUMB_IS_FUNC (fixP->fx_addsy)
24699 && fixP->fx_subsy == NULL)
c921be7d 24700 return FALSE;
a737bd4d 24701
c19d1205
ZW
24702 /* We need the symbol name for the VTABLE entries. */
24703 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
24704 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 24705 return FALSE;
404ff6b5 24706
c19d1205
ZW
24707 /* Don't allow symbols to be discarded on GOT related relocs. */
24708 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
24709 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
24710 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
24711 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
24712 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
24713 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
24714 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
24715 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
24716 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
24717 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
24718 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
24719 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
24720 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 24721 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 24722 return FALSE;
a737bd4d 24723
4962c51a
MS
24724 /* Similarly for group relocations. */
24725 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24726 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24727 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 24728 return FALSE;
4962c51a 24729
79947c54
CD
24730 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
24731 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
24732 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24733 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
24734 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
24735 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24736 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
24737 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
24738 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 24739 return FALSE;
79947c54 24740
72d98d16
MG
24741 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
24742 offsets, so keep these symbols. */
24743 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
24744 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
24745 return FALSE;
24746
c921be7d 24747 return TRUE;
a737bd4d 24748}
0ffdc86c
NC
24749#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
24750
24751#ifdef OBJ_ELF
c19d1205
ZW
24752const char *
24753elf32_arm_target_format (void)
404ff6b5 24754{
c19d1205
ZW
24755#ifdef TE_SYMBIAN
24756 return (target_big_endian
24757 ? "elf32-bigarm-symbian"
24758 : "elf32-littlearm-symbian");
24759#elif defined (TE_VXWORKS)
24760 return (target_big_endian
24761 ? "elf32-bigarm-vxworks"
24762 : "elf32-littlearm-vxworks");
b38cadfb
NC
24763#elif defined (TE_NACL)
24764 return (target_big_endian
24765 ? "elf32-bigarm-nacl"
24766 : "elf32-littlearm-nacl");
c19d1205
ZW
24767#else
24768 if (target_big_endian)
24769 return "elf32-bigarm";
24770 else
24771 return "elf32-littlearm";
24772#endif
404ff6b5
AH
24773}
24774
c19d1205
ZW
24775void
24776armelf_frob_symbol (symbolS * symp,
24777 int * puntp)
404ff6b5 24778{
c19d1205
ZW
24779 elf_frob_symbol (symp, puntp);
24780}
24781#endif
404ff6b5 24782
c19d1205 24783/* MD interface: Finalization. */
a737bd4d 24784
c19d1205
ZW
24785void
24786arm_cleanup (void)
24787{
24788 literal_pool * pool;
a737bd4d 24789
e07e6e58
NC
24790 /* Ensure that all the IT blocks are properly closed. */
24791 check_it_blocks_finished ();
24792
c19d1205
ZW
24793 for (pool = list_of_pools; pool; pool = pool->next)
24794 {
5f4273c7 24795 /* Put it at the end of the relevant section. */
c19d1205
ZW
24796 subseg_set (pool->section, pool->sub_section);
24797#ifdef OBJ_ELF
24798 arm_elf_change_section ();
24799#endif
24800 s_ltorg (0);
24801 }
404ff6b5
AH
24802}
24803
cd000bff
DJ
24804#ifdef OBJ_ELF
24805/* Remove any excess mapping symbols generated for alignment frags in
24806 SEC. We may have created a mapping symbol before a zero byte
24807 alignment; remove it if there's a mapping symbol after the
24808 alignment. */
24809static void
24810check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
24811 void *dummy ATTRIBUTE_UNUSED)
24812{
24813 segment_info_type *seginfo = seg_info (sec);
24814 fragS *fragp;
24815
24816 if (seginfo == NULL || seginfo->frchainP == NULL)
24817 return;
24818
24819 for (fragp = seginfo->frchainP->frch_root;
24820 fragp != NULL;
24821 fragp = fragp->fr_next)
24822 {
24823 symbolS *sym = fragp->tc_frag_data.last_map;
24824 fragS *next = fragp->fr_next;
24825
24826 /* Variable-sized frags have been converted to fixed size by
24827 this point. But if this was variable-sized to start with,
24828 there will be a fixed-size frag after it. So don't handle
24829 next == NULL. */
24830 if (sym == NULL || next == NULL)
24831 continue;
24832
24833 if (S_GET_VALUE (sym) < next->fr_address)
24834 /* Not at the end of this frag. */
24835 continue;
24836 know (S_GET_VALUE (sym) == next->fr_address);
24837
24838 do
24839 {
24840 if (next->tc_frag_data.first_map != NULL)
24841 {
24842 /* Next frag starts with a mapping symbol. Discard this
24843 one. */
24844 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24845 break;
24846 }
24847
24848 if (next->fr_next == NULL)
24849 {
24850 /* This mapping symbol is at the end of the section. Discard
24851 it. */
24852 know (next->fr_fix == 0 && next->fr_var == 0);
24853 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24854 break;
24855 }
24856
24857 /* As long as we have empty frags without any mapping symbols,
24858 keep looking. */
24859 /* If the next frag is non-empty and does not start with a
24860 mapping symbol, then this mapping symbol is required. */
24861 if (next->fr_address != next->fr_next->fr_address)
24862 break;
24863
24864 next = next->fr_next;
24865 }
24866 while (next != NULL);
24867 }
24868}
24869#endif
24870
c19d1205
ZW
24871/* Adjust the symbol table. This marks Thumb symbols as distinct from
24872 ARM ones. */
404ff6b5 24873
c19d1205
ZW
24874void
24875arm_adjust_symtab (void)
404ff6b5 24876{
c19d1205
ZW
24877#ifdef OBJ_COFF
24878 symbolS * sym;
404ff6b5 24879
c19d1205
ZW
24880 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
24881 {
24882 if (ARM_IS_THUMB (sym))
24883 {
24884 if (THUMB_IS_FUNC (sym))
24885 {
24886 /* Mark the symbol as a Thumb function. */
24887 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
24888 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
24889 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 24890
c19d1205
ZW
24891 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
24892 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
24893 else
24894 as_bad (_("%s: unexpected function type: %d"),
24895 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
24896 }
24897 else switch (S_GET_STORAGE_CLASS (sym))
24898 {
24899 case C_EXT:
24900 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
24901 break;
24902 case C_STAT:
24903 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
24904 break;
24905 case C_LABEL:
24906 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
24907 break;
24908 default:
24909 /* Do nothing. */
24910 break;
24911 }
24912 }
a737bd4d 24913
c19d1205
ZW
24914 if (ARM_IS_INTERWORK (sym))
24915 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 24916 }
c19d1205
ZW
24917#endif
24918#ifdef OBJ_ELF
24919 symbolS * sym;
24920 char bind;
404ff6b5 24921
c19d1205 24922 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 24923 {
c19d1205
ZW
24924 if (ARM_IS_THUMB (sym))
24925 {
24926 elf_symbol_type * elf_sym;
404ff6b5 24927
c19d1205
ZW
24928 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
24929 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 24930
b0796911
PB
24931 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
24932 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
24933 {
24934 /* If it's a .thumb_func, declare it as so,
24935 otherwise tag label as .code 16. */
24936 if (THUMB_IS_FUNC (sym))
39d911fc
TP
24937 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
24938 ST_BRANCH_TO_THUMB);
3ba67470 24939 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
24940 elf_sym->internal_elf_sym.st_info =
24941 ELF_ST_INFO (bind, STT_ARM_16BIT);
24942 }
24943 }
24944 }
cd000bff
DJ
24945
24946 /* Remove any overlapping mapping symbols generated by alignment frags. */
24947 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
24948 /* Now do generic ELF adjustments. */
24949 elf_adjust_symtab ();
c19d1205 24950#endif
404ff6b5
AH
24951}
24952
c19d1205 24953/* MD interface: Initialization. */
404ff6b5 24954
a737bd4d 24955static void
c19d1205 24956set_constant_flonums (void)
a737bd4d 24957{
c19d1205 24958 int i;
404ff6b5 24959
c19d1205
ZW
24960 for (i = 0; i < NUM_FLOAT_VALS; i++)
24961 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
24962 abort ();
a737bd4d 24963}
404ff6b5 24964
3e9e4fcf
JB
24965/* Auto-select Thumb mode if it's the only available instruction set for the
24966 given architecture. */
24967
24968static void
24969autoselect_thumb_from_cpu_variant (void)
24970{
24971 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
24972 opcode_select (16);
24973}
24974
c19d1205
ZW
24975void
24976md_begin (void)
a737bd4d 24977{
c19d1205
ZW
24978 unsigned mach;
24979 unsigned int i;
404ff6b5 24980
c19d1205
ZW
24981 if ( (arm_ops_hsh = hash_new ()) == NULL
24982 || (arm_cond_hsh = hash_new ()) == NULL
24983 || (arm_shift_hsh = hash_new ()) == NULL
24984 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 24985 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 24986 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
24987 || (arm_reloc_hsh = hash_new ()) == NULL
24988 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
24989 as_fatal (_("virtual memory exhausted"));
24990
24991 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 24992 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 24993 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 24994 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 24995 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 24996 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 24997 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24998 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 24999 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 25000 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 25001 (void *) (v7m_psrs + i));
c19d1205 25002 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 25003 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
25004 for (i = 0;
25005 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
25006 i++)
d3ce72d0 25007 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 25008 (void *) (barrier_opt_names + i));
c19d1205 25009#ifdef OBJ_ELF
3da1d841
NC
25010 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
25011 {
25012 struct reloc_entry * entry = reloc_names + i;
25013
25014 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
25015 /* This makes encode_branch() use the EABI versions of this relocation. */
25016 entry->reloc = BFD_RELOC_UNUSED;
25017
25018 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
25019 }
c19d1205
ZW
25020#endif
25021
25022 set_constant_flonums ();
404ff6b5 25023
c19d1205
ZW
25024 /* Set the cpu variant based on the command-line options. We prefer
25025 -mcpu= over -march= if both are set (as for GCC); and we prefer
25026 -mfpu= over any other way of setting the floating point unit.
25027 Use of legacy options with new options are faulted. */
e74cfd16 25028 if (legacy_cpu)
404ff6b5 25029 {
e74cfd16 25030 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
25031 as_bad (_("use of old and new-style options to set CPU type"));
25032
25033 mcpu_cpu_opt = legacy_cpu;
404ff6b5 25034 }
e74cfd16 25035 else if (!mcpu_cpu_opt)
c19d1205 25036 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 25037
e74cfd16 25038 if (legacy_fpu)
c19d1205 25039 {
e74cfd16 25040 if (mfpu_opt)
c19d1205 25041 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
25042
25043 mfpu_opt = legacy_fpu;
25044 }
e74cfd16 25045 else if (!mfpu_opt)
03b1477f 25046 {
45eb4c1b
NS
25047#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
25048 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
25049 /* Some environments specify a default FPU. If they don't, infer it
25050 from the processor. */
e74cfd16 25051 if (mcpu_fpu_opt)
03b1477f
RE
25052 mfpu_opt = mcpu_fpu_opt;
25053 else
25054 mfpu_opt = march_fpu_opt;
39c2da32 25055#else
e74cfd16 25056 mfpu_opt = &fpu_default;
39c2da32 25057#endif
03b1477f
RE
25058 }
25059
e74cfd16 25060 if (!mfpu_opt)
03b1477f 25061 {
493cb6ef 25062 if (mcpu_cpu_opt != NULL)
e74cfd16 25063 mfpu_opt = &fpu_default;
493cb6ef 25064 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 25065 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 25066 else
e74cfd16 25067 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
25068 }
25069
ee065d83 25070#ifdef CPU_DEFAULT
e74cfd16 25071 if (!mcpu_cpu_opt)
ee065d83 25072 {
e74cfd16
PB
25073 mcpu_cpu_opt = &cpu_default;
25074 selected_cpu = cpu_default;
ee065d83 25075 }
62785b09
TP
25076 else
25077 selected_cpu = *mcpu_cpu_opt;
e74cfd16
PB
25078#else
25079 if (mcpu_cpu_opt)
25080 selected_cpu = *mcpu_cpu_opt;
ee065d83 25081 else
e74cfd16 25082 mcpu_cpu_opt = &arm_arch_any;
ee065d83 25083#endif
03b1477f 25084
e74cfd16 25085 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 25086
3e9e4fcf
JB
25087 autoselect_thumb_from_cpu_variant ();
25088
e74cfd16 25089 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 25090
f17c130b 25091#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 25092 {
7cc69913
NC
25093 unsigned int flags = 0;
25094
25095#if defined OBJ_ELF
25096 flags = meabi_flags;
d507cf36
PB
25097
25098 switch (meabi_flags)
33a392fb 25099 {
d507cf36 25100 case EF_ARM_EABI_UNKNOWN:
7cc69913 25101#endif
d507cf36
PB
25102 /* Set the flags in the private structure. */
25103 if (uses_apcs_26) flags |= F_APCS26;
25104 if (support_interwork) flags |= F_INTERWORK;
25105 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 25106 if (pic_code) flags |= F_PIC;
e74cfd16 25107 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
25108 flags |= F_SOFT_FLOAT;
25109
d507cf36
PB
25110 switch (mfloat_abi_opt)
25111 {
25112 case ARM_FLOAT_ABI_SOFT:
25113 case ARM_FLOAT_ABI_SOFTFP:
25114 flags |= F_SOFT_FLOAT;
25115 break;
33a392fb 25116
d507cf36
PB
25117 case ARM_FLOAT_ABI_HARD:
25118 if (flags & F_SOFT_FLOAT)
25119 as_bad (_("hard-float conflicts with specified fpu"));
25120 break;
25121 }
03b1477f 25122
e74cfd16
PB
25123 /* Using pure-endian doubles (even if soft-float). */
25124 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 25125 flags |= F_VFP_FLOAT;
f17c130b 25126
fde78edd 25127#if defined OBJ_ELF
e74cfd16 25128 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 25129 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
25130 break;
25131
8cb51566 25132 case EF_ARM_EABI_VER4:
3a4a14e9 25133 case EF_ARM_EABI_VER5:
c19d1205 25134 /* No additional flags to set. */
d507cf36
PB
25135 break;
25136
25137 default:
25138 abort ();
25139 }
7cc69913 25140#endif
b99bd4ef
NC
25141 bfd_set_private_flags (stdoutput, flags);
25142
25143 /* We have run out flags in the COFF header to encode the
25144 status of ATPCS support, so instead we create a dummy,
c19d1205 25145 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
25146 if (atpcs)
25147 {
25148 asection * sec;
25149
25150 sec = bfd_make_section (stdoutput, ".arm.atpcs");
25151
25152 if (sec != NULL)
25153 {
25154 bfd_set_section_flags
25155 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
25156 bfd_set_section_size (stdoutput, sec, 0);
25157 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
25158 }
25159 }
7cc69913 25160 }
f17c130b 25161#endif
b99bd4ef
NC
25162
25163 /* Record the CPU type as well. */
2d447fca
JM
25164 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
25165 mach = bfd_mach_arm_iWMMXt2;
25166 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 25167 mach = bfd_mach_arm_iWMMXt;
e74cfd16 25168 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 25169 mach = bfd_mach_arm_XScale;
e74cfd16 25170 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 25171 mach = bfd_mach_arm_ep9312;
e74cfd16 25172 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 25173 mach = bfd_mach_arm_5TE;
e74cfd16 25174 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 25175 {
e74cfd16 25176 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25177 mach = bfd_mach_arm_5T;
25178 else
25179 mach = bfd_mach_arm_5;
25180 }
e74cfd16 25181 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 25182 {
e74cfd16 25183 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25184 mach = bfd_mach_arm_4T;
25185 else
25186 mach = bfd_mach_arm_4;
25187 }
e74cfd16 25188 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 25189 mach = bfd_mach_arm_3M;
e74cfd16
PB
25190 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
25191 mach = bfd_mach_arm_3;
25192 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
25193 mach = bfd_mach_arm_2a;
25194 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
25195 mach = bfd_mach_arm_2;
25196 else
25197 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
25198
25199 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
25200}
25201
c19d1205 25202/* Command line processing. */
b99bd4ef 25203
c19d1205
ZW
25204/* md_parse_option
25205 Invocation line includes a switch not recognized by the base assembler.
25206 See if it's a processor-specific option.
b99bd4ef 25207
c19d1205
ZW
25208 This routine is somewhat complicated by the need for backwards
25209 compatibility (since older releases of gcc can't be changed).
25210 The new options try to make the interface as compatible as
25211 possible with GCC.
b99bd4ef 25212
c19d1205 25213 New options (supported) are:
b99bd4ef 25214
c19d1205
ZW
25215 -mcpu=<cpu name> Assemble for selected processor
25216 -march=<architecture name> Assemble for selected architecture
25217 -mfpu=<fpu architecture> Assemble for selected FPU.
25218 -EB/-mbig-endian Big-endian
25219 -EL/-mlittle-endian Little-endian
25220 -k Generate PIC code
25221 -mthumb Start in Thumb mode
25222 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 25223
278df34e 25224 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 25225 -m[no-]warn-syms Warn when symbols match instructions
267bf995 25226
c19d1205 25227 For now we will also provide support for:
b99bd4ef 25228
c19d1205
ZW
25229 -mapcs-32 32-bit Program counter
25230 -mapcs-26 26-bit Program counter
25231 -macps-float Floats passed in FP registers
25232 -mapcs-reentrant Reentrant code
25233 -matpcs
25234 (sometime these will probably be replaced with -mapcs=<list of options>
25235 and -matpcs=<list of options>)
b99bd4ef 25236
c19d1205
ZW
25237 The remaining options are only supported for back-wards compatibility.
25238 Cpu variants, the arm part is optional:
25239 -m[arm]1 Currently not supported.
25240 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
25241 -m[arm]3 Arm 3 processor
25242 -m[arm]6[xx], Arm 6 processors
25243 -m[arm]7[xx][t][[d]m] Arm 7 processors
25244 -m[arm]8[10] Arm 8 processors
25245 -m[arm]9[20][tdmi] Arm 9 processors
25246 -mstrongarm[110[0]] StrongARM processors
25247 -mxscale XScale processors
25248 -m[arm]v[2345[t[e]]] Arm architectures
25249 -mall All (except the ARM1)
25250 FP variants:
25251 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
25252 -mfpe-old (No float load/store multiples)
25253 -mvfpxd VFP Single precision
25254 -mvfp All VFP
25255 -mno-fpu Disable all floating point instructions
b99bd4ef 25256
c19d1205
ZW
25257 The following CPU names are recognized:
25258 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
25259 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
25260 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
25261 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
25262 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
25263 arm10t arm10e, arm1020t, arm1020e, arm10200e,
25264 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 25265
c19d1205 25266 */
b99bd4ef 25267
c19d1205 25268const char * md_shortopts = "m:k";
b99bd4ef 25269
c19d1205
ZW
25270#ifdef ARM_BI_ENDIAN
25271#define OPTION_EB (OPTION_MD_BASE + 0)
25272#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 25273#else
c19d1205
ZW
25274#if TARGET_BYTES_BIG_ENDIAN
25275#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 25276#else
c19d1205
ZW
25277#define OPTION_EL (OPTION_MD_BASE + 1)
25278#endif
b99bd4ef 25279#endif
845b51d6 25280#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 25281
c19d1205 25282struct option md_longopts[] =
b99bd4ef 25283{
c19d1205
ZW
25284#ifdef OPTION_EB
25285 {"EB", no_argument, NULL, OPTION_EB},
25286#endif
25287#ifdef OPTION_EL
25288 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 25289#endif
845b51d6 25290 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
25291 {NULL, no_argument, NULL, 0}
25292};
b99bd4ef 25293
8b2d793c 25294
c19d1205 25295size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 25296
c19d1205 25297struct arm_option_table
b99bd4ef 25298{
e0471c16
TS
25299 const char *option; /* Option name to match. */
25300 const char *help; /* Help information. */
c19d1205
ZW
25301 int *var; /* Variable to change. */
25302 int value; /* What to change it to. */
e0471c16 25303 const char *deprecated; /* If non-null, print this message. */
c19d1205 25304};
b99bd4ef 25305
c19d1205
ZW
25306struct arm_option_table arm_opts[] =
25307{
25308 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
25309 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
25310 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
25311 &support_interwork, 1, NULL},
25312 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
25313 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
25314 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
25315 1, NULL},
25316 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
25317 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
25318 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
25319 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
25320 NULL},
b99bd4ef 25321
c19d1205
ZW
25322 /* These are recognized by the assembler, but have no affect on code. */
25323 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
25324 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
25325
25326 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
25327 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
25328 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
25329 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
25330 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
25331 {NULL, NULL, NULL, 0, NULL}
25332};
25333
25334struct arm_legacy_option_table
25335{
e0471c16 25336 const char *option; /* Option name to match. */
e74cfd16
PB
25337 const arm_feature_set **var; /* Variable to change. */
25338 const arm_feature_set value; /* What to change it to. */
e0471c16 25339 const char *deprecated; /* If non-null, print this message. */
e74cfd16 25340};
b99bd4ef 25341
e74cfd16
PB
25342const struct arm_legacy_option_table arm_legacy_opts[] =
25343{
c19d1205
ZW
25344 /* DON'T add any new processors to this list -- we want the whole list
25345 to go away... Add them to the processors table instead. */
e74cfd16
PB
25346 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25347 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25348 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25349 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25350 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25351 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25352 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25353 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25354 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25355 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25356 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25357 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25358 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25359 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25360 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25361 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25362 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25363 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25364 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25365 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25366 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25367 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25368 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25369 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25370 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25371 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25372 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25373 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25374 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25375 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25376 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25377 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25378 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25379 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25380 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25381 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25382 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25383 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25384 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25385 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25386 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25387 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25388 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25389 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25390 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25391 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25392 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25393 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25394 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25395 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25396 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25397 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25398 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25399 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25400 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25401 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25402 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25403 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25404 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25405 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25406 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25407 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25408 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25409 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25410 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25411 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25412 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25413 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25414 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
25415 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25416 N_("use -mcpu=strongarm110")},
e74cfd16 25417 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25418 N_("use -mcpu=strongarm1100")},
e74cfd16 25419 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25420 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
25421 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
25422 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
25423 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 25424
c19d1205 25425 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
25426 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25427 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25428 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25429 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25430 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25431 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25432 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25433 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25434 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25435 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25436 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25437 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25438 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25439 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25440 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25441 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25442 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
25443 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 25444
c19d1205 25445 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
25446 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
25447 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
25448 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
25449 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 25450 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 25451
e74cfd16 25452 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 25453};
7ed4c4c5 25454
c19d1205 25455struct arm_cpu_option_table
7ed4c4c5 25456{
e0471c16 25457 const char *name;
f3bad469 25458 size_t name_len;
e74cfd16 25459 const arm_feature_set value;
996b5569 25460 const arm_feature_set ext;
c19d1205
ZW
25461 /* For some CPUs we assume an FPU unless the user explicitly sets
25462 -mfpu=... */
e74cfd16 25463 const arm_feature_set default_fpu;
ee065d83
PB
25464 /* The canonical name of the CPU, or NULL to use NAME converted to upper
25465 case. */
25466 const char *canonical_name;
c19d1205 25467};
7ed4c4c5 25468
c19d1205
ZW
25469/* This list should, at a minimum, contain all the cpu names
25470 recognized by GCC. */
996b5569 25471#define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
e74cfd16 25472static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 25473{
996b5569
TP
25474 ARM_CPU_OPT ("all", NULL, ARM_ANY,
25475 ARM_ARCH_NONE,
25476 FPU_ARCH_FPA),
25477 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
25478 ARM_ARCH_NONE,
25479 FPU_ARCH_FPA),
25480 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
25481 ARM_ARCH_NONE,
25482 FPU_ARCH_FPA),
25483 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
25484 ARM_ARCH_NONE,
25485 FPU_ARCH_FPA),
25486 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
25487 ARM_ARCH_NONE,
25488 FPU_ARCH_FPA),
25489 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
25490 ARM_ARCH_NONE,
25491 FPU_ARCH_FPA),
25492 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
25493 ARM_ARCH_NONE,
25494 FPU_ARCH_FPA),
25495 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
25496 ARM_ARCH_NONE,
25497 FPU_ARCH_FPA),
25498 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
25499 ARM_ARCH_NONE,
25500 FPU_ARCH_FPA),
25501 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
25502 ARM_ARCH_NONE,
25503 FPU_ARCH_FPA),
25504 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
25505 ARM_ARCH_NONE,
25506 FPU_ARCH_FPA),
25507 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
25508 ARM_ARCH_NONE,
25509 FPU_ARCH_FPA),
25510 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
25511 ARM_ARCH_NONE,
25512 FPU_ARCH_FPA),
25513 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
25514 ARM_ARCH_NONE,
25515 FPU_ARCH_FPA),
25516 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
25517 ARM_ARCH_NONE,
25518 FPU_ARCH_FPA),
25519 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
25520 ARM_ARCH_NONE,
25521 FPU_ARCH_FPA),
25522 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
25523 ARM_ARCH_NONE,
25524 FPU_ARCH_FPA),
25525 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
25526 ARM_ARCH_NONE,
25527 FPU_ARCH_FPA),
25528 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
25529 ARM_ARCH_NONE,
25530 FPU_ARCH_FPA),
25531 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
25532 ARM_ARCH_NONE,
25533 FPU_ARCH_FPA),
25534 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
25535 ARM_ARCH_NONE,
25536 FPU_ARCH_FPA),
25537 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
25538 ARM_ARCH_NONE,
25539 FPU_ARCH_FPA),
25540 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
25541 ARM_ARCH_NONE,
25542 FPU_ARCH_FPA),
25543 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
25544 ARM_ARCH_NONE,
25545 FPU_ARCH_FPA),
25546 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
25547 ARM_ARCH_NONE,
25548 FPU_ARCH_FPA),
25549 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
25550 ARM_ARCH_NONE,
25551 FPU_ARCH_FPA),
25552 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
25553 ARM_ARCH_NONE,
25554 FPU_ARCH_FPA),
25555 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
25556 ARM_ARCH_NONE,
25557 FPU_ARCH_FPA),
25558 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
25559 ARM_ARCH_NONE,
25560 FPU_ARCH_FPA),
25561 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
25562 ARM_ARCH_NONE,
25563 FPU_ARCH_FPA),
25564 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
25565 ARM_ARCH_NONE,
25566 FPU_ARCH_FPA),
25567 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
25568 ARM_ARCH_NONE,
25569 FPU_ARCH_FPA),
25570 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
25571 ARM_ARCH_NONE,
25572 FPU_ARCH_FPA),
25573 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
25574 ARM_ARCH_NONE,
25575 FPU_ARCH_FPA),
25576 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
25577 ARM_ARCH_NONE,
25578 FPU_ARCH_FPA),
25579 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
25580 ARM_ARCH_NONE,
25581 FPU_ARCH_FPA),
25582 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
25583 ARM_ARCH_NONE,
25584 FPU_ARCH_FPA),
25585 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
25586 ARM_ARCH_NONE,
25587 FPU_ARCH_FPA),
25588 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
25589 ARM_ARCH_NONE,
25590 FPU_ARCH_FPA),
25591 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
25592 ARM_ARCH_NONE,
25593 FPU_ARCH_FPA),
25594 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
25595 ARM_ARCH_NONE,
25596 FPU_ARCH_FPA),
25597 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
25598 ARM_ARCH_NONE,
25599 FPU_ARCH_FPA),
25600 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
25601 ARM_ARCH_NONE,
25602 FPU_ARCH_FPA),
25603 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
25604 ARM_ARCH_NONE,
25605 FPU_ARCH_FPA),
25606 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
25607 ARM_ARCH_NONE,
25608 FPU_ARCH_FPA),
25609 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
25610 ARM_ARCH_NONE,
25611 FPU_ARCH_FPA),
25612
c19d1205
ZW
25613 /* For V5 or later processors we default to using VFP; but the user
25614 should really set the FPU type explicitly. */
996b5569
TP
25615 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
25616 ARM_ARCH_NONE,
25617 FPU_ARCH_VFP_V2),
25618 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
25619 ARM_ARCH_NONE,
25620 FPU_ARCH_VFP_V2),
25621 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
25622 ARM_ARCH_NONE,
25623 FPU_ARCH_VFP_V2),
25624 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
25625 ARM_ARCH_NONE,
25626 FPU_ARCH_VFP_V2),
25627 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
25628 ARM_ARCH_NONE,
25629 FPU_ARCH_VFP_V2),
25630 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
25631 ARM_ARCH_NONE,
25632 FPU_ARCH_VFP_V2),
25633 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
25634 ARM_ARCH_NONE,
25635 FPU_ARCH_VFP_V2),
25636 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
25637 ARM_ARCH_NONE,
25638 FPU_ARCH_VFP_V2),
25639 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
25640 ARM_ARCH_NONE,
25641 FPU_ARCH_VFP_V2),
25642 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
25643 ARM_ARCH_NONE,
25644 FPU_ARCH_VFP_V2),
25645 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
25646 ARM_ARCH_NONE,
25647 FPU_ARCH_VFP_V2),
25648 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
25649 ARM_ARCH_NONE,
25650 FPU_ARCH_VFP_V2),
25651 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
25652 ARM_ARCH_NONE,
25653 FPU_ARCH_VFP_V1),
25654 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
25655 ARM_ARCH_NONE,
25656 FPU_ARCH_VFP_V1),
25657 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
25658 ARM_ARCH_NONE,
25659 FPU_ARCH_VFP_V2),
25660 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
25661 ARM_ARCH_NONE,
25662 FPU_ARCH_VFP_V2),
25663 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
25664 ARM_ARCH_NONE,
25665 FPU_ARCH_VFP_V1),
25666 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
25667 ARM_ARCH_NONE,
25668 FPU_ARCH_VFP_V2),
25669 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
25670 ARM_ARCH_NONE,
25671 FPU_ARCH_VFP_V2),
25672 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
25673 ARM_ARCH_NONE,
25674 FPU_ARCH_VFP_V2),
25675 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
25676 ARM_ARCH_NONE,
25677 FPU_ARCH_VFP_V2),
25678 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
25679 ARM_ARCH_NONE,
25680 FPU_ARCH_VFP_V2),
25681 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
25682 ARM_ARCH_NONE,
25683 FPU_ARCH_VFP_V2),
25684 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
25685 ARM_ARCH_NONE,
25686 FPU_ARCH_VFP_V2),
25687 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
25688 ARM_ARCH_NONE,
25689 FPU_ARCH_VFP_V2),
25690 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
25691 ARM_ARCH_NONE,
25692 FPU_ARCH_VFP_V2),
25693 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
25694 ARM_ARCH_NONE,
25695 FPU_NONE),
25696 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
25697 ARM_ARCH_NONE,
25698 FPU_NONE),
25699 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
25700 ARM_ARCH_NONE,
25701 FPU_ARCH_VFP_V2),
25702 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
25703 ARM_ARCH_NONE,
25704 FPU_ARCH_VFP_V2),
25705 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
25706 ARM_ARCH_NONE,
25707 FPU_ARCH_VFP_V2),
25708 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
25709 ARM_ARCH_NONE,
25710 FPU_NONE),
25711 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
25712 ARM_ARCH_NONE,
25713 FPU_NONE),
25714 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
25715 ARM_ARCH_NONE,
25716 FPU_ARCH_VFP_V2),
25717 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
25718 ARM_ARCH_NONE,
25719 FPU_NONE),
25720 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
25721 ARM_ARCH_NONE,
25722 FPU_ARCH_VFP_V2),
25723 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
25724 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
25725 FPU_NONE),
25726 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
25727 ARM_ARCH_NONE,
25728 FPU_ARCH_NEON_VFP_V4),
25729 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
25730 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
25731 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
25732 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
25733 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
25734 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
25735 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
25736 ARM_ARCH_NONE,
25737 FPU_ARCH_NEON_VFP_V4),
25738 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
25739 ARM_ARCH_NONE,
25740 FPU_ARCH_NEON_VFP_V4),
25741 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
25742 ARM_ARCH_NONE,
25743 FPU_ARCH_NEON_VFP_V4),
25744 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
25745 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25746 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25747 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
25748 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25749 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25750 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
25751 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25752 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25753 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
25754 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25755 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25756 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
25757 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25758 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25759 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
25760 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25761 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25762 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
25763 ARM_ARCH_NONE,
25764 FPU_NONE),
25765 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
25766 ARM_ARCH_NONE,
25767 FPU_ARCH_VFP_V3D16),
25768 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
25769 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
25770 FPU_NONE),
25771 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
25772 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
25773 FPU_ARCH_VFP_V3D16),
25774 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
25775 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
25776 FPU_ARCH_VFP_V3D16),
25777 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
25778 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
25779 FPU_NONE),
25780 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
25781 ARM_ARCH_NONE,
25782 FPU_NONE),
25783 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
25784 ARM_ARCH_NONE,
25785 FPU_NONE),
25786 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
25787 ARM_ARCH_NONE,
25788 FPU_NONE),
25789 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
25790 ARM_ARCH_NONE,
25791 FPU_NONE),
25792 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
25793 ARM_ARCH_NONE,
25794 FPU_NONE),
25795 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
25796 ARM_ARCH_NONE,
25797 FPU_NONE),
25798 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
25799 ARM_ARCH_NONE,
25800 FPU_NONE),
25801 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
25802 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25803 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
6b21c2bf 25804
c19d1205 25805 /* ??? XSCALE is really an architecture. */
996b5569
TP
25806 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
25807 ARM_ARCH_NONE,
25808 FPU_ARCH_VFP_V2),
25809
c19d1205 25810 /* ??? iwmmxt is not a processor. */
996b5569
TP
25811 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
25812 ARM_ARCH_NONE,
25813 FPU_ARCH_VFP_V2),
25814 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
25815 ARM_ARCH_NONE,
25816 FPU_ARCH_VFP_V2),
25817 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
25818 ARM_ARCH_NONE,
25819 FPU_ARCH_VFP_V2),
25820
c19d1205 25821 /* Maverick */
996b5569
TP
25822 ARM_CPU_OPT ("ep9312", "ARM920T",
25823 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
25824 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
25825
da4339ed 25826 /* Marvell processors. */
996b5569
TP
25827 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
25828 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
25829 FPU_ARCH_VFP_V3D16),
25830 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
25831 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
25832 FPU_ARCH_NEON_VFP_V4),
da4339ed 25833
996b5569
TP
25834 /* APM X-Gene family. */
25835 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
25836 ARM_ARCH_NONE,
25837 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25838 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
25839 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25840 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
25841
25842 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 25843};
f3bad469 25844#undef ARM_CPU_OPT
7ed4c4c5 25845
c19d1205 25846struct arm_arch_option_table
7ed4c4c5 25847{
e0471c16 25848 const char *name;
f3bad469 25849 size_t name_len;
e74cfd16
PB
25850 const arm_feature_set value;
25851 const arm_feature_set default_fpu;
c19d1205 25852};
7ed4c4c5 25853
c19d1205
ZW
25854/* This list should, at a minimum, contain all the architecture names
25855 recognized by GCC. */
f3bad469 25856#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
e74cfd16 25857static const struct arm_arch_option_table arm_archs[] =
c19d1205 25858{
f3bad469
MGD
25859 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
25860 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
25861 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
25862 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
25863 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
25864 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
25865 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
25866 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
25867 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
25868 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
25869 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
25870 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
25871 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
25872 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
25873 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
25874 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
25875 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
25876 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
25877 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
25878 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
25879 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
f33026a9
MW
25880 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
25881 kept to preserve existing behaviour. */
25882 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
25883 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
f3bad469
MGD
25884 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
25885 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
25886 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
f33026a9
MW
25887 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
25888 kept to preserve existing behaviour. */
25889 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
25890 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
f3bad469
MGD
25891 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
25892 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
25893 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
25894 /* The official spelling of the ARMv7 profile variants is the dashed form.
25895 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 25896 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 25897 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
25898 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
25899 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
25900 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
25901 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
25902 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
25903 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
ff8646ee 25904 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
4ed7ed8d 25905 ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP),
bca38921 25906 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
a5932920 25907 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
56a1b672 25908 ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP),
a12fd8e1 25909 ARM_ARCH_OPT ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP),
f3bad469
MGD
25910 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
25911 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
25912 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
25913 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 25914};
f3bad469 25915#undef ARM_ARCH_OPT
7ed4c4c5 25916
69133863
MGD
25917/* ISA extensions in the co-processor and main instruction set space. */
25918struct arm_option_extension_value_table
c19d1205 25919{
e0471c16 25920 const char *name;
f3bad469 25921 size_t name_len;
5a70a223
JB
25922 const arm_feature_set merge_value;
25923 const arm_feature_set clear_value;
d942732e
TP
25924 /* List of architectures for which an extension is available. ARM_ARCH_NONE
25925 indicates that an extension is available for all architectures while
25926 ARM_ANY marks an empty entry. */
25927 const arm_feature_set allowed_archs[2];
c19d1205 25928};
7ed4c4c5 25929
69133863
MGD
25930/* The following table must be in alphabetical order with a NULL last entry.
25931 */
d942732e
TP
25932#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
25933#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
69133863 25934static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 25935{
823d2571
TG
25936 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25937 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 25938 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
25939 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
25940 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
15afaa63
TP
25941 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
25942 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
25943 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
25944 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
25945 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
25946 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25947 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25948 ARM_ARCH_V8_2A),
d942732e 25949 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 25950 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
25951 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
25952 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571 25953 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 25954 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 25955 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 25956 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 25957 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
25958 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
25959 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 25960 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
25961 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
25962 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
25963 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25964 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25965 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
25966 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
25967 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
25968 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
4d1464f2
MW
25969 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
25970 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
25971 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
643afb90
MW
25972 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
25973 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
25974 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
d942732e 25975 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 25976 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
25977 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
25978 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
25979 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
25980 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
25981 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
25982 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
25983 | ARM_EXT_DIV),
25984 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
25985 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
25986 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
25987 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
25988 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 25989};
f3bad469 25990#undef ARM_EXT_OPT
69133863
MGD
25991
25992/* ISA floating-point and Advanced SIMD extensions. */
25993struct arm_option_fpu_value_table
25994{
e0471c16 25995 const char *name;
69133863 25996 const arm_feature_set value;
c19d1205 25997};
7ed4c4c5 25998
c19d1205
ZW
25999/* This list should, at a minimum, contain all the fpu names
26000 recognized by GCC. */
69133863 26001static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
26002{
26003 {"softfpa", FPU_NONE},
26004 {"fpe", FPU_ARCH_FPE},
26005 {"fpe2", FPU_ARCH_FPE},
26006 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
26007 {"fpa", FPU_ARCH_FPA},
26008 {"fpa10", FPU_ARCH_FPA},
26009 {"fpa11", FPU_ARCH_FPA},
26010 {"arm7500fe", FPU_ARCH_FPA},
26011 {"softvfp", FPU_ARCH_VFP},
26012 {"softvfp+vfp", FPU_ARCH_VFP_V2},
26013 {"vfp", FPU_ARCH_VFP_V2},
26014 {"vfp9", FPU_ARCH_VFP_V2},
d5e0ba9c 26015 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
c19d1205
ZW
26016 {"vfp10", FPU_ARCH_VFP_V2},
26017 {"vfp10-r0", FPU_ARCH_VFP_V1},
26018 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
26019 {"vfpv2", FPU_ARCH_VFP_V2},
26020 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 26021 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 26022 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
26023 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
26024 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
26025 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
26026 {"arm1020t", FPU_ARCH_VFP_V1},
26027 {"arm1020e", FPU_ARCH_VFP_V2},
d5e0ba9c 26028 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
c19d1205
ZW
26029 {"arm1136jf-s", FPU_ARCH_VFP_V2},
26030 {"maverick", FPU_ARCH_MAVERICK},
d5e0ba9c 26031 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
d3375ddd 26032 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 26033 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
26034 {"vfpv4", FPU_ARCH_VFP_V4},
26035 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 26036 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
26037 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
26038 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 26039 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
26040 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
26041 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
26042 {"crypto-neon-fp-armv8",
26043 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 26044 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
26045 {"crypto-neon-fp-armv8.1",
26046 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
26047 {NULL, ARM_ARCH_NONE}
26048};
26049
26050struct arm_option_value_table
26051{
e0471c16 26052 const char *name;
e74cfd16 26053 long value;
c19d1205 26054};
7ed4c4c5 26055
e74cfd16 26056static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
26057{
26058 {"hard", ARM_FLOAT_ABI_HARD},
26059 {"softfp", ARM_FLOAT_ABI_SOFTFP},
26060 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 26061 {NULL, 0}
c19d1205 26062};
7ed4c4c5 26063
c19d1205 26064#ifdef OBJ_ELF
3a4a14e9 26065/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 26066static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
26067{
26068 {"gnu", EF_ARM_EABI_UNKNOWN},
26069 {"4", EF_ARM_EABI_VER4},
3a4a14e9 26070 {"5", EF_ARM_EABI_VER5},
e74cfd16 26071 {NULL, 0}
c19d1205
ZW
26072};
26073#endif
7ed4c4c5 26074
c19d1205
ZW
26075struct arm_long_option_table
26076{
e0471c16
TS
26077 const char * option; /* Substring to match. */
26078 const char * help; /* Help information. */
17b9d67d 26079 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 26080 const char * deprecated; /* If non-null, print this message. */
c19d1205 26081};
7ed4c4c5 26082
c921be7d 26083static bfd_boolean
82b8a785 26084arm_parse_extension (const char *str, const arm_feature_set **opt_p)
7ed4c4c5 26085{
325801bd 26086 arm_feature_set *ext_set = XNEW (arm_feature_set);
e74cfd16 26087
69133863 26088 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
26089 extensions being added before being removed. We achieve this by having
26090 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 26091 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 26092 or removing it (0) and only allowing it to change in the order
69133863
MGD
26093 -1 -> 1 -> 0. */
26094 const struct arm_option_extension_value_table * opt = NULL;
d942732e 26095 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
26096 int adding_value = -1;
26097
e74cfd16
PB
26098 /* Copy the feature set, so that we can modify it. */
26099 *ext_set = **opt_p;
26100 *opt_p = ext_set;
26101
c19d1205 26102 while (str != NULL && *str != 0)
7ed4c4c5 26103 {
82b8a785 26104 const char *ext;
f3bad469 26105 size_t len;
7ed4c4c5 26106
c19d1205
ZW
26107 if (*str != '+')
26108 {
26109 as_bad (_("invalid architectural extension"));
c921be7d 26110 return FALSE;
c19d1205 26111 }
7ed4c4c5 26112
c19d1205
ZW
26113 str++;
26114 ext = strchr (str, '+');
7ed4c4c5 26115
c19d1205 26116 if (ext != NULL)
f3bad469 26117 len = ext - str;
c19d1205 26118 else
f3bad469 26119 len = strlen (str);
7ed4c4c5 26120
f3bad469 26121 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
26122 {
26123 if (adding_value != 0)
26124 {
26125 adding_value = 0;
26126 opt = arm_extensions;
26127 }
26128
f3bad469 26129 len -= 2;
69133863
MGD
26130 str += 2;
26131 }
f3bad469 26132 else if (len > 0)
69133863
MGD
26133 {
26134 if (adding_value == -1)
26135 {
26136 adding_value = 1;
26137 opt = arm_extensions;
26138 }
26139 else if (adding_value != 1)
26140 {
26141 as_bad (_("must specify extensions to add before specifying "
26142 "those to remove"));
26143 return FALSE;
26144 }
26145 }
26146
f3bad469 26147 if (len == 0)
c19d1205
ZW
26148 {
26149 as_bad (_("missing architectural extension"));
c921be7d 26150 return FALSE;
c19d1205 26151 }
7ed4c4c5 26152
69133863
MGD
26153 gas_assert (adding_value != -1);
26154 gas_assert (opt != NULL);
26155
26156 /* Scan over the options table trying to find an exact match. */
26157 for (; opt->name != NULL; opt++)
f3bad469 26158 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26159 {
d942732e
TP
26160 int i, nb_allowed_archs =
26161 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 26162 /* Check we can apply the extension to this architecture. */
d942732e
TP
26163 for (i = 0; i < nb_allowed_archs; i++)
26164 {
26165 /* Empty entry. */
26166 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
26167 continue;
26168 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *ext_set))
26169 break;
26170 }
26171 if (i == nb_allowed_archs)
69133863
MGD
26172 {
26173 as_bad (_("extension does not apply to the base architecture"));
26174 return FALSE;
26175 }
26176
26177 /* Add or remove the extension. */
26178 if (adding_value)
5a70a223 26179 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 26180 else
5a70a223 26181 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 26182
c19d1205
ZW
26183 break;
26184 }
7ed4c4c5 26185
c19d1205
ZW
26186 if (opt->name == NULL)
26187 {
69133863
MGD
26188 /* Did we fail to find an extension because it wasn't specified in
26189 alphabetical order, or because it does not exist? */
26190
26191 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 26192 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
26193 break;
26194
26195 if (opt->name == NULL)
26196 as_bad (_("unknown architectural extension `%s'"), str);
26197 else
26198 as_bad (_("architectural extensions must be specified in "
26199 "alphabetical order"));
26200
c921be7d 26201 return FALSE;
c19d1205 26202 }
69133863
MGD
26203 else
26204 {
26205 /* We should skip the extension we've just matched the next time
26206 round. */
26207 opt++;
26208 }
7ed4c4c5 26209
c19d1205
ZW
26210 str = ext;
26211 };
7ed4c4c5 26212
c921be7d 26213 return TRUE;
c19d1205 26214}
7ed4c4c5 26215
c921be7d 26216static bfd_boolean
17b9d67d 26217arm_parse_cpu (const char *str)
7ed4c4c5 26218{
f3bad469 26219 const struct arm_cpu_option_table *opt;
82b8a785 26220 const char *ext = strchr (str, '+');
f3bad469 26221 size_t len;
7ed4c4c5 26222
c19d1205 26223 if (ext != NULL)
f3bad469 26224 len = ext - str;
7ed4c4c5 26225 else
f3bad469 26226 len = strlen (str);
7ed4c4c5 26227
f3bad469 26228 if (len == 0)
7ed4c4c5 26229 {
c19d1205 26230 as_bad (_("missing cpu name `%s'"), str);
c921be7d 26231 return FALSE;
7ed4c4c5
NC
26232 }
26233
c19d1205 26234 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 26235 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26236 {
996b5569
TP
26237 arm_feature_set *cpu_set = XNEW (arm_feature_set);
26238 ARM_MERGE_FEATURE_SETS (*cpu_set, opt->value, opt->ext);
26239 mcpu_cpu_opt = cpu_set;
e74cfd16 26240 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 26241 if (opt->canonical_name)
ef8e6722
JW
26242 {
26243 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
26244 strcpy (selected_cpu_name, opt->canonical_name);
26245 }
ee065d83
PB
26246 else
26247 {
f3bad469 26248 size_t i;
c921be7d 26249
ef8e6722
JW
26250 if (len >= sizeof selected_cpu_name)
26251 len = (sizeof selected_cpu_name) - 1;
26252
f3bad469 26253 for (i = 0; i < len; i++)
ee065d83
PB
26254 selected_cpu_name[i] = TOUPPER (opt->name[i]);
26255 selected_cpu_name[i] = 0;
26256 }
7ed4c4c5 26257
c19d1205
ZW
26258 if (ext != NULL)
26259 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 26260
c921be7d 26261 return TRUE;
c19d1205 26262 }
7ed4c4c5 26263
c19d1205 26264 as_bad (_("unknown cpu `%s'"), str);
c921be7d 26265 return FALSE;
7ed4c4c5
NC
26266}
26267
c921be7d 26268static bfd_boolean
17b9d67d 26269arm_parse_arch (const char *str)
7ed4c4c5 26270{
e74cfd16 26271 const struct arm_arch_option_table *opt;
82b8a785 26272 const char *ext = strchr (str, '+');
f3bad469 26273 size_t len;
7ed4c4c5 26274
c19d1205 26275 if (ext != NULL)
f3bad469 26276 len = ext - str;
7ed4c4c5 26277 else
f3bad469 26278 len = strlen (str);
7ed4c4c5 26279
f3bad469 26280 if (len == 0)
7ed4c4c5 26281 {
c19d1205 26282 as_bad (_("missing architecture name `%s'"), str);
c921be7d 26283 return FALSE;
7ed4c4c5
NC
26284 }
26285
c19d1205 26286 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 26287 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26288 {
e74cfd16
PB
26289 march_cpu_opt = &opt->value;
26290 march_fpu_opt = &opt->default_fpu;
5f4273c7 26291 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 26292
c19d1205
ZW
26293 if (ext != NULL)
26294 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 26295
c921be7d 26296 return TRUE;
c19d1205
ZW
26297 }
26298
26299 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 26300 return FALSE;
7ed4c4c5 26301}
eb043451 26302
c921be7d 26303static bfd_boolean
17b9d67d 26304arm_parse_fpu (const char * str)
c19d1205 26305{
69133863 26306 const struct arm_option_fpu_value_table * opt;
b99bd4ef 26307
c19d1205
ZW
26308 for (opt = arm_fpus; opt->name != NULL; opt++)
26309 if (streq (opt->name, str))
26310 {
e74cfd16 26311 mfpu_opt = &opt->value;
c921be7d 26312 return TRUE;
c19d1205 26313 }
b99bd4ef 26314
c19d1205 26315 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 26316 return FALSE;
c19d1205
ZW
26317}
26318
c921be7d 26319static bfd_boolean
17b9d67d 26320arm_parse_float_abi (const char * str)
b99bd4ef 26321{
e74cfd16 26322 const struct arm_option_value_table * opt;
b99bd4ef 26323
c19d1205
ZW
26324 for (opt = arm_float_abis; opt->name != NULL; opt++)
26325 if (streq (opt->name, str))
26326 {
26327 mfloat_abi_opt = opt->value;
c921be7d 26328 return TRUE;
c19d1205 26329 }
cc8a6dd0 26330
c19d1205 26331 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 26332 return FALSE;
c19d1205 26333}
b99bd4ef 26334
c19d1205 26335#ifdef OBJ_ELF
c921be7d 26336static bfd_boolean
17b9d67d 26337arm_parse_eabi (const char * str)
c19d1205 26338{
e74cfd16 26339 const struct arm_option_value_table *opt;
cc8a6dd0 26340
c19d1205
ZW
26341 for (opt = arm_eabis; opt->name != NULL; opt++)
26342 if (streq (opt->name, str))
26343 {
26344 meabi_flags = opt->value;
c921be7d 26345 return TRUE;
c19d1205
ZW
26346 }
26347 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 26348 return FALSE;
c19d1205
ZW
26349}
26350#endif
cc8a6dd0 26351
c921be7d 26352static bfd_boolean
17b9d67d 26353arm_parse_it_mode (const char * str)
e07e6e58 26354{
c921be7d 26355 bfd_boolean ret = TRUE;
e07e6e58
NC
26356
26357 if (streq ("arm", str))
26358 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
26359 else if (streq ("thumb", str))
26360 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
26361 else if (streq ("always", str))
26362 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
26363 else if (streq ("never", str))
26364 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
26365 else
26366 {
26367 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 26368 "arm, thumb, always, or never."), str);
c921be7d 26369 ret = FALSE;
e07e6e58
NC
26370 }
26371
26372 return ret;
26373}
26374
2e6976a8 26375static bfd_boolean
17b9d67d 26376arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
26377{
26378 codecomposer_syntax = TRUE;
26379 arm_comment_chars[0] = ';';
26380 arm_line_separator_chars[0] = 0;
26381 return TRUE;
26382}
26383
c19d1205
ZW
26384struct arm_long_option_table arm_long_opts[] =
26385{
26386 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
26387 arm_parse_cpu, NULL},
26388 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
26389 arm_parse_arch, NULL},
26390 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
26391 arm_parse_fpu, NULL},
26392 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
26393 arm_parse_float_abi, NULL},
26394#ifdef OBJ_ELF
7fac0536 26395 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
26396 arm_parse_eabi, NULL},
26397#endif
e07e6e58
NC
26398 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
26399 arm_parse_it_mode, NULL},
2e6976a8
DG
26400 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
26401 arm_ccs_mode, NULL},
c19d1205
ZW
26402 {NULL, NULL, 0, NULL}
26403};
cc8a6dd0 26404
c19d1205 26405int
17b9d67d 26406md_parse_option (int c, const char * arg)
c19d1205
ZW
26407{
26408 struct arm_option_table *opt;
e74cfd16 26409 const struct arm_legacy_option_table *fopt;
c19d1205 26410 struct arm_long_option_table *lopt;
b99bd4ef 26411
c19d1205 26412 switch (c)
b99bd4ef 26413 {
c19d1205
ZW
26414#ifdef OPTION_EB
26415 case OPTION_EB:
26416 target_big_endian = 1;
26417 break;
26418#endif
cc8a6dd0 26419
c19d1205
ZW
26420#ifdef OPTION_EL
26421 case OPTION_EL:
26422 target_big_endian = 0;
26423 break;
26424#endif
b99bd4ef 26425
845b51d6
PB
26426 case OPTION_FIX_V4BX:
26427 fix_v4bx = TRUE;
26428 break;
26429
c19d1205
ZW
26430 case 'a':
26431 /* Listing option. Just ignore these, we don't support additional
26432 ones. */
26433 return 0;
b99bd4ef 26434
c19d1205
ZW
26435 default:
26436 for (opt = arm_opts; opt->option != NULL; opt++)
26437 {
26438 if (c == opt->option[0]
26439 && ((arg == NULL && opt->option[1] == 0)
26440 || streq (arg, opt->option + 1)))
26441 {
c19d1205 26442 /* If the option is deprecated, tell the user. */
278df34e 26443 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
26444 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26445 arg ? arg : "", _(opt->deprecated));
b99bd4ef 26446
c19d1205
ZW
26447 if (opt->var != NULL)
26448 *opt->var = opt->value;
cc8a6dd0 26449
c19d1205
ZW
26450 return 1;
26451 }
26452 }
b99bd4ef 26453
e74cfd16
PB
26454 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
26455 {
26456 if (c == fopt->option[0]
26457 && ((arg == NULL && fopt->option[1] == 0)
26458 || streq (arg, fopt->option + 1)))
26459 {
e74cfd16 26460 /* If the option is deprecated, tell the user. */
278df34e 26461 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
26462 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26463 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
26464
26465 if (fopt->var != NULL)
26466 *fopt->var = &fopt->value;
26467
26468 return 1;
26469 }
26470 }
26471
c19d1205
ZW
26472 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26473 {
26474 /* These options are expected to have an argument. */
26475 if (c == lopt->option[0]
26476 && arg != NULL
26477 && strncmp (arg, lopt->option + 1,
26478 strlen (lopt->option + 1)) == 0)
26479 {
c19d1205 26480 /* If the option is deprecated, tell the user. */
278df34e 26481 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
26482 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
26483 _(lopt->deprecated));
b99bd4ef 26484
c19d1205
ZW
26485 /* Call the sup-option parser. */
26486 return lopt->func (arg + strlen (lopt->option) - 1);
26487 }
26488 }
a737bd4d 26489
c19d1205
ZW
26490 return 0;
26491 }
a394c00f 26492
c19d1205
ZW
26493 return 1;
26494}
a394c00f 26495
c19d1205
ZW
26496void
26497md_show_usage (FILE * fp)
a394c00f 26498{
c19d1205
ZW
26499 struct arm_option_table *opt;
26500 struct arm_long_option_table *lopt;
a394c00f 26501
c19d1205 26502 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 26503
c19d1205
ZW
26504 for (opt = arm_opts; opt->option != NULL; opt++)
26505 if (opt->help != NULL)
26506 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 26507
c19d1205
ZW
26508 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26509 if (lopt->help != NULL)
26510 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 26511
c19d1205
ZW
26512#ifdef OPTION_EB
26513 fprintf (fp, _("\
26514 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
26515#endif
26516
c19d1205
ZW
26517#ifdef OPTION_EL
26518 fprintf (fp, _("\
26519 -EL assemble code for a little-endian cpu\n"));
a737bd4d 26520#endif
845b51d6
PB
26521
26522 fprintf (fp, _("\
26523 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 26524}
ee065d83
PB
26525
26526
26527#ifdef OBJ_ELF
62b3e311
PB
26528typedef struct
26529{
26530 int val;
26531 arm_feature_set flags;
26532} cpu_arch_ver_table;
26533
4ed7ed8d
TP
26534/* Mapping from CPU features to EABI CPU arch values. As a general rule, table
26535 must be sorted least features first but some reordering is needed, eg. for
26536 Thumb-2 instructions to be detected as coming from ARMv6T2. */
62b3e311
PB
26537static const cpu_arch_ver_table cpu_arch_ver[] =
26538{
26539 {1, ARM_ARCH_V4},
26540 {2, ARM_ARCH_V4T},
26541 {3, ARM_ARCH_V5},
ee3c0378 26542 {3, ARM_ARCH_V5T},
62b3e311
PB
26543 {4, ARM_ARCH_V5TE},
26544 {5, ARM_ARCH_V5TEJ},
26545 {6, ARM_ARCH_V6},
7e806470 26546 {9, ARM_ARCH_V6K},
f4c65163 26547 {7, ARM_ARCH_V6Z},
91e22acd 26548 {11, ARM_ARCH_V6M},
b2a5fbdc 26549 {12, ARM_ARCH_V6SM},
7e806470 26550 {8, ARM_ARCH_V6T2},
c9fb6e58 26551 {10, ARM_ARCH_V7VE},
62b3e311
PB
26552 {10, ARM_ARCH_V7R},
26553 {10, ARM_ARCH_V7M},
bca38921 26554 {14, ARM_ARCH_V8A},
ff8646ee 26555 {16, ARM_ARCH_V8M_BASE},
4ed7ed8d 26556 {17, ARM_ARCH_V8M_MAIN},
62b3e311
PB
26557 {0, ARM_ARCH_NONE}
26558};
26559
ee3c0378
AS
26560/* Set an attribute if it has not already been set by the user. */
26561static void
26562aeabi_set_attribute_int (int tag, int value)
26563{
26564 if (tag < 1
26565 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26566 || !attributes_set_explicitly[tag])
26567 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
26568}
26569
26570static void
26571aeabi_set_attribute_string (int tag, const char *value)
26572{
26573 if (tag < 1
26574 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26575 || !attributes_set_explicitly[tag])
26576 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
26577}
26578
ee065d83 26579/* Set the public EABI object attributes. */
3cfdb781 26580void
ee065d83
PB
26581aeabi_set_public_attributes (void)
26582{
26583 int arch;
69239280 26584 char profile;
90ec0d68 26585 int virt_sec = 0;
bca38921 26586 int fp16_optional = 0;
15afaa63 26587 arm_feature_set arm_arch = ARM_ARCH_NONE;
e74cfd16 26588 arm_feature_set flags;
62b3e311 26589 arm_feature_set tmp;
ff8646ee 26590 arm_feature_set arm_arch_v8m_base = ARM_ARCH_V8M_BASE;
62b3e311 26591 const cpu_arch_ver_table *p;
ee065d83
PB
26592
26593 /* Choose the architecture based on the capabilities of the requested cpu
26594 (if any) and/or the instructions actually used. */
e74cfd16
PB
26595 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
26596 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
26597 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
ddd7f988
RE
26598
26599 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
26600 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
26601
26602 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
26603 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
26604
7f78eb34
JW
26605 selected_cpu = flags;
26606
ddd7f988 26607 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
26608 if (object_arch)
26609 {
26610 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
26611 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
26612 }
26613
251665fc
MGD
26614 /* We need to make sure that the attributes do not identify us as v6S-M
26615 when the only v6S-M feature in use is the Operating System Extensions. */
26616 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
26617 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
477330fc 26618 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
251665fc 26619
62b3e311
PB
26620 tmp = flags;
26621 arch = 0;
26622 for (p = cpu_arch_ver; p->val; p++)
26623 {
26624 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
26625 {
26626 arch = p->val;
15afaa63 26627 arm_arch = p->flags;
62b3e311
PB
26628 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
26629 }
26630 }
ee065d83 26631
9e3c6df6
PB
26632 /* The table lookup above finds the last architecture to contribute
26633 a new feature. Unfortunately, Tag13 is a subset of the union of
26634 v6T2 and v7-M, so it is never seen as contributing a new feature.
26635 We can not search for the last entry which is entirely used,
26636 because if no CPU is specified we build up only those flags
26637 actually used. Perhaps we should separate out the specified
26638 and implicit cases. Avoid taking this path for -march=all by
26639 checking for contradictory v7-A / v7-M features. */
4ed7ed8d 26640 if (arch == TAG_CPU_ARCH_V7
9e3c6df6
PB
26641 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
26642 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
26643 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
15afaa63
TP
26644 {
26645 arch = TAG_CPU_ARCH_V7E_M;
26646 arm_arch = (arm_feature_set) ARM_ARCH_V7EM;
26647 }
4ed7ed8d 26648
ff8646ee
TP
26649 ARM_CLEAR_FEATURE (tmp, flags, arm_arch_v8m_base);
26650 if (arch == TAG_CPU_ARCH_V8M_BASE && ARM_CPU_HAS_FEATURE (tmp, arm_arch_any))
15afaa63
TP
26651 {
26652 arch = TAG_CPU_ARCH_V8M_MAIN;
26653 arm_arch = (arm_feature_set) ARM_ARCH_V8M_MAIN;
26654 }
ff8646ee 26655
4ed7ed8d
TP
26656 /* In cpu_arch_ver ARMv8-A is before ARMv8-M for atomics to be detected as
26657 coming from ARMv8-A. However, since ARMv8-A has more instructions than
26658 ARMv8-M, -march=all must be detected as ARMv8-A. */
26659 if (arch == TAG_CPU_ARCH_V8M_MAIN
26660 && ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
15afaa63
TP
26661 {
26662 arch = TAG_CPU_ARCH_V8;
26663 arm_arch = (arm_feature_set) ARM_ARCH_V8A;
26664 }
9e3c6df6 26665
ee065d83
PB
26666 /* Tag_CPU_name. */
26667 if (selected_cpu_name[0])
26668 {
91d6fa6a 26669 char *q;
ee065d83 26670
91d6fa6a
NC
26671 q = selected_cpu_name;
26672 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
26673 {
26674 int i;
5f4273c7 26675
91d6fa6a
NC
26676 q += 4;
26677 for (i = 0; q[i]; i++)
26678 q[i] = TOUPPER (q[i]);
ee065d83 26679 }
91d6fa6a 26680 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 26681 }
62f3b8c8 26682
ee065d83 26683 /* Tag_CPU_arch. */
ee3c0378 26684 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 26685
62b3e311 26686 /* Tag_CPU_arch_profile. */
10c9892b 26687 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
4ed7ed8d
TP
26688 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26689 || (ARM_CPU_HAS_FEATURE (flags, arm_ext_atomics)
16a1fa25 26690 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only)))
69239280 26691 profile = 'A';
62b3e311 26692 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
69239280 26693 profile = 'R';
7e806470 26694 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
69239280
MGD
26695 profile = 'M';
26696 else
26697 profile = '\0';
26698
26699 if (profile != '\0')
26700 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 26701
15afaa63
TP
26702 /* Tag_DSP_extension. */
26703 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_dsp))
26704 {
26705 arm_feature_set ext;
26706
26707 /* DSP instructions not in architecture. */
26708 ARM_CLEAR_FEATURE (ext, flags, arm_arch);
26709 if (ARM_CPU_HAS_FEATURE (ext, arm_ext_dsp))
26710 aeabi_set_attribute_int (Tag_DSP_extension, 1);
26711 }
26712
ee065d83 26713 /* Tag_ARM_ISA_use. */
ee3c0378
AS
26714 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
26715 || arch == 0)
26716 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 26717
ee065d83 26718 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
26719 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
26720 || arch == 0)
4ed7ed8d
TP
26721 {
26722 int thumb_isa_use;
26723
26724 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 26725 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
26726 thumb_isa_use = 3;
26727 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
26728 thumb_isa_use = 2;
26729 else
26730 thumb_isa_use = 1;
26731 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
26732 }
62f3b8c8 26733
ee065d83 26734 /* Tag_VFP_arch. */
a715796b
TG
26735 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
26736 aeabi_set_attribute_int (Tag_VFP_arch,
26737 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
26738 ? 7 : 8);
bca38921 26739 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
26740 aeabi_set_attribute_int (Tag_VFP_arch,
26741 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
26742 ? 5 : 6);
26743 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
26744 {
26745 fp16_optional = 1;
26746 aeabi_set_attribute_int (Tag_VFP_arch, 3);
26747 }
ada65aa3 26748 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
26749 {
26750 aeabi_set_attribute_int (Tag_VFP_arch, 4);
26751 fp16_optional = 1;
26752 }
ee3c0378
AS
26753 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
26754 aeabi_set_attribute_int (Tag_VFP_arch, 2);
26755 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 26756 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 26757 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 26758
4547cb56
NC
26759 /* Tag_ABI_HardFP_use. */
26760 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
26761 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
26762 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
26763
ee065d83 26764 /* Tag_WMMX_arch. */
ee3c0378
AS
26765 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
26766 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
26767 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
26768 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 26769
ee3c0378 26770 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
26771 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
26772 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
26773 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
26774 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
26775 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
26776 {
26777 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
26778 {
26779 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
26780 }
26781 else
26782 {
26783 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
26784 fp16_optional = 1;
26785 }
26786 }
fa94de6b 26787
ee3c0378 26788 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 26789 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 26790 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 26791
69239280
MGD
26792 /* Tag_DIV_use.
26793
26794 We set Tag_DIV_use to two when integer divide instructions have been used
26795 in ARM state, or when Thumb integer divide instructions have been used,
26796 but we have no architecture profile set, nor have we any ARM instructions.
26797
4ed7ed8d
TP
26798 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
26799 by the base architecture.
bca38921 26800
69239280 26801 For new architectures we will have to check these tests. */
ff8646ee
TP
26802 gas_assert (arch <= TAG_CPU_ARCH_V8
26803 || (arch >= TAG_CPU_ARCH_V8M_BASE
26804 && arch <= TAG_CPU_ARCH_V8M_MAIN));
4ed7ed8d
TP
26805 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26806 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
26807 aeabi_set_attribute_int (Tag_DIV_use, 0);
26808 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
26809 || (profile == '\0'
26810 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
26811 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 26812 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
26813
26814 /* Tag_MP_extension_use. */
26815 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
26816 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
26817
26818 /* Tag Virtualization_use. */
26819 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
26820 virt_sec |= 1;
26821 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
26822 virt_sec |= 2;
26823 if (virt_sec != 0)
26824 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
26825}
26826
104d59d1 26827/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
26828void
26829arm_md_end (void)
26830{
ee065d83
PB
26831 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
26832 return;
26833
26834 aeabi_set_public_attributes ();
ee065d83 26835}
8463be01 26836#endif /* OBJ_ELF */
ee065d83
PB
26837
26838
26839/* Parse a .cpu directive. */
26840
26841static void
26842s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
26843{
e74cfd16 26844 const struct arm_cpu_option_table *opt;
ee065d83
PB
26845 char *name;
26846 char saved_char;
26847
26848 name = input_line_pointer;
5f4273c7 26849 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26850 input_line_pointer++;
26851 saved_char = *input_line_pointer;
26852 *input_line_pointer = 0;
26853
26854 /* Skip the first "all" entry. */
26855 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
26856 if (streq (opt->name, name))
26857 {
996b5569
TP
26858 arm_feature_set *cpu_set = XNEW (arm_feature_set);
26859 ARM_MERGE_FEATURE_SETS (*cpu_set, opt->value, opt->ext);
26860 mcpu_cpu_opt = cpu_set;
26861 selected_cpu = *mcpu_cpu_opt;
ee065d83 26862 if (opt->canonical_name)
5f4273c7 26863 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
26864 else
26865 {
26866 int i;
26867 for (i = 0; opt->name[i]; i++)
26868 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 26869
ee065d83
PB
26870 selected_cpu_name[i] = 0;
26871 }
e74cfd16 26872 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26873 *input_line_pointer = saved_char;
26874 demand_empty_rest_of_line ();
26875 return;
26876 }
26877 as_bad (_("unknown cpu `%s'"), name);
26878 *input_line_pointer = saved_char;
26879 ignore_rest_of_line ();
26880}
26881
26882
26883/* Parse a .arch directive. */
26884
26885static void
26886s_arm_arch (int ignored ATTRIBUTE_UNUSED)
26887{
e74cfd16 26888 const struct arm_arch_option_table *opt;
ee065d83
PB
26889 char saved_char;
26890 char *name;
26891
26892 name = input_line_pointer;
5f4273c7 26893 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26894 input_line_pointer++;
26895 saved_char = *input_line_pointer;
26896 *input_line_pointer = 0;
26897
26898 /* Skip the first "all" entry. */
26899 for (opt = arm_archs + 1; opt->name != NULL; opt++)
26900 if (streq (opt->name, name))
26901 {
e74cfd16
PB
26902 mcpu_cpu_opt = &opt->value;
26903 selected_cpu = opt->value;
5f4273c7 26904 strcpy (selected_cpu_name, opt->name);
e74cfd16 26905 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26906 *input_line_pointer = saved_char;
26907 demand_empty_rest_of_line ();
26908 return;
26909 }
26910
26911 as_bad (_("unknown architecture `%s'\n"), name);
26912 *input_line_pointer = saved_char;
26913 ignore_rest_of_line ();
26914}
26915
26916
7a1d4c38
PB
26917/* Parse a .object_arch directive. */
26918
26919static void
26920s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
26921{
26922 const struct arm_arch_option_table *opt;
26923 char saved_char;
26924 char *name;
26925
26926 name = input_line_pointer;
5f4273c7 26927 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
26928 input_line_pointer++;
26929 saved_char = *input_line_pointer;
26930 *input_line_pointer = 0;
26931
26932 /* Skip the first "all" entry. */
26933 for (opt = arm_archs + 1; opt->name != NULL; opt++)
26934 if (streq (opt->name, name))
26935 {
26936 object_arch = &opt->value;
26937 *input_line_pointer = saved_char;
26938 demand_empty_rest_of_line ();
26939 return;
26940 }
26941
26942 as_bad (_("unknown architecture `%s'\n"), name);
26943 *input_line_pointer = saved_char;
26944 ignore_rest_of_line ();
26945}
26946
69133863
MGD
26947/* Parse a .arch_extension directive. */
26948
26949static void
26950s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
26951{
26952 const struct arm_option_extension_value_table *opt;
d942732e 26953 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
26954 char saved_char;
26955 char *name;
26956 int adding_value = 1;
26957
26958 name = input_line_pointer;
26959 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
26960 input_line_pointer++;
26961 saved_char = *input_line_pointer;
26962 *input_line_pointer = 0;
26963
26964 if (strlen (name) >= 2
26965 && strncmp (name, "no", 2) == 0)
26966 {
26967 adding_value = 0;
26968 name += 2;
26969 }
26970
26971 for (opt = arm_extensions; opt->name != NULL; opt++)
26972 if (streq (opt->name, name))
26973 {
d942732e
TP
26974 int i, nb_allowed_archs =
26975 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
26976 for (i = 0; i < nb_allowed_archs; i++)
26977 {
26978 /* Empty entry. */
26979 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
26980 continue;
26981 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *mcpu_cpu_opt))
26982 break;
26983 }
26984
26985 if (i == nb_allowed_archs)
69133863
MGD
26986 {
26987 as_bad (_("architectural extension `%s' is not allowed for the "
26988 "current base architecture"), name);
26989 break;
26990 }
26991
26992 if (adding_value)
5a70a223
JB
26993 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu,
26994 opt->merge_value);
69133863 26995 else
5a70a223 26996 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->clear_value);
69133863
MGD
26997
26998 mcpu_cpu_opt = &selected_cpu;
26999 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
27000 *input_line_pointer = saved_char;
27001 demand_empty_rest_of_line ();
27002 return;
27003 }
27004
27005 if (opt->name == NULL)
e673710a 27006 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
27007
27008 *input_line_pointer = saved_char;
27009 ignore_rest_of_line ();
27010}
27011
ee065d83
PB
27012/* Parse a .fpu directive. */
27013
27014static void
27015s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
27016{
69133863 27017 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
27018 char saved_char;
27019 char *name;
27020
27021 name = input_line_pointer;
5f4273c7 27022 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
27023 input_line_pointer++;
27024 saved_char = *input_line_pointer;
27025 *input_line_pointer = 0;
5f4273c7 27026
ee065d83
PB
27027 for (opt = arm_fpus; opt->name != NULL; opt++)
27028 if (streq (opt->name, name))
27029 {
e74cfd16
PB
27030 mfpu_opt = &opt->value;
27031 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
27032 *input_line_pointer = saved_char;
27033 demand_empty_rest_of_line ();
27034 return;
27035 }
27036
27037 as_bad (_("unknown floating point format `%s'\n"), name);
27038 *input_line_pointer = saved_char;
27039 ignore_rest_of_line ();
27040}
ee065d83 27041
794ba86a 27042/* Copy symbol information. */
f31fef98 27043
794ba86a
DJ
27044void
27045arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
27046{
27047 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
27048}
e04befd0 27049
f31fef98 27050#ifdef OBJ_ELF
e04befd0
AS
27051/* Given a symbolic attribute NAME, return the proper integer value.
27052 Returns -1 if the attribute is not known. */
f31fef98 27053
e04befd0
AS
27054int
27055arm_convert_symbolic_attribute (const char *name)
27056{
f31fef98
NC
27057 static const struct
27058 {
27059 const char * name;
27060 const int tag;
27061 }
27062 attribute_table[] =
27063 {
27064 /* When you modify this table you should
27065 also modify the list in doc/c-arm.texi. */
e04befd0 27066#define T(tag) {#tag, tag}
f31fef98
NC
27067 T (Tag_CPU_raw_name),
27068 T (Tag_CPU_name),
27069 T (Tag_CPU_arch),
27070 T (Tag_CPU_arch_profile),
27071 T (Tag_ARM_ISA_use),
27072 T (Tag_THUMB_ISA_use),
75375b3e 27073 T (Tag_FP_arch),
f31fef98
NC
27074 T (Tag_VFP_arch),
27075 T (Tag_WMMX_arch),
27076 T (Tag_Advanced_SIMD_arch),
27077 T (Tag_PCS_config),
27078 T (Tag_ABI_PCS_R9_use),
27079 T (Tag_ABI_PCS_RW_data),
27080 T (Tag_ABI_PCS_RO_data),
27081 T (Tag_ABI_PCS_GOT_use),
27082 T (Tag_ABI_PCS_wchar_t),
27083 T (Tag_ABI_FP_rounding),
27084 T (Tag_ABI_FP_denormal),
27085 T (Tag_ABI_FP_exceptions),
27086 T (Tag_ABI_FP_user_exceptions),
27087 T (Tag_ABI_FP_number_model),
75375b3e 27088 T (Tag_ABI_align_needed),
f31fef98 27089 T (Tag_ABI_align8_needed),
75375b3e 27090 T (Tag_ABI_align_preserved),
f31fef98
NC
27091 T (Tag_ABI_align8_preserved),
27092 T (Tag_ABI_enum_size),
27093 T (Tag_ABI_HardFP_use),
27094 T (Tag_ABI_VFP_args),
27095 T (Tag_ABI_WMMX_args),
27096 T (Tag_ABI_optimization_goals),
27097 T (Tag_ABI_FP_optimization_goals),
27098 T (Tag_compatibility),
27099 T (Tag_CPU_unaligned_access),
75375b3e 27100 T (Tag_FP_HP_extension),
f31fef98
NC
27101 T (Tag_VFP_HP_extension),
27102 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
27103 T (Tag_MPextension_use),
27104 T (Tag_DIV_use),
f31fef98
NC
27105 T (Tag_nodefaults),
27106 T (Tag_also_compatible_with),
27107 T (Tag_conformance),
27108 T (Tag_T2EE_use),
27109 T (Tag_Virtualization_use),
15afaa63 27110 T (Tag_DSP_extension),
cd21e546 27111 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 27112#undef T
f31fef98 27113 };
e04befd0
AS
27114 unsigned int i;
27115
27116 if (name == NULL)
27117 return -1;
27118
f31fef98 27119 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 27120 if (streq (name, attribute_table[i].name))
e04befd0
AS
27121 return attribute_table[i].tag;
27122
27123 return -1;
27124}
267bf995
RR
27125
27126
93ef582d
NC
27127/* Apply sym value for relocations only in the case that they are for
27128 local symbols in the same segment as the fixup and you have the
27129 respective architectural feature for blx and simple switches. */
267bf995 27130int
93ef582d 27131arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
27132{
27133 if (fixP->fx_addsy
27134 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
27135 /* PR 17444: If the local symbol is in a different section then a reloc
27136 will always be generated for it, so applying the symbol value now
27137 will result in a double offset being stored in the relocation. */
27138 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 27139 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
27140 {
27141 switch (fixP->fx_r_type)
27142 {
27143 case BFD_RELOC_ARM_PCREL_BLX:
27144 case BFD_RELOC_THUMB_PCREL_BRANCH23:
27145 if (ARM_IS_FUNC (fixP->fx_addsy))
27146 return 1;
27147 break;
27148
27149 case BFD_RELOC_ARM_PCREL_CALL:
27150 case BFD_RELOC_THUMB_PCREL_BLX:
27151 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 27152 return 1;
267bf995
RR
27153 break;
27154
27155 default:
27156 break;
27157 }
27158
27159 }
27160 return 0;
27161}
f31fef98 27162#endif /* OBJ_ELF */