]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
Automatic date update in version.in
[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;
7192 else if (inst.operands[i].reg == REG_SP)
7193 inst.error = BAD_SP;
7194 }
7195 break;
7196
55881a11 7197 case OP_RRnpctw:
fa94de6b
RM
7198 if (inst.operands[i].isreg
7199 && inst.operands[i].reg == REG_PC
55881a11
MGD
7200 && (inst.operands[i].writeback || thumb))
7201 inst.error = BAD_PC;
7202 break;
7203
c19d1205
ZW
7204 case OP_CPSF:
7205 case OP_ENDI:
7206 case OP_oROR:
d2cd1205
JB
7207 case OP_wPSR:
7208 case OP_rPSR:
c19d1205 7209 case OP_COND:
52e7f43d 7210 case OP_oBARRIER_I15:
c19d1205
ZW
7211 case OP_REGLST:
7212 case OP_VRSLST:
7213 case OP_VRDLST:
477330fc
RM
7214 case OP_VRSDLST:
7215 case OP_NRDLST:
7216 case OP_NSTRLST:
c19d1205
ZW
7217 if (val == FAIL)
7218 goto failure;
7219 inst.operands[i].imm = val;
7220 break;
a737bd4d 7221
c19d1205
ZW
7222 default:
7223 break;
7224 }
09d92015 7225
c19d1205
ZW
7226 /* If we get here, this operand was successfully parsed. */
7227 inst.operands[i].present = 1;
7228 continue;
09d92015 7229
c19d1205 7230 bad_args:
09d92015 7231 inst.error = BAD_ARGS;
c19d1205
ZW
7232
7233 failure:
7234 if (!backtrack_pos)
d252fdde
PB
7235 {
7236 /* The parse routine should already have set inst.error, but set a
5f4273c7 7237 default here just in case. */
d252fdde
PB
7238 if (!inst.error)
7239 inst.error = _("syntax error");
7240 return FAIL;
7241 }
c19d1205
ZW
7242
7243 /* Do not backtrack over a trailing optional argument that
7244 absorbed some text. We will only fail again, with the
7245 'garbage following instruction' error message, which is
7246 probably less helpful than the current one. */
7247 if (backtrack_index == i && backtrack_pos != str
7248 && upat[i+1] == OP_stop)
d252fdde
PB
7249 {
7250 if (!inst.error)
7251 inst.error = _("syntax error");
7252 return FAIL;
7253 }
c19d1205
ZW
7254
7255 /* Try again, skipping the optional argument at backtrack_pos. */
7256 str = backtrack_pos;
7257 inst.error = backtrack_error;
7258 inst.operands[backtrack_index].present = 0;
7259 i = backtrack_index;
7260 backtrack_pos = 0;
09d92015 7261 }
09d92015 7262
c19d1205
ZW
7263 /* Check that we have parsed all the arguments. */
7264 if (*str != '\0' && !inst.error)
7265 inst.error = _("garbage following instruction");
09d92015 7266
c19d1205 7267 return inst.error ? FAIL : SUCCESS;
09d92015
MM
7268}
7269
c19d1205
ZW
7270#undef po_char_or_fail
7271#undef po_reg_or_fail
7272#undef po_reg_or_goto
7273#undef po_imm_or_fail
5287ad62 7274#undef po_scalar_or_fail
52e7f43d 7275#undef po_barrier_or_imm
e07e6e58 7276
c19d1205 7277/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
7278#define constraint(expr, err) \
7279 do \
c19d1205 7280 { \
e07e6e58
NC
7281 if (expr) \
7282 { \
7283 inst.error = err; \
7284 return; \
7285 } \
c19d1205 7286 } \
e07e6e58 7287 while (0)
c19d1205 7288
fdfde340
JM
7289/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7290 instructions are unpredictable if these registers are used. This
7291 is the BadReg predicate in ARM's Thumb-2 documentation. */
7292#define reject_bad_reg(reg) \
7293 do \
7294 if (reg == REG_SP || reg == REG_PC) \
7295 { \
7296 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
7297 return; \
7298 } \
7299 while (0)
7300
94206790
MM
7301/* If REG is R13 (the stack pointer), warn that its use is
7302 deprecated. */
7303#define warn_deprecated_sp(reg) \
7304 do \
7305 if (warn_on_deprecated && reg == REG_SP) \
5c3696f8 7306 as_tsktsk (_("use of r13 is deprecated")); \
94206790
MM
7307 while (0)
7308
c19d1205
ZW
7309/* Functions for operand encoding. ARM, then Thumb. */
7310
d840c081 7311#define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
c19d1205 7312
9db2f6b4
RL
7313/* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7314
7315 The only binary encoding difference is the Coprocessor number. Coprocessor
7316 9 is used for half-precision calculations or conversions. The format of the
2b0f3761 7317 instruction is the same as the equivalent Coprocessor 10 instruction that
9db2f6b4
RL
7318 exists for Single-Precision operation. */
7319
7320static void
7321do_scalar_fp16_v82_encode (void)
7322{
7323 if (inst.cond != COND_ALWAYS)
7324 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7325 " the behaviour is UNPREDICTABLE"));
7326 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7327 _(BAD_FP16));
7328
7329 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7330 mark_feature_used (&arm_ext_fp16);
7331}
7332
c19d1205
ZW
7333/* If VAL can be encoded in the immediate field of an ARM instruction,
7334 return the encoded form. Otherwise, return FAIL. */
7335
7336static unsigned int
7337encode_arm_immediate (unsigned int val)
09d92015 7338{
c19d1205
ZW
7339 unsigned int a, i;
7340
4f1d6205
L
7341 if (val <= 0xff)
7342 return val;
7343
7344 for (i = 2; i < 32; i += 2)
c19d1205
ZW
7345 if ((a = rotate_left (val, i)) <= 0xff)
7346 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7347
7348 return FAIL;
09d92015
MM
7349}
7350
c19d1205
ZW
7351/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7352 return the encoded form. Otherwise, return FAIL. */
7353static unsigned int
7354encode_thumb32_immediate (unsigned int val)
09d92015 7355{
c19d1205 7356 unsigned int a, i;
09d92015 7357
9c3c69f2 7358 if (val <= 0xff)
c19d1205 7359 return val;
a737bd4d 7360
9c3c69f2 7361 for (i = 1; i <= 24; i++)
09d92015 7362 {
9c3c69f2
PB
7363 a = val >> i;
7364 if ((val & ~(0xff << i)) == 0)
7365 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 7366 }
a737bd4d 7367
c19d1205
ZW
7368 a = val & 0xff;
7369 if (val == ((a << 16) | a))
7370 return 0x100 | a;
7371 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7372 return 0x300 | a;
09d92015 7373
c19d1205
ZW
7374 a = val & 0xff00;
7375 if (val == ((a << 16) | a))
7376 return 0x200 | (a >> 8);
a737bd4d 7377
c19d1205 7378 return FAIL;
09d92015 7379}
5287ad62 7380/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
7381
7382static void
5287ad62
JB
7383encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7384{
7385 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7386 && reg > 15)
7387 {
b1cc4aeb 7388 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
477330fc
RM
7389 {
7390 if (thumb_mode)
7391 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7392 fpu_vfp_ext_d32);
7393 else
7394 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7395 fpu_vfp_ext_d32);
7396 }
5287ad62 7397 else
477330fc
RM
7398 {
7399 first_error (_("D register out of range for selected VFP version"));
7400 return;
7401 }
5287ad62
JB
7402 }
7403
c19d1205 7404 switch (pos)
09d92015 7405 {
c19d1205
ZW
7406 case VFP_REG_Sd:
7407 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7408 break;
7409
7410 case VFP_REG_Sn:
7411 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7412 break;
7413
7414 case VFP_REG_Sm:
7415 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7416 break;
7417
5287ad62
JB
7418 case VFP_REG_Dd:
7419 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7420 break;
5f4273c7 7421
5287ad62
JB
7422 case VFP_REG_Dn:
7423 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7424 break;
5f4273c7 7425
5287ad62
JB
7426 case VFP_REG_Dm:
7427 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7428 break;
7429
c19d1205
ZW
7430 default:
7431 abort ();
09d92015 7432 }
09d92015
MM
7433}
7434
c19d1205 7435/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 7436 if any, is handled by md_apply_fix. */
09d92015 7437static void
c19d1205 7438encode_arm_shift (int i)
09d92015 7439{
008a97ef
RL
7440 /* register-shifted register. */
7441 if (inst.operands[i].immisreg)
7442 {
bf355b69
MR
7443 int op_index;
7444 for (op_index = 0; op_index <= i; ++op_index)
008a97ef 7445 {
5689c942
RL
7446 /* Check the operand only when it's presented. In pre-UAL syntax,
7447 if the destination register is the same as the first operand, two
7448 register form of the instruction can be used. */
bf355b69
MR
7449 if (inst.operands[op_index].present && inst.operands[op_index].isreg
7450 && inst.operands[op_index].reg == REG_PC)
008a97ef
RL
7451 as_warn (UNPRED_REG ("r15"));
7452 }
7453
7454 if (inst.operands[i].imm == REG_PC)
7455 as_warn (UNPRED_REG ("r15"));
7456 }
7457
c19d1205
ZW
7458 if (inst.operands[i].shift_kind == SHIFT_RRX)
7459 inst.instruction |= SHIFT_ROR << 5;
7460 else
09d92015 7461 {
c19d1205
ZW
7462 inst.instruction |= inst.operands[i].shift_kind << 5;
7463 if (inst.operands[i].immisreg)
7464 {
7465 inst.instruction |= SHIFT_BY_REG;
7466 inst.instruction |= inst.operands[i].imm << 8;
7467 }
7468 else
7469 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 7470 }
c19d1205 7471}
09d92015 7472
c19d1205
ZW
7473static void
7474encode_arm_shifter_operand (int i)
7475{
7476 if (inst.operands[i].isreg)
09d92015 7477 {
c19d1205
ZW
7478 inst.instruction |= inst.operands[i].reg;
7479 encode_arm_shift (i);
09d92015 7480 }
c19d1205 7481 else
a415b1cd
JB
7482 {
7483 inst.instruction |= INST_IMMEDIATE;
7484 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7485 inst.instruction |= inst.operands[i].imm;
7486 }
09d92015
MM
7487}
7488
c19d1205 7489/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 7490static void
c19d1205 7491encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 7492{
2b2f5df9
NC
7493 /* PR 14260:
7494 Generate an error if the operand is not a register. */
7495 constraint (!inst.operands[i].isreg,
7496 _("Instruction does not support =N addresses"));
7497
c19d1205 7498 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 7499
c19d1205 7500 if (inst.operands[i].preind)
09d92015 7501 {
c19d1205
ZW
7502 if (is_t)
7503 {
7504 inst.error = _("instruction does not accept preindexed addressing");
7505 return;
7506 }
7507 inst.instruction |= PRE_INDEX;
7508 if (inst.operands[i].writeback)
7509 inst.instruction |= WRITE_BACK;
09d92015 7510
c19d1205
ZW
7511 }
7512 else if (inst.operands[i].postind)
7513 {
9c2799c2 7514 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
7515 if (is_t)
7516 inst.instruction |= WRITE_BACK;
7517 }
7518 else /* unindexed - only for coprocessor */
09d92015 7519 {
c19d1205 7520 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
7521 return;
7522 }
7523
c19d1205
ZW
7524 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7525 && (((inst.instruction & 0x000f0000) >> 16)
7526 == ((inst.instruction & 0x0000f000) >> 12)))
7527 as_warn ((inst.instruction & LOAD_BIT)
7528 ? _("destination register same as write-back base")
7529 : _("source register same as write-back base"));
09d92015
MM
7530}
7531
c19d1205
ZW
7532/* inst.operands[i] was set up by parse_address. Encode it into an
7533 ARM-format mode 2 load or store instruction. If is_t is true,
7534 reject forms that cannot be used with a T instruction (i.e. not
7535 post-indexed). */
a737bd4d 7536static void
c19d1205 7537encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 7538{
5be8be5d
DG
7539 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7540
c19d1205 7541 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7542
c19d1205 7543 if (inst.operands[i].immisreg)
09d92015 7544 {
5be8be5d
DG
7545 constraint ((inst.operands[i].imm == REG_PC
7546 || (is_pc && inst.operands[i].writeback)),
7547 BAD_PC_ADDRESSING);
c19d1205
ZW
7548 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7549 inst.instruction |= inst.operands[i].imm;
7550 if (!inst.operands[i].negative)
7551 inst.instruction |= INDEX_UP;
7552 if (inst.operands[i].shifted)
7553 {
7554 if (inst.operands[i].shift_kind == SHIFT_RRX)
7555 inst.instruction |= SHIFT_ROR << 5;
7556 else
7557 {
7558 inst.instruction |= inst.operands[i].shift_kind << 5;
7559 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7560 }
7561 }
09d92015 7562 }
c19d1205 7563 else /* immediate offset in inst.reloc */
09d92015 7564 {
5be8be5d
DG
7565 if (is_pc && !inst.reloc.pc_rel)
7566 {
7567 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
23a10334
JZ
7568
7569 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7570 cannot use PC in addressing.
7571 PC cannot be used in writeback addressing, either. */
7572 constraint ((is_t || inst.operands[i].writeback),
5be8be5d 7573 BAD_PC_ADDRESSING);
23a10334 7574
dc5ec521 7575 /* Use of PC in str is deprecated for ARMv7. */
23a10334
JZ
7576 if (warn_on_deprecated
7577 && !is_load
7578 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
5c3696f8 7579 as_tsktsk (_("use of PC in this instruction is deprecated"));
5be8be5d
DG
7580 }
7581
c19d1205 7582 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7583 {
7584 /* Prefer + for zero encoded value. */
7585 if (!inst.operands[i].negative)
7586 inst.instruction |= INDEX_UP;
7587 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7588 }
09d92015 7589 }
09d92015
MM
7590}
7591
c19d1205
ZW
7592/* inst.operands[i] was set up by parse_address. Encode it into an
7593 ARM-format mode 3 load or store instruction. Reject forms that
7594 cannot be used with such instructions. If is_t is true, reject
7595 forms that cannot be used with a T instruction (i.e. not
7596 post-indexed). */
7597static void
7598encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 7599{
c19d1205 7600 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 7601 {
c19d1205
ZW
7602 inst.error = _("instruction does not accept scaled register index");
7603 return;
09d92015 7604 }
a737bd4d 7605
c19d1205 7606 encode_arm_addr_mode_common (i, is_t);
a737bd4d 7607
c19d1205
ZW
7608 if (inst.operands[i].immisreg)
7609 {
5be8be5d 7610 constraint ((inst.operands[i].imm == REG_PC
eb9f3f00 7611 || (is_t && inst.operands[i].reg == REG_PC)),
5be8be5d 7612 BAD_PC_ADDRESSING);
eb9f3f00
JB
7613 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7614 BAD_PC_WRITEBACK);
c19d1205
ZW
7615 inst.instruction |= inst.operands[i].imm;
7616 if (!inst.operands[i].negative)
7617 inst.instruction |= INDEX_UP;
7618 }
7619 else /* immediate offset in inst.reloc */
7620 {
5be8be5d
DG
7621 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7622 && inst.operands[i].writeback),
7623 BAD_PC_WRITEBACK);
c19d1205
ZW
7624 inst.instruction |= HWOFFSET_IMM;
7625 if (inst.reloc.type == BFD_RELOC_UNUSED)
26d97720
NS
7626 {
7627 /* Prefer + for zero encoded value. */
7628 if (!inst.operands[i].negative)
7629 inst.instruction |= INDEX_UP;
7630
7631 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7632 }
c19d1205 7633 }
a737bd4d
NC
7634}
7635
8335d6aa
JW
7636/* Write immediate bits [7:0] to the following locations:
7637
7638 |28/24|23 19|18 16|15 4|3 0|
7639 | 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|
7640
7641 This function is used by VMOV/VMVN/VORR/VBIC. */
7642
7643static void
7644neon_write_immbits (unsigned immbits)
7645{
7646 inst.instruction |= immbits & 0xf;
7647 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7648 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7649}
7650
7651/* Invert low-order SIZE bits of XHI:XLO. */
7652
7653static void
7654neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7655{
7656 unsigned immlo = xlo ? *xlo : 0;
7657 unsigned immhi = xhi ? *xhi : 0;
7658
7659 switch (size)
7660 {
7661 case 8:
7662 immlo = (~immlo) & 0xff;
7663 break;
7664
7665 case 16:
7666 immlo = (~immlo) & 0xffff;
7667 break;
7668
7669 case 64:
7670 immhi = (~immhi) & 0xffffffff;
7671 /* fall through. */
7672
7673 case 32:
7674 immlo = (~immlo) & 0xffffffff;
7675 break;
7676
7677 default:
7678 abort ();
7679 }
7680
7681 if (xlo)
7682 *xlo = immlo;
7683
7684 if (xhi)
7685 *xhi = immhi;
7686}
7687
7688/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7689 A, B, C, D. */
09d92015 7690
c19d1205 7691static int
8335d6aa 7692neon_bits_same_in_bytes (unsigned imm)
09d92015 7693{
8335d6aa
JW
7694 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7695 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7696 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7697 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7698}
a737bd4d 7699
8335d6aa 7700/* For immediate of above form, return 0bABCD. */
09d92015 7701
8335d6aa
JW
7702static unsigned
7703neon_squash_bits (unsigned imm)
7704{
7705 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7706 | ((imm & 0x01000000) >> 21);
7707}
7708
7709/* Compress quarter-float representation to 0b...000 abcdefgh. */
7710
7711static unsigned
7712neon_qfloat_bits (unsigned imm)
7713{
7714 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7715}
7716
7717/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7718 the instruction. *OP is passed as the initial value of the op field, and
7719 may be set to a different value depending on the constant (i.e.
7720 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7721 MVN). If the immediate looks like a repeated pattern then also
7722 try smaller element sizes. */
7723
7724static int
7725neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7726 unsigned *immbits, int *op, int size,
7727 enum neon_el_type type)
7728{
7729 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7730 float. */
7731 if (type == NT_float && !float_p)
7732 return FAIL;
7733
7734 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
09d92015 7735 {
8335d6aa
JW
7736 if (size != 32 || *op == 1)
7737 return FAIL;
7738 *immbits = neon_qfloat_bits (immlo);
7739 return 0xf;
7740 }
7741
7742 if (size == 64)
7743 {
7744 if (neon_bits_same_in_bytes (immhi)
7745 && neon_bits_same_in_bytes (immlo))
c19d1205 7746 {
8335d6aa
JW
7747 if (*op == 1)
7748 return FAIL;
7749 *immbits = (neon_squash_bits (immhi) << 4)
7750 | neon_squash_bits (immlo);
7751 *op = 1;
7752 return 0xe;
c19d1205 7753 }
a737bd4d 7754
8335d6aa
JW
7755 if (immhi != immlo)
7756 return FAIL;
7757 }
a737bd4d 7758
8335d6aa 7759 if (size >= 32)
09d92015 7760 {
8335d6aa 7761 if (immlo == (immlo & 0x000000ff))
c19d1205 7762 {
8335d6aa
JW
7763 *immbits = immlo;
7764 return 0x0;
c19d1205 7765 }
8335d6aa 7766 else if (immlo == (immlo & 0x0000ff00))
c19d1205 7767 {
8335d6aa
JW
7768 *immbits = immlo >> 8;
7769 return 0x2;
c19d1205 7770 }
8335d6aa
JW
7771 else if (immlo == (immlo & 0x00ff0000))
7772 {
7773 *immbits = immlo >> 16;
7774 return 0x4;
7775 }
7776 else if (immlo == (immlo & 0xff000000))
7777 {
7778 *immbits = immlo >> 24;
7779 return 0x6;
7780 }
7781 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7782 {
7783 *immbits = (immlo >> 8) & 0xff;
7784 return 0xc;
7785 }
7786 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7787 {
7788 *immbits = (immlo >> 16) & 0xff;
7789 return 0xd;
7790 }
7791
7792 if ((immlo & 0xffff) != (immlo >> 16))
7793 return FAIL;
7794 immlo &= 0xffff;
09d92015 7795 }
a737bd4d 7796
8335d6aa 7797 if (size >= 16)
4962c51a 7798 {
8335d6aa
JW
7799 if (immlo == (immlo & 0x000000ff))
7800 {
7801 *immbits = immlo;
7802 return 0x8;
7803 }
7804 else if (immlo == (immlo & 0x0000ff00))
7805 {
7806 *immbits = immlo >> 8;
7807 return 0xa;
7808 }
7809
7810 if ((immlo & 0xff) != (immlo >> 8))
7811 return FAIL;
7812 immlo &= 0xff;
4962c51a
MS
7813 }
7814
8335d6aa
JW
7815 if (immlo == (immlo & 0x000000ff))
7816 {
7817 /* Don't allow MVN with 8-bit immediate. */
7818 if (*op == 1)
7819 return FAIL;
7820 *immbits = immlo;
7821 return 0xe;
7822 }
26d97720 7823
8335d6aa 7824 return FAIL;
c19d1205 7825}
a737bd4d 7826
5fc177c8 7827#if defined BFD_HOST_64_BIT
ba592044
AM
7828/* Returns TRUE if double precision value V may be cast
7829 to single precision without loss of accuracy. */
7830
7831static bfd_boolean
5fc177c8 7832is_double_a_single (bfd_int64_t v)
ba592044 7833{
5fc177c8 7834 int exp = (int)((v >> 52) & 0x7FF);
8fe3f3d6 7835 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7836
7837 return (exp == 0 || exp == 0x7FF
7838 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7839 && (mantissa & 0x1FFFFFFFl) == 0;
7840}
7841
3739860c 7842/* Returns a double precision value casted to single precision
ba592044
AM
7843 (ignoring the least significant bits in exponent and mantissa). */
7844
7845static int
5fc177c8 7846double_to_single (bfd_int64_t v)
ba592044
AM
7847{
7848 int sign = (int) ((v >> 63) & 1l);
5fc177c8 7849 int exp = (int) ((v >> 52) & 0x7FF);
8fe3f3d6 7850 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
ba592044
AM
7851
7852 if (exp == 0x7FF)
7853 exp = 0xFF;
7854 else
7855 {
7856 exp = exp - 1023 + 127;
7857 if (exp >= 0xFF)
7858 {
7859 /* Infinity. */
7860 exp = 0x7F;
7861 mantissa = 0;
7862 }
7863 else if (exp < 0)
7864 {
7865 /* No denormalized numbers. */
7866 exp = 0;
7867 mantissa = 0;
7868 }
7869 }
7870 mantissa >>= 29;
7871 return (sign << 31) | (exp << 23) | mantissa;
7872}
5fc177c8 7873#endif /* BFD_HOST_64_BIT */
ba592044 7874
8335d6aa
JW
7875enum lit_type
7876{
7877 CONST_THUMB,
7878 CONST_ARM,
7879 CONST_VEC
7880};
7881
ba592044
AM
7882static void do_vfp_nsyn_opcode (const char *);
7883
c19d1205
ZW
7884/* inst.reloc.exp describes an "=expr" load pseudo-operation.
7885 Determine whether it can be performed with a move instruction; if
7886 it can, convert inst.instruction to that move instruction and
c921be7d
NC
7887 return TRUE; if it can't, convert inst.instruction to a literal-pool
7888 load and return FALSE. If this is not a valid thing to do in the
7889 current context, set inst.error and return TRUE.
a737bd4d 7890
c19d1205
ZW
7891 inst.operands[i] describes the destination register. */
7892
c921be7d 7893static bfd_boolean
8335d6aa 7894move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
c19d1205 7895{
53365c0d 7896 unsigned long tbit;
8335d6aa
JW
7897 bfd_boolean thumb_p = (t == CONST_THUMB);
7898 bfd_boolean arm_p = (t == CONST_ARM);
53365c0d
PB
7899
7900 if (thumb_p)
7901 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7902 else
7903 tbit = LOAD_BIT;
7904
7905 if ((inst.instruction & tbit) == 0)
09d92015 7906 {
c19d1205 7907 inst.error = _("invalid pseudo operation");
c921be7d 7908 return TRUE;
09d92015 7909 }
ba592044 7910
8335d6aa
JW
7911 if (inst.reloc.exp.X_op != O_constant
7912 && inst.reloc.exp.X_op != O_symbol
7913 && inst.reloc.exp.X_op != O_big)
09d92015
MM
7914 {
7915 inst.error = _("constant expression expected");
c921be7d 7916 return TRUE;
09d92015 7917 }
ba592044
AM
7918
7919 if (inst.reloc.exp.X_op == O_constant
7920 || inst.reloc.exp.X_op == O_big)
8335d6aa 7921 {
5fc177c8
NC
7922#if defined BFD_HOST_64_BIT
7923 bfd_int64_t v;
7924#else
ba592044 7925 offsetT v;
5fc177c8 7926#endif
ba592044 7927 if (inst.reloc.exp.X_op == O_big)
8335d6aa 7928 {
ba592044
AM
7929 LITTLENUM_TYPE w[X_PRECISION];
7930 LITTLENUM_TYPE * l;
7931
7932 if (inst.reloc.exp.X_add_number == -1)
8335d6aa 7933 {
ba592044
AM
7934 gen_to_words (w, X_PRECISION, E_PRECISION);
7935 l = w;
7936 /* FIXME: Should we check words w[2..5] ? */
8335d6aa 7937 }
ba592044
AM
7938 else
7939 l = generic_bignum;
3739860c 7940
5fc177c8
NC
7941#if defined BFD_HOST_64_BIT
7942 v =
7943 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
7944 << LITTLENUM_NUMBER_OF_BITS)
7945 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
7946 << LITTLENUM_NUMBER_OF_BITS)
7947 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
7948 << LITTLENUM_NUMBER_OF_BITS)
7949 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
7950#else
ba592044
AM
7951 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
7952 | (l[0] & LITTLENUM_MASK);
5fc177c8 7953#endif
8335d6aa 7954 }
ba592044
AM
7955 else
7956 v = inst.reloc.exp.X_add_number;
7957
7958 if (!inst.operands[i].issingle)
8335d6aa 7959 {
12569877 7960 if (thumb_p)
8335d6aa 7961 {
2c32be70
CM
7962 /* This can be encoded only for a low register. */
7963 if ((v & ~0xFF) == 0 && (inst.operands[i].reg < 8))
ba592044
AM
7964 {
7965 /* This can be done with a mov(1) instruction. */
7966 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7967 inst.instruction |= v;
7968 return TRUE;
7969 }
12569877 7970
ff8646ee
TP
7971 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
7972 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
12569877 7973 {
fc289b0a
TP
7974 /* Check if on thumb2 it can be done with a mov.w, mvn or
7975 movw instruction. */
12569877
AM
7976 unsigned int newimm;
7977 bfd_boolean isNegated;
7978
7979 newimm = encode_thumb32_immediate (v);
7980 if (newimm != (unsigned int) FAIL)
7981 isNegated = FALSE;
7982 else
7983 {
582cfe03 7984 newimm = encode_thumb32_immediate (~v);
12569877
AM
7985 if (newimm != (unsigned int) FAIL)
7986 isNegated = TRUE;
7987 }
7988
fc289b0a
TP
7989 /* The number can be loaded with a mov.w or mvn
7990 instruction. */
ff8646ee
TP
7991 if (newimm != (unsigned int) FAIL
7992 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
12569877 7993 {
fc289b0a 7994 inst.instruction = (0xf04f0000 /* MOV.W. */
582cfe03 7995 | (inst.operands[i].reg << 8));
fc289b0a 7996 /* Change to MOVN. */
582cfe03 7997 inst.instruction |= (isNegated ? 0x200000 : 0);
12569877
AM
7998 inst.instruction |= (newimm & 0x800) << 15;
7999 inst.instruction |= (newimm & 0x700) << 4;
8000 inst.instruction |= (newimm & 0x0ff);
8001 return TRUE;
8002 }
fc289b0a 8003 /* The number can be loaded with a movw instruction. */
ff8646ee
TP
8004 else if ((v & ~0xFFFF) == 0
8005 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
3739860c 8006 {
582cfe03 8007 int imm = v & 0xFFFF;
12569877 8008
582cfe03 8009 inst.instruction = 0xf2400000; /* MOVW. */
12569877
AM
8010 inst.instruction |= (inst.operands[i].reg << 8);
8011 inst.instruction |= (imm & 0xf000) << 4;
8012 inst.instruction |= (imm & 0x0800) << 15;
8013 inst.instruction |= (imm & 0x0700) << 4;
8014 inst.instruction |= (imm & 0x00ff);
8015 return TRUE;
8016 }
8017 }
8335d6aa 8018 }
12569877 8019 else if (arm_p)
ba592044
AM
8020 {
8021 int value = encode_arm_immediate (v);
12569877 8022
ba592044
AM
8023 if (value != FAIL)
8024 {
8025 /* This can be done with a mov instruction. */
8026 inst.instruction &= LITERAL_MASK;
8027 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8028 inst.instruction |= value & 0xfff;
8029 return TRUE;
8030 }
8335d6aa 8031
ba592044
AM
8032 value = encode_arm_immediate (~ v);
8033 if (value != FAIL)
8034 {
8035 /* This can be done with a mvn instruction. */
8036 inst.instruction &= LITERAL_MASK;
8037 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8038 inst.instruction |= value & 0xfff;
8039 return TRUE;
8040 }
8041 }
934c2632 8042 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8335d6aa 8043 {
ba592044
AM
8044 int op = 0;
8045 unsigned immbits = 0;
8046 unsigned immlo = inst.operands[1].imm;
8047 unsigned immhi = inst.operands[1].regisimm
8048 ? inst.operands[1].reg
8049 : inst.reloc.exp.X_unsigned
8050 ? 0
8051 : ((bfd_int64_t)((int) immlo)) >> 32;
8052 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8053 &op, 64, NT_invtype);
8054
8055 if (cmode == FAIL)
8056 {
8057 neon_invert_size (&immlo, &immhi, 64);
8058 op = !op;
8059 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8060 &op, 64, NT_invtype);
8061 }
8062
8063 if (cmode != FAIL)
8064 {
8065 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8066 | (1 << 23)
8067 | (cmode << 8)
8068 | (op << 5)
8069 | (1 << 4);
8070
8071 /* Fill other bits in vmov encoding for both thumb and arm. */
8072 if (thumb_mode)
eff0bc54 8073 inst.instruction |= (0x7U << 29) | (0xF << 24);
ba592044 8074 else
eff0bc54 8075 inst.instruction |= (0xFU << 28) | (0x1 << 25);
ba592044
AM
8076 neon_write_immbits (immbits);
8077 return TRUE;
8078 }
8335d6aa
JW
8079 }
8080 }
8335d6aa 8081
ba592044
AM
8082 if (t == CONST_VEC)
8083 {
8084 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8085 if (inst.operands[i].issingle
8086 && is_quarter_float (inst.operands[1].imm)
8087 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8335d6aa 8088 {
ba592044
AM
8089 inst.operands[1].imm =
8090 neon_qfloat_bits (v);
8091 do_vfp_nsyn_opcode ("fconsts");
8092 return TRUE;
8335d6aa 8093 }
5fc177c8
NC
8094
8095 /* If our host does not support a 64-bit type then we cannot perform
8096 the following optimization. This mean that there will be a
8097 discrepancy between the output produced by an assembler built for
8098 a 32-bit-only host and the output produced from a 64-bit host, but
8099 this cannot be helped. */
8100#if defined BFD_HOST_64_BIT
ba592044
AM
8101 else if (!inst.operands[1].issingle
8102 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8335d6aa 8103 {
ba592044
AM
8104 if (is_double_a_single (v)
8105 && is_quarter_float (double_to_single (v)))
8106 {
8107 inst.operands[1].imm =
8108 neon_qfloat_bits (double_to_single (v));
8109 do_vfp_nsyn_opcode ("fconstd");
8110 return TRUE;
8111 }
8335d6aa 8112 }
5fc177c8 8113#endif
8335d6aa
JW
8114 }
8115 }
8116
8117 if (add_to_lit_pool ((!inst.operands[i].isvec
8118 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8119 return TRUE;
8120
8121 inst.operands[1].reg = REG_PC;
8122 inst.operands[1].isreg = 1;
8123 inst.operands[1].preind = 1;
8124 inst.reloc.pc_rel = 1;
8125 inst.reloc.type = (thumb_p
8126 ? BFD_RELOC_ARM_THUMB_OFFSET
8127 : (mode_3
8128 ? BFD_RELOC_ARM_HWLITERAL
8129 : BFD_RELOC_ARM_LITERAL));
8130 return FALSE;
8131}
8132
8133/* inst.operands[i] was set up by parse_address. Encode it into an
8134 ARM-format instruction. Reject all forms which cannot be encoded
8135 into a coprocessor load/store instruction. If wb_ok is false,
8136 reject use of writeback; if unind_ok is false, reject use of
8137 unindexed addressing. If reloc_override is not 0, use it instead
8138 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8139 (in which case it is preserved). */
8140
8141static int
8142encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8143{
8144 if (!inst.operands[i].isreg)
8145 {
99b2a2dd
NC
8146 /* PR 18256 */
8147 if (! inst.operands[0].isvec)
8148 {
8149 inst.error = _("invalid co-processor operand");
8150 return FAIL;
8151 }
8335d6aa
JW
8152 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8153 return SUCCESS;
8154 }
8155
8156 inst.instruction |= inst.operands[i].reg << 16;
8157
8158 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8159
8160 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8161 {
8162 gas_assert (!inst.operands[i].writeback);
8163 if (!unind_ok)
8164 {
8165 inst.error = _("instruction does not support unindexed addressing");
8166 return FAIL;
8167 }
8168 inst.instruction |= inst.operands[i].imm;
8169 inst.instruction |= INDEX_UP;
8170 return SUCCESS;
8171 }
8172
8173 if (inst.operands[i].preind)
8174 inst.instruction |= PRE_INDEX;
8175
8176 if (inst.operands[i].writeback)
09d92015 8177 {
8335d6aa 8178 if (inst.operands[i].reg == REG_PC)
c19d1205 8179 {
8335d6aa
JW
8180 inst.error = _("pc may not be used with write-back");
8181 return FAIL;
c19d1205 8182 }
8335d6aa 8183 if (!wb_ok)
c19d1205 8184 {
8335d6aa
JW
8185 inst.error = _("instruction does not support writeback");
8186 return FAIL;
c19d1205 8187 }
8335d6aa 8188 inst.instruction |= WRITE_BACK;
09d92015
MM
8189 }
8190
8335d6aa
JW
8191 if (reloc_override)
8192 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8193 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8194 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8195 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
c19d1205 8196 {
8335d6aa
JW
8197 if (thumb_mode)
8198 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8199 else
8200 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
c19d1205 8201 }
8335d6aa
JW
8202
8203 /* Prefer + for zero encoded value. */
8204 if (!inst.operands[i].negative)
8205 inst.instruction |= INDEX_UP;
8206
8207 return SUCCESS;
09d92015
MM
8208}
8209
5f4273c7 8210/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
8211 First some generics; their names are taken from the conventional
8212 bit positions for register arguments in ARM format instructions. */
09d92015 8213
a737bd4d 8214static void
c19d1205 8215do_noargs (void)
09d92015 8216{
c19d1205 8217}
a737bd4d 8218
c19d1205
ZW
8219static void
8220do_rd (void)
8221{
8222 inst.instruction |= inst.operands[0].reg << 12;
8223}
a737bd4d 8224
16a1fa25
TP
8225static void
8226do_rn (void)
8227{
8228 inst.instruction |= inst.operands[0].reg << 16;
8229}
8230
c19d1205
ZW
8231static void
8232do_rd_rm (void)
8233{
8234 inst.instruction |= inst.operands[0].reg << 12;
8235 inst.instruction |= inst.operands[1].reg;
8236}
09d92015 8237
9eb6c0f1
MGD
8238static void
8239do_rm_rn (void)
8240{
8241 inst.instruction |= inst.operands[0].reg;
8242 inst.instruction |= inst.operands[1].reg << 16;
8243}
8244
c19d1205
ZW
8245static void
8246do_rd_rn (void)
8247{
8248 inst.instruction |= inst.operands[0].reg << 12;
8249 inst.instruction |= inst.operands[1].reg << 16;
8250}
a737bd4d 8251
c19d1205
ZW
8252static void
8253do_rn_rd (void)
8254{
8255 inst.instruction |= inst.operands[0].reg << 16;
8256 inst.instruction |= inst.operands[1].reg << 12;
8257}
09d92015 8258
4ed7ed8d
TP
8259static void
8260do_tt (void)
8261{
8262 inst.instruction |= inst.operands[0].reg << 8;
8263 inst.instruction |= inst.operands[1].reg << 16;
8264}
8265
59d09be6
MGD
8266static bfd_boolean
8267check_obsolete (const arm_feature_set *feature, const char *msg)
8268{
8269 if (ARM_CPU_IS_ANY (cpu_variant))
8270 {
5c3696f8 8271 as_tsktsk ("%s", msg);
59d09be6
MGD
8272 return TRUE;
8273 }
8274 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8275 {
8276 as_bad ("%s", msg);
8277 return TRUE;
8278 }
8279
8280 return FALSE;
8281}
8282
c19d1205
ZW
8283static void
8284do_rd_rm_rn (void)
8285{
9a64e435 8286 unsigned Rn = inst.operands[2].reg;
708587a4 8287 /* Enforce restrictions on SWP instruction. */
9a64e435 8288 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
56adecf4
DG
8289 {
8290 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8291 _("Rn must not overlap other operands"));
8292
59d09be6
MGD
8293 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8294 */
8295 if (!check_obsolete (&arm_ext_v8,
8296 _("swp{b} use is obsoleted for ARMv8 and later"))
8297 && warn_on_deprecated
8298 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
5c3696f8 8299 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
56adecf4 8300 }
59d09be6 8301
c19d1205
ZW
8302 inst.instruction |= inst.operands[0].reg << 12;
8303 inst.instruction |= inst.operands[1].reg;
9a64e435 8304 inst.instruction |= Rn << 16;
c19d1205 8305}
09d92015 8306
c19d1205
ZW
8307static void
8308do_rd_rn_rm (void)
8309{
8310 inst.instruction |= inst.operands[0].reg << 12;
8311 inst.instruction |= inst.operands[1].reg << 16;
8312 inst.instruction |= inst.operands[2].reg;
8313}
a737bd4d 8314
c19d1205
ZW
8315static void
8316do_rm_rd_rn (void)
8317{
5be8be5d
DG
8318 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8319 constraint (((inst.reloc.exp.X_op != O_constant
8320 && inst.reloc.exp.X_op != O_illegal)
8321 || inst.reloc.exp.X_add_number != 0),
8322 BAD_ADDR_MODE);
c19d1205
ZW
8323 inst.instruction |= inst.operands[0].reg;
8324 inst.instruction |= inst.operands[1].reg << 12;
8325 inst.instruction |= inst.operands[2].reg << 16;
8326}
09d92015 8327
c19d1205
ZW
8328static void
8329do_imm0 (void)
8330{
8331 inst.instruction |= inst.operands[0].imm;
8332}
09d92015 8333
c19d1205
ZW
8334static void
8335do_rd_cpaddr (void)
8336{
8337 inst.instruction |= inst.operands[0].reg << 12;
8338 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 8339}
a737bd4d 8340
c19d1205
ZW
8341/* ARM instructions, in alphabetical order by function name (except
8342 that wrapper functions appear immediately after the function they
8343 wrap). */
09d92015 8344
c19d1205
ZW
8345/* This is a pseudo-op of the form "adr rd, label" to be converted
8346 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
8347
8348static void
c19d1205 8349do_adr (void)
09d92015 8350{
c19d1205 8351 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8352
c19d1205
ZW
8353 /* Frag hacking will turn this into a sub instruction if the offset turns
8354 out to be negative. */
8355 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 8356 inst.reloc.pc_rel = 1;
2fc8bdac 8357 inst.reloc.exp.X_add_number -= 8;
c19d1205 8358}
b99bd4ef 8359
c19d1205
ZW
8360/* This is a pseudo-op of the form "adrl rd, label" to be converted
8361 into a relative address of the form:
8362 add rd, pc, #low(label-.-8)"
8363 add rd, rd, #high(label-.-8)" */
b99bd4ef 8364
c19d1205
ZW
8365static void
8366do_adrl (void)
8367{
8368 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 8369
c19d1205
ZW
8370 /* Frag hacking will turn this into a sub instruction if the offset turns
8371 out to be negative. */
8372 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
8373 inst.reloc.pc_rel = 1;
8374 inst.size = INSN_SIZE * 2;
2fc8bdac 8375 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
8376}
8377
b99bd4ef 8378static void
c19d1205 8379do_arit (void)
b99bd4ef 8380{
a9f02af8
MG
8381 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8382 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
8383 THUMB1_RELOC_ONLY);
c19d1205
ZW
8384 if (!inst.operands[1].present)
8385 inst.operands[1].reg = inst.operands[0].reg;
8386 inst.instruction |= inst.operands[0].reg << 12;
8387 inst.instruction |= inst.operands[1].reg << 16;
8388 encode_arm_shifter_operand (2);
8389}
b99bd4ef 8390
62b3e311
PB
8391static void
8392do_barrier (void)
8393{
8394 if (inst.operands[0].present)
ccb84d65 8395 inst.instruction |= inst.operands[0].imm;
62b3e311
PB
8396 else
8397 inst.instruction |= 0xf;
8398}
8399
c19d1205
ZW
8400static void
8401do_bfc (void)
8402{
8403 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8404 constraint (msb > 32, _("bit-field extends past end of register"));
8405 /* The instruction encoding stores the LSB and MSB,
8406 not the LSB and width. */
8407 inst.instruction |= inst.operands[0].reg << 12;
8408 inst.instruction |= inst.operands[1].imm << 7;
8409 inst.instruction |= (msb - 1) << 16;
8410}
b99bd4ef 8411
c19d1205
ZW
8412static void
8413do_bfi (void)
8414{
8415 unsigned int msb;
b99bd4ef 8416
c19d1205
ZW
8417 /* #0 in second position is alternative syntax for bfc, which is
8418 the same instruction but with REG_PC in the Rm field. */
8419 if (!inst.operands[1].isreg)
8420 inst.operands[1].reg = REG_PC;
b99bd4ef 8421
c19d1205
ZW
8422 msb = inst.operands[2].imm + inst.operands[3].imm;
8423 constraint (msb > 32, _("bit-field extends past end of register"));
8424 /* The instruction encoding stores the LSB and MSB,
8425 not the LSB and width. */
8426 inst.instruction |= inst.operands[0].reg << 12;
8427 inst.instruction |= inst.operands[1].reg;
8428 inst.instruction |= inst.operands[2].imm << 7;
8429 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
8430}
8431
b99bd4ef 8432static void
c19d1205 8433do_bfx (void)
b99bd4ef 8434{
c19d1205
ZW
8435 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8436 _("bit-field extends past end of register"));
8437 inst.instruction |= inst.operands[0].reg << 12;
8438 inst.instruction |= inst.operands[1].reg;
8439 inst.instruction |= inst.operands[2].imm << 7;
8440 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8441}
09d92015 8442
c19d1205
ZW
8443/* ARM V5 breakpoint instruction (argument parse)
8444 BKPT <16 bit unsigned immediate>
8445 Instruction is not conditional.
8446 The bit pattern given in insns[] has the COND_ALWAYS condition,
8447 and it is an error if the caller tried to override that. */
b99bd4ef 8448
c19d1205
ZW
8449static void
8450do_bkpt (void)
8451{
8452 /* Top 12 of 16 bits to bits 19:8. */
8453 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 8454
c19d1205
ZW
8455 /* Bottom 4 of 16 bits to bits 3:0. */
8456 inst.instruction |= inst.operands[0].imm & 0xf;
8457}
09d92015 8458
c19d1205
ZW
8459static void
8460encode_branch (int default_reloc)
8461{
8462 if (inst.operands[0].hasreloc)
8463 {
0855e32b
NS
8464 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8465 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8466 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8467 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8468 ? BFD_RELOC_ARM_PLT32
8469 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
c19d1205 8470 }
b99bd4ef 8471 else
9ae92b05 8472 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
2fc8bdac 8473 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8474}
8475
b99bd4ef 8476static void
c19d1205 8477do_branch (void)
b99bd4ef 8478{
39b41c9c
PB
8479#ifdef OBJ_ELF
8480 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8481 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8482 else
8483#endif
8484 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8485}
8486
8487static void
8488do_bl (void)
8489{
8490#ifdef OBJ_ELF
8491 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8492 {
8493 if (inst.cond == COND_ALWAYS)
8494 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8495 else
8496 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8497 }
8498 else
8499#endif
8500 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 8501}
b99bd4ef 8502
c19d1205
ZW
8503/* ARM V5 branch-link-exchange instruction (argument parse)
8504 BLX <target_addr> ie BLX(1)
8505 BLX{<condition>} <Rm> ie BLX(2)
8506 Unfortunately, there are two different opcodes for this mnemonic.
8507 So, the insns[].value is not used, and the code here zaps values
8508 into inst.instruction.
8509 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 8510
c19d1205
ZW
8511static void
8512do_blx (void)
8513{
8514 if (inst.operands[0].isreg)
b99bd4ef 8515 {
c19d1205
ZW
8516 /* Arg is a register; the opcode provided by insns[] is correct.
8517 It is not illegal to do "blx pc", just useless. */
8518 if (inst.operands[0].reg == REG_PC)
8519 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 8520
c19d1205
ZW
8521 inst.instruction |= inst.operands[0].reg;
8522 }
8523 else
b99bd4ef 8524 {
c19d1205 8525 /* Arg is an address; this instruction cannot be executed
267bf995
RR
8526 conditionally, and the opcode must be adjusted.
8527 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8528 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 8529 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 8530 inst.instruction = 0xfa000000;
267bf995 8531 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 8532 }
c19d1205
ZW
8533}
8534
8535static void
8536do_bx (void)
8537{
845b51d6
PB
8538 bfd_boolean want_reloc;
8539
c19d1205
ZW
8540 if (inst.operands[0].reg == REG_PC)
8541 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 8542
c19d1205 8543 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
8544 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8545 it is for ARMv4t or earlier. */
8546 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8547 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
8548 want_reloc = TRUE;
8549
5ad34203 8550#ifdef OBJ_ELF
845b51d6 8551 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 8552#endif
584206db 8553 want_reloc = FALSE;
845b51d6
PB
8554
8555 if (want_reloc)
8556 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
8557}
8558
c19d1205
ZW
8559
8560/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
8561
8562static void
c19d1205 8563do_bxj (void)
a737bd4d 8564{
c19d1205
ZW
8565 if (inst.operands[0].reg == REG_PC)
8566 as_tsktsk (_("use of r15 in bxj is not really useful"));
8567
8568 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
8569}
8570
c19d1205
ZW
8571/* Co-processor data operation:
8572 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8573 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8574static void
8575do_cdp (void)
8576{
8577 inst.instruction |= inst.operands[0].reg << 8;
8578 inst.instruction |= inst.operands[1].imm << 20;
8579 inst.instruction |= inst.operands[2].reg << 12;
8580 inst.instruction |= inst.operands[3].reg << 16;
8581 inst.instruction |= inst.operands[4].reg;
8582 inst.instruction |= inst.operands[5].imm << 5;
8583}
a737bd4d
NC
8584
8585static void
c19d1205 8586do_cmp (void)
a737bd4d 8587{
c19d1205
ZW
8588 inst.instruction |= inst.operands[0].reg << 16;
8589 encode_arm_shifter_operand (1);
a737bd4d
NC
8590}
8591
c19d1205
ZW
8592/* Transfer between coprocessor and ARM registers.
8593 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8594 MRC2
8595 MCR{cond}
8596 MCR2
8597
8598 No special properties. */
09d92015 8599
dcbd0d71
MGD
8600struct deprecated_coproc_regs_s
8601{
8602 unsigned cp;
8603 int opc1;
8604 unsigned crn;
8605 unsigned crm;
8606 int opc2;
8607 arm_feature_set deprecated;
8608 arm_feature_set obsoleted;
8609 const char *dep_msg;
8610 const char *obs_msg;
8611};
8612
8613#define DEPR_ACCESS_V8 \
8614 N_("This coprocessor register access is deprecated in ARMv8")
8615
8616/* Table of all deprecated coprocessor registers. */
8617static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8618{
8619 {15, 0, 7, 10, 5, /* CP15DMB. */
823d2571 8620 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8621 DEPR_ACCESS_V8, NULL},
8622 {15, 0, 7, 10, 4, /* CP15DSB. */
823d2571 8623 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8624 DEPR_ACCESS_V8, NULL},
8625 {15, 0, 7, 5, 4, /* CP15ISB. */
823d2571 8626 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8627 DEPR_ACCESS_V8, NULL},
8628 {14, 6, 1, 0, 0, /* TEEHBR. */
823d2571 8629 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8630 DEPR_ACCESS_V8, NULL},
8631 {14, 6, 0, 0, 0, /* TEECR. */
823d2571 8632 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
dcbd0d71
MGD
8633 DEPR_ACCESS_V8, NULL},
8634};
8635
8636#undef DEPR_ACCESS_V8
8637
8638static const size_t deprecated_coproc_reg_count =
8639 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8640
09d92015 8641static void
c19d1205 8642do_co_reg (void)
09d92015 8643{
fdfde340 8644 unsigned Rd;
dcbd0d71 8645 size_t i;
fdfde340
JM
8646
8647 Rd = inst.operands[2].reg;
8648 if (thumb_mode)
8649 {
8650 if (inst.instruction == 0xee000010
8651 || inst.instruction == 0xfe000010)
8652 /* MCR, MCR2 */
8653 reject_bad_reg (Rd);
8654 else
8655 /* MRC, MRC2 */
8656 constraint (Rd == REG_SP, BAD_SP);
8657 }
8658 else
8659 {
8660 /* MCR */
8661 if (inst.instruction == 0xe000010)
8662 constraint (Rd == REG_PC, BAD_PC);
8663 }
8664
dcbd0d71
MGD
8665 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8666 {
8667 const struct deprecated_coproc_regs_s *r =
8668 deprecated_coproc_regs + i;
8669
8670 if (inst.operands[0].reg == r->cp
8671 && inst.operands[1].imm == r->opc1
8672 && inst.operands[3].reg == r->crn
8673 && inst.operands[4].reg == r->crm
8674 && inst.operands[5].imm == r->opc2)
8675 {
b10bf8c5 8676 if (! ARM_CPU_IS_ANY (cpu_variant)
477330fc 8677 && warn_on_deprecated
dcbd0d71 8678 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
5c3696f8 8679 as_tsktsk ("%s", r->dep_msg);
dcbd0d71
MGD
8680 }
8681 }
fdfde340 8682
c19d1205
ZW
8683 inst.instruction |= inst.operands[0].reg << 8;
8684 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 8685 inst.instruction |= Rd << 12;
c19d1205
ZW
8686 inst.instruction |= inst.operands[3].reg << 16;
8687 inst.instruction |= inst.operands[4].reg;
8688 inst.instruction |= inst.operands[5].imm << 5;
8689}
09d92015 8690
c19d1205
ZW
8691/* Transfer between coprocessor register and pair of ARM registers.
8692 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8693 MCRR2
8694 MRRC{cond}
8695 MRRC2
b99bd4ef 8696
c19d1205 8697 Two XScale instructions are special cases of these:
09d92015 8698
c19d1205
ZW
8699 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8700 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 8701
5f4273c7 8702 Result unpredictable if Rd or Rn is R15. */
a737bd4d 8703
c19d1205
ZW
8704static void
8705do_co_reg2c (void)
8706{
fdfde340
JM
8707 unsigned Rd, Rn;
8708
8709 Rd = inst.operands[2].reg;
8710 Rn = inst.operands[3].reg;
8711
8712 if (thumb_mode)
8713 {
8714 reject_bad_reg (Rd);
8715 reject_bad_reg (Rn);
8716 }
8717 else
8718 {
8719 constraint (Rd == REG_PC, BAD_PC);
8720 constraint (Rn == REG_PC, BAD_PC);
8721 }
8722
873f10f0
TC
8723 /* Only check the MRRC{2} variants. */
8724 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
8725 {
8726 /* If Rd == Rn, error that the operation is
8727 unpredictable (example MRRC p3,#1,r1,r1,c4). */
8728 constraint (Rd == Rn, BAD_OVERLAP);
8729 }
8730
c19d1205
ZW
8731 inst.instruction |= inst.operands[0].reg << 8;
8732 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
8733 inst.instruction |= Rd << 12;
8734 inst.instruction |= Rn << 16;
c19d1205 8735 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
8736}
8737
c19d1205
ZW
8738static void
8739do_cpsi (void)
8740{
8741 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
8742 if (inst.operands[1].present)
8743 {
8744 inst.instruction |= CPSI_MMOD;
8745 inst.instruction |= inst.operands[1].imm;
8746 }
c19d1205 8747}
b99bd4ef 8748
62b3e311
PB
8749static void
8750do_dbg (void)
8751{
8752 inst.instruction |= inst.operands[0].imm;
8753}
8754
eea54501
MGD
8755static void
8756do_div (void)
8757{
8758 unsigned Rd, Rn, Rm;
8759
8760 Rd = inst.operands[0].reg;
8761 Rn = (inst.operands[1].present
8762 ? inst.operands[1].reg : Rd);
8763 Rm = inst.operands[2].reg;
8764
8765 constraint ((Rd == REG_PC), BAD_PC);
8766 constraint ((Rn == REG_PC), BAD_PC);
8767 constraint ((Rm == REG_PC), BAD_PC);
8768
8769 inst.instruction |= Rd << 16;
8770 inst.instruction |= Rn << 0;
8771 inst.instruction |= Rm << 8;
8772}
8773
b99bd4ef 8774static void
c19d1205 8775do_it (void)
b99bd4ef 8776{
c19d1205 8777 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
8778 process it to do the validation as if in
8779 thumb mode, just in case the code gets
8780 assembled for thumb using the unified syntax. */
8781
c19d1205 8782 inst.size = 0;
e07e6e58
NC
8783 if (unified_syntax)
8784 {
8785 set_it_insn_type (IT_INSN);
8786 now_it.mask = (inst.instruction & 0xf) | 0x10;
8787 now_it.cc = inst.operands[0].imm;
8788 }
09d92015 8789}
b99bd4ef 8790
6530b175
NC
8791/* If there is only one register in the register list,
8792 then return its register number. Otherwise return -1. */
8793static int
8794only_one_reg_in_list (int range)
8795{
8796 int i = ffs (range) - 1;
8797 return (i > 15 || range != (1 << i)) ? -1 : i;
8798}
8799
09d92015 8800static void
6530b175 8801encode_ldmstm(int from_push_pop_mnem)
ea6ef066 8802{
c19d1205
ZW
8803 int base_reg = inst.operands[0].reg;
8804 int range = inst.operands[1].imm;
6530b175 8805 int one_reg;
ea6ef066 8806
c19d1205
ZW
8807 inst.instruction |= base_reg << 16;
8808 inst.instruction |= range;
ea6ef066 8809
c19d1205
ZW
8810 if (inst.operands[1].writeback)
8811 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 8812
c19d1205 8813 if (inst.operands[0].writeback)
ea6ef066 8814 {
c19d1205
ZW
8815 inst.instruction |= WRITE_BACK;
8816 /* Check for unpredictable uses of writeback. */
8817 if (inst.instruction & LOAD_BIT)
09d92015 8818 {
c19d1205
ZW
8819 /* Not allowed in LDM type 2. */
8820 if ((inst.instruction & LDM_TYPE_2_OR_3)
8821 && ((range & (1 << REG_PC)) == 0))
8822 as_warn (_("writeback of base register is UNPREDICTABLE"));
8823 /* Only allowed if base reg not in list for other types. */
8824 else if (range & (1 << base_reg))
8825 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8826 }
8827 else /* STM. */
8828 {
8829 /* Not allowed for type 2. */
8830 if (inst.instruction & LDM_TYPE_2_OR_3)
8831 as_warn (_("writeback of base register is UNPREDICTABLE"));
8832 /* Only allowed if base reg not in list, or first in list. */
8833 else if ((range & (1 << base_reg))
8834 && (range & ((1 << base_reg) - 1)))
8835 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 8836 }
ea6ef066 8837 }
6530b175
NC
8838
8839 /* If PUSH/POP has only one register, then use the A2 encoding. */
8840 one_reg = only_one_reg_in_list (range);
8841 if (from_push_pop_mnem && one_reg >= 0)
8842 {
8843 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8844
8845 inst.instruction &= A_COND_MASK;
8846 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8847 inst.instruction |= one_reg << 12;
8848 }
8849}
8850
8851static void
8852do_ldmstm (void)
8853{
8854 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
a737bd4d
NC
8855}
8856
c19d1205
ZW
8857/* ARMv5TE load-consecutive (argument parse)
8858 Mode is like LDRH.
8859
8860 LDRccD R, mode
8861 STRccD R, mode. */
8862
a737bd4d 8863static void
c19d1205 8864do_ldrd (void)
a737bd4d 8865{
c19d1205 8866 constraint (inst.operands[0].reg % 2 != 0,
c56791bb 8867 _("first transfer register must be even"));
c19d1205
ZW
8868 constraint (inst.operands[1].present
8869 && inst.operands[1].reg != inst.operands[0].reg + 1,
c56791bb 8870 _("can only transfer two consecutive registers"));
c19d1205
ZW
8871 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8872 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 8873
c19d1205
ZW
8874 if (!inst.operands[1].present)
8875 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 8876
c56791bb
RE
8877 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8878 register and the first register written; we have to diagnose
8879 overlap between the base and the second register written here. */
ea6ef066 8880
c56791bb
RE
8881 if (inst.operands[2].reg == inst.operands[1].reg
8882 && (inst.operands[2].writeback || inst.operands[2].postind))
8883 as_warn (_("base register written back, and overlaps "
8884 "second transfer register"));
b05fe5cf 8885
c56791bb
RE
8886 if (!(inst.instruction & V4_STR_BIT))
8887 {
c19d1205 8888 /* For an index-register load, the index register must not overlap the
c56791bb
RE
8889 destination (even if not write-back). */
8890 if (inst.operands[2].immisreg
8891 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8892 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8893 as_warn (_("index register overlaps transfer register"));
b05fe5cf 8894 }
c19d1205
ZW
8895 inst.instruction |= inst.operands[0].reg << 12;
8896 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
8897}
8898
8899static void
c19d1205 8900do_ldrex (void)
b05fe5cf 8901{
c19d1205
ZW
8902 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8903 || inst.operands[1].postind || inst.operands[1].writeback
8904 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
8905 || inst.operands[1].negative
8906 /* This can arise if the programmer has written
8907 strex rN, rM, foo
8908 or if they have mistakenly used a register name as the last
8909 operand, eg:
8910 strex rN, rM, rX
8911 It is very difficult to distinguish between these two cases
8912 because "rX" might actually be a label. ie the register
8913 name has been occluded by a symbol of the same name. So we
8914 just generate a general 'bad addressing mode' type error
8915 message and leave it up to the programmer to discover the
8916 true cause and fix their mistake. */
8917 || (inst.operands[1].reg == REG_PC),
8918 BAD_ADDR_MODE);
b05fe5cf 8919
c19d1205
ZW
8920 constraint (inst.reloc.exp.X_op != O_constant
8921 || inst.reloc.exp.X_add_number != 0,
8922 _("offset must be zero in ARM encoding"));
b05fe5cf 8923
5be8be5d
DG
8924 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8925
c19d1205
ZW
8926 inst.instruction |= inst.operands[0].reg << 12;
8927 inst.instruction |= inst.operands[1].reg << 16;
8928 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
8929}
8930
8931static void
c19d1205 8932do_ldrexd (void)
b05fe5cf 8933{
c19d1205
ZW
8934 constraint (inst.operands[0].reg % 2 != 0,
8935 _("even register required"));
8936 constraint (inst.operands[1].present
8937 && inst.operands[1].reg != inst.operands[0].reg + 1,
8938 _("can only load two consecutive registers"));
8939 /* If op 1 were present and equal to PC, this function wouldn't
8940 have been called in the first place. */
8941 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 8942
c19d1205
ZW
8943 inst.instruction |= inst.operands[0].reg << 12;
8944 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
8945}
8946
1be5fd2e
NC
8947/* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8948 which is not a multiple of four is UNPREDICTABLE. */
8949static void
8950check_ldr_r15_aligned (void)
8951{
8952 constraint (!(inst.operands[1].immisreg)
8953 && (inst.operands[0].reg == REG_PC
8954 && inst.operands[1].reg == REG_PC
8955 && (inst.reloc.exp.X_add_number & 0x3)),
8956 _("ldr to register 15 must be 4-byte alligned"));
8957}
8958
b05fe5cf 8959static void
c19d1205 8960do_ldst (void)
b05fe5cf 8961{
c19d1205
ZW
8962 inst.instruction |= inst.operands[0].reg << 12;
8963 if (!inst.operands[1].isreg)
8335d6aa 8964 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
b05fe5cf 8965 return;
c19d1205 8966 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
1be5fd2e 8967 check_ldr_r15_aligned ();
b05fe5cf
ZW
8968}
8969
8970static void
c19d1205 8971do_ldstt (void)
b05fe5cf 8972{
c19d1205
ZW
8973 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8974 reject [Rn,...]. */
8975 if (inst.operands[1].preind)
b05fe5cf 8976 {
bd3ba5d1
NC
8977 constraint (inst.reloc.exp.X_op != O_constant
8978 || inst.reloc.exp.X_add_number != 0,
c19d1205 8979 _("this instruction requires a post-indexed address"));
b05fe5cf 8980
c19d1205
ZW
8981 inst.operands[1].preind = 0;
8982 inst.operands[1].postind = 1;
8983 inst.operands[1].writeback = 1;
b05fe5cf 8984 }
c19d1205
ZW
8985 inst.instruction |= inst.operands[0].reg << 12;
8986 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
8987}
b05fe5cf 8988
c19d1205 8989/* Halfword and signed-byte load/store operations. */
b05fe5cf 8990
c19d1205
ZW
8991static void
8992do_ldstv4 (void)
8993{
ff4a8d2b 8994 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205
ZW
8995 inst.instruction |= inst.operands[0].reg << 12;
8996 if (!inst.operands[1].isreg)
8335d6aa 8997 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
b05fe5cf 8998 return;
c19d1205 8999 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
9000}
9001
9002static void
c19d1205 9003do_ldsttv4 (void)
b05fe5cf 9004{
c19d1205
ZW
9005 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9006 reject [Rn,...]. */
9007 if (inst.operands[1].preind)
b05fe5cf 9008 {
bd3ba5d1
NC
9009 constraint (inst.reloc.exp.X_op != O_constant
9010 || inst.reloc.exp.X_add_number != 0,
c19d1205 9011 _("this instruction requires a post-indexed address"));
b05fe5cf 9012
c19d1205
ZW
9013 inst.operands[1].preind = 0;
9014 inst.operands[1].postind = 1;
9015 inst.operands[1].writeback = 1;
b05fe5cf 9016 }
c19d1205
ZW
9017 inst.instruction |= inst.operands[0].reg << 12;
9018 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9019}
b05fe5cf 9020
c19d1205
ZW
9021/* Co-processor register load/store.
9022 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9023static void
9024do_lstc (void)
9025{
9026 inst.instruction |= inst.operands[0].reg << 8;
9027 inst.instruction |= inst.operands[1].reg << 12;
9028 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
9029}
9030
b05fe5cf 9031static void
c19d1205 9032do_mlas (void)
b05fe5cf 9033{
8fb9d7b9 9034 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 9035 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 9036 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 9037 && !(inst.instruction & 0x00400000))
8fb9d7b9 9038 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 9039
c19d1205
ZW
9040 inst.instruction |= inst.operands[0].reg << 16;
9041 inst.instruction |= inst.operands[1].reg;
9042 inst.instruction |= inst.operands[2].reg << 8;
9043 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 9044}
b05fe5cf 9045
c19d1205
ZW
9046static void
9047do_mov (void)
9048{
a9f02af8
MG
9049 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9050 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9051 THUMB1_RELOC_ONLY);
c19d1205
ZW
9052 inst.instruction |= inst.operands[0].reg << 12;
9053 encode_arm_shifter_operand (1);
9054}
b05fe5cf 9055
c19d1205
ZW
9056/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9057static void
9058do_mov16 (void)
9059{
b6895b4f
PB
9060 bfd_vma imm;
9061 bfd_boolean top;
9062
9063 top = (inst.instruction & 0x00400000) != 0;
9064 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
33eaf5de 9065 _(":lower16: not allowed in this instruction"));
b6895b4f 9066 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
33eaf5de 9067 _(":upper16: not allowed in this instruction"));
c19d1205 9068 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
9069 if (inst.reloc.type == BFD_RELOC_UNUSED)
9070 {
9071 imm = inst.reloc.exp.X_add_number;
9072 /* The value is in two pieces: 0:11, 16:19. */
9073 inst.instruction |= (imm & 0x00000fff);
9074 inst.instruction |= (imm & 0x0000f000) << 4;
9075 }
b05fe5cf 9076}
b99bd4ef 9077
037e8744
JB
9078static int
9079do_vfp_nsyn_mrs (void)
9080{
9081 if (inst.operands[0].isvec)
9082 {
9083 if (inst.operands[1].reg != 1)
477330fc 9084 first_error (_("operand 1 must be FPSCR"));
037e8744
JB
9085 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9086 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9087 do_vfp_nsyn_opcode ("fmstat");
9088 }
9089 else if (inst.operands[1].isvec)
9090 do_vfp_nsyn_opcode ("fmrx");
9091 else
9092 return FAIL;
5f4273c7 9093
037e8744
JB
9094 return SUCCESS;
9095}
9096
9097static int
9098do_vfp_nsyn_msr (void)
9099{
9100 if (inst.operands[0].isvec)
9101 do_vfp_nsyn_opcode ("fmxr");
9102 else
9103 return FAIL;
9104
9105 return SUCCESS;
9106}
9107
f7c21dc7
NC
9108static void
9109do_vmrs (void)
9110{
9111 unsigned Rt = inst.operands[0].reg;
fa94de6b 9112
16d02dc9 9113 if (thumb_mode && Rt == REG_SP)
f7c21dc7
NC
9114 {
9115 inst.error = BAD_SP;
9116 return;
9117 }
9118
9119 /* APSR_ sets isvec. All other refs to PC are illegal. */
16d02dc9 9120 if (!inst.operands[0].isvec && Rt == REG_PC)
f7c21dc7
NC
9121 {
9122 inst.error = BAD_PC;
9123 return;
9124 }
9125
16d02dc9
JB
9126 /* If we get through parsing the register name, we just insert the number
9127 generated into the instruction without further validation. */
9128 inst.instruction |= (inst.operands[1].reg << 16);
f7c21dc7
NC
9129 inst.instruction |= (Rt << 12);
9130}
9131
9132static void
9133do_vmsr (void)
9134{
9135 unsigned Rt = inst.operands[1].reg;
fa94de6b 9136
f7c21dc7
NC
9137 if (thumb_mode)
9138 reject_bad_reg (Rt);
9139 else if (Rt == REG_PC)
9140 {
9141 inst.error = BAD_PC;
9142 return;
9143 }
9144
16d02dc9
JB
9145 /* If we get through parsing the register name, we just insert the number
9146 generated into the instruction without further validation. */
9147 inst.instruction |= (inst.operands[0].reg << 16);
f7c21dc7
NC
9148 inst.instruction |= (Rt << 12);
9149}
9150
b99bd4ef 9151static void
c19d1205 9152do_mrs (void)
b99bd4ef 9153{
90ec0d68
MGD
9154 unsigned br;
9155
037e8744
JB
9156 if (do_vfp_nsyn_mrs () == SUCCESS)
9157 return;
9158
ff4a8d2b 9159 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
c19d1205 9160 inst.instruction |= inst.operands[0].reg << 12;
90ec0d68
MGD
9161
9162 if (inst.operands[1].isreg)
9163 {
9164 br = inst.operands[1].reg;
9165 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
9166 as_bad (_("bad register for mrs"));
9167 }
9168 else
9169 {
9170 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9171 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9172 != (PSR_c|PSR_f),
d2cd1205 9173 _("'APSR', 'CPSR' or 'SPSR' expected"));
90ec0d68
MGD
9174 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9175 }
9176
9177 inst.instruction |= br;
c19d1205 9178}
b99bd4ef 9179
c19d1205
ZW
9180/* Two possible forms:
9181 "{C|S}PSR_<field>, Rm",
9182 "{C|S}PSR_f, #expression". */
b99bd4ef 9183
c19d1205
ZW
9184static void
9185do_msr (void)
9186{
037e8744
JB
9187 if (do_vfp_nsyn_msr () == SUCCESS)
9188 return;
9189
c19d1205
ZW
9190 inst.instruction |= inst.operands[0].imm;
9191 if (inst.operands[1].isreg)
9192 inst.instruction |= inst.operands[1].reg;
9193 else
b99bd4ef 9194 {
c19d1205
ZW
9195 inst.instruction |= INST_IMMEDIATE;
9196 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9197 inst.reloc.pc_rel = 0;
b99bd4ef 9198 }
b99bd4ef
NC
9199}
9200
c19d1205
ZW
9201static void
9202do_mul (void)
a737bd4d 9203{
ff4a8d2b
NC
9204 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9205
c19d1205
ZW
9206 if (!inst.operands[2].present)
9207 inst.operands[2].reg = inst.operands[0].reg;
9208 inst.instruction |= inst.operands[0].reg << 16;
9209 inst.instruction |= inst.operands[1].reg;
9210 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 9211
8fb9d7b9
MS
9212 if (inst.operands[0].reg == inst.operands[1].reg
9213 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9214 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
9215}
9216
c19d1205
ZW
9217/* Long Multiply Parser
9218 UMULL RdLo, RdHi, Rm, Rs
9219 SMULL RdLo, RdHi, Rm, Rs
9220 UMLAL RdLo, RdHi, Rm, Rs
9221 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
9222
9223static void
c19d1205 9224do_mull (void)
b99bd4ef 9225{
c19d1205
ZW
9226 inst.instruction |= inst.operands[0].reg << 12;
9227 inst.instruction |= inst.operands[1].reg << 16;
9228 inst.instruction |= inst.operands[2].reg;
9229 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 9230
682b27ad
PB
9231 /* rdhi and rdlo must be different. */
9232 if (inst.operands[0].reg == inst.operands[1].reg)
9233 as_tsktsk (_("rdhi and rdlo must be different"));
9234
9235 /* rdhi, rdlo and rm must all be different before armv6. */
9236 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 9237 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 9238 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
9239 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9240}
b99bd4ef 9241
c19d1205
ZW
9242static void
9243do_nop (void)
9244{
e7495e45
NS
9245 if (inst.operands[0].present
9246 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
9247 {
9248 /* Architectural NOP hints are CPSR sets with no bits selected. */
9249 inst.instruction &= 0xf0000000;
e7495e45
NS
9250 inst.instruction |= 0x0320f000;
9251 if (inst.operands[0].present)
9252 inst.instruction |= inst.operands[0].imm;
c19d1205 9253 }
b99bd4ef
NC
9254}
9255
c19d1205
ZW
9256/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9257 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9258 Condition defaults to COND_ALWAYS.
9259 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
9260
9261static void
c19d1205 9262do_pkhbt (void)
b99bd4ef 9263{
c19d1205
ZW
9264 inst.instruction |= inst.operands[0].reg << 12;
9265 inst.instruction |= inst.operands[1].reg << 16;
9266 inst.instruction |= inst.operands[2].reg;
9267 if (inst.operands[3].present)
9268 encode_arm_shift (3);
9269}
b99bd4ef 9270
c19d1205 9271/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 9272
c19d1205
ZW
9273static void
9274do_pkhtb (void)
9275{
9276 if (!inst.operands[3].present)
b99bd4ef 9277 {
c19d1205
ZW
9278 /* If the shift specifier is omitted, turn the instruction
9279 into pkhbt rd, rm, rn. */
9280 inst.instruction &= 0xfff00010;
9281 inst.instruction |= inst.operands[0].reg << 12;
9282 inst.instruction |= inst.operands[1].reg;
9283 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9284 }
9285 else
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 encode_arm_shift (3);
b99bd4ef
NC
9291 }
9292}
9293
c19d1205 9294/* ARMv5TE: Preload-Cache
60e5ef9f 9295 MP Extensions: Preload for write
c19d1205 9296
60e5ef9f 9297 PLD(W) <addr_mode>
c19d1205
ZW
9298
9299 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
9300
9301static void
c19d1205 9302do_pld (void)
b99bd4ef 9303{
c19d1205
ZW
9304 constraint (!inst.operands[0].isreg,
9305 _("'[' expected after PLD mnemonic"));
9306 constraint (inst.operands[0].postind,
9307 _("post-indexed expression used in preload instruction"));
9308 constraint (inst.operands[0].writeback,
9309 _("writeback used in preload instruction"));
9310 constraint (!inst.operands[0].preind,
9311 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
9312 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9313}
b99bd4ef 9314
62b3e311
PB
9315/* ARMv7: PLI <addr_mode> */
9316static void
9317do_pli (void)
9318{
9319 constraint (!inst.operands[0].isreg,
9320 _("'[' expected after PLI mnemonic"));
9321 constraint (inst.operands[0].postind,
9322 _("post-indexed expression used in preload instruction"));
9323 constraint (inst.operands[0].writeback,
9324 _("writeback used in preload instruction"));
9325 constraint (!inst.operands[0].preind,
9326 _("unindexed addressing used in preload instruction"));
9327 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9328 inst.instruction &= ~PRE_INDEX;
9329}
9330
c19d1205
ZW
9331static void
9332do_push_pop (void)
9333{
5e0d7f77
MP
9334 constraint (inst.operands[0].writeback,
9335 _("push/pop do not support {reglist}^"));
c19d1205
ZW
9336 inst.operands[1] = inst.operands[0];
9337 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9338 inst.operands[0].isreg = 1;
9339 inst.operands[0].writeback = 1;
9340 inst.operands[0].reg = REG_SP;
6530b175 9341 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
c19d1205 9342}
b99bd4ef 9343
c19d1205
ZW
9344/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9345 word at the specified address and the following word
9346 respectively.
9347 Unconditionally executed.
9348 Error if Rn is R15. */
b99bd4ef 9349
c19d1205
ZW
9350static void
9351do_rfe (void)
9352{
9353 inst.instruction |= inst.operands[0].reg << 16;
9354 if (inst.operands[0].writeback)
9355 inst.instruction |= WRITE_BACK;
9356}
b99bd4ef 9357
c19d1205 9358/* ARM V6 ssat (argument parse). */
b99bd4ef 9359
c19d1205
ZW
9360static void
9361do_ssat (void)
9362{
9363 inst.instruction |= inst.operands[0].reg << 12;
9364 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9365 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9366
c19d1205
ZW
9367 if (inst.operands[3].present)
9368 encode_arm_shift (3);
b99bd4ef
NC
9369}
9370
c19d1205 9371/* ARM V6 usat (argument parse). */
b99bd4ef
NC
9372
9373static void
c19d1205 9374do_usat (void)
b99bd4ef 9375{
c19d1205
ZW
9376 inst.instruction |= inst.operands[0].reg << 12;
9377 inst.instruction |= inst.operands[1].imm << 16;
9378 inst.instruction |= inst.operands[2].reg;
b99bd4ef 9379
c19d1205
ZW
9380 if (inst.operands[3].present)
9381 encode_arm_shift (3);
b99bd4ef
NC
9382}
9383
c19d1205 9384/* ARM V6 ssat16 (argument parse). */
09d92015
MM
9385
9386static void
c19d1205 9387do_ssat16 (void)
09d92015 9388{
c19d1205
ZW
9389 inst.instruction |= inst.operands[0].reg << 12;
9390 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9391 inst.instruction |= inst.operands[2].reg;
09d92015
MM
9392}
9393
c19d1205
ZW
9394static void
9395do_usat16 (void)
a737bd4d 9396{
c19d1205
ZW
9397 inst.instruction |= inst.operands[0].reg << 12;
9398 inst.instruction |= inst.operands[1].imm << 16;
9399 inst.instruction |= inst.operands[2].reg;
9400}
a737bd4d 9401
c19d1205
ZW
9402/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9403 preserving the other bits.
a737bd4d 9404
c19d1205
ZW
9405 setend <endian_specifier>, where <endian_specifier> is either
9406 BE or LE. */
a737bd4d 9407
c19d1205
ZW
9408static void
9409do_setend (void)
9410{
12e37cbc
MGD
9411 if (warn_on_deprecated
9412 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 9413 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 9414
c19d1205
ZW
9415 if (inst.operands[0].imm)
9416 inst.instruction |= 0x200;
a737bd4d
NC
9417}
9418
9419static void
c19d1205 9420do_shift (void)
a737bd4d 9421{
c19d1205
ZW
9422 unsigned int Rm = (inst.operands[1].present
9423 ? inst.operands[1].reg
9424 : inst.operands[0].reg);
a737bd4d 9425
c19d1205
ZW
9426 inst.instruction |= inst.operands[0].reg << 12;
9427 inst.instruction |= Rm;
9428 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 9429 {
c19d1205
ZW
9430 inst.instruction |= inst.operands[2].reg << 8;
9431 inst.instruction |= SHIFT_BY_REG;
94342ec3
NC
9432 /* PR 12854: Error on extraneous shifts. */
9433 constraint (inst.operands[2].shifted,
9434 _("extraneous shift as part of operand to shift insn"));
a737bd4d
NC
9435 }
9436 else
c19d1205 9437 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
9438}
9439
09d92015 9440static void
3eb17e6b 9441do_smc (void)
09d92015 9442{
3eb17e6b 9443 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 9444 inst.reloc.pc_rel = 0;
09d92015
MM
9445}
9446
90ec0d68
MGD
9447static void
9448do_hvc (void)
9449{
9450 inst.reloc.type = BFD_RELOC_ARM_HVC;
9451 inst.reloc.pc_rel = 0;
9452}
9453
09d92015 9454static void
c19d1205 9455do_swi (void)
09d92015 9456{
c19d1205
ZW
9457 inst.reloc.type = BFD_RELOC_ARM_SWI;
9458 inst.reloc.pc_rel = 0;
09d92015
MM
9459}
9460
ddfded2f
MW
9461static void
9462do_setpan (void)
9463{
9464 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9465 _("selected processor does not support SETPAN instruction"));
9466
9467 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9468}
9469
9470static void
9471do_t_setpan (void)
9472{
9473 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9474 _("selected processor does not support SETPAN instruction"));
9475
9476 inst.instruction |= (inst.operands[0].imm << 3);
9477}
9478
c19d1205
ZW
9479/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9480 SMLAxy{cond} Rd,Rm,Rs,Rn
9481 SMLAWy{cond} Rd,Rm,Rs,Rn
9482 Error if any register is R15. */
e16bb312 9483
c19d1205
ZW
9484static void
9485do_smla (void)
e16bb312 9486{
c19d1205
ZW
9487 inst.instruction |= inst.operands[0].reg << 16;
9488 inst.instruction |= inst.operands[1].reg;
9489 inst.instruction |= inst.operands[2].reg << 8;
9490 inst.instruction |= inst.operands[3].reg << 12;
9491}
a737bd4d 9492
c19d1205
ZW
9493/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9494 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9495 Error if any register is R15.
9496 Warning if Rdlo == Rdhi. */
a737bd4d 9497
c19d1205
ZW
9498static void
9499do_smlal (void)
9500{
9501 inst.instruction |= inst.operands[0].reg << 12;
9502 inst.instruction |= inst.operands[1].reg << 16;
9503 inst.instruction |= inst.operands[2].reg;
9504 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 9505
c19d1205
ZW
9506 if (inst.operands[0].reg == inst.operands[1].reg)
9507 as_tsktsk (_("rdhi and rdlo must be different"));
9508}
a737bd4d 9509
c19d1205
ZW
9510/* ARM V5E (El Segundo) signed-multiply (argument parse)
9511 SMULxy{cond} Rd,Rm,Rs
9512 Error if any register is R15. */
a737bd4d 9513
c19d1205
ZW
9514static void
9515do_smul (void)
9516{
9517 inst.instruction |= inst.operands[0].reg << 16;
9518 inst.instruction |= inst.operands[1].reg;
9519 inst.instruction |= inst.operands[2].reg << 8;
9520}
a737bd4d 9521
b6702015
PB
9522/* ARM V6 srs (argument parse). The variable fields in the encoding are
9523 the same for both ARM and Thumb-2. */
a737bd4d 9524
c19d1205
ZW
9525static void
9526do_srs (void)
9527{
b6702015
PB
9528 int reg;
9529
9530 if (inst.operands[0].present)
9531 {
9532 reg = inst.operands[0].reg;
fdfde340 9533 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
9534 }
9535 else
fdfde340 9536 reg = REG_SP;
b6702015
PB
9537
9538 inst.instruction |= reg << 16;
9539 inst.instruction |= inst.operands[1].imm;
9540 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
9541 inst.instruction |= WRITE_BACK;
9542}
a737bd4d 9543
c19d1205 9544/* ARM V6 strex (argument parse). */
a737bd4d 9545
c19d1205
ZW
9546static void
9547do_strex (void)
9548{
9549 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9550 || inst.operands[2].postind || inst.operands[2].writeback
9551 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
9552 || inst.operands[2].negative
9553 /* See comment in do_ldrex(). */
9554 || (inst.operands[2].reg == REG_PC),
9555 BAD_ADDR_MODE);
a737bd4d 9556
c19d1205
ZW
9557 constraint (inst.operands[0].reg == inst.operands[1].reg
9558 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 9559
c19d1205
ZW
9560 constraint (inst.reloc.exp.X_op != O_constant
9561 || inst.reloc.exp.X_add_number != 0,
9562 _("offset must be zero in ARM encoding"));
a737bd4d 9563
c19d1205
ZW
9564 inst.instruction |= inst.operands[0].reg << 12;
9565 inst.instruction |= inst.operands[1].reg;
9566 inst.instruction |= inst.operands[2].reg << 16;
9567 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
9568}
9569
877807f8
NC
9570static void
9571do_t_strexbh (void)
9572{
9573 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9574 || inst.operands[2].postind || inst.operands[2].writeback
9575 || inst.operands[2].immisreg || inst.operands[2].shifted
9576 || inst.operands[2].negative,
9577 BAD_ADDR_MODE);
9578
9579 constraint (inst.operands[0].reg == inst.operands[1].reg
9580 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9581
9582 do_rm_rd_rn ();
9583}
9584
e16bb312 9585static void
c19d1205 9586do_strexd (void)
e16bb312 9587{
c19d1205
ZW
9588 constraint (inst.operands[1].reg % 2 != 0,
9589 _("even register required"));
9590 constraint (inst.operands[2].present
9591 && inst.operands[2].reg != inst.operands[1].reg + 1,
9592 _("can only store two consecutive registers"));
9593 /* If op 2 were present and equal to PC, this function wouldn't
9594 have been called in the first place. */
9595 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 9596
c19d1205
ZW
9597 constraint (inst.operands[0].reg == inst.operands[1].reg
9598 || inst.operands[0].reg == inst.operands[1].reg + 1
9599 || inst.operands[0].reg == inst.operands[3].reg,
9600 BAD_OVERLAP);
e16bb312 9601
c19d1205
ZW
9602 inst.instruction |= inst.operands[0].reg << 12;
9603 inst.instruction |= inst.operands[1].reg;
9604 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
9605}
9606
9eb6c0f1
MGD
9607/* ARM V8 STRL. */
9608static void
4b8c8c02 9609do_stlex (void)
9eb6c0f1
MGD
9610{
9611 constraint (inst.operands[0].reg == inst.operands[1].reg
9612 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9613
9614 do_rd_rm_rn ();
9615}
9616
9617static void
4b8c8c02 9618do_t_stlex (void)
9eb6c0f1
MGD
9619{
9620 constraint (inst.operands[0].reg == inst.operands[1].reg
9621 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9622
9623 do_rm_rd_rn ();
9624}
9625
c19d1205
ZW
9626/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9627 extends it to 32-bits, and adds the result to a value in another
9628 register. You can specify a rotation by 0, 8, 16, or 24 bits
9629 before extracting the 16-bit value.
9630 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9631 Condition defaults to COND_ALWAYS.
9632 Error if any register uses R15. */
9633
e16bb312 9634static void
c19d1205 9635do_sxtah (void)
e16bb312 9636{
c19d1205
ZW
9637 inst.instruction |= inst.operands[0].reg << 12;
9638 inst.instruction |= inst.operands[1].reg << 16;
9639 inst.instruction |= inst.operands[2].reg;
9640 inst.instruction |= inst.operands[3].imm << 10;
9641}
e16bb312 9642
c19d1205 9643/* ARM V6 SXTH.
e16bb312 9644
c19d1205
ZW
9645 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9646 Condition defaults to COND_ALWAYS.
9647 Error if any register uses R15. */
e16bb312
NC
9648
9649static void
c19d1205 9650do_sxth (void)
e16bb312 9651{
c19d1205
ZW
9652 inst.instruction |= inst.operands[0].reg << 12;
9653 inst.instruction |= inst.operands[1].reg;
9654 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 9655}
c19d1205
ZW
9656\f
9657/* VFP instructions. In a logical order: SP variant first, monad
9658 before dyad, arithmetic then move then load/store. */
e16bb312
NC
9659
9660static void
c19d1205 9661do_vfp_sp_monadic (void)
e16bb312 9662{
5287ad62
JB
9663 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9664 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9665}
9666
9667static void
c19d1205 9668do_vfp_sp_dyadic (void)
e16bb312 9669{
5287ad62
JB
9670 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9671 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9672 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9673}
9674
9675static void
c19d1205 9676do_vfp_sp_compare_z (void)
e16bb312 9677{
5287ad62 9678 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
9679}
9680
9681static void
c19d1205 9682do_vfp_dp_sp_cvt (void)
e16bb312 9683{
5287ad62
JB
9684 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9685 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
9686}
9687
9688static void
c19d1205 9689do_vfp_sp_dp_cvt (void)
e16bb312 9690{
5287ad62
JB
9691 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9692 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
9693}
9694
9695static void
c19d1205 9696do_vfp_reg_from_sp (void)
e16bb312 9697{
c19d1205 9698 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 9699 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
9700}
9701
9702static void
c19d1205 9703do_vfp_reg2_from_sp2 (void)
e16bb312 9704{
c19d1205
ZW
9705 constraint (inst.operands[2].imm != 2,
9706 _("only two consecutive VFP SP registers allowed here"));
9707 inst.instruction |= inst.operands[0].reg << 12;
9708 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 9709 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
9710}
9711
9712static void
c19d1205 9713do_vfp_sp_from_reg (void)
e16bb312 9714{
5287ad62 9715 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 9716 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
9717}
9718
9719static void
c19d1205 9720do_vfp_sp2_from_reg2 (void)
e16bb312 9721{
c19d1205
ZW
9722 constraint (inst.operands[0].imm != 2,
9723 _("only two consecutive VFP SP registers allowed here"));
5287ad62 9724 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
9725 inst.instruction |= inst.operands[1].reg << 12;
9726 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
9727}
9728
9729static void
c19d1205 9730do_vfp_sp_ldst (void)
e16bb312 9731{
5287ad62 9732 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 9733 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9734}
9735
9736static void
c19d1205 9737do_vfp_dp_ldst (void)
e16bb312 9738{
5287ad62 9739 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 9740 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
9741}
9742
c19d1205 9743
e16bb312 9744static void
c19d1205 9745vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9746{
c19d1205
ZW
9747 if (inst.operands[0].writeback)
9748 inst.instruction |= WRITE_BACK;
9749 else
9750 constraint (ldstm_type != VFP_LDSTMIA,
9751 _("this addressing mode requires base-register writeback"));
9752 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9753 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 9754 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
9755}
9756
9757static void
c19d1205 9758vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 9759{
c19d1205 9760 int count;
e16bb312 9761
c19d1205
ZW
9762 if (inst.operands[0].writeback)
9763 inst.instruction |= WRITE_BACK;
9764 else
9765 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9766 _("this addressing mode requires base-register writeback"));
e16bb312 9767
c19d1205 9768 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 9769 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 9770
c19d1205
ZW
9771 count = inst.operands[1].imm << 1;
9772 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9773 count += 1;
e16bb312 9774
c19d1205 9775 inst.instruction |= count;
e16bb312
NC
9776}
9777
9778static void
c19d1205 9779do_vfp_sp_ldstmia (void)
e16bb312 9780{
c19d1205 9781 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9782}
9783
9784static void
c19d1205 9785do_vfp_sp_ldstmdb (void)
e16bb312 9786{
c19d1205 9787 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9788}
9789
9790static void
c19d1205 9791do_vfp_dp_ldstmia (void)
e16bb312 9792{
c19d1205 9793 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
9794}
9795
9796static void
c19d1205 9797do_vfp_dp_ldstmdb (void)
e16bb312 9798{
c19d1205 9799 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
9800}
9801
9802static void
c19d1205 9803do_vfp_xp_ldstmia (void)
e16bb312 9804{
c19d1205
ZW
9805 vfp_dp_ldstm (VFP_LDSTMIAX);
9806}
e16bb312 9807
c19d1205
ZW
9808static void
9809do_vfp_xp_ldstmdb (void)
9810{
9811 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 9812}
5287ad62
JB
9813
9814static void
9815do_vfp_dp_rd_rm (void)
9816{
9817 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9818 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9819}
9820
9821static void
9822do_vfp_dp_rn_rd (void)
9823{
9824 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9825 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9826}
9827
9828static void
9829do_vfp_dp_rd_rn (void)
9830{
9831 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9832 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9833}
9834
9835static void
9836do_vfp_dp_rd_rn_rm (void)
9837{
9838 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9839 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9840 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9841}
9842
9843static void
9844do_vfp_dp_rd (void)
9845{
9846 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9847}
9848
9849static void
9850do_vfp_dp_rm_rd_rn (void)
9851{
9852 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9853 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9854 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9855}
9856
9857/* VFPv3 instructions. */
9858static void
9859do_vfp_sp_const (void)
9860{
9861 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
9862 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9863 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9864}
9865
9866static void
9867do_vfp_dp_const (void)
9868{
9869 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
9870 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9871 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
9872}
9873
9874static void
9875vfp_conv (int srcsize)
9876{
5f1af56b
MGD
9877 int immbits = srcsize - inst.operands[1].imm;
9878
fa94de6b
RM
9879 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9880 {
5f1af56b 9881 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
477330fc 9882 i.e. immbits must be in range 0 - 16. */
5f1af56b
MGD
9883 inst.error = _("immediate value out of range, expected range [0, 16]");
9884 return;
9885 }
fa94de6b 9886 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
5f1af56b
MGD
9887 {
9888 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
477330fc 9889 i.e. immbits must be in range 0 - 31. */
5f1af56b
MGD
9890 inst.error = _("immediate value out of range, expected range [1, 32]");
9891 return;
9892 }
9893
5287ad62
JB
9894 inst.instruction |= (immbits & 1) << 5;
9895 inst.instruction |= (immbits >> 1);
9896}
9897
9898static void
9899do_vfp_sp_conv_16 (void)
9900{
9901 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9902 vfp_conv (16);
9903}
9904
9905static void
9906do_vfp_dp_conv_16 (void)
9907{
9908 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9909 vfp_conv (16);
9910}
9911
9912static void
9913do_vfp_sp_conv_32 (void)
9914{
9915 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9916 vfp_conv (32);
9917}
9918
9919static void
9920do_vfp_dp_conv_32 (void)
9921{
9922 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9923 vfp_conv (32);
9924}
c19d1205
ZW
9925\f
9926/* FPA instructions. Also in a logical order. */
e16bb312 9927
c19d1205
ZW
9928static void
9929do_fpa_cmp (void)
9930{
9931 inst.instruction |= inst.operands[0].reg << 16;
9932 inst.instruction |= inst.operands[1].reg;
9933}
b99bd4ef
NC
9934
9935static void
c19d1205 9936do_fpa_ldmstm (void)
b99bd4ef 9937{
c19d1205
ZW
9938 inst.instruction |= inst.operands[0].reg << 12;
9939 switch (inst.operands[1].imm)
9940 {
9941 case 1: inst.instruction |= CP_T_X; break;
9942 case 2: inst.instruction |= CP_T_Y; break;
9943 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9944 case 4: break;
9945 default: abort ();
9946 }
b99bd4ef 9947
c19d1205
ZW
9948 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9949 {
9950 /* The instruction specified "ea" or "fd", so we can only accept
9951 [Rn]{!}. The instruction does not really support stacking or
9952 unstacking, so we have to emulate these by setting appropriate
9953 bits and offsets. */
9954 constraint (inst.reloc.exp.X_op != O_constant
9955 || inst.reloc.exp.X_add_number != 0,
9956 _("this instruction does not support indexing"));
b99bd4ef 9957
c19d1205
ZW
9958 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9959 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 9960
c19d1205
ZW
9961 if (!(inst.instruction & INDEX_UP))
9962 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 9963
c19d1205
ZW
9964 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
9965 {
9966 inst.operands[2].preind = 0;
9967 inst.operands[2].postind = 1;
9968 }
9969 }
b99bd4ef 9970
c19d1205 9971 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 9972}
c19d1205
ZW
9973\f
9974/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 9975
c19d1205
ZW
9976static void
9977do_iwmmxt_tandorc (void)
9978{
9979 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
9980}
b99bd4ef 9981
c19d1205
ZW
9982static void
9983do_iwmmxt_textrc (void)
9984{
9985 inst.instruction |= inst.operands[0].reg << 12;
9986 inst.instruction |= inst.operands[1].imm;
9987}
b99bd4ef
NC
9988
9989static void
c19d1205 9990do_iwmmxt_textrm (void)
b99bd4ef 9991{
c19d1205
ZW
9992 inst.instruction |= inst.operands[0].reg << 12;
9993 inst.instruction |= inst.operands[1].reg << 16;
9994 inst.instruction |= inst.operands[2].imm;
9995}
b99bd4ef 9996
c19d1205
ZW
9997static void
9998do_iwmmxt_tinsr (void)
9999{
10000 inst.instruction |= inst.operands[0].reg << 16;
10001 inst.instruction |= inst.operands[1].reg << 12;
10002 inst.instruction |= inst.operands[2].imm;
10003}
b99bd4ef 10004
c19d1205
ZW
10005static void
10006do_iwmmxt_tmia (void)
10007{
10008 inst.instruction |= inst.operands[0].reg << 5;
10009 inst.instruction |= inst.operands[1].reg;
10010 inst.instruction |= inst.operands[2].reg << 12;
10011}
b99bd4ef 10012
c19d1205
ZW
10013static void
10014do_iwmmxt_waligni (void)
10015{
10016 inst.instruction |= inst.operands[0].reg << 12;
10017 inst.instruction |= inst.operands[1].reg << 16;
10018 inst.instruction |= inst.operands[2].reg;
10019 inst.instruction |= inst.operands[3].imm << 20;
10020}
b99bd4ef 10021
2d447fca
JM
10022static void
10023do_iwmmxt_wmerge (void)
10024{
10025 inst.instruction |= inst.operands[0].reg << 12;
10026 inst.instruction |= inst.operands[1].reg << 16;
10027 inst.instruction |= inst.operands[2].reg;
10028 inst.instruction |= inst.operands[3].imm << 21;
10029}
10030
c19d1205
ZW
10031static void
10032do_iwmmxt_wmov (void)
10033{
10034 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10035 inst.instruction |= inst.operands[0].reg << 12;
10036 inst.instruction |= inst.operands[1].reg << 16;
10037 inst.instruction |= inst.operands[1].reg;
10038}
b99bd4ef 10039
c19d1205
ZW
10040static void
10041do_iwmmxt_wldstbh (void)
10042{
8f06b2d8 10043 int reloc;
c19d1205 10044 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
10045 if (thumb_mode)
10046 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10047 else
10048 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10049 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
10050}
10051
c19d1205
ZW
10052static void
10053do_iwmmxt_wldstw (void)
10054{
10055 /* RIWR_RIWC clears .isreg for a control register. */
10056 if (!inst.operands[0].isreg)
10057 {
10058 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10059 inst.instruction |= 0xf0000000;
10060 }
b99bd4ef 10061
c19d1205
ZW
10062 inst.instruction |= inst.operands[0].reg << 12;
10063 encode_arm_cp_address (1, TRUE, TRUE, 0);
10064}
b99bd4ef
NC
10065
10066static void
c19d1205 10067do_iwmmxt_wldstd (void)
b99bd4ef 10068{
c19d1205 10069 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
10070 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10071 && inst.operands[1].immisreg)
10072 {
10073 inst.instruction &= ~0x1a000ff;
eff0bc54 10074 inst.instruction |= (0xfU << 28);
2d447fca
JM
10075 if (inst.operands[1].preind)
10076 inst.instruction |= PRE_INDEX;
10077 if (!inst.operands[1].negative)
10078 inst.instruction |= INDEX_UP;
10079 if (inst.operands[1].writeback)
10080 inst.instruction |= WRITE_BACK;
10081 inst.instruction |= inst.operands[1].reg << 16;
10082 inst.instruction |= inst.reloc.exp.X_add_number << 4;
10083 inst.instruction |= inst.operands[1].imm;
10084 }
10085 else
10086 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 10087}
b99bd4ef 10088
c19d1205
ZW
10089static void
10090do_iwmmxt_wshufh (void)
10091{
10092 inst.instruction |= inst.operands[0].reg << 12;
10093 inst.instruction |= inst.operands[1].reg << 16;
10094 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10095 inst.instruction |= (inst.operands[2].imm & 0x0f);
10096}
b99bd4ef 10097
c19d1205
ZW
10098static void
10099do_iwmmxt_wzero (void)
10100{
10101 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10102 inst.instruction |= inst.operands[0].reg;
10103 inst.instruction |= inst.operands[0].reg << 12;
10104 inst.instruction |= inst.operands[0].reg << 16;
10105}
2d447fca
JM
10106
10107static void
10108do_iwmmxt_wrwrwr_or_imm5 (void)
10109{
10110 if (inst.operands[2].isreg)
10111 do_rd_rn_rm ();
10112 else {
10113 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10114 _("immediate operand requires iWMMXt2"));
10115 do_rd_rn ();
10116 if (inst.operands[2].imm == 0)
10117 {
10118 switch ((inst.instruction >> 20) & 0xf)
10119 {
10120 case 4:
10121 case 5:
10122 case 6:
5f4273c7 10123 case 7:
2d447fca
JM
10124 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10125 inst.operands[2].imm = 16;
10126 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10127 break;
10128 case 8:
10129 case 9:
10130 case 10:
10131 case 11:
10132 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10133 inst.operands[2].imm = 32;
10134 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10135 break;
10136 case 12:
10137 case 13:
10138 case 14:
10139 case 15:
10140 {
10141 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10142 unsigned long wrn;
10143 wrn = (inst.instruction >> 16) & 0xf;
10144 inst.instruction &= 0xff0fff0f;
10145 inst.instruction |= wrn;
10146 /* Bail out here; the instruction is now assembled. */
10147 return;
10148 }
10149 }
10150 }
10151 /* Map 32 -> 0, etc. */
10152 inst.operands[2].imm &= 0x1f;
eff0bc54 10153 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
2d447fca
JM
10154 }
10155}
c19d1205
ZW
10156\f
10157/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10158 operations first, then control, shift, and load/store. */
b99bd4ef 10159
c19d1205 10160/* Insns like "foo X,Y,Z". */
b99bd4ef 10161
c19d1205
ZW
10162static void
10163do_mav_triple (void)
10164{
10165 inst.instruction |= inst.operands[0].reg << 16;
10166 inst.instruction |= inst.operands[1].reg;
10167 inst.instruction |= inst.operands[2].reg << 12;
10168}
b99bd4ef 10169
c19d1205
ZW
10170/* Insns like "foo W,X,Y,Z".
10171 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 10172
c19d1205
ZW
10173static void
10174do_mav_quad (void)
10175{
10176 inst.instruction |= inst.operands[0].reg << 5;
10177 inst.instruction |= inst.operands[1].reg << 12;
10178 inst.instruction |= inst.operands[2].reg << 16;
10179 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
10180}
10181
c19d1205
ZW
10182/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10183static void
10184do_mav_dspsc (void)
a737bd4d 10185{
c19d1205
ZW
10186 inst.instruction |= inst.operands[1].reg << 12;
10187}
a737bd4d 10188
c19d1205
ZW
10189/* Maverick shift immediate instructions.
10190 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10191 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 10192
c19d1205
ZW
10193static void
10194do_mav_shift (void)
10195{
10196 int imm = inst.operands[2].imm;
a737bd4d 10197
c19d1205
ZW
10198 inst.instruction |= inst.operands[0].reg << 12;
10199 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 10200
c19d1205
ZW
10201 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10202 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10203 Bit 4 should be 0. */
10204 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 10205
c19d1205
ZW
10206 inst.instruction |= imm;
10207}
10208\f
10209/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 10210
c19d1205
ZW
10211/* Xscale multiply-accumulate (argument parse)
10212 MIAcc acc0,Rm,Rs
10213 MIAPHcc acc0,Rm,Rs
10214 MIAxycc acc0,Rm,Rs. */
a737bd4d 10215
c19d1205
ZW
10216static void
10217do_xsc_mia (void)
10218{
10219 inst.instruction |= inst.operands[1].reg;
10220 inst.instruction |= inst.operands[2].reg << 12;
10221}
a737bd4d 10222
c19d1205 10223/* Xscale move-accumulator-register (argument parse)
a737bd4d 10224
c19d1205 10225 MARcc acc0,RdLo,RdHi. */
b99bd4ef 10226
c19d1205
ZW
10227static void
10228do_xsc_mar (void)
10229{
10230 inst.instruction |= inst.operands[1].reg << 12;
10231 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
10232}
10233
c19d1205 10234/* Xscale move-register-accumulator (argument parse)
b99bd4ef 10235
c19d1205 10236 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
10237
10238static void
c19d1205 10239do_xsc_mra (void)
b99bd4ef 10240{
c19d1205
ZW
10241 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10242 inst.instruction |= inst.operands[0].reg << 12;
10243 inst.instruction |= inst.operands[1].reg << 16;
10244}
10245\f
10246/* Encoding functions relevant only to Thumb. */
b99bd4ef 10247
c19d1205
ZW
10248/* inst.operands[i] is a shifted-register operand; encode
10249 it into inst.instruction in the format used by Thumb32. */
10250
10251static void
10252encode_thumb32_shifted_operand (int i)
10253{
10254 unsigned int value = inst.reloc.exp.X_add_number;
10255 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 10256
9c3c69f2
PB
10257 constraint (inst.operands[i].immisreg,
10258 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
10259 inst.instruction |= inst.operands[i].reg;
10260 if (shift == SHIFT_RRX)
10261 inst.instruction |= SHIFT_ROR << 4;
10262 else
b99bd4ef 10263 {
c19d1205
ZW
10264 constraint (inst.reloc.exp.X_op != O_constant,
10265 _("expression too complex"));
10266
10267 constraint (value > 32
10268 || (value == 32 && (shift == SHIFT_LSL
10269 || shift == SHIFT_ROR)),
10270 _("shift expression is too large"));
10271
10272 if (value == 0)
10273 shift = SHIFT_LSL;
10274 else if (value == 32)
10275 value = 0;
10276
10277 inst.instruction |= shift << 4;
10278 inst.instruction |= (value & 0x1c) << 10;
10279 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 10280 }
c19d1205 10281}
b99bd4ef 10282
b99bd4ef 10283
c19d1205
ZW
10284/* inst.operands[i] was set up by parse_address. Encode it into a
10285 Thumb32 format load or store instruction. Reject forms that cannot
10286 be used with such instructions. If is_t is true, reject forms that
10287 cannot be used with a T instruction; if is_d is true, reject forms
5be8be5d
DG
10288 that cannot be used with a D instruction. If it is a store insn,
10289 reject PC in Rn. */
b99bd4ef 10290
c19d1205
ZW
10291static void
10292encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10293{
5be8be5d 10294 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
c19d1205
ZW
10295
10296 constraint (!inst.operands[i].isreg,
53365c0d 10297 _("Instruction does not support =N addresses"));
b99bd4ef 10298
c19d1205
ZW
10299 inst.instruction |= inst.operands[i].reg << 16;
10300 if (inst.operands[i].immisreg)
b99bd4ef 10301 {
5be8be5d 10302 constraint (is_pc, BAD_PC_ADDRESSING);
c19d1205
ZW
10303 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10304 constraint (inst.operands[i].negative,
10305 _("Thumb does not support negative register indexing"));
10306 constraint (inst.operands[i].postind,
10307 _("Thumb does not support register post-indexing"));
10308 constraint (inst.operands[i].writeback,
10309 _("Thumb does not support register indexing with writeback"));
10310 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10311 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 10312
f40d1643 10313 inst.instruction |= inst.operands[i].imm;
c19d1205 10314 if (inst.operands[i].shifted)
b99bd4ef 10315 {
c19d1205
ZW
10316 constraint (inst.reloc.exp.X_op != O_constant,
10317 _("expression too complex"));
9c3c69f2
PB
10318 constraint (inst.reloc.exp.X_add_number < 0
10319 || inst.reloc.exp.X_add_number > 3,
c19d1205 10320 _("shift out of range"));
9c3c69f2 10321 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
10322 }
10323 inst.reloc.type = BFD_RELOC_UNUSED;
10324 }
10325 else if (inst.operands[i].preind)
10326 {
5be8be5d 10327 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
f40d1643 10328 constraint (is_t && inst.operands[i].writeback,
c19d1205 10329 _("cannot use writeback with this instruction"));
4755303e
WN
10330 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10331 BAD_PC_ADDRESSING);
c19d1205
ZW
10332
10333 if (is_d)
10334 {
10335 inst.instruction |= 0x01000000;
10336 if (inst.operands[i].writeback)
10337 inst.instruction |= 0x00200000;
b99bd4ef 10338 }
c19d1205 10339 else
b99bd4ef 10340 {
c19d1205
ZW
10341 inst.instruction |= 0x00000c00;
10342 if (inst.operands[i].writeback)
10343 inst.instruction |= 0x00000100;
b99bd4ef 10344 }
c19d1205 10345 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 10346 }
c19d1205 10347 else if (inst.operands[i].postind)
b99bd4ef 10348 {
9c2799c2 10349 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
10350 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10351 constraint (is_t, _("cannot use post-indexing with this instruction"));
10352
10353 if (is_d)
10354 inst.instruction |= 0x00200000;
10355 else
10356 inst.instruction |= 0x00000900;
10357 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10358 }
10359 else /* unindexed - only for coprocessor */
10360 inst.error = _("instruction does not accept unindexed addressing");
10361}
10362
10363/* Table of Thumb instructions which exist in both 16- and 32-bit
10364 encodings (the latter only in post-V6T2 cores). The index is the
10365 value used in the insns table below. When there is more than one
10366 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
10367 holds variant (1).
10368 Also contains several pseudo-instructions used during relaxation. */
c19d1205 10369#define T16_32_TAB \
21d799b5
NC
10370 X(_adc, 4140, eb400000), \
10371 X(_adcs, 4140, eb500000), \
10372 X(_add, 1c00, eb000000), \
10373 X(_adds, 1c00, eb100000), \
10374 X(_addi, 0000, f1000000), \
10375 X(_addis, 0000, f1100000), \
10376 X(_add_pc,000f, f20f0000), \
10377 X(_add_sp,000d, f10d0000), \
10378 X(_adr, 000f, f20f0000), \
10379 X(_and, 4000, ea000000), \
10380 X(_ands, 4000, ea100000), \
10381 X(_asr, 1000, fa40f000), \
10382 X(_asrs, 1000, fa50f000), \
10383 X(_b, e000, f000b000), \
10384 X(_bcond, d000, f0008000), \
10385 X(_bic, 4380, ea200000), \
10386 X(_bics, 4380, ea300000), \
10387 X(_cmn, 42c0, eb100f00), \
10388 X(_cmp, 2800, ebb00f00), \
10389 X(_cpsie, b660, f3af8400), \
10390 X(_cpsid, b670, f3af8600), \
10391 X(_cpy, 4600, ea4f0000), \
10392 X(_dec_sp,80dd, f1ad0d00), \
10393 X(_eor, 4040, ea800000), \
10394 X(_eors, 4040, ea900000), \
10395 X(_inc_sp,00dd, f10d0d00), \
10396 X(_ldmia, c800, e8900000), \
10397 X(_ldr, 6800, f8500000), \
10398 X(_ldrb, 7800, f8100000), \
10399 X(_ldrh, 8800, f8300000), \
10400 X(_ldrsb, 5600, f9100000), \
10401 X(_ldrsh, 5e00, f9300000), \
10402 X(_ldr_pc,4800, f85f0000), \
10403 X(_ldr_pc2,4800, f85f0000), \
10404 X(_ldr_sp,9800, f85d0000), \
10405 X(_lsl, 0000, fa00f000), \
10406 X(_lsls, 0000, fa10f000), \
10407 X(_lsr, 0800, fa20f000), \
10408 X(_lsrs, 0800, fa30f000), \
10409 X(_mov, 2000, ea4f0000), \
10410 X(_movs, 2000, ea5f0000), \
10411 X(_mul, 4340, fb00f000), \
10412 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10413 X(_mvn, 43c0, ea6f0000), \
10414 X(_mvns, 43c0, ea7f0000), \
10415 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10416 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10417 X(_orr, 4300, ea400000), \
10418 X(_orrs, 4300, ea500000), \
10419 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10420 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10421 X(_rev, ba00, fa90f080), \
10422 X(_rev16, ba40, fa90f090), \
10423 X(_revsh, bac0, fa90f0b0), \
10424 X(_ror, 41c0, fa60f000), \
10425 X(_rors, 41c0, fa70f000), \
10426 X(_sbc, 4180, eb600000), \
10427 X(_sbcs, 4180, eb700000), \
10428 X(_stmia, c000, e8800000), \
10429 X(_str, 6000, f8400000), \
10430 X(_strb, 7000, f8000000), \
10431 X(_strh, 8000, f8200000), \
10432 X(_str_sp,9000, f84d0000), \
10433 X(_sub, 1e00, eba00000), \
10434 X(_subs, 1e00, ebb00000), \
10435 X(_subi, 8000, f1a00000), \
10436 X(_subis, 8000, f1b00000), \
10437 X(_sxtb, b240, fa4ff080), \
10438 X(_sxth, b200, fa0ff080), \
10439 X(_tst, 4200, ea100f00), \
10440 X(_uxtb, b2c0, fa5ff080), \
10441 X(_uxth, b280, fa1ff080), \
10442 X(_nop, bf00, f3af8000), \
10443 X(_yield, bf10, f3af8001), \
10444 X(_wfe, bf20, f3af8002), \
10445 X(_wfi, bf30, f3af8003), \
53c4b28b 10446 X(_sev, bf40, f3af8004), \
74db7efb
NC
10447 X(_sevl, bf50, f3af8005), \
10448 X(_udf, de00, f7f0a000)
c19d1205
ZW
10449
10450/* To catch errors in encoding functions, the codes are all offset by
10451 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10452 as 16-bit instructions. */
21d799b5 10453#define X(a,b,c) T_MNEM##a
c19d1205
ZW
10454enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10455#undef X
10456
10457#define X(a,b,c) 0x##b
10458static const unsigned short thumb_op16[] = { T16_32_TAB };
10459#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10460#undef X
10461
10462#define X(a,b,c) 0x##c
10463static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
10464#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10465#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
10466#undef X
10467#undef T16_32_TAB
10468
10469/* Thumb instruction encoders, in alphabetical order. */
10470
92e90b6e 10471/* ADDW or SUBW. */
c921be7d 10472
92e90b6e
PB
10473static void
10474do_t_add_sub_w (void)
10475{
10476 int Rd, Rn;
10477
10478 Rd = inst.operands[0].reg;
10479 Rn = inst.operands[1].reg;
10480
539d4391
NC
10481 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10482 is the SP-{plus,minus}-immediate form of the instruction. */
10483 if (Rn == REG_SP)
10484 constraint (Rd == REG_PC, BAD_PC);
10485 else
10486 reject_bad_reg (Rd);
fdfde340 10487
92e90b6e
PB
10488 inst.instruction |= (Rn << 16) | (Rd << 8);
10489 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10490}
10491
c19d1205 10492/* Parse an add or subtract instruction. We get here with inst.instruction
33eaf5de 10493 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
c19d1205
ZW
10494
10495static void
10496do_t_add_sub (void)
10497{
10498 int Rd, Rs, Rn;
10499
10500 Rd = inst.operands[0].reg;
10501 Rs = (inst.operands[1].present
10502 ? inst.operands[1].reg /* Rd, Rs, foo */
10503 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10504
e07e6e58
NC
10505 if (Rd == REG_PC)
10506 set_it_insn_type_last ();
10507
c19d1205
ZW
10508 if (unified_syntax)
10509 {
0110f2b8
PB
10510 bfd_boolean flags;
10511 bfd_boolean narrow;
10512 int opcode;
10513
10514 flags = (inst.instruction == T_MNEM_adds
10515 || inst.instruction == T_MNEM_subs);
10516 if (flags)
e07e6e58 10517 narrow = !in_it_block ();
0110f2b8 10518 else
e07e6e58 10519 narrow = in_it_block ();
c19d1205 10520 if (!inst.operands[2].isreg)
b99bd4ef 10521 {
16805f35
PB
10522 int add;
10523
fdfde340
JM
10524 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10525
16805f35
PB
10526 add = (inst.instruction == T_MNEM_add
10527 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
10528 opcode = 0;
10529 if (inst.size_req != 4)
10530 {
0110f2b8 10531 /* Attempt to use a narrow opcode, with relaxation if
477330fc 10532 appropriate. */
0110f2b8
PB
10533 if (Rd == REG_SP && Rs == REG_SP && !flags)
10534 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10535 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10536 opcode = T_MNEM_add_sp;
10537 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10538 opcode = T_MNEM_add_pc;
10539 else if (Rd <= 7 && Rs <= 7 && narrow)
10540 {
10541 if (flags)
10542 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10543 else
10544 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10545 }
10546 if (opcode)
10547 {
10548 inst.instruction = THUMB_OP16(opcode);
10549 inst.instruction |= (Rd << 4) | Rs;
72d98d16
MG
10550 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10551 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
a9f02af8
MG
10552 {
10553 if (inst.size_req == 2)
10554 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10555 else
10556 inst.relax = opcode;
10557 }
0110f2b8
PB
10558 }
10559 else
10560 constraint (inst.size_req == 2, BAD_HIREG);
10561 }
10562 if (inst.size_req == 4
10563 || (inst.size_req != 2 && !opcode))
10564 {
a9f02af8
MG
10565 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10566 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
10567 THUMB1_RELOC_ONLY);
efd81785
PB
10568 if (Rd == REG_PC)
10569 {
fdfde340 10570 constraint (add, BAD_PC);
efd81785
PB
10571 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10572 _("only SUBS PC, LR, #const allowed"));
10573 constraint (inst.reloc.exp.X_op != O_constant,
10574 _("expression too complex"));
10575 constraint (inst.reloc.exp.X_add_number < 0
10576 || inst.reloc.exp.X_add_number > 0xff,
10577 _("immediate value out of range"));
10578 inst.instruction = T2_SUBS_PC_LR
10579 | inst.reloc.exp.X_add_number;
10580 inst.reloc.type = BFD_RELOC_UNUSED;
10581 return;
10582 }
10583 else if (Rs == REG_PC)
16805f35
PB
10584 {
10585 /* Always use addw/subw. */
10586 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10587 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10588 }
10589 else
10590 {
10591 inst.instruction = THUMB_OP32 (inst.instruction);
10592 inst.instruction = (inst.instruction & 0xe1ffffff)
10593 | 0x10000000;
10594 if (flags)
10595 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10596 else
10597 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10598 }
dc4503c6
PB
10599 inst.instruction |= Rd << 8;
10600 inst.instruction |= Rs << 16;
0110f2b8 10601 }
b99bd4ef 10602 }
c19d1205
ZW
10603 else
10604 {
5f4cb198
NC
10605 unsigned int value = inst.reloc.exp.X_add_number;
10606 unsigned int shift = inst.operands[2].shift_kind;
10607
c19d1205
ZW
10608 Rn = inst.operands[2].reg;
10609 /* See if we can do this with a 16-bit instruction. */
10610 if (!inst.operands[2].shifted && inst.size_req != 4)
10611 {
e27ec89e
PB
10612 if (Rd > 7 || Rs > 7 || Rn > 7)
10613 narrow = FALSE;
10614
10615 if (narrow)
c19d1205 10616 {
e27ec89e
PB
10617 inst.instruction = ((inst.instruction == T_MNEM_adds
10618 || inst.instruction == T_MNEM_add)
c19d1205
ZW
10619 ? T_OPCODE_ADD_R3
10620 : T_OPCODE_SUB_R3);
10621 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10622 return;
10623 }
b99bd4ef 10624
7e806470 10625 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 10626 {
7e806470
PB
10627 /* Thumb-1 cores (except v6-M) require at least one high
10628 register in a narrow non flag setting add. */
10629 if (Rd > 7 || Rn > 7
10630 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10631 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 10632 {
7e806470
PB
10633 if (Rd == Rn)
10634 {
10635 Rn = Rs;
10636 Rs = Rd;
10637 }
c19d1205
ZW
10638 inst.instruction = T_OPCODE_ADD_HI;
10639 inst.instruction |= (Rd & 8) << 4;
10640 inst.instruction |= (Rd & 7);
10641 inst.instruction |= Rn << 3;
10642 return;
10643 }
c19d1205
ZW
10644 }
10645 }
c921be7d 10646
fdfde340
JM
10647 constraint (Rd == REG_PC, BAD_PC);
10648 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10649 constraint (Rs == REG_PC, BAD_PC);
10650 reject_bad_reg (Rn);
10651
c19d1205
ZW
10652 /* If we get here, it can't be done in 16 bits. */
10653 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10654 _("shift must be constant"));
10655 inst.instruction = THUMB_OP32 (inst.instruction);
10656 inst.instruction |= Rd << 8;
10657 inst.instruction |= Rs << 16;
5f4cb198
NC
10658 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10659 _("shift value over 3 not allowed in thumb mode"));
10660 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10661 _("only LSL shift allowed in thumb mode"));
c19d1205
ZW
10662 encode_thumb32_shifted_operand (2);
10663 }
10664 }
10665 else
10666 {
10667 constraint (inst.instruction == T_MNEM_adds
10668 || inst.instruction == T_MNEM_subs,
10669 BAD_THUMB32);
b99bd4ef 10670
c19d1205 10671 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 10672 {
c19d1205
ZW
10673 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10674 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10675 BAD_HIREG);
10676
10677 inst.instruction = (inst.instruction == T_MNEM_add
10678 ? 0x0000 : 0x8000);
10679 inst.instruction |= (Rd << 4) | Rs;
10680 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
10681 return;
10682 }
10683
c19d1205
ZW
10684 Rn = inst.operands[2].reg;
10685 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 10686
c19d1205
ZW
10687 /* We now have Rd, Rs, and Rn set to registers. */
10688 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 10689 {
c19d1205
ZW
10690 /* Can't do this for SUB. */
10691 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10692 inst.instruction = T_OPCODE_ADD_HI;
10693 inst.instruction |= (Rd & 8) << 4;
10694 inst.instruction |= (Rd & 7);
10695 if (Rs == Rd)
10696 inst.instruction |= Rn << 3;
10697 else if (Rn == Rd)
10698 inst.instruction |= Rs << 3;
10699 else
10700 constraint (1, _("dest must overlap one source register"));
10701 }
10702 else
10703 {
10704 inst.instruction = (inst.instruction == T_MNEM_add
10705 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10706 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 10707 }
b99bd4ef 10708 }
b99bd4ef
NC
10709}
10710
c19d1205
ZW
10711static void
10712do_t_adr (void)
10713{
fdfde340
JM
10714 unsigned Rd;
10715
10716 Rd = inst.operands[0].reg;
10717 reject_bad_reg (Rd);
10718
10719 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
10720 {
10721 /* Defer to section relaxation. */
10722 inst.relax = inst.instruction;
10723 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10724 inst.instruction |= Rd << 4;
0110f2b8
PB
10725 }
10726 else if (unified_syntax && inst.size_req != 2)
e9f89963 10727 {
0110f2b8 10728 /* Generate a 32-bit opcode. */
e9f89963 10729 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10730 inst.instruction |= Rd << 8;
e9f89963
PB
10731 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10732 inst.reloc.pc_rel = 1;
10733 }
10734 else
10735 {
0110f2b8 10736 /* Generate a 16-bit opcode. */
e9f89963
PB
10737 inst.instruction = THUMB_OP16 (inst.instruction);
10738 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10739 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10740 inst.reloc.pc_rel = 1;
b99bd4ef 10741
fdfde340 10742 inst.instruction |= Rd << 4;
e9f89963 10743 }
c19d1205 10744}
b99bd4ef 10745
c19d1205
ZW
10746/* Arithmetic instructions for which there is just one 16-bit
10747 instruction encoding, and it allows only two low registers.
10748 For maximal compatibility with ARM syntax, we allow three register
10749 operands even when Thumb-32 instructions are not available, as long
10750 as the first two are identical. For instance, both "sbc r0,r1" and
10751 "sbc r0,r0,r1" are allowed. */
b99bd4ef 10752static void
c19d1205 10753do_t_arit3 (void)
b99bd4ef 10754{
c19d1205 10755 int Rd, Rs, Rn;
b99bd4ef 10756
c19d1205
ZW
10757 Rd = inst.operands[0].reg;
10758 Rs = (inst.operands[1].present
10759 ? inst.operands[1].reg /* Rd, Rs, foo */
10760 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10761 Rn = inst.operands[2].reg;
b99bd4ef 10762
fdfde340
JM
10763 reject_bad_reg (Rd);
10764 reject_bad_reg (Rs);
10765 if (inst.operands[2].isreg)
10766 reject_bad_reg (Rn);
10767
c19d1205 10768 if (unified_syntax)
b99bd4ef 10769 {
c19d1205
ZW
10770 if (!inst.operands[2].isreg)
10771 {
10772 /* For an immediate, we always generate a 32-bit opcode;
10773 section relaxation will shrink it later if possible. */
10774 inst.instruction = THUMB_OP32 (inst.instruction);
10775 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10776 inst.instruction |= Rd << 8;
10777 inst.instruction |= Rs << 16;
10778 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10779 }
10780 else
10781 {
e27ec89e
PB
10782 bfd_boolean narrow;
10783
c19d1205 10784 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10785 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10786 narrow = !in_it_block ();
e27ec89e 10787 else
e07e6e58 10788 narrow = in_it_block ();
e27ec89e
PB
10789
10790 if (Rd > 7 || Rn > 7 || Rs > 7)
10791 narrow = FALSE;
10792 if (inst.operands[2].shifted)
10793 narrow = FALSE;
10794 if (inst.size_req == 4)
10795 narrow = FALSE;
10796
10797 if (narrow
c19d1205
ZW
10798 && Rd == Rs)
10799 {
10800 inst.instruction = THUMB_OP16 (inst.instruction);
10801 inst.instruction |= Rd;
10802 inst.instruction |= Rn << 3;
10803 return;
10804 }
b99bd4ef 10805
c19d1205
ZW
10806 /* If we get here, it can't be done in 16 bits. */
10807 constraint (inst.operands[2].shifted
10808 && inst.operands[2].immisreg,
10809 _("shift must be constant"));
10810 inst.instruction = THUMB_OP32 (inst.instruction);
10811 inst.instruction |= Rd << 8;
10812 inst.instruction |= Rs << 16;
10813 encode_thumb32_shifted_operand (2);
10814 }
a737bd4d 10815 }
c19d1205 10816 else
b99bd4ef 10817 {
c19d1205
ZW
10818 /* On its face this is a lie - the instruction does set the
10819 flags. However, the only supported mnemonic in this mode
10820 says it doesn't. */
10821 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10822
c19d1205
ZW
10823 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10824 _("unshifted register required"));
10825 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10826 constraint (Rd != Rs,
10827 _("dest and source1 must be the same register"));
a737bd4d 10828
c19d1205
ZW
10829 inst.instruction = THUMB_OP16 (inst.instruction);
10830 inst.instruction |= Rd;
10831 inst.instruction |= Rn << 3;
b99bd4ef 10832 }
a737bd4d 10833}
b99bd4ef 10834
c19d1205
ZW
10835/* Similarly, but for instructions where the arithmetic operation is
10836 commutative, so we can allow either of them to be different from
10837 the destination operand in a 16-bit instruction. For instance, all
10838 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10839 accepted. */
10840static void
10841do_t_arit3c (void)
a737bd4d 10842{
c19d1205 10843 int Rd, Rs, Rn;
b99bd4ef 10844
c19d1205
ZW
10845 Rd = inst.operands[0].reg;
10846 Rs = (inst.operands[1].present
10847 ? inst.operands[1].reg /* Rd, Rs, foo */
10848 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10849 Rn = inst.operands[2].reg;
c921be7d 10850
fdfde340
JM
10851 reject_bad_reg (Rd);
10852 reject_bad_reg (Rs);
10853 if (inst.operands[2].isreg)
10854 reject_bad_reg (Rn);
a737bd4d 10855
c19d1205 10856 if (unified_syntax)
a737bd4d 10857 {
c19d1205 10858 if (!inst.operands[2].isreg)
b99bd4ef 10859 {
c19d1205
ZW
10860 /* For an immediate, we always generate a 32-bit opcode;
10861 section relaxation will shrink it later if possible. */
10862 inst.instruction = THUMB_OP32 (inst.instruction);
10863 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10864 inst.instruction |= Rd << 8;
10865 inst.instruction |= Rs << 16;
10866 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10867 }
c19d1205 10868 else
a737bd4d 10869 {
e27ec89e
PB
10870 bfd_boolean narrow;
10871
c19d1205 10872 /* See if we can do this with a 16-bit instruction. */
e27ec89e 10873 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10874 narrow = !in_it_block ();
e27ec89e 10875 else
e07e6e58 10876 narrow = in_it_block ();
e27ec89e
PB
10877
10878 if (Rd > 7 || Rn > 7 || Rs > 7)
10879 narrow = FALSE;
10880 if (inst.operands[2].shifted)
10881 narrow = FALSE;
10882 if (inst.size_req == 4)
10883 narrow = FALSE;
10884
10885 if (narrow)
a737bd4d 10886 {
c19d1205 10887 if (Rd == Rs)
a737bd4d 10888 {
c19d1205
ZW
10889 inst.instruction = THUMB_OP16 (inst.instruction);
10890 inst.instruction |= Rd;
10891 inst.instruction |= Rn << 3;
10892 return;
a737bd4d 10893 }
c19d1205 10894 if (Rd == Rn)
a737bd4d 10895 {
c19d1205
ZW
10896 inst.instruction = THUMB_OP16 (inst.instruction);
10897 inst.instruction |= Rd;
10898 inst.instruction |= Rs << 3;
10899 return;
a737bd4d
NC
10900 }
10901 }
c19d1205
ZW
10902
10903 /* If we get here, it can't be done in 16 bits. */
10904 constraint (inst.operands[2].shifted
10905 && inst.operands[2].immisreg,
10906 _("shift must be constant"));
10907 inst.instruction = THUMB_OP32 (inst.instruction);
10908 inst.instruction |= Rd << 8;
10909 inst.instruction |= Rs << 16;
10910 encode_thumb32_shifted_operand (2);
a737bd4d 10911 }
b99bd4ef 10912 }
c19d1205
ZW
10913 else
10914 {
10915 /* On its face this is a lie - the instruction does set the
10916 flags. However, the only supported mnemonic in this mode
10917 says it doesn't. */
10918 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 10919
c19d1205
ZW
10920 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10921 _("unshifted register required"));
10922 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10923
10924 inst.instruction = THUMB_OP16 (inst.instruction);
10925 inst.instruction |= Rd;
10926
10927 if (Rd == Rs)
10928 inst.instruction |= Rn << 3;
10929 else if (Rd == Rn)
10930 inst.instruction |= Rs << 3;
10931 else
10932 constraint (1, _("dest must overlap one source register"));
10933 }
a737bd4d
NC
10934}
10935
c19d1205
ZW
10936static void
10937do_t_bfc (void)
a737bd4d 10938{
fdfde340 10939 unsigned Rd;
c19d1205
ZW
10940 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10941 constraint (msb > 32, _("bit-field extends past end of register"));
10942 /* The instruction encoding stores the LSB and MSB,
10943 not the LSB and width. */
fdfde340
JM
10944 Rd = inst.operands[0].reg;
10945 reject_bad_reg (Rd);
10946 inst.instruction |= Rd << 8;
c19d1205
ZW
10947 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10948 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10949 inst.instruction |= msb - 1;
b99bd4ef
NC
10950}
10951
c19d1205
ZW
10952static void
10953do_t_bfi (void)
b99bd4ef 10954{
fdfde340 10955 int Rd, Rn;
c19d1205 10956 unsigned int msb;
b99bd4ef 10957
fdfde340
JM
10958 Rd = inst.operands[0].reg;
10959 reject_bad_reg (Rd);
10960
c19d1205
ZW
10961 /* #0 in second position is alternative syntax for bfc, which is
10962 the same instruction but with REG_PC in the Rm field. */
10963 if (!inst.operands[1].isreg)
fdfde340
JM
10964 Rn = REG_PC;
10965 else
10966 {
10967 Rn = inst.operands[1].reg;
10968 reject_bad_reg (Rn);
10969 }
b99bd4ef 10970
c19d1205
ZW
10971 msb = inst.operands[2].imm + inst.operands[3].imm;
10972 constraint (msb > 32, _("bit-field extends past end of register"));
10973 /* The instruction encoding stores the LSB and MSB,
10974 not the LSB and width. */
fdfde340
JM
10975 inst.instruction |= Rd << 8;
10976 inst.instruction |= Rn << 16;
c19d1205
ZW
10977 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10978 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10979 inst.instruction |= msb - 1;
b99bd4ef
NC
10980}
10981
c19d1205
ZW
10982static void
10983do_t_bfx (void)
b99bd4ef 10984{
fdfde340
JM
10985 unsigned Rd, Rn;
10986
10987 Rd = inst.operands[0].reg;
10988 Rn = inst.operands[1].reg;
10989
10990 reject_bad_reg (Rd);
10991 reject_bad_reg (Rn);
10992
c19d1205
ZW
10993 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
10994 _("bit-field extends past end of register"));
fdfde340
JM
10995 inst.instruction |= Rd << 8;
10996 inst.instruction |= Rn << 16;
c19d1205
ZW
10997 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10998 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10999 inst.instruction |= inst.operands[3].imm - 1;
11000}
b99bd4ef 11001
c19d1205
ZW
11002/* ARM V5 Thumb BLX (argument parse)
11003 BLX <target_addr> which is BLX(1)
11004 BLX <Rm> which is BLX(2)
11005 Unfortunately, there are two different opcodes for this mnemonic.
11006 So, the insns[].value is not used, and the code here zaps values
11007 into inst.instruction.
b99bd4ef 11008
c19d1205
ZW
11009 ??? How to take advantage of the additional two bits of displacement
11010 available in Thumb32 mode? Need new relocation? */
b99bd4ef 11011
c19d1205
ZW
11012static void
11013do_t_blx (void)
11014{
e07e6e58
NC
11015 set_it_insn_type_last ();
11016
c19d1205 11017 if (inst.operands[0].isreg)
fdfde340
JM
11018 {
11019 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11020 /* We have a register, so this is BLX(2). */
11021 inst.instruction |= inst.operands[0].reg << 3;
11022 }
b99bd4ef
NC
11023 else
11024 {
c19d1205 11025 /* No register. This must be BLX(1). */
2fc8bdac 11026 inst.instruction = 0xf000e800;
0855e32b 11027 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
b99bd4ef
NC
11028 }
11029}
11030
c19d1205
ZW
11031static void
11032do_t_branch (void)
b99bd4ef 11033{
0110f2b8 11034 int opcode;
dfa9f0d5 11035 int cond;
2fe88214 11036 bfd_reloc_code_real_type reloc;
dfa9f0d5 11037
e07e6e58
NC
11038 cond = inst.cond;
11039 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
11040
11041 if (in_it_block ())
dfa9f0d5
PB
11042 {
11043 /* Conditional branches inside IT blocks are encoded as unconditional
477330fc 11044 branches. */
dfa9f0d5 11045 cond = COND_ALWAYS;
dfa9f0d5
PB
11046 }
11047 else
11048 cond = inst.cond;
11049
11050 if (cond != COND_ALWAYS)
0110f2b8
PB
11051 opcode = T_MNEM_bcond;
11052 else
11053 opcode = inst.instruction;
11054
12d6b0b7
RS
11055 if (unified_syntax
11056 && (inst.size_req == 4
10960bfb
PB
11057 || (inst.size_req != 2
11058 && (inst.operands[0].hasreloc
11059 || inst.reloc.exp.X_op == O_constant))))
c19d1205 11060 {
0110f2b8 11061 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 11062 if (cond == COND_ALWAYS)
9ae92b05 11063 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
11064 else
11065 {
ff8646ee
TP
11066 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11067 _("selected architecture does not support "
11068 "wide conditional branch instruction"));
11069
9c2799c2 11070 gas_assert (cond != 0xF);
dfa9f0d5 11071 inst.instruction |= cond << 22;
9ae92b05 11072 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
c19d1205
ZW
11073 }
11074 }
b99bd4ef
NC
11075 else
11076 {
0110f2b8 11077 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 11078 if (cond == COND_ALWAYS)
9ae92b05 11079 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
c19d1205 11080 else
b99bd4ef 11081 {
dfa9f0d5 11082 inst.instruction |= cond << 8;
9ae92b05 11083 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 11084 }
0110f2b8
PB
11085 /* Allow section relaxation. */
11086 if (unified_syntax && inst.size_req != 2)
11087 inst.relax = opcode;
b99bd4ef 11088 }
9ae92b05 11089 inst.reloc.type = reloc;
c19d1205 11090 inst.reloc.pc_rel = 1;
b99bd4ef
NC
11091}
11092
8884b720 11093/* Actually do the work for Thumb state bkpt and hlt. The only difference
bacebabc 11094 between the two is the maximum immediate allowed - which is passed in
8884b720 11095 RANGE. */
b99bd4ef 11096static void
8884b720 11097do_t_bkpt_hlt1 (int range)
b99bd4ef 11098{
dfa9f0d5
PB
11099 constraint (inst.cond != COND_ALWAYS,
11100 _("instruction is always unconditional"));
c19d1205 11101 if (inst.operands[0].present)
b99bd4ef 11102 {
8884b720 11103 constraint (inst.operands[0].imm > range,
c19d1205
ZW
11104 _("immediate value out of range"));
11105 inst.instruction |= inst.operands[0].imm;
b99bd4ef 11106 }
8884b720
MGD
11107
11108 set_it_insn_type (NEUTRAL_IT_INSN);
11109}
11110
11111static void
11112do_t_hlt (void)
11113{
11114 do_t_bkpt_hlt1 (63);
11115}
11116
11117static void
11118do_t_bkpt (void)
11119{
11120 do_t_bkpt_hlt1 (255);
b99bd4ef
NC
11121}
11122
11123static void
c19d1205 11124do_t_branch23 (void)
b99bd4ef 11125{
e07e6e58 11126 set_it_insn_type_last ();
0855e32b 11127 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
fa94de6b 11128
0855e32b
NS
11129 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11130 this file. We used to simply ignore the PLT reloc type here --
11131 the branch encoding is now needed to deal with TLSCALL relocs.
11132 So if we see a PLT reloc now, put it back to how it used to be to
11133 keep the preexisting behaviour. */
11134 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
11135 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a 11136
4343666d 11137#if defined(OBJ_COFF)
c19d1205
ZW
11138 /* If the destination of the branch is a defined symbol which does not have
11139 the THUMB_FUNC attribute, then we must be calling a function which has
11140 the (interfacearm) attribute. We look for the Thumb entry point to that
11141 function and change the branch to refer to that function instead. */
11142 if ( inst.reloc.exp.X_op == O_symbol
11143 && inst.reloc.exp.X_add_symbol != NULL
11144 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
11145 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
11146 inst.reloc.exp.X_add_symbol =
11147 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 11148#endif
90e4755a
RE
11149}
11150
11151static void
c19d1205 11152do_t_bx (void)
90e4755a 11153{
e07e6e58 11154 set_it_insn_type_last ();
c19d1205
ZW
11155 inst.instruction |= inst.operands[0].reg << 3;
11156 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11157 should cause the alignment to be checked once it is known. This is
11158 because BX PC only works if the instruction is word aligned. */
11159}
90e4755a 11160
c19d1205
ZW
11161static void
11162do_t_bxj (void)
11163{
fdfde340 11164 int Rm;
90e4755a 11165
e07e6e58 11166 set_it_insn_type_last ();
fdfde340
JM
11167 Rm = inst.operands[0].reg;
11168 reject_bad_reg (Rm);
11169 inst.instruction |= Rm << 16;
90e4755a
RE
11170}
11171
11172static void
c19d1205 11173do_t_clz (void)
90e4755a 11174{
fdfde340
JM
11175 unsigned Rd;
11176 unsigned Rm;
11177
11178 Rd = inst.operands[0].reg;
11179 Rm = inst.operands[1].reg;
11180
11181 reject_bad_reg (Rd);
11182 reject_bad_reg (Rm);
11183
11184 inst.instruction |= Rd << 8;
11185 inst.instruction |= Rm << 16;
11186 inst.instruction |= Rm;
c19d1205 11187}
90e4755a 11188
dfa9f0d5
PB
11189static void
11190do_t_cps (void)
11191{
e07e6e58 11192 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
11193 inst.instruction |= inst.operands[0].imm;
11194}
11195
c19d1205
ZW
11196static void
11197do_t_cpsi (void)
11198{
e07e6e58 11199 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 11200 if (unified_syntax
62b3e311
PB
11201 && (inst.operands[1].present || inst.size_req == 4)
11202 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 11203 {
c19d1205
ZW
11204 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11205 inst.instruction = 0xf3af8000;
11206 inst.instruction |= imod << 9;
11207 inst.instruction |= inst.operands[0].imm << 5;
11208 if (inst.operands[1].present)
11209 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 11210 }
c19d1205 11211 else
90e4755a 11212 {
62b3e311
PB
11213 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11214 && (inst.operands[0].imm & 4),
11215 _("selected processor does not support 'A' form "
11216 "of this instruction"));
11217 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
11218 _("Thumb does not support the 2-argument "
11219 "form of this instruction"));
11220 inst.instruction |= inst.operands[0].imm;
90e4755a 11221 }
90e4755a
RE
11222}
11223
c19d1205
ZW
11224/* THUMB CPY instruction (argument parse). */
11225
90e4755a 11226static void
c19d1205 11227do_t_cpy (void)
90e4755a 11228{
c19d1205 11229 if (inst.size_req == 4)
90e4755a 11230 {
c19d1205
ZW
11231 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11232 inst.instruction |= inst.operands[0].reg << 8;
11233 inst.instruction |= inst.operands[1].reg;
90e4755a 11234 }
c19d1205 11235 else
90e4755a 11236 {
c19d1205
ZW
11237 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11238 inst.instruction |= (inst.operands[0].reg & 0x7);
11239 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 11240 }
90e4755a
RE
11241}
11242
90e4755a 11243static void
25fe350b 11244do_t_cbz (void)
90e4755a 11245{
e07e6e58 11246 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
11247 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11248 inst.instruction |= inst.operands[0].reg;
11249 inst.reloc.pc_rel = 1;
11250 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11251}
90e4755a 11252
62b3e311
PB
11253static void
11254do_t_dbg (void)
11255{
11256 inst.instruction |= inst.operands[0].imm;
11257}
11258
11259static void
11260do_t_div (void)
11261{
fdfde340
JM
11262 unsigned Rd, Rn, Rm;
11263
11264 Rd = inst.operands[0].reg;
11265 Rn = (inst.operands[1].present
11266 ? inst.operands[1].reg : Rd);
11267 Rm = inst.operands[2].reg;
11268
11269 reject_bad_reg (Rd);
11270 reject_bad_reg (Rn);
11271 reject_bad_reg (Rm);
11272
11273 inst.instruction |= Rd << 8;
11274 inst.instruction |= Rn << 16;
11275 inst.instruction |= Rm;
62b3e311
PB
11276}
11277
c19d1205
ZW
11278static void
11279do_t_hint (void)
11280{
11281 if (unified_syntax && inst.size_req == 4)
11282 inst.instruction = THUMB_OP32 (inst.instruction);
11283 else
11284 inst.instruction = THUMB_OP16 (inst.instruction);
11285}
90e4755a 11286
c19d1205
ZW
11287static void
11288do_t_it (void)
11289{
11290 unsigned int cond = inst.operands[0].imm;
e27ec89e 11291
e07e6e58
NC
11292 set_it_insn_type (IT_INSN);
11293 now_it.mask = (inst.instruction & 0xf) | 0x10;
11294 now_it.cc = cond;
5a01bb1d 11295 now_it.warn_deprecated = FALSE;
e27ec89e
PB
11296
11297 /* If the condition is a negative condition, invert the mask. */
c19d1205 11298 if ((cond & 0x1) == 0x0)
90e4755a 11299 {
c19d1205 11300 unsigned int mask = inst.instruction & 0x000f;
90e4755a 11301
c19d1205 11302 if ((mask & 0x7) == 0)
5a01bb1d
MGD
11303 {
11304 /* No conversion needed. */
11305 now_it.block_length = 1;
11306 }
c19d1205 11307 else if ((mask & 0x3) == 0)
5a01bb1d
MGD
11308 {
11309 mask ^= 0x8;
11310 now_it.block_length = 2;
11311 }
e27ec89e 11312 else if ((mask & 0x1) == 0)
5a01bb1d
MGD
11313 {
11314 mask ^= 0xC;
11315 now_it.block_length = 3;
11316 }
c19d1205 11317 else
5a01bb1d
MGD
11318 {
11319 mask ^= 0xE;
11320 now_it.block_length = 4;
11321 }
90e4755a 11322
e27ec89e
PB
11323 inst.instruction &= 0xfff0;
11324 inst.instruction |= mask;
c19d1205 11325 }
90e4755a 11326
c19d1205
ZW
11327 inst.instruction |= cond << 4;
11328}
90e4755a 11329
3c707909
PB
11330/* Helper function used for both push/pop and ldm/stm. */
11331static void
11332encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11333{
11334 bfd_boolean load;
11335
11336 load = (inst.instruction & (1 << 20)) != 0;
11337
11338 if (mask & (1 << 13))
11339 inst.error = _("SP not allowed in register list");
1e5b0379
NC
11340
11341 if ((mask & (1 << base)) != 0
11342 && writeback)
11343 inst.error = _("having the base register in the register list when "
11344 "using write back is UNPREDICTABLE");
11345
3c707909
PB
11346 if (load)
11347 {
e07e6e58 11348 if (mask & (1 << 15))
477330fc
RM
11349 {
11350 if (mask & (1 << 14))
11351 inst.error = _("LR and PC should not both be in register list");
11352 else
11353 set_it_insn_type_last ();
11354 }
3c707909
PB
11355 }
11356 else
11357 {
11358 if (mask & (1 << 15))
11359 inst.error = _("PC not allowed in register list");
3c707909
PB
11360 }
11361
11362 if ((mask & (mask - 1)) == 0)
11363 {
11364 /* Single register transfers implemented as str/ldr. */
11365 if (writeback)
11366 {
11367 if (inst.instruction & (1 << 23))
11368 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11369 else
11370 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11371 }
11372 else
11373 {
11374 if (inst.instruction & (1 << 23))
11375 inst.instruction = 0x00800000; /* ia -> [base] */
11376 else
11377 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11378 }
11379
11380 inst.instruction |= 0xf8400000;
11381 if (load)
11382 inst.instruction |= 0x00100000;
11383
5f4273c7 11384 mask = ffs (mask) - 1;
3c707909
PB
11385 mask <<= 12;
11386 }
11387 else if (writeback)
11388 inst.instruction |= WRITE_BACK;
11389
11390 inst.instruction |= mask;
11391 inst.instruction |= base << 16;
11392}
11393
c19d1205
ZW
11394static void
11395do_t_ldmstm (void)
11396{
11397 /* This really doesn't seem worth it. */
11398 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11399 _("expression too complex"));
11400 constraint (inst.operands[1].writeback,
11401 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 11402
c19d1205
ZW
11403 if (unified_syntax)
11404 {
3c707909
PB
11405 bfd_boolean narrow;
11406 unsigned mask;
11407
11408 narrow = FALSE;
c19d1205
ZW
11409 /* See if we can use a 16-bit instruction. */
11410 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11411 && inst.size_req != 4
3c707909 11412 && !(inst.operands[1].imm & ~0xff))
90e4755a 11413 {
3c707909 11414 mask = 1 << inst.operands[0].reg;
90e4755a 11415
eab4f823 11416 if (inst.operands[0].reg <= 7)
90e4755a 11417 {
3c707909 11418 if (inst.instruction == T_MNEM_stmia
eab4f823
MGD
11419 ? inst.operands[0].writeback
11420 : (inst.operands[0].writeback
11421 == !(inst.operands[1].imm & mask)))
477330fc 11422 {
eab4f823
MGD
11423 if (inst.instruction == T_MNEM_stmia
11424 && (inst.operands[1].imm & mask)
11425 && (inst.operands[1].imm & (mask - 1)))
11426 as_warn (_("value stored for r%d is UNKNOWN"),
11427 inst.operands[0].reg);
3c707909 11428
eab4f823
MGD
11429 inst.instruction = THUMB_OP16 (inst.instruction);
11430 inst.instruction |= inst.operands[0].reg << 8;
11431 inst.instruction |= inst.operands[1].imm;
11432 narrow = TRUE;
11433 }
11434 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11435 {
11436 /* This means 1 register in reg list one of 3 situations:
11437 1. Instruction is stmia, but without writeback.
11438 2. lmdia without writeback, but with Rn not in
477330fc 11439 reglist.
eab4f823
MGD
11440 3. ldmia with writeback, but with Rn in reglist.
11441 Case 3 is UNPREDICTABLE behaviour, so we handle
11442 case 1 and 2 which can be converted into a 16-bit
11443 str or ldr. The SP cases are handled below. */
11444 unsigned long opcode;
11445 /* First, record an error for Case 3. */
11446 if (inst.operands[1].imm & mask
11447 && inst.operands[0].writeback)
fa94de6b 11448 inst.error =
eab4f823
MGD
11449 _("having the base register in the register list when "
11450 "using write back is UNPREDICTABLE");
fa94de6b
RM
11451
11452 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
eab4f823
MGD
11453 : T_MNEM_ldr);
11454 inst.instruction = THUMB_OP16 (opcode);
11455 inst.instruction |= inst.operands[0].reg << 3;
11456 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11457 narrow = TRUE;
11458 }
90e4755a 11459 }
eab4f823 11460 else if (inst.operands[0] .reg == REG_SP)
90e4755a 11461 {
eab4f823
MGD
11462 if (inst.operands[0].writeback)
11463 {
fa94de6b 11464 inst.instruction =
eab4f823 11465 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11466 ? T_MNEM_push : T_MNEM_pop);
eab4f823 11467 inst.instruction |= inst.operands[1].imm;
477330fc 11468 narrow = TRUE;
eab4f823
MGD
11469 }
11470 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11471 {
fa94de6b 11472 inst.instruction =
eab4f823 11473 THUMB_OP16 (inst.instruction == T_MNEM_stmia
477330fc 11474 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
eab4f823 11475 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
477330fc 11476 narrow = TRUE;
eab4f823 11477 }
90e4755a 11478 }
3c707909
PB
11479 }
11480
11481 if (!narrow)
11482 {
c19d1205
ZW
11483 if (inst.instruction < 0xffff)
11484 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 11485
5f4273c7
NC
11486 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11487 inst.operands[0].writeback);
90e4755a
RE
11488 }
11489 }
c19d1205 11490 else
90e4755a 11491 {
c19d1205
ZW
11492 constraint (inst.operands[0].reg > 7
11493 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
11494 constraint (inst.instruction != T_MNEM_ldmia
11495 && inst.instruction != T_MNEM_stmia,
11496 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 11497 if (inst.instruction == T_MNEM_stmia)
f03698e6 11498 {
c19d1205
ZW
11499 if (!inst.operands[0].writeback)
11500 as_warn (_("this instruction will write back the base register"));
11501 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11502 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
1e5b0379 11503 as_warn (_("value stored for r%d is UNKNOWN"),
c19d1205 11504 inst.operands[0].reg);
f03698e6 11505 }
c19d1205 11506 else
90e4755a 11507 {
c19d1205
ZW
11508 if (!inst.operands[0].writeback
11509 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11510 as_warn (_("this instruction will write back the base register"));
11511 else if (inst.operands[0].writeback
11512 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11513 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
11514 }
11515
c19d1205
ZW
11516 inst.instruction = THUMB_OP16 (inst.instruction);
11517 inst.instruction |= inst.operands[0].reg << 8;
11518 inst.instruction |= inst.operands[1].imm;
11519 }
11520}
e28cd48c 11521
c19d1205
ZW
11522static void
11523do_t_ldrex (void)
11524{
11525 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11526 || inst.operands[1].postind || inst.operands[1].writeback
11527 || inst.operands[1].immisreg || inst.operands[1].shifted
11528 || inst.operands[1].negative,
01cfc07f 11529 BAD_ADDR_MODE);
e28cd48c 11530
5be8be5d
DG
11531 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11532
c19d1205
ZW
11533 inst.instruction |= inst.operands[0].reg << 12;
11534 inst.instruction |= inst.operands[1].reg << 16;
11535 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11536}
e28cd48c 11537
c19d1205
ZW
11538static void
11539do_t_ldrexd (void)
11540{
11541 if (!inst.operands[1].present)
1cac9012 11542 {
c19d1205
ZW
11543 constraint (inst.operands[0].reg == REG_LR,
11544 _("r14 not allowed as first register "
11545 "when second register is omitted"));
11546 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 11547 }
c19d1205
ZW
11548 constraint (inst.operands[0].reg == inst.operands[1].reg,
11549 BAD_OVERLAP);
b99bd4ef 11550
c19d1205
ZW
11551 inst.instruction |= inst.operands[0].reg << 12;
11552 inst.instruction |= inst.operands[1].reg << 8;
11553 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
11554}
11555
11556static void
c19d1205 11557do_t_ldst (void)
b99bd4ef 11558{
0110f2b8
PB
11559 unsigned long opcode;
11560 int Rn;
11561
e07e6e58
NC
11562 if (inst.operands[0].isreg
11563 && !inst.operands[0].preind
11564 && inst.operands[0].reg == REG_PC)
11565 set_it_insn_type_last ();
11566
0110f2b8 11567 opcode = inst.instruction;
c19d1205 11568 if (unified_syntax)
b99bd4ef 11569 {
53365c0d
PB
11570 if (!inst.operands[1].isreg)
11571 {
11572 if (opcode <= 0xffff)
11573 inst.instruction = THUMB_OP32 (opcode);
8335d6aa 11574 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
53365c0d
PB
11575 return;
11576 }
0110f2b8
PB
11577 if (inst.operands[1].isreg
11578 && !inst.operands[1].writeback
c19d1205
ZW
11579 && !inst.operands[1].shifted && !inst.operands[1].postind
11580 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
11581 && opcode <= 0xffff
11582 && inst.size_req != 4)
c19d1205 11583 {
0110f2b8
PB
11584 /* Insn may have a 16-bit form. */
11585 Rn = inst.operands[1].reg;
11586 if (inst.operands[1].immisreg)
11587 {
11588 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 11589 /* [Rn, Rik] */
0110f2b8
PB
11590 if (Rn <= 7 && inst.operands[1].imm <= 7)
11591 goto op16;
5be8be5d
DG
11592 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11593 reject_bad_reg (inst.operands[1].imm);
0110f2b8
PB
11594 }
11595 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11596 && opcode != T_MNEM_ldrsb)
11597 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11598 || (Rn == REG_SP && opcode == T_MNEM_str))
11599 {
11600 /* [Rn, #const] */
11601 if (Rn > 7)
11602 {
11603 if (Rn == REG_PC)
11604 {
11605 if (inst.reloc.pc_rel)
11606 opcode = T_MNEM_ldr_pc2;
11607 else
11608 opcode = T_MNEM_ldr_pc;
11609 }
11610 else
11611 {
11612 if (opcode == T_MNEM_ldr)
11613 opcode = T_MNEM_ldr_sp;
11614 else
11615 opcode = T_MNEM_str_sp;
11616 }
11617 inst.instruction = inst.operands[0].reg << 8;
11618 }
11619 else
11620 {
11621 inst.instruction = inst.operands[0].reg;
11622 inst.instruction |= inst.operands[1].reg << 3;
11623 }
11624 inst.instruction |= THUMB_OP16 (opcode);
11625 if (inst.size_req == 2)
11626 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11627 else
11628 inst.relax = opcode;
11629 return;
11630 }
c19d1205 11631 }
0110f2b8 11632 /* Definitely a 32-bit variant. */
5be8be5d 11633
8d67f500
NC
11634 /* Warning for Erratum 752419. */
11635 if (opcode == T_MNEM_ldr
11636 && inst.operands[0].reg == REG_SP
11637 && inst.operands[1].writeback == 1
11638 && !inst.operands[1].immisreg)
11639 {
11640 if (no_cpu_selected ()
11641 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
477330fc
RM
11642 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11643 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
8d67f500
NC
11644 as_warn (_("This instruction may be unpredictable "
11645 "if executed on M-profile cores "
11646 "with interrupts enabled."));
11647 }
11648
5be8be5d 11649 /* Do some validations regarding addressing modes. */
1be5fd2e 11650 if (inst.operands[1].immisreg)
5be8be5d
DG
11651 reject_bad_reg (inst.operands[1].imm);
11652
1be5fd2e
NC
11653 constraint (inst.operands[1].writeback == 1
11654 && inst.operands[0].reg == inst.operands[1].reg,
11655 BAD_OVERLAP);
11656
0110f2b8 11657 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
11658 inst.instruction |= inst.operands[0].reg << 12;
11659 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
1be5fd2e 11660 check_ldr_r15_aligned ();
b99bd4ef
NC
11661 return;
11662 }
11663
c19d1205
ZW
11664 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11665
11666 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 11667 {
c19d1205
ZW
11668 /* Only [Rn,Rm] is acceptable. */
11669 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11670 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11671 || inst.operands[1].postind || inst.operands[1].shifted
11672 || inst.operands[1].negative,
11673 _("Thumb does not support this addressing mode"));
11674 inst.instruction = THUMB_OP16 (inst.instruction);
11675 goto op16;
b99bd4ef 11676 }
5f4273c7 11677
c19d1205
ZW
11678 inst.instruction = THUMB_OP16 (inst.instruction);
11679 if (!inst.operands[1].isreg)
8335d6aa 11680 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
c19d1205 11681 return;
b99bd4ef 11682
c19d1205
ZW
11683 constraint (!inst.operands[1].preind
11684 || inst.operands[1].shifted
11685 || inst.operands[1].writeback,
11686 _("Thumb does not support this addressing mode"));
11687 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 11688 {
c19d1205
ZW
11689 constraint (inst.instruction & 0x0600,
11690 _("byte or halfword not valid for base register"));
11691 constraint (inst.operands[1].reg == REG_PC
11692 && !(inst.instruction & THUMB_LOAD_BIT),
11693 _("r15 based store not allowed"));
11694 constraint (inst.operands[1].immisreg,
11695 _("invalid base register for register offset"));
b99bd4ef 11696
c19d1205
ZW
11697 if (inst.operands[1].reg == REG_PC)
11698 inst.instruction = T_OPCODE_LDR_PC;
11699 else if (inst.instruction & THUMB_LOAD_BIT)
11700 inst.instruction = T_OPCODE_LDR_SP;
11701 else
11702 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 11703
c19d1205
ZW
11704 inst.instruction |= inst.operands[0].reg << 8;
11705 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11706 return;
11707 }
90e4755a 11708
c19d1205
ZW
11709 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11710 if (!inst.operands[1].immisreg)
11711 {
11712 /* Immediate offset. */
11713 inst.instruction |= inst.operands[0].reg;
11714 inst.instruction |= inst.operands[1].reg << 3;
11715 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11716 return;
11717 }
90e4755a 11718
c19d1205
ZW
11719 /* Register offset. */
11720 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11721 constraint (inst.operands[1].negative,
11722 _("Thumb does not support this addressing mode"));
90e4755a 11723
c19d1205
ZW
11724 op16:
11725 switch (inst.instruction)
11726 {
11727 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11728 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11729 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11730 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11731 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11732 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11733 case 0x5600 /* ldrsb */:
11734 case 0x5e00 /* ldrsh */: break;
11735 default: abort ();
11736 }
90e4755a 11737
c19d1205
ZW
11738 inst.instruction |= inst.operands[0].reg;
11739 inst.instruction |= inst.operands[1].reg << 3;
11740 inst.instruction |= inst.operands[1].imm << 6;
11741}
90e4755a 11742
c19d1205
ZW
11743static void
11744do_t_ldstd (void)
11745{
11746 if (!inst.operands[1].present)
b99bd4ef 11747 {
c19d1205
ZW
11748 inst.operands[1].reg = inst.operands[0].reg + 1;
11749 constraint (inst.operands[0].reg == REG_LR,
11750 _("r14 not allowed here"));
bd340a04 11751 constraint (inst.operands[0].reg == REG_R12,
477330fc 11752 _("r12 not allowed here"));
b99bd4ef 11753 }
bd340a04
MGD
11754
11755 if (inst.operands[2].writeback
11756 && (inst.operands[0].reg == inst.operands[2].reg
11757 || inst.operands[1].reg == inst.operands[2].reg))
11758 as_warn (_("base register written back, and overlaps "
477330fc 11759 "one of transfer registers"));
bd340a04 11760
c19d1205
ZW
11761 inst.instruction |= inst.operands[0].reg << 12;
11762 inst.instruction |= inst.operands[1].reg << 8;
11763 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
11764}
11765
c19d1205
ZW
11766static void
11767do_t_ldstt (void)
11768{
11769 inst.instruction |= inst.operands[0].reg << 12;
11770 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11771}
a737bd4d 11772
b99bd4ef 11773static void
c19d1205 11774do_t_mla (void)
b99bd4ef 11775{
fdfde340 11776 unsigned Rd, Rn, Rm, Ra;
c921be7d 11777
fdfde340
JM
11778 Rd = inst.operands[0].reg;
11779 Rn = inst.operands[1].reg;
11780 Rm = inst.operands[2].reg;
11781 Ra = inst.operands[3].reg;
11782
11783 reject_bad_reg (Rd);
11784 reject_bad_reg (Rn);
11785 reject_bad_reg (Rm);
11786 reject_bad_reg (Ra);
11787
11788 inst.instruction |= Rd << 8;
11789 inst.instruction |= Rn << 16;
11790 inst.instruction |= Rm;
11791 inst.instruction |= Ra << 12;
c19d1205 11792}
b99bd4ef 11793
c19d1205
ZW
11794static void
11795do_t_mlal (void)
11796{
fdfde340
JM
11797 unsigned RdLo, RdHi, Rn, Rm;
11798
11799 RdLo = inst.operands[0].reg;
11800 RdHi = inst.operands[1].reg;
11801 Rn = inst.operands[2].reg;
11802 Rm = inst.operands[3].reg;
11803
11804 reject_bad_reg (RdLo);
11805 reject_bad_reg (RdHi);
11806 reject_bad_reg (Rn);
11807 reject_bad_reg (Rm);
11808
11809 inst.instruction |= RdLo << 12;
11810 inst.instruction |= RdHi << 8;
11811 inst.instruction |= Rn << 16;
11812 inst.instruction |= Rm;
c19d1205 11813}
b99bd4ef 11814
c19d1205
ZW
11815static void
11816do_t_mov_cmp (void)
11817{
fdfde340
JM
11818 unsigned Rn, Rm;
11819
11820 Rn = inst.operands[0].reg;
11821 Rm = inst.operands[1].reg;
11822
e07e6e58
NC
11823 if (Rn == REG_PC)
11824 set_it_insn_type_last ();
11825
c19d1205 11826 if (unified_syntax)
b99bd4ef 11827 {
c19d1205
ZW
11828 int r0off = (inst.instruction == T_MNEM_mov
11829 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 11830 unsigned long opcode;
3d388997
PB
11831 bfd_boolean narrow;
11832 bfd_boolean low_regs;
11833
fdfde340 11834 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 11835 opcode = inst.instruction;
e07e6e58 11836 if (in_it_block ())
0110f2b8 11837 narrow = opcode != T_MNEM_movs;
3d388997 11838 else
0110f2b8 11839 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
11840 if (inst.size_req == 4
11841 || inst.operands[1].shifted)
11842 narrow = FALSE;
11843
efd81785
PB
11844 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11845 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11846 && !inst.operands[1].shifted
fdfde340
JM
11847 && Rn == REG_PC
11848 && Rm == REG_LR)
efd81785
PB
11849 {
11850 inst.instruction = T2_SUBS_PC_LR;
11851 return;
11852 }
11853
fdfde340
JM
11854 if (opcode == T_MNEM_cmp)
11855 {
11856 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
11857 if (narrow)
11858 {
11859 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11860 but valid. */
11861 warn_deprecated_sp (Rm);
11862 /* R15 was documented as a valid choice for Rm in ARMv6,
11863 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11864 tools reject R15, so we do too. */
11865 constraint (Rm == REG_PC, BAD_PC);
11866 }
11867 else
11868 reject_bad_reg (Rm);
fdfde340
JM
11869 }
11870 else if (opcode == T_MNEM_mov
11871 || opcode == T_MNEM_movs)
11872 {
11873 if (inst.operands[1].isreg)
11874 {
11875 if (opcode == T_MNEM_movs)
11876 {
11877 reject_bad_reg (Rn);
11878 reject_bad_reg (Rm);
11879 }
76fa04a4
MGD
11880 else if (narrow)
11881 {
11882 /* This is mov.n. */
11883 if ((Rn == REG_SP || Rn == REG_PC)
11884 && (Rm == REG_SP || Rm == REG_PC))
11885 {
5c3696f8 11886 as_tsktsk (_("Use of r%u as a source register is "
76fa04a4
MGD
11887 "deprecated when r%u is the destination "
11888 "register."), Rm, Rn);
11889 }
11890 }
11891 else
11892 {
11893 /* This is mov.w. */
11894 constraint (Rn == REG_PC, BAD_PC);
11895 constraint (Rm == REG_PC, BAD_PC);
11896 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
11897 }
fdfde340
JM
11898 }
11899 else
11900 reject_bad_reg (Rn);
11901 }
11902
c19d1205
ZW
11903 if (!inst.operands[1].isreg)
11904 {
0110f2b8 11905 /* Immediate operand. */
e07e6e58 11906 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
11907 narrow = 0;
11908 if (low_regs && narrow)
11909 {
11910 inst.instruction = THUMB_OP16 (opcode);
fdfde340 11911 inst.instruction |= Rn << 8;
a9f02af8
MG
11912 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11913 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
72d98d16 11914 {
a9f02af8 11915 if (inst.size_req == 2)
72d98d16 11916 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
a9f02af8
MG
11917 else
11918 inst.relax = opcode;
72d98d16 11919 }
0110f2b8
PB
11920 }
11921 else
11922 {
a9f02af8
MG
11923 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11924 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
11925 THUMB1_RELOC_ONLY);
11926
0110f2b8
PB
11927 inst.instruction = THUMB_OP32 (inst.instruction);
11928 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 11929 inst.instruction |= Rn << r0off;
0110f2b8
PB
11930 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11931 }
c19d1205 11932 }
728ca7c9
PB
11933 else if (inst.operands[1].shifted && inst.operands[1].immisreg
11934 && (inst.instruction == T_MNEM_mov
11935 || inst.instruction == T_MNEM_movs))
11936 {
11937 /* Register shifts are encoded as separate shift instructions. */
11938 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
11939
e07e6e58 11940 if (in_it_block ())
728ca7c9
PB
11941 narrow = !flags;
11942 else
11943 narrow = flags;
11944
11945 if (inst.size_req == 4)
11946 narrow = FALSE;
11947
11948 if (!low_regs || inst.operands[1].imm > 7)
11949 narrow = FALSE;
11950
fdfde340 11951 if (Rn != Rm)
728ca7c9
PB
11952 narrow = FALSE;
11953
11954 switch (inst.operands[1].shift_kind)
11955 {
11956 case SHIFT_LSL:
11957 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
11958 break;
11959 case SHIFT_ASR:
11960 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
11961 break;
11962 case SHIFT_LSR:
11963 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
11964 break;
11965 case SHIFT_ROR:
11966 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
11967 break;
11968 default:
5f4273c7 11969 abort ();
728ca7c9
PB
11970 }
11971
11972 inst.instruction = opcode;
11973 if (narrow)
11974 {
fdfde340 11975 inst.instruction |= Rn;
728ca7c9
PB
11976 inst.instruction |= inst.operands[1].imm << 3;
11977 }
11978 else
11979 {
11980 if (flags)
11981 inst.instruction |= CONDS_BIT;
11982
fdfde340
JM
11983 inst.instruction |= Rn << 8;
11984 inst.instruction |= Rm << 16;
728ca7c9
PB
11985 inst.instruction |= inst.operands[1].imm;
11986 }
11987 }
3d388997 11988 else if (!narrow)
c19d1205 11989 {
728ca7c9
PB
11990 /* Some mov with immediate shift have narrow variants.
11991 Register shifts are handled above. */
11992 if (low_regs && inst.operands[1].shifted
11993 && (inst.instruction == T_MNEM_mov
11994 || inst.instruction == T_MNEM_movs))
11995 {
e07e6e58 11996 if (in_it_block ())
728ca7c9
PB
11997 narrow = (inst.instruction == T_MNEM_mov);
11998 else
11999 narrow = (inst.instruction == T_MNEM_movs);
12000 }
12001
12002 if (narrow)
12003 {
12004 switch (inst.operands[1].shift_kind)
12005 {
12006 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12007 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12008 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12009 default: narrow = FALSE; break;
12010 }
12011 }
12012
12013 if (narrow)
12014 {
fdfde340
JM
12015 inst.instruction |= Rn;
12016 inst.instruction |= Rm << 3;
728ca7c9
PB
12017 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12018 }
12019 else
12020 {
12021 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12022 inst.instruction |= Rn << r0off;
728ca7c9
PB
12023 encode_thumb32_shifted_operand (1);
12024 }
c19d1205
ZW
12025 }
12026 else
12027 switch (inst.instruction)
12028 {
12029 case T_MNEM_mov:
837b3435 12030 /* In v4t or v5t a move of two lowregs produces unpredictable
c6400f8a
MGD
12031 results. Don't allow this. */
12032 if (low_regs)
12033 {
12034 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
12035 "MOV Rd, Rs with two low registers is not "
12036 "permitted on this architecture");
fa94de6b 12037 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
c6400f8a
MGD
12038 arm_ext_v6);
12039 }
12040
c19d1205 12041 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
12042 inst.instruction |= (Rn & 0x8) << 4;
12043 inst.instruction |= (Rn & 0x7);
12044 inst.instruction |= Rm << 3;
c19d1205 12045 break;
b99bd4ef 12046
c19d1205
ZW
12047 case T_MNEM_movs:
12048 /* We know we have low registers at this point.
941a8a52
MGD
12049 Generate LSLS Rd, Rs, #0. */
12050 inst.instruction = T_OPCODE_LSL_I;
fdfde340
JM
12051 inst.instruction |= Rn;
12052 inst.instruction |= Rm << 3;
c19d1205
ZW
12053 break;
12054
12055 case T_MNEM_cmp:
3d388997 12056 if (low_regs)
c19d1205
ZW
12057 {
12058 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
12059 inst.instruction |= Rn;
12060 inst.instruction |= Rm << 3;
c19d1205
ZW
12061 }
12062 else
12063 {
12064 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
12065 inst.instruction |= (Rn & 0x8) << 4;
12066 inst.instruction |= (Rn & 0x7);
12067 inst.instruction |= Rm << 3;
c19d1205
ZW
12068 }
12069 break;
12070 }
b99bd4ef
NC
12071 return;
12072 }
12073
c19d1205 12074 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
12075
12076 /* PR 10443: Do not silently ignore shifted operands. */
12077 constraint (inst.operands[1].shifted,
12078 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12079
c19d1205 12080 if (inst.operands[1].isreg)
b99bd4ef 12081 {
fdfde340 12082 if (Rn < 8 && Rm < 8)
b99bd4ef 12083 {
c19d1205
ZW
12084 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12085 since a MOV instruction produces unpredictable results. */
12086 if (inst.instruction == T_OPCODE_MOV_I8)
12087 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 12088 else
c19d1205 12089 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 12090
fdfde340
JM
12091 inst.instruction |= Rn;
12092 inst.instruction |= Rm << 3;
b99bd4ef
NC
12093 }
12094 else
12095 {
c19d1205
ZW
12096 if (inst.instruction == T_OPCODE_MOV_I8)
12097 inst.instruction = T_OPCODE_MOV_HR;
12098 else
12099 inst.instruction = T_OPCODE_CMP_HR;
12100 do_t_cpy ();
b99bd4ef
NC
12101 }
12102 }
c19d1205 12103 else
b99bd4ef 12104 {
fdfde340 12105 constraint (Rn > 7,
c19d1205 12106 _("only lo regs allowed with immediate"));
fdfde340 12107 inst.instruction |= Rn << 8;
c19d1205
ZW
12108 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
12109 }
12110}
b99bd4ef 12111
c19d1205
ZW
12112static void
12113do_t_mov16 (void)
12114{
fdfde340 12115 unsigned Rd;
b6895b4f
PB
12116 bfd_vma imm;
12117 bfd_boolean top;
12118
12119 top = (inst.instruction & 0x00800000) != 0;
12120 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
12121 {
33eaf5de 12122 constraint (top, _(":lower16: not allowed in this instruction"));
b6895b4f
PB
12123 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
12124 }
12125 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
12126 {
33eaf5de 12127 constraint (!top, _(":upper16: not allowed in this instruction"));
b6895b4f
PB
12128 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
12129 }
12130
fdfde340
JM
12131 Rd = inst.operands[0].reg;
12132 reject_bad_reg (Rd);
12133
12134 inst.instruction |= Rd << 8;
b6895b4f
PB
12135 if (inst.reloc.type == BFD_RELOC_UNUSED)
12136 {
12137 imm = inst.reloc.exp.X_add_number;
12138 inst.instruction |= (imm & 0xf000) << 4;
12139 inst.instruction |= (imm & 0x0800) << 15;
12140 inst.instruction |= (imm & 0x0700) << 4;
12141 inst.instruction |= (imm & 0x00ff);
12142 }
c19d1205 12143}
b99bd4ef 12144
c19d1205
ZW
12145static void
12146do_t_mvn_tst (void)
12147{
fdfde340 12148 unsigned Rn, Rm;
c921be7d 12149
fdfde340
JM
12150 Rn = inst.operands[0].reg;
12151 Rm = inst.operands[1].reg;
12152
12153 if (inst.instruction == T_MNEM_cmp
12154 || inst.instruction == T_MNEM_cmn)
12155 constraint (Rn == REG_PC, BAD_PC);
12156 else
12157 reject_bad_reg (Rn);
12158 reject_bad_reg (Rm);
12159
c19d1205
ZW
12160 if (unified_syntax)
12161 {
12162 int r0off = (inst.instruction == T_MNEM_mvn
12163 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
12164 bfd_boolean narrow;
12165
12166 if (inst.size_req == 4
12167 || inst.instruction > 0xffff
12168 || inst.operands[1].shifted
fdfde340 12169 || Rn > 7 || Rm > 7)
3d388997 12170 narrow = FALSE;
fe8b4cc3
KT
12171 else if (inst.instruction == T_MNEM_cmn
12172 || inst.instruction == T_MNEM_tst)
3d388997
PB
12173 narrow = TRUE;
12174 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12175 narrow = !in_it_block ();
3d388997 12176 else
e07e6e58 12177 narrow = in_it_block ();
3d388997 12178
c19d1205 12179 if (!inst.operands[1].isreg)
b99bd4ef 12180 {
c19d1205
ZW
12181 /* For an immediate, we always generate a 32-bit opcode;
12182 section relaxation will shrink it later if possible. */
12183 if (inst.instruction < 0xffff)
12184 inst.instruction = THUMB_OP32 (inst.instruction);
12185 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 12186 inst.instruction |= Rn << r0off;
c19d1205 12187 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 12188 }
c19d1205 12189 else
b99bd4ef 12190 {
c19d1205 12191 /* See if we can do this with a 16-bit instruction. */
3d388997 12192 if (narrow)
b99bd4ef 12193 {
c19d1205 12194 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12195 inst.instruction |= Rn;
12196 inst.instruction |= Rm << 3;
b99bd4ef 12197 }
c19d1205 12198 else
b99bd4ef 12199 {
c19d1205
ZW
12200 constraint (inst.operands[1].shifted
12201 && inst.operands[1].immisreg,
12202 _("shift must be constant"));
12203 if (inst.instruction < 0xffff)
12204 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 12205 inst.instruction |= Rn << r0off;
c19d1205 12206 encode_thumb32_shifted_operand (1);
b99bd4ef 12207 }
b99bd4ef
NC
12208 }
12209 }
12210 else
12211 {
c19d1205
ZW
12212 constraint (inst.instruction > 0xffff
12213 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12214 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12215 _("unshifted register required"));
fdfde340 12216 constraint (Rn > 7 || Rm > 7,
c19d1205 12217 BAD_HIREG);
b99bd4ef 12218
c19d1205 12219 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12220 inst.instruction |= Rn;
12221 inst.instruction |= Rm << 3;
b99bd4ef 12222 }
b99bd4ef
NC
12223}
12224
b05fe5cf 12225static void
c19d1205 12226do_t_mrs (void)
b05fe5cf 12227{
fdfde340 12228 unsigned Rd;
037e8744
JB
12229
12230 if (do_vfp_nsyn_mrs () == SUCCESS)
12231 return;
12232
90ec0d68
MGD
12233 Rd = inst.operands[0].reg;
12234 reject_bad_reg (Rd);
12235 inst.instruction |= Rd << 8;
12236
12237 if (inst.operands[1].isreg)
62b3e311 12238 {
90ec0d68
MGD
12239 unsigned br = inst.operands[1].reg;
12240 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12241 as_bad (_("bad register for mrs"));
12242
12243 inst.instruction |= br & (0xf << 16);
12244 inst.instruction |= (br & 0x300) >> 4;
12245 inst.instruction |= (br & SPSR_BIT) >> 2;
62b3e311
PB
12246 }
12247 else
12248 {
90ec0d68 12249 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
5f4273c7 12250
d2cd1205 12251 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
1a43faaf
NC
12252 {
12253 /* PR gas/12698: The constraint is only applied for m_profile.
12254 If the user has specified -march=all, we want to ignore it as
12255 we are building for any CPU type, including non-m variants. */
823d2571
TG
12256 bfd_boolean m_profile =
12257 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf
NC
12258 constraint ((flags != 0) && m_profile, _("selected processor does "
12259 "not support requested special purpose register"));
12260 }
90ec0d68 12261 else
d2cd1205
JB
12262 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12263 devices). */
12264 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12265 _("'APSR', 'CPSR' or 'SPSR' expected"));
fdfde340 12266
90ec0d68
MGD
12267 inst.instruction |= (flags & SPSR_BIT) >> 2;
12268 inst.instruction |= inst.operands[1].imm & 0xff;
12269 inst.instruction |= 0xf0000;
12270 }
c19d1205 12271}
b05fe5cf 12272
c19d1205
ZW
12273static void
12274do_t_msr (void)
12275{
62b3e311 12276 int flags;
fdfde340 12277 unsigned Rn;
62b3e311 12278
037e8744
JB
12279 if (do_vfp_nsyn_msr () == SUCCESS)
12280 return;
12281
c19d1205
ZW
12282 constraint (!inst.operands[1].isreg,
12283 _("Thumb encoding does not support an immediate here"));
90ec0d68
MGD
12284
12285 if (inst.operands[0].isreg)
12286 flags = (int)(inst.operands[0].reg);
12287 else
12288 flags = inst.operands[0].imm;
12289
d2cd1205 12290 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
62b3e311 12291 {
d2cd1205
JB
12292 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12293
1a43faaf 12294 /* PR gas/12698: The constraint is only applied for m_profile.
477330fc
RM
12295 If the user has specified -march=all, we want to ignore it as
12296 we are building for any CPU type, including non-m variants. */
823d2571
TG
12297 bfd_boolean m_profile =
12298 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
1a43faaf 12299 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
477330fc
RM
12300 && (bits & ~(PSR_s | PSR_f)) != 0)
12301 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12302 && bits != PSR_f)) && m_profile,
12303 _("selected processor does not support requested special "
12304 "purpose register"));
62b3e311
PB
12305 }
12306 else
d2cd1205
JB
12307 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12308 "requested special purpose register"));
c921be7d 12309
fdfde340
JM
12310 Rn = inst.operands[1].reg;
12311 reject_bad_reg (Rn);
12312
62b3e311 12313 inst.instruction |= (flags & SPSR_BIT) >> 2;
90ec0d68
MGD
12314 inst.instruction |= (flags & 0xf0000) >> 8;
12315 inst.instruction |= (flags & 0x300) >> 4;
62b3e311 12316 inst.instruction |= (flags & 0xff);
fdfde340 12317 inst.instruction |= Rn << 16;
c19d1205 12318}
b05fe5cf 12319
c19d1205
ZW
12320static void
12321do_t_mul (void)
12322{
17828f45 12323 bfd_boolean narrow;
fdfde340 12324 unsigned Rd, Rn, Rm;
17828f45 12325
c19d1205
ZW
12326 if (!inst.operands[2].present)
12327 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 12328
fdfde340
JM
12329 Rd = inst.operands[0].reg;
12330 Rn = inst.operands[1].reg;
12331 Rm = inst.operands[2].reg;
12332
17828f45 12333 if (unified_syntax)
b05fe5cf 12334 {
17828f45 12335 if (inst.size_req == 4
fdfde340
JM
12336 || (Rd != Rn
12337 && Rd != Rm)
12338 || Rn > 7
12339 || Rm > 7)
17828f45
JM
12340 narrow = FALSE;
12341 else if (inst.instruction == T_MNEM_muls)
e07e6e58 12342 narrow = !in_it_block ();
17828f45 12343 else
e07e6e58 12344 narrow = in_it_block ();
b05fe5cf 12345 }
c19d1205 12346 else
b05fe5cf 12347 {
17828f45 12348 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 12349 constraint (Rn > 7 || Rm > 7,
c19d1205 12350 BAD_HIREG);
17828f45
JM
12351 narrow = TRUE;
12352 }
b05fe5cf 12353
17828f45
JM
12354 if (narrow)
12355 {
12356 /* 16-bit MULS/Conditional MUL. */
c19d1205 12357 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 12358 inst.instruction |= Rd;
b05fe5cf 12359
fdfde340
JM
12360 if (Rd == Rn)
12361 inst.instruction |= Rm << 3;
12362 else if (Rd == Rm)
12363 inst.instruction |= Rn << 3;
c19d1205
ZW
12364 else
12365 constraint (1, _("dest must overlap one source register"));
12366 }
17828f45
JM
12367 else
12368 {
e07e6e58
NC
12369 constraint (inst.instruction != T_MNEM_mul,
12370 _("Thumb-2 MUL must not set flags"));
17828f45
JM
12371 /* 32-bit MUL. */
12372 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12373 inst.instruction |= Rd << 8;
12374 inst.instruction |= Rn << 16;
12375 inst.instruction |= Rm << 0;
12376
12377 reject_bad_reg (Rd);
12378 reject_bad_reg (Rn);
12379 reject_bad_reg (Rm);
17828f45 12380 }
c19d1205 12381}
b05fe5cf 12382
c19d1205
ZW
12383static void
12384do_t_mull (void)
12385{
fdfde340 12386 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 12387
fdfde340
JM
12388 RdLo = inst.operands[0].reg;
12389 RdHi = inst.operands[1].reg;
12390 Rn = inst.operands[2].reg;
12391 Rm = inst.operands[3].reg;
12392
12393 reject_bad_reg (RdLo);
12394 reject_bad_reg (RdHi);
12395 reject_bad_reg (Rn);
12396 reject_bad_reg (Rm);
12397
12398 inst.instruction |= RdLo << 12;
12399 inst.instruction |= RdHi << 8;
12400 inst.instruction |= Rn << 16;
12401 inst.instruction |= Rm;
12402
12403 if (RdLo == RdHi)
c19d1205
ZW
12404 as_tsktsk (_("rdhi and rdlo must be different"));
12405}
b05fe5cf 12406
c19d1205
ZW
12407static void
12408do_t_nop (void)
12409{
e07e6e58
NC
12410 set_it_insn_type (NEUTRAL_IT_INSN);
12411
c19d1205
ZW
12412 if (unified_syntax)
12413 {
12414 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 12415 {
c19d1205
ZW
12416 inst.instruction = THUMB_OP32 (inst.instruction);
12417 inst.instruction |= inst.operands[0].imm;
12418 }
12419 else
12420 {
bc2d1808
NC
12421 /* PR9722: Check for Thumb2 availability before
12422 generating a thumb2 nop instruction. */
afa62d5e 12423 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
bc2d1808
NC
12424 {
12425 inst.instruction = THUMB_OP16 (inst.instruction);
12426 inst.instruction |= inst.operands[0].imm << 4;
12427 }
12428 else
12429 inst.instruction = 0x46c0;
c19d1205
ZW
12430 }
12431 }
12432 else
12433 {
12434 constraint (inst.operands[0].present,
12435 _("Thumb does not support NOP with hints"));
12436 inst.instruction = 0x46c0;
12437 }
12438}
b05fe5cf 12439
c19d1205
ZW
12440static void
12441do_t_neg (void)
12442{
12443 if (unified_syntax)
12444 {
3d388997
PB
12445 bfd_boolean narrow;
12446
12447 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12448 narrow = !in_it_block ();
3d388997 12449 else
e07e6e58 12450 narrow = in_it_block ();
3d388997
PB
12451 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12452 narrow = FALSE;
12453 if (inst.size_req == 4)
12454 narrow = FALSE;
12455
12456 if (!narrow)
c19d1205
ZW
12457 {
12458 inst.instruction = THUMB_OP32 (inst.instruction);
12459 inst.instruction |= inst.operands[0].reg << 8;
12460 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
12461 }
12462 else
12463 {
c19d1205
ZW
12464 inst.instruction = THUMB_OP16 (inst.instruction);
12465 inst.instruction |= inst.operands[0].reg;
12466 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
12467 }
12468 }
12469 else
12470 {
c19d1205
ZW
12471 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12472 BAD_HIREG);
12473 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12474
12475 inst.instruction = THUMB_OP16 (inst.instruction);
12476 inst.instruction |= inst.operands[0].reg;
12477 inst.instruction |= inst.operands[1].reg << 3;
12478 }
12479}
12480
1c444d06
JM
12481static void
12482do_t_orn (void)
12483{
12484 unsigned Rd, Rn;
12485
12486 Rd = inst.operands[0].reg;
12487 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12488
fdfde340
JM
12489 reject_bad_reg (Rd);
12490 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12491 reject_bad_reg (Rn);
12492
1c444d06
JM
12493 inst.instruction |= Rd << 8;
12494 inst.instruction |= Rn << 16;
12495
12496 if (!inst.operands[2].isreg)
12497 {
12498 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12499 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12500 }
12501 else
12502 {
12503 unsigned Rm;
12504
12505 Rm = inst.operands[2].reg;
fdfde340 12506 reject_bad_reg (Rm);
1c444d06
JM
12507
12508 constraint (inst.operands[2].shifted
12509 && inst.operands[2].immisreg,
12510 _("shift must be constant"));
12511 encode_thumb32_shifted_operand (2);
12512 }
12513}
12514
c19d1205
ZW
12515static void
12516do_t_pkhbt (void)
12517{
fdfde340
JM
12518 unsigned Rd, Rn, Rm;
12519
12520 Rd = inst.operands[0].reg;
12521 Rn = inst.operands[1].reg;
12522 Rm = inst.operands[2].reg;
12523
12524 reject_bad_reg (Rd);
12525 reject_bad_reg (Rn);
12526 reject_bad_reg (Rm);
12527
12528 inst.instruction |= Rd << 8;
12529 inst.instruction |= Rn << 16;
12530 inst.instruction |= Rm;
c19d1205
ZW
12531 if (inst.operands[3].present)
12532 {
12533 unsigned int val = inst.reloc.exp.X_add_number;
12534 constraint (inst.reloc.exp.X_op != O_constant,
12535 _("expression too complex"));
12536 inst.instruction |= (val & 0x1c) << 10;
12537 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 12538 }
c19d1205 12539}
b05fe5cf 12540
c19d1205
ZW
12541static void
12542do_t_pkhtb (void)
12543{
12544 if (!inst.operands[3].present)
1ef52f49
NC
12545 {
12546 unsigned Rtmp;
12547
12548 inst.instruction &= ~0x00000020;
12549
12550 /* PR 10168. Swap the Rm and Rn registers. */
12551 Rtmp = inst.operands[1].reg;
12552 inst.operands[1].reg = inst.operands[2].reg;
12553 inst.operands[2].reg = Rtmp;
12554 }
c19d1205 12555 do_t_pkhbt ();
b05fe5cf
ZW
12556}
12557
c19d1205
ZW
12558static void
12559do_t_pld (void)
12560{
fdfde340
JM
12561 if (inst.operands[0].immisreg)
12562 reject_bad_reg (inst.operands[0].imm);
12563
c19d1205
ZW
12564 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12565}
b05fe5cf 12566
c19d1205
ZW
12567static void
12568do_t_push_pop (void)
b99bd4ef 12569{
e9f89963 12570 unsigned mask;
5f4273c7 12571
c19d1205
ZW
12572 constraint (inst.operands[0].writeback,
12573 _("push/pop do not support {reglist}^"));
12574 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12575 _("expression too complex"));
b99bd4ef 12576
e9f89963 12577 mask = inst.operands[0].imm;
d3bfe16e 12578 if (inst.size_req != 4 && (mask & ~0xff) == 0)
3c707909 12579 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
d3bfe16e 12580 else if (inst.size_req != 4
c6025a80 12581 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
d3bfe16e 12582 ? REG_LR : REG_PC)))
b99bd4ef 12583 {
c19d1205
ZW
12584 inst.instruction = THUMB_OP16 (inst.instruction);
12585 inst.instruction |= THUMB_PP_PC_LR;
3c707909 12586 inst.instruction |= mask & 0xff;
c19d1205
ZW
12587 }
12588 else if (unified_syntax)
12589 {
3c707909 12590 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 12591 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
12592 }
12593 else
12594 {
12595 inst.error = _("invalid register list to push/pop instruction");
12596 return;
12597 }
c19d1205 12598}
b99bd4ef 12599
c19d1205
ZW
12600static void
12601do_t_rbit (void)
12602{
fdfde340
JM
12603 unsigned Rd, Rm;
12604
12605 Rd = inst.operands[0].reg;
12606 Rm = inst.operands[1].reg;
12607
12608 reject_bad_reg (Rd);
12609 reject_bad_reg (Rm);
12610
12611 inst.instruction |= Rd << 8;
12612 inst.instruction |= Rm << 16;
12613 inst.instruction |= Rm;
c19d1205 12614}
b99bd4ef 12615
c19d1205
ZW
12616static void
12617do_t_rev (void)
12618{
fdfde340
JM
12619 unsigned Rd, Rm;
12620
12621 Rd = inst.operands[0].reg;
12622 Rm = inst.operands[1].reg;
12623
12624 reject_bad_reg (Rd);
12625 reject_bad_reg (Rm);
12626
12627 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
12628 && inst.size_req != 4)
12629 {
12630 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
12631 inst.instruction |= Rd;
12632 inst.instruction |= Rm << 3;
c19d1205
ZW
12633 }
12634 else if (unified_syntax)
12635 {
12636 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
12637 inst.instruction |= Rd << 8;
12638 inst.instruction |= Rm << 16;
12639 inst.instruction |= Rm;
c19d1205
ZW
12640 }
12641 else
12642 inst.error = BAD_HIREG;
12643}
b99bd4ef 12644
1c444d06
JM
12645static void
12646do_t_rrx (void)
12647{
12648 unsigned Rd, Rm;
12649
12650 Rd = inst.operands[0].reg;
12651 Rm = inst.operands[1].reg;
12652
fdfde340
JM
12653 reject_bad_reg (Rd);
12654 reject_bad_reg (Rm);
c921be7d 12655
1c444d06
JM
12656 inst.instruction |= Rd << 8;
12657 inst.instruction |= Rm;
12658}
12659
c19d1205
ZW
12660static void
12661do_t_rsb (void)
12662{
fdfde340 12663 unsigned Rd, Rs;
b99bd4ef 12664
c19d1205
ZW
12665 Rd = inst.operands[0].reg;
12666 Rs = (inst.operands[1].present
12667 ? inst.operands[1].reg /* Rd, Rs, foo */
12668 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 12669
fdfde340
JM
12670 reject_bad_reg (Rd);
12671 reject_bad_reg (Rs);
12672 if (inst.operands[2].isreg)
12673 reject_bad_reg (inst.operands[2].reg);
12674
c19d1205
ZW
12675 inst.instruction |= Rd << 8;
12676 inst.instruction |= Rs << 16;
12677 if (!inst.operands[2].isreg)
12678 {
026d3abb
PB
12679 bfd_boolean narrow;
12680
12681 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 12682 narrow = !in_it_block ();
026d3abb 12683 else
e07e6e58 12684 narrow = in_it_block ();
026d3abb
PB
12685
12686 if (Rd > 7 || Rs > 7)
12687 narrow = FALSE;
12688
12689 if (inst.size_req == 4 || !unified_syntax)
12690 narrow = FALSE;
12691
12692 if (inst.reloc.exp.X_op != O_constant
12693 || inst.reloc.exp.X_add_number != 0)
12694 narrow = FALSE;
12695
12696 /* Turn rsb #0 into 16-bit neg. We should probably do this via
477330fc 12697 relaxation, but it doesn't seem worth the hassle. */
026d3abb
PB
12698 if (narrow)
12699 {
12700 inst.reloc.type = BFD_RELOC_UNUSED;
12701 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12702 inst.instruction |= Rs << 3;
12703 inst.instruction |= Rd;
12704 }
12705 else
12706 {
12707 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12708 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12709 }
c19d1205
ZW
12710 }
12711 else
12712 encode_thumb32_shifted_operand (2);
12713}
b99bd4ef 12714
c19d1205
ZW
12715static void
12716do_t_setend (void)
12717{
12e37cbc
MGD
12718 if (warn_on_deprecated
12719 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
5c3696f8 12720 as_tsktsk (_("setend use is deprecated for ARMv8"));
12e37cbc 12721
e07e6e58 12722 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
12723 if (inst.operands[0].imm)
12724 inst.instruction |= 0x8;
12725}
b99bd4ef 12726
c19d1205
ZW
12727static void
12728do_t_shift (void)
12729{
12730 if (!inst.operands[1].present)
12731 inst.operands[1].reg = inst.operands[0].reg;
12732
12733 if (unified_syntax)
12734 {
3d388997
PB
12735 bfd_boolean narrow;
12736 int shift_kind;
12737
12738 switch (inst.instruction)
12739 {
12740 case T_MNEM_asr:
12741 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12742 case T_MNEM_lsl:
12743 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12744 case T_MNEM_lsr:
12745 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12746 case T_MNEM_ror:
12747 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12748 default: abort ();
12749 }
12750
12751 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 12752 narrow = !in_it_block ();
3d388997 12753 else
e07e6e58 12754 narrow = in_it_block ();
3d388997
PB
12755 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12756 narrow = FALSE;
12757 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12758 narrow = FALSE;
12759 if (inst.operands[2].isreg
12760 && (inst.operands[1].reg != inst.operands[0].reg
12761 || inst.operands[2].reg > 7))
12762 narrow = FALSE;
12763 if (inst.size_req == 4)
12764 narrow = FALSE;
12765
fdfde340
JM
12766 reject_bad_reg (inst.operands[0].reg);
12767 reject_bad_reg (inst.operands[1].reg);
c921be7d 12768
3d388997 12769 if (!narrow)
c19d1205
ZW
12770 {
12771 if (inst.operands[2].isreg)
b99bd4ef 12772 {
fdfde340 12773 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
12774 inst.instruction = THUMB_OP32 (inst.instruction);
12775 inst.instruction |= inst.operands[0].reg << 8;
12776 inst.instruction |= inst.operands[1].reg << 16;
12777 inst.instruction |= inst.operands[2].reg;
94342ec3
NC
12778
12779 /* PR 12854: Error on extraneous shifts. */
12780 constraint (inst.operands[2].shifted,
12781 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12782 }
12783 else
12784 {
12785 inst.operands[1].shifted = 1;
3d388997 12786 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
12787 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12788 ? T_MNEM_movs : T_MNEM_mov);
12789 inst.instruction |= inst.operands[0].reg << 8;
12790 encode_thumb32_shifted_operand (1);
12791 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12792 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
12793 }
12794 }
12795 else
12796 {
c19d1205 12797 if (inst.operands[2].isreg)
b99bd4ef 12798 {
3d388997 12799 switch (shift_kind)
b99bd4ef 12800 {
3d388997
PB
12801 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12802 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12803 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12804 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 12805 default: abort ();
b99bd4ef 12806 }
5f4273c7 12807
c19d1205
ZW
12808 inst.instruction |= inst.operands[0].reg;
12809 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12810
12811 /* PR 12854: Error on extraneous shifts. */
12812 constraint (inst.operands[2].shifted,
12813 _("extraneous shift as part of operand to shift insn"));
b99bd4ef
NC
12814 }
12815 else
12816 {
3d388997 12817 switch (shift_kind)
b99bd4ef 12818 {
3d388997
PB
12819 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12820 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12821 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 12822 default: abort ();
b99bd4ef 12823 }
c19d1205
ZW
12824 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12825 inst.instruction |= inst.operands[0].reg;
12826 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12827 }
12828 }
c19d1205
ZW
12829 }
12830 else
12831 {
12832 constraint (inst.operands[0].reg > 7
12833 || inst.operands[1].reg > 7, BAD_HIREG);
12834 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 12835
c19d1205
ZW
12836 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12837 {
12838 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12839 constraint (inst.operands[0].reg != inst.operands[1].reg,
12840 _("source1 and dest must be same register"));
b99bd4ef 12841
c19d1205
ZW
12842 switch (inst.instruction)
12843 {
12844 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12845 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12846 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12847 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12848 default: abort ();
12849 }
5f4273c7 12850
c19d1205
ZW
12851 inst.instruction |= inst.operands[0].reg;
12852 inst.instruction |= inst.operands[2].reg << 3;
af199b06
NC
12853
12854 /* PR 12854: Error on extraneous shifts. */
12855 constraint (inst.operands[2].shifted,
12856 _("extraneous shift as part of operand to shift insn"));
c19d1205
ZW
12857 }
12858 else
b99bd4ef 12859 {
c19d1205
ZW
12860 switch (inst.instruction)
12861 {
12862 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12863 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12864 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12865 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12866 default: abort ();
12867 }
12868 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12869 inst.instruction |= inst.operands[0].reg;
12870 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
12871 }
12872 }
b99bd4ef
NC
12873}
12874
12875static void
c19d1205 12876do_t_simd (void)
b99bd4ef 12877{
fdfde340
JM
12878 unsigned Rd, Rn, Rm;
12879
12880 Rd = inst.operands[0].reg;
12881 Rn = inst.operands[1].reg;
12882 Rm = inst.operands[2].reg;
12883
12884 reject_bad_reg (Rd);
12885 reject_bad_reg (Rn);
12886 reject_bad_reg (Rm);
12887
12888 inst.instruction |= Rd << 8;
12889 inst.instruction |= Rn << 16;
12890 inst.instruction |= Rm;
c19d1205 12891}
b99bd4ef 12892
03ee1b7f
NC
12893static void
12894do_t_simd2 (void)
12895{
12896 unsigned Rd, Rn, Rm;
12897
12898 Rd = inst.operands[0].reg;
12899 Rm = inst.operands[1].reg;
12900 Rn = inst.operands[2].reg;
12901
12902 reject_bad_reg (Rd);
12903 reject_bad_reg (Rn);
12904 reject_bad_reg (Rm);
12905
12906 inst.instruction |= Rd << 8;
12907 inst.instruction |= Rn << 16;
12908 inst.instruction |= Rm;
12909}
12910
c19d1205 12911static void
3eb17e6b 12912do_t_smc (void)
c19d1205
ZW
12913{
12914 unsigned int value = inst.reloc.exp.X_add_number;
f4c65163
MGD
12915 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
12916 _("SMC is not permitted on this architecture"));
c19d1205
ZW
12917 constraint (inst.reloc.exp.X_op != O_constant,
12918 _("expression too complex"));
12919 inst.reloc.type = BFD_RELOC_UNUSED;
12920 inst.instruction |= (value & 0xf000) >> 12;
12921 inst.instruction |= (value & 0x0ff0);
12922 inst.instruction |= (value & 0x000f) << 16;
24382199
NC
12923 /* PR gas/15623: SMC instructions must be last in an IT block. */
12924 set_it_insn_type_last ();
c19d1205 12925}
b99bd4ef 12926
90ec0d68
MGD
12927static void
12928do_t_hvc (void)
12929{
12930 unsigned int value = inst.reloc.exp.X_add_number;
12931
12932 inst.reloc.type = BFD_RELOC_UNUSED;
12933 inst.instruction |= (value & 0x0fff);
12934 inst.instruction |= (value & 0xf000) << 4;
12935}
12936
c19d1205 12937static void
3a21c15a 12938do_t_ssat_usat (int bias)
c19d1205 12939{
fdfde340
JM
12940 unsigned Rd, Rn;
12941
12942 Rd = inst.operands[0].reg;
12943 Rn = inst.operands[2].reg;
12944
12945 reject_bad_reg (Rd);
12946 reject_bad_reg (Rn);
12947
12948 inst.instruction |= Rd << 8;
3a21c15a 12949 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 12950 inst.instruction |= Rn << 16;
b99bd4ef 12951
c19d1205 12952 if (inst.operands[3].present)
b99bd4ef 12953 {
3a21c15a
NC
12954 offsetT shift_amount = inst.reloc.exp.X_add_number;
12955
12956 inst.reloc.type = BFD_RELOC_UNUSED;
12957
c19d1205
ZW
12958 constraint (inst.reloc.exp.X_op != O_constant,
12959 _("expression too complex"));
b99bd4ef 12960
3a21c15a 12961 if (shift_amount != 0)
6189168b 12962 {
3a21c15a
NC
12963 constraint (shift_amount > 31,
12964 _("shift expression is too large"));
12965
c19d1205 12966 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
12967 inst.instruction |= 0x00200000; /* sh bit. */
12968
12969 inst.instruction |= (shift_amount & 0x1c) << 10;
12970 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
12971 }
12972 }
b99bd4ef 12973}
c921be7d 12974
3a21c15a
NC
12975static void
12976do_t_ssat (void)
12977{
12978 do_t_ssat_usat (1);
12979}
b99bd4ef 12980
0dd132b6 12981static void
c19d1205 12982do_t_ssat16 (void)
0dd132b6 12983{
fdfde340
JM
12984 unsigned Rd, Rn;
12985
12986 Rd = inst.operands[0].reg;
12987 Rn = inst.operands[2].reg;
12988
12989 reject_bad_reg (Rd);
12990 reject_bad_reg (Rn);
12991
12992 inst.instruction |= Rd << 8;
c19d1205 12993 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 12994 inst.instruction |= Rn << 16;
c19d1205 12995}
0dd132b6 12996
c19d1205
ZW
12997static void
12998do_t_strex (void)
12999{
13000 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
13001 || inst.operands[2].postind || inst.operands[2].writeback
13002 || inst.operands[2].immisreg || inst.operands[2].shifted
13003 || inst.operands[2].negative,
01cfc07f 13004 BAD_ADDR_MODE);
0dd132b6 13005
5be8be5d
DG
13006 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
13007
c19d1205
ZW
13008 inst.instruction |= inst.operands[0].reg << 8;
13009 inst.instruction |= inst.operands[1].reg << 12;
13010 inst.instruction |= inst.operands[2].reg << 16;
13011 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
13012}
13013
b99bd4ef 13014static void
c19d1205 13015do_t_strexd (void)
b99bd4ef 13016{
c19d1205
ZW
13017 if (!inst.operands[2].present)
13018 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 13019
c19d1205
ZW
13020 constraint (inst.operands[0].reg == inst.operands[1].reg
13021 || inst.operands[0].reg == inst.operands[2].reg
f8a8e9d6 13022 || inst.operands[0].reg == inst.operands[3].reg,
c19d1205 13023 BAD_OVERLAP);
b99bd4ef 13024
c19d1205
ZW
13025 inst.instruction |= inst.operands[0].reg;
13026 inst.instruction |= inst.operands[1].reg << 12;
13027 inst.instruction |= inst.operands[2].reg << 8;
13028 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
13029}
13030
13031static void
c19d1205 13032do_t_sxtah (void)
b99bd4ef 13033{
fdfde340
JM
13034 unsigned Rd, Rn, Rm;
13035
13036 Rd = inst.operands[0].reg;
13037 Rn = inst.operands[1].reg;
13038 Rm = inst.operands[2].reg;
13039
13040 reject_bad_reg (Rd);
13041 reject_bad_reg (Rn);
13042 reject_bad_reg (Rm);
13043
13044 inst.instruction |= Rd << 8;
13045 inst.instruction |= Rn << 16;
13046 inst.instruction |= Rm;
c19d1205
ZW
13047 inst.instruction |= inst.operands[3].imm << 4;
13048}
b99bd4ef 13049
c19d1205
ZW
13050static void
13051do_t_sxth (void)
13052{
fdfde340
JM
13053 unsigned Rd, Rm;
13054
13055 Rd = inst.operands[0].reg;
13056 Rm = inst.operands[1].reg;
13057
13058 reject_bad_reg (Rd);
13059 reject_bad_reg (Rm);
c921be7d
NC
13060
13061 if (inst.instruction <= 0xffff
13062 && inst.size_req != 4
fdfde340 13063 && Rd <= 7 && Rm <= 7
c19d1205 13064 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 13065 {
c19d1205 13066 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
13067 inst.instruction |= Rd;
13068 inst.instruction |= Rm << 3;
b99bd4ef 13069 }
c19d1205 13070 else if (unified_syntax)
b99bd4ef 13071 {
c19d1205
ZW
13072 if (inst.instruction <= 0xffff)
13073 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
13074 inst.instruction |= Rd << 8;
13075 inst.instruction |= Rm;
c19d1205 13076 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 13077 }
c19d1205 13078 else
b99bd4ef 13079 {
c19d1205
ZW
13080 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13081 _("Thumb encoding does not support rotation"));
13082 constraint (1, BAD_HIREG);
b99bd4ef 13083 }
c19d1205 13084}
b99bd4ef 13085
c19d1205
ZW
13086static void
13087do_t_swi (void)
13088{
b2a5fbdc
MGD
13089 /* We have to do the following check manually as ARM_EXT_OS only applies
13090 to ARM_EXT_V6M. */
13091 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
13092 {
ac7f631b 13093 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
2b0f3761 13094 /* This only applies to the v6m however, not later architectures. */
ac7f631b 13095 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
b2a5fbdc
MGD
13096 as_bad (_("SVC is not permitted on this architecture"));
13097 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
13098 }
13099
c19d1205
ZW
13100 inst.reloc.type = BFD_RELOC_ARM_SWI;
13101}
b99bd4ef 13102
92e90b6e
PB
13103static void
13104do_t_tb (void)
13105{
fdfde340 13106 unsigned Rn, Rm;
92e90b6e
PB
13107 int half;
13108
13109 half = (inst.instruction & 0x10) != 0;
e07e6e58 13110 set_it_insn_type_last ();
dfa9f0d5
PB
13111 constraint (inst.operands[0].immisreg,
13112 _("instruction requires register index"));
fdfde340
JM
13113
13114 Rn = inst.operands[0].reg;
13115 Rm = inst.operands[0].imm;
c921be7d 13116
fdfde340
JM
13117 constraint (Rn == REG_SP, BAD_SP);
13118 reject_bad_reg (Rm);
13119
92e90b6e
PB
13120 constraint (!half && inst.operands[0].shifted,
13121 _("instruction does not allow shifted index"));
fdfde340 13122 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
13123}
13124
74db7efb
NC
13125static void
13126do_t_udf (void)
13127{
13128 if (!inst.operands[0].present)
13129 inst.operands[0].imm = 0;
13130
13131 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13132 {
13133 constraint (inst.size_req == 2,
13134 _("immediate value out of range"));
13135 inst.instruction = THUMB_OP32 (inst.instruction);
13136 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13137 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13138 }
13139 else
13140 {
13141 inst.instruction = THUMB_OP16 (inst.instruction);
13142 inst.instruction |= inst.operands[0].imm;
13143 }
13144
13145 set_it_insn_type (NEUTRAL_IT_INSN);
13146}
13147
13148
c19d1205
ZW
13149static void
13150do_t_usat (void)
13151{
3a21c15a 13152 do_t_ssat_usat (0);
b99bd4ef
NC
13153}
13154
13155static void
c19d1205 13156do_t_usat16 (void)
b99bd4ef 13157{
fdfde340
JM
13158 unsigned Rd, Rn;
13159
13160 Rd = inst.operands[0].reg;
13161 Rn = inst.operands[2].reg;
13162
13163 reject_bad_reg (Rd);
13164 reject_bad_reg (Rn);
13165
13166 inst.instruction |= Rd << 8;
c19d1205 13167 inst.instruction |= inst.operands[1].imm;
fdfde340 13168 inst.instruction |= Rn << 16;
b99bd4ef 13169}
c19d1205 13170
5287ad62 13171/* Neon instruction encoder helpers. */
5f4273c7 13172
5287ad62 13173/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 13174
5287ad62
JB
13175/* An "invalid" code for the following tables. */
13176#define N_INV -1u
13177
13178struct neon_tab_entry
b99bd4ef 13179{
5287ad62
JB
13180 unsigned integer;
13181 unsigned float_or_poly;
13182 unsigned scalar_or_imm;
13183};
5f4273c7 13184
5287ad62
JB
13185/* Map overloaded Neon opcodes to their respective encodings. */
13186#define NEON_ENC_TAB \
13187 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13188 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13189 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13190 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13191 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13192 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13193 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13194 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13195 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13196 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13197 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13198 /* Register variants of the following two instructions are encoded as
e07e6e58 13199 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
13200 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13201 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
13202 X(vfma, N_INV, 0x0000c10, N_INV), \
13203 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
13204 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13205 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13206 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13207 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13208 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13209 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13210 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13211 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13212 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13213 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13214 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
d6b4b13e
MW
13215 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13216 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
5287ad62
JB
13217 X(vshl, 0x0000400, N_INV, 0x0800510), \
13218 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13219 X(vand, 0x0000110, N_INV, 0x0800030), \
13220 X(vbic, 0x0100110, N_INV, 0x0800030), \
13221 X(veor, 0x1000110, N_INV, N_INV), \
13222 X(vorn, 0x0300110, N_INV, 0x0800010), \
13223 X(vorr, 0x0200110, N_INV, 0x0800010), \
13224 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13225 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13226 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13227 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13228 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13229 X(vst1, 0x0000000, 0x0800000, N_INV), \
13230 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13231 X(vst2, 0x0000100, 0x0800100, N_INV), \
13232 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13233 X(vst3, 0x0000200, 0x0800200, N_INV), \
13234 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13235 X(vst4, 0x0000300, 0x0800300, N_INV), \
13236 X(vmovn, 0x1b20200, N_INV, N_INV), \
13237 X(vtrn, 0x1b20080, N_INV, N_INV), \
13238 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
13239 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13240 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
13241 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13242 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
13243 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13244 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
13245 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13246 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13247 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
33399f07
MGD
13248 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13249 X(vseleq, 0xe000a00, N_INV, N_INV), \
13250 X(vselvs, 0xe100a00, N_INV, N_INV), \
13251 X(vselge, 0xe200a00, N_INV, N_INV), \
73924fbc
MGD
13252 X(vselgt, 0xe300a00, N_INV, N_INV), \
13253 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
7e8e6784 13254 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
30bdf752
MGD
13255 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13256 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
91ff7894 13257 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
48adcd8e 13258 X(aes, 0x3b00300, N_INV, N_INV), \
3c9017d2
MGD
13259 X(sha3op, 0x2000c00, N_INV, N_INV), \
13260 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13261 X(sha2op, 0x3ba0380, N_INV, N_INV)
5287ad62
JB
13262
13263enum neon_opc
13264{
13265#define X(OPC,I,F,S) N_MNEM_##OPC
13266NEON_ENC_TAB
13267#undef X
13268};
b99bd4ef 13269
5287ad62
JB
13270static const struct neon_tab_entry neon_enc_tab[] =
13271{
13272#define X(OPC,I,F,S) { (I), (F), (S) }
13273NEON_ENC_TAB
13274#undef X
13275};
b99bd4ef 13276
88714cb8
DG
13277/* Do not use these macros; instead, use NEON_ENCODE defined below. */
13278#define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13279#define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13280#define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13281#define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13282#define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13283#define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13284#define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13285#define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13286#define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13287#define NEON_ENC_SINGLE_(X) \
037e8744 13288 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
88714cb8 13289#define NEON_ENC_DOUBLE_(X) \
037e8744 13290 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
33399f07
MGD
13291#define NEON_ENC_FPV8_(X) \
13292 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
5287ad62 13293
88714cb8
DG
13294#define NEON_ENCODE(type, inst) \
13295 do \
13296 { \
13297 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13298 inst.is_neon = 1; \
13299 } \
13300 while (0)
13301
13302#define check_neon_suffixes \
13303 do \
13304 { \
13305 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13306 { \
13307 as_bad (_("invalid neon suffix for non neon instruction")); \
13308 return; \
13309 } \
13310 } \
13311 while (0)
13312
037e8744
JB
13313/* Define shapes for instruction operands. The following mnemonic characters
13314 are used in this table:
5287ad62 13315
037e8744 13316 F - VFP S<n> register
5287ad62
JB
13317 D - Neon D<n> register
13318 Q - Neon Q<n> register
13319 I - Immediate
13320 S - Scalar
13321 R - ARM register
13322 L - D<n> register list
5f4273c7 13323
037e8744
JB
13324 This table is used to generate various data:
13325 - enumerations of the form NS_DDR to be used as arguments to
13326 neon_select_shape.
13327 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 13328 - a table used to drive neon_select_shape. */
b99bd4ef 13329
037e8744
JB
13330#define NEON_SHAPE_DEF \
13331 X(3, (D, D, D), DOUBLE), \
13332 X(3, (Q, Q, Q), QUAD), \
13333 X(3, (D, D, I), DOUBLE), \
13334 X(3, (Q, Q, I), QUAD), \
13335 X(3, (D, D, S), DOUBLE), \
13336 X(3, (Q, Q, S), QUAD), \
13337 X(2, (D, D), DOUBLE), \
13338 X(2, (Q, Q), QUAD), \
13339 X(2, (D, S), DOUBLE), \
13340 X(2, (Q, S), QUAD), \
13341 X(2, (D, R), DOUBLE), \
13342 X(2, (Q, R), QUAD), \
13343 X(2, (D, I), DOUBLE), \
13344 X(2, (Q, I), QUAD), \
13345 X(3, (D, L, D), DOUBLE), \
13346 X(2, (D, Q), MIXED), \
13347 X(2, (Q, D), MIXED), \
13348 X(3, (D, Q, I), MIXED), \
13349 X(3, (Q, D, I), MIXED), \
13350 X(3, (Q, D, D), MIXED), \
13351 X(3, (D, Q, Q), MIXED), \
13352 X(3, (Q, Q, D), MIXED), \
13353 X(3, (Q, D, S), MIXED), \
13354 X(3, (D, Q, S), MIXED), \
13355 X(4, (D, D, D, I), DOUBLE), \
13356 X(4, (Q, Q, Q, I), QUAD), \
c28eeff2
SN
13357 X(4, (D, D, S, I), DOUBLE), \
13358 X(4, (Q, Q, S, I), QUAD), \
037e8744
JB
13359 X(2, (F, F), SINGLE), \
13360 X(3, (F, F, F), SINGLE), \
13361 X(2, (F, I), SINGLE), \
13362 X(2, (F, D), MIXED), \
13363 X(2, (D, F), MIXED), \
13364 X(3, (F, F, I), MIXED), \
13365 X(4, (R, R, F, F), SINGLE), \
13366 X(4, (F, F, R, R), SINGLE), \
13367 X(3, (D, R, R), DOUBLE), \
13368 X(3, (R, R, D), DOUBLE), \
13369 X(2, (S, R), SINGLE), \
13370 X(2, (R, S), SINGLE), \
13371 X(2, (F, R), SINGLE), \
d54af2d0
RL
13372 X(2, (R, F), SINGLE), \
13373/* Half float shape supported so far. */\
13374 X (2, (H, D), MIXED), \
13375 X (2, (D, H), MIXED), \
13376 X (2, (H, F), MIXED), \
13377 X (2, (F, H), MIXED), \
13378 X (2, (H, H), HALF), \
13379 X (2, (H, R), HALF), \
13380 X (2, (R, H), HALF), \
13381 X (2, (H, I), HALF), \
13382 X (3, (H, H, H), HALF), \
13383 X (3, (H, F, I), MIXED), \
13384 X (3, (F, H, I), MIXED)
037e8744
JB
13385
13386#define S2(A,B) NS_##A##B
13387#define S3(A,B,C) NS_##A##B##C
13388#define S4(A,B,C,D) NS_##A##B##C##D
13389
13390#define X(N, L, C) S##N L
13391
5287ad62
JB
13392enum neon_shape
13393{
037e8744
JB
13394 NEON_SHAPE_DEF,
13395 NS_NULL
5287ad62 13396};
b99bd4ef 13397
037e8744
JB
13398#undef X
13399#undef S2
13400#undef S3
13401#undef S4
13402
13403enum neon_shape_class
13404{
d54af2d0 13405 SC_HALF,
037e8744
JB
13406 SC_SINGLE,
13407 SC_DOUBLE,
13408 SC_QUAD,
13409 SC_MIXED
13410};
13411
13412#define X(N, L, C) SC_##C
13413
13414static enum neon_shape_class neon_shape_class[] =
13415{
13416 NEON_SHAPE_DEF
13417};
13418
13419#undef X
13420
13421enum neon_shape_el
13422{
d54af2d0 13423 SE_H,
037e8744
JB
13424 SE_F,
13425 SE_D,
13426 SE_Q,
13427 SE_I,
13428 SE_S,
13429 SE_R,
13430 SE_L
13431};
13432
13433/* Register widths of above. */
13434static unsigned neon_shape_el_size[] =
13435{
d54af2d0 13436 16,
037e8744
JB
13437 32,
13438 64,
13439 128,
13440 0,
13441 32,
13442 32,
13443 0
13444};
13445
13446struct neon_shape_info
13447{
13448 unsigned els;
13449 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13450};
13451
13452#define S2(A,B) { SE_##A, SE_##B }
13453#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13454#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13455
13456#define X(N, L, C) { N, S##N L }
13457
13458static struct neon_shape_info neon_shape_tab[] =
13459{
13460 NEON_SHAPE_DEF
13461};
13462
13463#undef X
13464#undef S2
13465#undef S3
13466#undef S4
13467
5287ad62
JB
13468/* Bit masks used in type checking given instructions.
13469 'N_EQK' means the type must be the same as (or based on in some way) the key
13470 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13471 set, various other bits can be set as well in order to modify the meaning of
13472 the type constraint. */
13473
13474enum neon_type_mask
13475{
8e79c3df
CM
13476 N_S8 = 0x0000001,
13477 N_S16 = 0x0000002,
13478 N_S32 = 0x0000004,
13479 N_S64 = 0x0000008,
13480 N_U8 = 0x0000010,
13481 N_U16 = 0x0000020,
13482 N_U32 = 0x0000040,
13483 N_U64 = 0x0000080,
13484 N_I8 = 0x0000100,
13485 N_I16 = 0x0000200,
13486 N_I32 = 0x0000400,
13487 N_I64 = 0x0000800,
13488 N_8 = 0x0001000,
13489 N_16 = 0x0002000,
13490 N_32 = 0x0004000,
13491 N_64 = 0x0008000,
13492 N_P8 = 0x0010000,
13493 N_P16 = 0x0020000,
13494 N_F16 = 0x0040000,
13495 N_F32 = 0x0080000,
13496 N_F64 = 0x0100000,
4f51b4bd 13497 N_P64 = 0x0200000,
c921be7d
NC
13498 N_KEY = 0x1000000, /* Key element (main type specifier). */
13499 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 13500 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
91ff7894 13501 N_UNT = 0x8000000, /* Must be explicitly untyped. */
c921be7d
NC
13502 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13503 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13504 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13505 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13506 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13507 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13508 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 13509 N_UTYP = 0,
4f51b4bd 13510 N_MAX_NONSPECIAL = N_P64
5287ad62
JB
13511};
13512
dcbf9037
JB
13513#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13514
5287ad62
JB
13515#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13516#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13517#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
cc933301
JW
13518#define N_S_32 (N_S8 | N_S16 | N_S32)
13519#define N_F_16_32 (N_F16 | N_F32)
13520#define N_SUF_32 (N_SU_32 | N_F_16_32)
5287ad62 13521#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
cc933301 13522#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
d54af2d0 13523#define N_F_ALL (N_F16 | N_F32 | N_F64)
5287ad62
JB
13524
13525/* Pass this as the first type argument to neon_check_type to ignore types
13526 altogether. */
13527#define N_IGNORE_TYPE (N_KEY | N_EQK)
13528
037e8744
JB
13529/* Select a "shape" for the current instruction (describing register types or
13530 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13531 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13532 function of operand parsing, so this function doesn't need to be called.
13533 Shapes should be listed in order of decreasing length. */
5287ad62
JB
13534
13535static enum neon_shape
037e8744 13536neon_select_shape (enum neon_shape shape, ...)
5287ad62 13537{
037e8744
JB
13538 va_list ap;
13539 enum neon_shape first_shape = shape;
5287ad62
JB
13540
13541 /* Fix missing optional operands. FIXME: we don't know at this point how
13542 many arguments we should have, so this makes the assumption that we have
13543 > 1. This is true of all current Neon opcodes, I think, but may not be
13544 true in the future. */
13545 if (!inst.operands[1].present)
13546 inst.operands[1] = inst.operands[0];
13547
037e8744 13548 va_start (ap, shape);
5f4273c7 13549
21d799b5 13550 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
13551 {
13552 unsigned j;
13553 int matches = 1;
13554
13555 for (j = 0; j < neon_shape_tab[shape].els; j++)
477330fc
RM
13556 {
13557 if (!inst.operands[j].present)
13558 {
13559 matches = 0;
13560 break;
13561 }
13562
13563 switch (neon_shape_tab[shape].el[j])
13564 {
d54af2d0
RL
13565 /* If a .f16, .16, .u16, .s16 type specifier is given over
13566 a VFP single precision register operand, it's essentially
13567 means only half of the register is used.
13568
13569 If the type specifier is given after the mnemonics, the
13570 information is stored in inst.vectype. If the type specifier
13571 is given after register operand, the information is stored
13572 in inst.operands[].vectype.
13573
13574 When there is only one type specifier, and all the register
13575 operands are the same type of hardware register, the type
13576 specifier applies to all register operands.
13577
13578 If no type specifier is given, the shape is inferred from
13579 operand information.
13580
13581 for example:
13582 vadd.f16 s0, s1, s2: NS_HHH
13583 vabs.f16 s0, s1: NS_HH
13584 vmov.f16 s0, r1: NS_HR
13585 vmov.f16 r0, s1: NS_RH
13586 vcvt.f16 r0, s1: NS_RH
13587 vcvt.f16.s32 s2, s2, #29: NS_HFI
13588 vcvt.f16.s32 s2, s2: NS_HF
13589 */
13590 case SE_H:
13591 if (!(inst.operands[j].isreg
13592 && inst.operands[j].isvec
13593 && inst.operands[j].issingle
13594 && !inst.operands[j].isquad
13595 && ((inst.vectype.elems == 1
13596 && inst.vectype.el[0].size == 16)
13597 || (inst.vectype.elems > 1
13598 && inst.vectype.el[j].size == 16)
13599 || (inst.vectype.elems == 0
13600 && inst.operands[j].vectype.type != NT_invtype
13601 && inst.operands[j].vectype.size == 16))))
13602 matches = 0;
13603 break;
13604
477330fc
RM
13605 case SE_F:
13606 if (!(inst.operands[j].isreg
13607 && inst.operands[j].isvec
13608 && inst.operands[j].issingle
d54af2d0
RL
13609 && !inst.operands[j].isquad
13610 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13611 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13612 || (inst.vectype.elems == 0
13613 && (inst.operands[j].vectype.size == 32
13614 || inst.operands[j].vectype.type == NT_invtype)))))
477330fc
RM
13615 matches = 0;
13616 break;
13617
13618 case SE_D:
13619 if (!(inst.operands[j].isreg
13620 && inst.operands[j].isvec
13621 && !inst.operands[j].isquad
13622 && !inst.operands[j].issingle))
13623 matches = 0;
13624 break;
13625
13626 case SE_R:
13627 if (!(inst.operands[j].isreg
13628 && !inst.operands[j].isvec))
13629 matches = 0;
13630 break;
13631
13632 case SE_Q:
13633 if (!(inst.operands[j].isreg
13634 && inst.operands[j].isvec
13635 && inst.operands[j].isquad
13636 && !inst.operands[j].issingle))
13637 matches = 0;
13638 break;
13639
13640 case SE_I:
13641 if (!(!inst.operands[j].isreg
13642 && !inst.operands[j].isscalar))
13643 matches = 0;
13644 break;
13645
13646 case SE_S:
13647 if (!(!inst.operands[j].isreg
13648 && inst.operands[j].isscalar))
13649 matches = 0;
13650 break;
13651
13652 case SE_L:
13653 break;
13654 }
3fde54a2
JZ
13655 if (!matches)
13656 break;
477330fc 13657 }
ad6cec43
MGD
13658 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13659 /* We've matched all the entries in the shape table, and we don't
13660 have any left over operands which have not been matched. */
477330fc 13661 break;
037e8744 13662 }
5f4273c7 13663
037e8744 13664 va_end (ap);
5287ad62 13665
037e8744
JB
13666 if (shape == NS_NULL && first_shape != NS_NULL)
13667 first_error (_("invalid instruction shape"));
5287ad62 13668
037e8744
JB
13669 return shape;
13670}
5287ad62 13671
037e8744
JB
13672/* True if SHAPE is predominantly a quadword operation (most of the time, this
13673 means the Q bit should be set). */
13674
13675static int
13676neon_quad (enum neon_shape shape)
13677{
13678 return neon_shape_class[shape] == SC_QUAD;
5287ad62 13679}
037e8744 13680
5287ad62
JB
13681static void
13682neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
477330fc 13683 unsigned *g_size)
5287ad62
JB
13684{
13685 /* Allow modification to be made to types which are constrained to be
13686 based on the key element, based on bits set alongside N_EQK. */
13687 if ((typebits & N_EQK) != 0)
13688 {
13689 if ((typebits & N_HLF) != 0)
13690 *g_size /= 2;
13691 else if ((typebits & N_DBL) != 0)
13692 *g_size *= 2;
13693 if ((typebits & N_SGN) != 0)
13694 *g_type = NT_signed;
13695 else if ((typebits & N_UNS) != 0)
477330fc 13696 *g_type = NT_unsigned;
5287ad62 13697 else if ((typebits & N_INT) != 0)
477330fc 13698 *g_type = NT_integer;
5287ad62 13699 else if ((typebits & N_FLT) != 0)
477330fc 13700 *g_type = NT_float;
dcbf9037 13701 else if ((typebits & N_SIZ) != 0)
477330fc 13702 *g_type = NT_untyped;
5287ad62
JB
13703 }
13704}
5f4273c7 13705
5287ad62
JB
13706/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13707 operand type, i.e. the single type specified in a Neon instruction when it
13708 is the only one given. */
13709
13710static struct neon_type_el
13711neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13712{
13713 struct neon_type_el dest = *key;
5f4273c7 13714
9c2799c2 13715 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 13716
5287ad62
JB
13717 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13718
13719 return dest;
13720}
13721
13722/* Convert Neon type and size into compact bitmask representation. */
13723
13724static enum neon_type_mask
13725type_chk_of_el_type (enum neon_el_type type, unsigned size)
13726{
13727 switch (type)
13728 {
13729 case NT_untyped:
13730 switch (size)
477330fc
RM
13731 {
13732 case 8: return N_8;
13733 case 16: return N_16;
13734 case 32: return N_32;
13735 case 64: return N_64;
13736 default: ;
13737 }
5287ad62
JB
13738 break;
13739
13740 case NT_integer:
13741 switch (size)
477330fc
RM
13742 {
13743 case 8: return N_I8;
13744 case 16: return N_I16;
13745 case 32: return N_I32;
13746 case 64: return N_I64;
13747 default: ;
13748 }
5287ad62
JB
13749 break;
13750
13751 case NT_float:
037e8744 13752 switch (size)
477330fc 13753 {
8e79c3df 13754 case 16: return N_F16;
477330fc
RM
13755 case 32: return N_F32;
13756 case 64: return N_F64;
13757 default: ;
13758 }
5287ad62
JB
13759 break;
13760
13761 case NT_poly:
13762 switch (size)
477330fc
RM
13763 {
13764 case 8: return N_P8;
13765 case 16: return N_P16;
4f51b4bd 13766 case 64: return N_P64;
477330fc
RM
13767 default: ;
13768 }
5287ad62
JB
13769 break;
13770
13771 case NT_signed:
13772 switch (size)
477330fc
RM
13773 {
13774 case 8: return N_S8;
13775 case 16: return N_S16;
13776 case 32: return N_S32;
13777 case 64: return N_S64;
13778 default: ;
13779 }
5287ad62
JB
13780 break;
13781
13782 case NT_unsigned:
13783 switch (size)
477330fc
RM
13784 {
13785 case 8: return N_U8;
13786 case 16: return N_U16;
13787 case 32: return N_U32;
13788 case 64: return N_U64;
13789 default: ;
13790 }
5287ad62
JB
13791 break;
13792
13793 default: ;
13794 }
5f4273c7 13795
5287ad62
JB
13796 return N_UTYP;
13797}
13798
13799/* Convert compact Neon bitmask type representation to a type and size. Only
13800 handles the case where a single bit is set in the mask. */
13801
dcbf9037 13802static int
5287ad62 13803el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
477330fc 13804 enum neon_type_mask mask)
5287ad62 13805{
dcbf9037
JB
13806 if ((mask & N_EQK) != 0)
13807 return FAIL;
13808
5287ad62
JB
13809 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13810 *size = 8;
c70a8987 13811 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
5287ad62 13812 *size = 16;
dcbf9037 13813 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 13814 *size = 32;
4f51b4bd 13815 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
5287ad62 13816 *size = 64;
dcbf9037
JB
13817 else
13818 return FAIL;
13819
5287ad62
JB
13820 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13821 *type = NT_signed;
dcbf9037 13822 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 13823 *type = NT_unsigned;
dcbf9037 13824 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 13825 *type = NT_integer;
dcbf9037 13826 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 13827 *type = NT_untyped;
4f51b4bd 13828 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
5287ad62 13829 *type = NT_poly;
d54af2d0 13830 else if ((mask & (N_F_ALL)) != 0)
5287ad62 13831 *type = NT_float;
dcbf9037
JB
13832 else
13833 return FAIL;
5f4273c7 13834
dcbf9037 13835 return SUCCESS;
5287ad62
JB
13836}
13837
13838/* Modify a bitmask of allowed types. This is only needed for type
13839 relaxation. */
13840
13841static unsigned
13842modify_types_allowed (unsigned allowed, unsigned mods)
13843{
13844 unsigned size;
13845 enum neon_el_type type;
13846 unsigned destmask;
13847 int i;
5f4273c7 13848
5287ad62 13849 destmask = 0;
5f4273c7 13850
5287ad62
JB
13851 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13852 {
21d799b5 13853 if (el_type_of_type_chk (&type, &size,
477330fc
RM
13854 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13855 {
13856 neon_modify_type_size (mods, &type, &size);
13857 destmask |= type_chk_of_el_type (type, size);
13858 }
5287ad62 13859 }
5f4273c7 13860
5287ad62
JB
13861 return destmask;
13862}
13863
13864/* Check type and return type classification.
13865 The manual states (paraphrase): If one datatype is given, it indicates the
13866 type given in:
13867 - the second operand, if there is one
13868 - the operand, if there is no second operand
13869 - the result, if there are no operands.
13870 This isn't quite good enough though, so we use a concept of a "key" datatype
13871 which is set on a per-instruction basis, which is the one which matters when
13872 only one data type is written.
13873 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 13874 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
13875
13876static struct neon_type_el
13877neon_check_type (unsigned els, enum neon_shape ns, ...)
13878{
13879 va_list ap;
13880 unsigned i, pass, key_el = 0;
13881 unsigned types[NEON_MAX_TYPE_ELS];
13882 enum neon_el_type k_type = NT_invtype;
13883 unsigned k_size = -1u;
13884 struct neon_type_el badtype = {NT_invtype, -1};
13885 unsigned key_allowed = 0;
13886
13887 /* Optional registers in Neon instructions are always (not) in operand 1.
13888 Fill in the missing operand here, if it was omitted. */
13889 if (els > 1 && !inst.operands[1].present)
13890 inst.operands[1] = inst.operands[0];
13891
13892 /* Suck up all the varargs. */
13893 va_start (ap, ns);
13894 for (i = 0; i < els; i++)
13895 {
13896 unsigned thisarg = va_arg (ap, unsigned);
13897 if (thisarg == N_IGNORE_TYPE)
477330fc
RM
13898 {
13899 va_end (ap);
13900 return badtype;
13901 }
5287ad62
JB
13902 types[i] = thisarg;
13903 if ((thisarg & N_KEY) != 0)
477330fc 13904 key_el = i;
5287ad62
JB
13905 }
13906 va_end (ap);
13907
dcbf9037
JB
13908 if (inst.vectype.elems > 0)
13909 for (i = 0; i < els; i++)
13910 if (inst.operands[i].vectype.type != NT_invtype)
477330fc
RM
13911 {
13912 first_error (_("types specified in both the mnemonic and operands"));
13913 return badtype;
13914 }
dcbf9037 13915
5287ad62
JB
13916 /* Duplicate inst.vectype elements here as necessary.
13917 FIXME: No idea if this is exactly the same as the ARM assembler,
13918 particularly when an insn takes one register and one non-register
13919 operand. */
13920 if (inst.vectype.elems == 1 && els > 1)
13921 {
13922 unsigned j;
13923 inst.vectype.elems = els;
13924 inst.vectype.el[key_el] = inst.vectype.el[0];
13925 for (j = 0; j < els; j++)
477330fc
RM
13926 if (j != key_el)
13927 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13928 types[j]);
dcbf9037
JB
13929 }
13930 else if (inst.vectype.elems == 0 && els > 0)
13931 {
13932 unsigned j;
13933 /* No types were given after the mnemonic, so look for types specified
477330fc
RM
13934 after each operand. We allow some flexibility here; as long as the
13935 "key" operand has a type, we can infer the others. */
dcbf9037 13936 for (j = 0; j < els; j++)
477330fc
RM
13937 if (inst.operands[j].vectype.type != NT_invtype)
13938 inst.vectype.el[j] = inst.operands[j].vectype;
dcbf9037
JB
13939
13940 if (inst.operands[key_el].vectype.type != NT_invtype)
477330fc
RM
13941 {
13942 for (j = 0; j < els; j++)
13943 if (inst.operands[j].vectype.type == NT_invtype)
13944 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
13945 types[j]);
13946 }
dcbf9037 13947 else
477330fc
RM
13948 {
13949 first_error (_("operand types can't be inferred"));
13950 return badtype;
13951 }
5287ad62
JB
13952 }
13953 else if (inst.vectype.elems != els)
13954 {
dcbf9037 13955 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
13956 return badtype;
13957 }
13958
13959 for (pass = 0; pass < 2; pass++)
13960 {
13961 for (i = 0; i < els; i++)
477330fc
RM
13962 {
13963 unsigned thisarg = types[i];
13964 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
13965 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
13966 enum neon_el_type g_type = inst.vectype.el[i].type;
13967 unsigned g_size = inst.vectype.el[i].size;
13968
13969 /* Decay more-specific signed & unsigned types to sign-insensitive
5287ad62 13970 integer types if sign-specific variants are unavailable. */
477330fc 13971 if ((g_type == NT_signed || g_type == NT_unsigned)
5287ad62
JB
13972 && (types_allowed & N_SU_ALL) == 0)
13973 g_type = NT_integer;
13974
477330fc 13975 /* If only untyped args are allowed, decay any more specific types to
5287ad62
JB
13976 them. Some instructions only care about signs for some element
13977 sizes, so handle that properly. */
477330fc 13978 if (((types_allowed & N_UNT) == 0)
91ff7894
MGD
13979 && ((g_size == 8 && (types_allowed & N_8) != 0)
13980 || (g_size == 16 && (types_allowed & N_16) != 0)
13981 || (g_size == 32 && (types_allowed & N_32) != 0)
13982 || (g_size == 64 && (types_allowed & N_64) != 0)))
5287ad62
JB
13983 g_type = NT_untyped;
13984
477330fc
RM
13985 if (pass == 0)
13986 {
13987 if ((thisarg & N_KEY) != 0)
13988 {
13989 k_type = g_type;
13990 k_size = g_size;
13991 key_allowed = thisarg & ~N_KEY;
cc933301
JW
13992
13993 /* Check architecture constraint on FP16 extension. */
13994 if (k_size == 16
13995 && k_type == NT_float
13996 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
13997 {
13998 inst.error = _(BAD_FP16);
13999 return badtype;
14000 }
477330fc
RM
14001 }
14002 }
14003 else
14004 {
14005 if ((thisarg & N_VFP) != 0)
14006 {
14007 enum neon_shape_el regshape;
14008 unsigned regwidth, match;
99b253c5
NC
14009
14010 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
14011 if (ns == NS_NULL)
14012 {
14013 first_error (_("invalid instruction shape"));
14014 return badtype;
14015 }
477330fc
RM
14016 regshape = neon_shape_tab[ns].el[i];
14017 regwidth = neon_shape_el_size[regshape];
14018
14019 /* In VFP mode, operands must match register widths. If we
14020 have a key operand, use its width, else use the width of
14021 the current operand. */
14022 if (k_size != -1u)
14023 match = k_size;
14024 else
14025 match = g_size;
14026
9db2f6b4
RL
14027 /* FP16 will use a single precision register. */
14028 if (regwidth == 32 && match == 16)
14029 {
14030 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14031 match = regwidth;
14032 else
14033 {
14034 inst.error = _(BAD_FP16);
14035 return badtype;
14036 }
14037 }
14038
477330fc
RM
14039 if (regwidth != match)
14040 {
14041 first_error (_("operand size must match register width"));
14042 return badtype;
14043 }
14044 }
14045
14046 if ((thisarg & N_EQK) == 0)
14047 {
14048 unsigned given_type = type_chk_of_el_type (g_type, g_size);
14049
14050 if ((given_type & types_allowed) == 0)
14051 {
14052 first_error (_("bad type in Neon instruction"));
14053 return badtype;
14054 }
14055 }
14056 else
14057 {
14058 enum neon_el_type mod_k_type = k_type;
14059 unsigned mod_k_size = k_size;
14060 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
14061 if (g_type != mod_k_type || g_size != mod_k_size)
14062 {
14063 first_error (_("inconsistent types in Neon instruction"));
14064 return badtype;
14065 }
14066 }
14067 }
14068 }
5287ad62
JB
14069 }
14070
14071 return inst.vectype.el[key_el];
14072}
14073
037e8744 14074/* Neon-style VFP instruction forwarding. */
5287ad62 14075
037e8744
JB
14076/* Thumb VFP instructions have 0xE in the condition field. */
14077
14078static void
14079do_vfp_cond_or_thumb (void)
5287ad62 14080{
88714cb8
DG
14081 inst.is_neon = 1;
14082
5287ad62 14083 if (thumb_mode)
037e8744 14084 inst.instruction |= 0xe0000000;
5287ad62 14085 else
037e8744 14086 inst.instruction |= inst.cond << 28;
5287ad62
JB
14087}
14088
037e8744
JB
14089/* Look up and encode a simple mnemonic, for use as a helper function for the
14090 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14091 etc. It is assumed that operand parsing has already been done, and that the
14092 operands are in the form expected by the given opcode (this isn't necessarily
14093 the same as the form in which they were parsed, hence some massaging must
14094 take place before this function is called).
14095 Checks current arch version against that in the looked-up opcode. */
5287ad62 14096
037e8744
JB
14097static void
14098do_vfp_nsyn_opcode (const char *opname)
5287ad62 14099{
037e8744 14100 const struct asm_opcode *opcode;
5f4273c7 14101
21d799b5 14102 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 14103
037e8744
JB
14104 if (!opcode)
14105 abort ();
5287ad62 14106
037e8744 14107 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
477330fc
RM
14108 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14109 _(BAD_FPU));
5287ad62 14110
88714cb8
DG
14111 inst.is_neon = 1;
14112
037e8744
JB
14113 if (thumb_mode)
14114 {
14115 inst.instruction = opcode->tvalue;
14116 opcode->tencode ();
14117 }
14118 else
14119 {
14120 inst.instruction = (inst.cond << 28) | opcode->avalue;
14121 opcode->aencode ();
14122 }
14123}
5287ad62
JB
14124
14125static void
037e8744 14126do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 14127{
037e8744
JB
14128 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14129
9db2f6b4 14130 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14131 {
14132 if (is_add)
477330fc 14133 do_vfp_nsyn_opcode ("fadds");
037e8744 14134 else
477330fc 14135 do_vfp_nsyn_opcode ("fsubs");
9db2f6b4
RL
14136
14137 /* ARMv8.2 fp16 instruction. */
14138 if (rs == NS_HHH)
14139 do_scalar_fp16_v82_encode ();
037e8744
JB
14140 }
14141 else
14142 {
14143 if (is_add)
477330fc 14144 do_vfp_nsyn_opcode ("faddd");
037e8744 14145 else
477330fc 14146 do_vfp_nsyn_opcode ("fsubd");
037e8744
JB
14147 }
14148}
14149
14150/* Check operand types to see if this is a VFP instruction, and if so call
14151 PFN (). */
14152
14153static int
14154try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14155{
14156 enum neon_shape rs;
14157 struct neon_type_el et;
14158
14159 switch (args)
14160 {
14161 case 2:
9db2f6b4
RL
14162 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14163 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
037e8744 14164 break;
5f4273c7 14165
037e8744 14166 case 3:
9db2f6b4
RL
14167 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14168 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14169 N_F_ALL | N_KEY | N_VFP);
037e8744
JB
14170 break;
14171
14172 default:
14173 abort ();
14174 }
14175
14176 if (et.type != NT_invtype)
14177 {
14178 pfn (rs);
14179 return SUCCESS;
14180 }
037e8744 14181
99b253c5 14182 inst.error = NULL;
037e8744
JB
14183 return FAIL;
14184}
14185
14186static void
14187do_vfp_nsyn_mla_mls (enum neon_shape rs)
14188{
14189 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 14190
9db2f6b4 14191 if (rs == NS_FFF || rs == NS_HHH)
037e8744
JB
14192 {
14193 if (is_mla)
477330fc 14194 do_vfp_nsyn_opcode ("fmacs");
037e8744 14195 else
477330fc 14196 do_vfp_nsyn_opcode ("fnmacs");
9db2f6b4
RL
14197
14198 /* ARMv8.2 fp16 instruction. */
14199 if (rs == NS_HHH)
14200 do_scalar_fp16_v82_encode ();
037e8744
JB
14201 }
14202 else
14203 {
14204 if (is_mla)
477330fc 14205 do_vfp_nsyn_opcode ("fmacd");
037e8744 14206 else
477330fc 14207 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
14208 }
14209}
14210
62f3b8c8
PB
14211static void
14212do_vfp_nsyn_fma_fms (enum neon_shape rs)
14213{
14214 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14215
9db2f6b4 14216 if (rs == NS_FFF || rs == NS_HHH)
62f3b8c8
PB
14217 {
14218 if (is_fma)
477330fc 14219 do_vfp_nsyn_opcode ("ffmas");
62f3b8c8 14220 else
477330fc 14221 do_vfp_nsyn_opcode ("ffnmas");
9db2f6b4
RL
14222
14223 /* ARMv8.2 fp16 instruction. */
14224 if (rs == NS_HHH)
14225 do_scalar_fp16_v82_encode ();
62f3b8c8
PB
14226 }
14227 else
14228 {
14229 if (is_fma)
477330fc 14230 do_vfp_nsyn_opcode ("ffmad");
62f3b8c8 14231 else
477330fc 14232 do_vfp_nsyn_opcode ("ffnmad");
62f3b8c8
PB
14233 }
14234}
14235
037e8744
JB
14236static void
14237do_vfp_nsyn_mul (enum neon_shape rs)
14238{
9db2f6b4
RL
14239 if (rs == NS_FFF || rs == NS_HHH)
14240 {
14241 do_vfp_nsyn_opcode ("fmuls");
14242
14243 /* ARMv8.2 fp16 instruction. */
14244 if (rs == NS_HHH)
14245 do_scalar_fp16_v82_encode ();
14246 }
037e8744
JB
14247 else
14248 do_vfp_nsyn_opcode ("fmuld");
14249}
14250
14251static void
14252do_vfp_nsyn_abs_neg (enum neon_shape rs)
14253{
14254 int is_neg = (inst.instruction & 0x80) != 0;
9db2f6b4 14255 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
037e8744 14256
9db2f6b4 14257 if (rs == NS_FF || rs == NS_HH)
037e8744
JB
14258 {
14259 if (is_neg)
477330fc 14260 do_vfp_nsyn_opcode ("fnegs");
037e8744 14261 else
477330fc 14262 do_vfp_nsyn_opcode ("fabss");
9db2f6b4
RL
14263
14264 /* ARMv8.2 fp16 instruction. */
14265 if (rs == NS_HH)
14266 do_scalar_fp16_v82_encode ();
037e8744
JB
14267 }
14268 else
14269 {
14270 if (is_neg)
477330fc 14271 do_vfp_nsyn_opcode ("fnegd");
037e8744 14272 else
477330fc 14273 do_vfp_nsyn_opcode ("fabsd");
037e8744
JB
14274 }
14275}
14276
14277/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14278 insns belong to Neon, and are handled elsewhere. */
14279
14280static void
14281do_vfp_nsyn_ldm_stm (int is_dbmode)
14282{
14283 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14284 if (is_ldm)
14285 {
14286 if (is_dbmode)
477330fc 14287 do_vfp_nsyn_opcode ("fldmdbs");
037e8744 14288 else
477330fc 14289 do_vfp_nsyn_opcode ("fldmias");
037e8744
JB
14290 }
14291 else
14292 {
14293 if (is_dbmode)
477330fc 14294 do_vfp_nsyn_opcode ("fstmdbs");
037e8744 14295 else
477330fc 14296 do_vfp_nsyn_opcode ("fstmias");
037e8744
JB
14297 }
14298}
14299
037e8744
JB
14300static void
14301do_vfp_nsyn_sqrt (void)
14302{
9db2f6b4
RL
14303 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14304 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14305
9db2f6b4
RL
14306 if (rs == NS_FF || rs == NS_HH)
14307 {
14308 do_vfp_nsyn_opcode ("fsqrts");
14309
14310 /* ARMv8.2 fp16 instruction. */
14311 if (rs == NS_HH)
14312 do_scalar_fp16_v82_encode ();
14313 }
037e8744
JB
14314 else
14315 do_vfp_nsyn_opcode ("fsqrtd");
14316}
14317
14318static void
14319do_vfp_nsyn_div (void)
14320{
9db2f6b4 14321 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14322 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14323 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14324
9db2f6b4
RL
14325 if (rs == NS_FFF || rs == NS_HHH)
14326 {
14327 do_vfp_nsyn_opcode ("fdivs");
14328
14329 /* ARMv8.2 fp16 instruction. */
14330 if (rs == NS_HHH)
14331 do_scalar_fp16_v82_encode ();
14332 }
037e8744
JB
14333 else
14334 do_vfp_nsyn_opcode ("fdivd");
14335}
14336
14337static void
14338do_vfp_nsyn_nmul (void)
14339{
9db2f6b4 14340 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
037e8744 14341 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
9db2f6b4 14342 N_F_ALL | N_KEY | N_VFP);
5f4273c7 14343
9db2f6b4 14344 if (rs == NS_FFF || rs == NS_HHH)
037e8744 14345 {
88714cb8 14346 NEON_ENCODE (SINGLE, inst);
037e8744 14347 do_vfp_sp_dyadic ();
9db2f6b4
RL
14348
14349 /* ARMv8.2 fp16 instruction. */
14350 if (rs == NS_HHH)
14351 do_scalar_fp16_v82_encode ();
037e8744
JB
14352 }
14353 else
14354 {
88714cb8 14355 NEON_ENCODE (DOUBLE, inst);
037e8744
JB
14356 do_vfp_dp_rd_rn_rm ();
14357 }
14358 do_vfp_cond_or_thumb ();
9db2f6b4 14359
037e8744
JB
14360}
14361
14362static void
14363do_vfp_nsyn_cmp (void)
14364{
9db2f6b4 14365 enum neon_shape rs;
037e8744
JB
14366 if (inst.operands[1].isreg)
14367 {
9db2f6b4
RL
14368 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14369 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
5f4273c7 14370
9db2f6b4 14371 if (rs == NS_FF || rs == NS_HH)
477330fc
RM
14372 {
14373 NEON_ENCODE (SINGLE, inst);
14374 do_vfp_sp_monadic ();
14375 }
037e8744 14376 else
477330fc
RM
14377 {
14378 NEON_ENCODE (DOUBLE, inst);
14379 do_vfp_dp_rd_rm ();
14380 }
037e8744
JB
14381 }
14382 else
14383 {
9db2f6b4
RL
14384 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14385 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
037e8744
JB
14386
14387 switch (inst.instruction & 0x0fffffff)
477330fc
RM
14388 {
14389 case N_MNEM_vcmp:
14390 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14391 break;
14392 case N_MNEM_vcmpe:
14393 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14394 break;
14395 default:
14396 abort ();
14397 }
5f4273c7 14398
9db2f6b4 14399 if (rs == NS_FI || rs == NS_HI)
477330fc
RM
14400 {
14401 NEON_ENCODE (SINGLE, inst);
14402 do_vfp_sp_compare_z ();
14403 }
037e8744 14404 else
477330fc
RM
14405 {
14406 NEON_ENCODE (DOUBLE, inst);
14407 do_vfp_dp_rd ();
14408 }
037e8744
JB
14409 }
14410 do_vfp_cond_or_thumb ();
9db2f6b4
RL
14411
14412 /* ARMv8.2 fp16 instruction. */
14413 if (rs == NS_HI || rs == NS_HH)
14414 do_scalar_fp16_v82_encode ();
037e8744
JB
14415}
14416
14417static void
14418nsyn_insert_sp (void)
14419{
14420 inst.operands[1] = inst.operands[0];
14421 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 14422 inst.operands[0].reg = REG_SP;
037e8744
JB
14423 inst.operands[0].isreg = 1;
14424 inst.operands[0].writeback = 1;
14425 inst.operands[0].present = 1;
14426}
14427
14428static void
14429do_vfp_nsyn_push (void)
14430{
14431 nsyn_insert_sp ();
b126985e
NC
14432
14433 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14434 _("register list must contain at least 1 and at most 16 "
14435 "registers"));
14436
037e8744
JB
14437 if (inst.operands[1].issingle)
14438 do_vfp_nsyn_opcode ("fstmdbs");
14439 else
14440 do_vfp_nsyn_opcode ("fstmdbd");
14441}
14442
14443static void
14444do_vfp_nsyn_pop (void)
14445{
14446 nsyn_insert_sp ();
b126985e
NC
14447
14448 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14449 _("register list must contain at least 1 and at most 16 "
14450 "registers"));
14451
037e8744 14452 if (inst.operands[1].issingle)
22b5b651 14453 do_vfp_nsyn_opcode ("fldmias");
037e8744 14454 else
22b5b651 14455 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
14456}
14457
14458/* Fix up Neon data-processing instructions, ORing in the correct bits for
14459 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14460
88714cb8
DG
14461static void
14462neon_dp_fixup (struct arm_it* insn)
037e8744 14463{
88714cb8
DG
14464 unsigned int i = insn->instruction;
14465 insn->is_neon = 1;
14466
037e8744
JB
14467 if (thumb_mode)
14468 {
14469 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14470 if (i & (1 << 24))
477330fc 14471 i |= 1 << 28;
5f4273c7 14472
037e8744 14473 i &= ~(1 << 24);
5f4273c7 14474
037e8744
JB
14475 i |= 0xef000000;
14476 }
14477 else
14478 i |= 0xf2000000;
5f4273c7 14479
88714cb8 14480 insn->instruction = i;
037e8744
JB
14481}
14482
14483/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14484 (0, 1, 2, 3). */
14485
14486static unsigned
14487neon_logbits (unsigned x)
14488{
14489 return ffs (x) - 4;
14490}
14491
14492#define LOW4(R) ((R) & 0xf)
14493#define HI1(R) (((R) >> 4) & 1)
14494
14495/* Encode insns with bit pattern:
14496
14497 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14498 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 14499
037e8744
JB
14500 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14501 different meaning for some instruction. */
14502
14503static void
14504neon_three_same (int isquad, int ubit, int size)
14505{
14506 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14507 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14508 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14509 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14510 inst.instruction |= LOW4 (inst.operands[2].reg);
14511 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14512 inst.instruction |= (isquad != 0) << 6;
14513 inst.instruction |= (ubit != 0) << 24;
14514 if (size != -1)
14515 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 14516
88714cb8 14517 neon_dp_fixup (&inst);
037e8744
JB
14518}
14519
14520/* Encode instructions of the form:
14521
14522 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14523 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
14524
14525 Don't write size if SIZE == -1. */
14526
14527static void
14528neon_two_same (int qbit, int ubit, int size)
14529{
14530 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14531 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14532 inst.instruction |= LOW4 (inst.operands[1].reg);
14533 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14534 inst.instruction |= (qbit != 0) << 6;
14535 inst.instruction |= (ubit != 0) << 24;
14536
14537 if (size != -1)
14538 inst.instruction |= neon_logbits (size) << 18;
14539
88714cb8 14540 neon_dp_fixup (&inst);
5287ad62
JB
14541}
14542
14543/* Neon instruction encoders, in approximate order of appearance. */
14544
14545static void
14546do_neon_dyadic_i_su (void)
14547{
037e8744 14548 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14549 struct neon_type_el et = neon_check_type (3, rs,
14550 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 14551 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14552}
14553
14554static void
14555do_neon_dyadic_i64_su (void)
14556{
037e8744 14557 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14558 struct neon_type_el et = neon_check_type (3, rs,
14559 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 14560 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14561}
14562
14563static void
14564neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
477330fc 14565 unsigned immbits)
5287ad62
JB
14566{
14567 unsigned size = et.size >> 3;
14568 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14569 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14570 inst.instruction |= LOW4 (inst.operands[1].reg);
14571 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14572 inst.instruction |= (isquad != 0) << 6;
14573 inst.instruction |= immbits << 16;
14574 inst.instruction |= (size >> 3) << 7;
14575 inst.instruction |= (size & 0x7) << 19;
14576 if (write_ubit)
14577 inst.instruction |= (uval != 0) << 24;
14578
88714cb8 14579 neon_dp_fixup (&inst);
5287ad62
JB
14580}
14581
14582static void
14583do_neon_shl_imm (void)
14584{
14585 if (!inst.operands[2].isreg)
14586 {
037e8744 14587 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14588 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
cb3b1e65
JB
14589 int imm = inst.operands[2].imm;
14590
14591 constraint (imm < 0 || (unsigned)imm >= et.size,
14592 _("immediate out of range for shift"));
88714cb8 14593 NEON_ENCODE (IMMED, inst);
cb3b1e65 14594 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
14595 }
14596 else
14597 {
037e8744 14598 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14599 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14600 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14601 unsigned int tmp;
14602
14603 /* VSHL/VQSHL 3-register variants have syntax such as:
477330fc
RM
14604 vshl.xx Dd, Dm, Dn
14605 whereas other 3-register operations encoded by neon_three_same have
14606 syntax like:
14607 vadd.xx Dd, Dn, Dm
14608 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14609 here. */
627907b7
JB
14610 tmp = inst.operands[2].reg;
14611 inst.operands[2].reg = inst.operands[1].reg;
14612 inst.operands[1].reg = tmp;
88714cb8 14613 NEON_ENCODE (INTEGER, inst);
037e8744 14614 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14615 }
14616}
14617
14618static void
14619do_neon_qshl_imm (void)
14620{
14621 if (!inst.operands[2].isreg)
14622 {
037e8744 14623 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 14624 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
cb3b1e65 14625 int imm = inst.operands[2].imm;
627907b7 14626
cb3b1e65
JB
14627 constraint (imm < 0 || (unsigned)imm >= et.size,
14628 _("immediate out of range for shift"));
88714cb8 14629 NEON_ENCODE (IMMED, inst);
cb3b1e65 14630 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
5287ad62
JB
14631 }
14632 else
14633 {
037e8744 14634 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 14635 struct neon_type_el et = neon_check_type (3, rs,
477330fc 14636 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
14637 unsigned int tmp;
14638
14639 /* See note in do_neon_shl_imm. */
14640 tmp = inst.operands[2].reg;
14641 inst.operands[2].reg = inst.operands[1].reg;
14642 inst.operands[1].reg = tmp;
88714cb8 14643 NEON_ENCODE (INTEGER, inst);
037e8744 14644 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
14645 }
14646}
14647
627907b7
JB
14648static void
14649do_neon_rshl (void)
14650{
14651 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14652 struct neon_type_el et = neon_check_type (3, rs,
14653 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14654 unsigned int tmp;
14655
14656 tmp = inst.operands[2].reg;
14657 inst.operands[2].reg = inst.operands[1].reg;
14658 inst.operands[1].reg = tmp;
14659 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14660}
14661
5287ad62
JB
14662static int
14663neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14664{
036dc3f7
PB
14665 /* Handle .I8 pseudo-instructions. */
14666 if (size == 8)
5287ad62 14667 {
5287ad62 14668 /* Unfortunately, this will make everything apart from zero out-of-range.
477330fc
RM
14669 FIXME is this the intended semantics? There doesn't seem much point in
14670 accepting .I8 if so. */
5287ad62
JB
14671 immediate |= immediate << 8;
14672 size = 16;
036dc3f7
PB
14673 }
14674
14675 if (size >= 32)
14676 {
14677 if (immediate == (immediate & 0x000000ff))
14678 {
14679 *immbits = immediate;
14680 return 0x1;
14681 }
14682 else if (immediate == (immediate & 0x0000ff00))
14683 {
14684 *immbits = immediate >> 8;
14685 return 0x3;
14686 }
14687 else if (immediate == (immediate & 0x00ff0000))
14688 {
14689 *immbits = immediate >> 16;
14690 return 0x5;
14691 }
14692 else if (immediate == (immediate & 0xff000000))
14693 {
14694 *immbits = immediate >> 24;
14695 return 0x7;
14696 }
14697 if ((immediate & 0xffff) != (immediate >> 16))
14698 goto bad_immediate;
14699 immediate &= 0xffff;
5287ad62
JB
14700 }
14701
14702 if (immediate == (immediate & 0x000000ff))
14703 {
14704 *immbits = immediate;
036dc3f7 14705 return 0x9;
5287ad62
JB
14706 }
14707 else if (immediate == (immediate & 0x0000ff00))
14708 {
14709 *immbits = immediate >> 8;
036dc3f7 14710 return 0xb;
5287ad62
JB
14711 }
14712
14713 bad_immediate:
dcbf9037 14714 first_error (_("immediate value out of range"));
5287ad62
JB
14715 return FAIL;
14716}
14717
5287ad62
JB
14718static void
14719do_neon_logic (void)
14720{
14721 if (inst.operands[2].present && inst.operands[2].isreg)
14722 {
037e8744 14723 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
14724 neon_check_type (3, rs, N_IGNORE_TYPE);
14725 /* U bit and size field were set as part of the bitmask. */
88714cb8 14726 NEON_ENCODE (INTEGER, inst);
037e8744 14727 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14728 }
14729 else
14730 {
4316f0d2
DG
14731 const int three_ops_form = (inst.operands[2].present
14732 && !inst.operands[2].isreg);
14733 const int immoperand = (three_ops_form ? 2 : 1);
14734 enum neon_shape rs = (three_ops_form
14735 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14736 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
037e8744 14737 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14738 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 14739 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
14740 unsigned immbits;
14741 int cmode;
5f4273c7 14742
5287ad62 14743 if (et.type == NT_invtype)
477330fc 14744 return;
5f4273c7 14745
4316f0d2
DG
14746 if (three_ops_form)
14747 constraint (inst.operands[0].reg != inst.operands[1].reg,
14748 _("first and second operands shall be the same register"));
14749
88714cb8 14750 NEON_ENCODE (IMMED, inst);
5287ad62 14751
4316f0d2 14752 immbits = inst.operands[immoperand].imm;
036dc3f7
PB
14753 if (et.size == 64)
14754 {
14755 /* .i64 is a pseudo-op, so the immediate must be a repeating
14756 pattern. */
4316f0d2
DG
14757 if (immbits != (inst.operands[immoperand].regisimm ?
14758 inst.operands[immoperand].reg : 0))
036dc3f7
PB
14759 {
14760 /* Set immbits to an invalid constant. */
14761 immbits = 0xdeadbeef;
14762 }
14763 }
14764
5287ad62 14765 switch (opcode)
477330fc
RM
14766 {
14767 case N_MNEM_vbic:
14768 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14769 break;
14770
14771 case N_MNEM_vorr:
14772 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14773 break;
14774
14775 case N_MNEM_vand:
14776 /* Pseudo-instruction for VBIC. */
14777 neon_invert_size (&immbits, 0, et.size);
14778 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14779 break;
14780
14781 case N_MNEM_vorn:
14782 /* Pseudo-instruction for VORR. */
14783 neon_invert_size (&immbits, 0, et.size);
14784 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14785 break;
14786
14787 default:
14788 abort ();
14789 }
5287ad62
JB
14790
14791 if (cmode == FAIL)
477330fc 14792 return;
5287ad62 14793
037e8744 14794 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14795 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14796 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14797 inst.instruction |= cmode << 8;
14798 neon_write_immbits (immbits);
5f4273c7 14799
88714cb8 14800 neon_dp_fixup (&inst);
5287ad62
JB
14801 }
14802}
14803
14804static void
14805do_neon_bitfield (void)
14806{
037e8744 14807 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14808 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 14809 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
14810}
14811
14812static void
dcbf9037 14813neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
477330fc 14814 unsigned destbits)
5287ad62 14815{
037e8744 14816 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 14817 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
477330fc 14818 types | N_KEY);
5287ad62
JB
14819 if (et.type == NT_float)
14820 {
88714cb8 14821 NEON_ENCODE (FLOAT, inst);
cc933301 14822 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
14823 }
14824 else
14825 {
88714cb8 14826 NEON_ENCODE (INTEGER, inst);
037e8744 14827 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
14828 }
14829}
14830
14831static void
14832do_neon_dyadic_if_su (void)
14833{
dcbf9037 14834 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14835}
14836
14837static void
14838do_neon_dyadic_if_su_d (void)
14839{
14840 /* This version only allow D registers, but that constraint is enforced during
14841 operand parsing so we don't need to do anything extra here. */
dcbf9037 14842 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
14843}
14844
5287ad62
JB
14845static void
14846do_neon_dyadic_if_i_d (void)
14847{
428e3f1f
PB
14848 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14849 affected if we specify unsigned args. */
14850 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
14851}
14852
037e8744
JB
14853enum vfp_or_neon_is_neon_bits
14854{
14855 NEON_CHECK_CC = 1,
73924fbc
MGD
14856 NEON_CHECK_ARCH = 2,
14857 NEON_CHECK_ARCH8 = 4
037e8744
JB
14858};
14859
14860/* Call this function if an instruction which may have belonged to the VFP or
14861 Neon instruction sets, but turned out to be a Neon instruction (due to the
14862 operand types involved, etc.). We have to check and/or fix-up a couple of
14863 things:
14864
14865 - Make sure the user hasn't attempted to make a Neon instruction
14866 conditional.
14867 - Alter the value in the condition code field if necessary.
14868 - Make sure that the arch supports Neon instructions.
14869
14870 Which of these operations take place depends on bits from enum
14871 vfp_or_neon_is_neon_bits.
14872
14873 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14874 current instruction's condition is COND_ALWAYS, the condition field is
14875 changed to inst.uncond_value. This is necessary because instructions shared
14876 between VFP and Neon may be conditional for the VFP variants only, and the
14877 unconditional Neon version must have, e.g., 0xF in the condition field. */
14878
14879static int
14880vfp_or_neon_is_neon (unsigned check)
14881{
14882 /* Conditions are always legal in Thumb mode (IT blocks). */
14883 if (!thumb_mode && (check & NEON_CHECK_CC))
14884 {
14885 if (inst.cond != COND_ALWAYS)
477330fc
RM
14886 {
14887 first_error (_(BAD_COND));
14888 return FAIL;
14889 }
037e8744 14890 if (inst.uncond_value != -1)
477330fc 14891 inst.instruction |= inst.uncond_value << 28;
037e8744 14892 }
5f4273c7 14893
037e8744 14894 if ((check & NEON_CHECK_ARCH)
73924fbc
MGD
14895 && !mark_feature_used (&fpu_neon_ext_v1))
14896 {
14897 first_error (_(BAD_FPU));
14898 return FAIL;
14899 }
14900
14901 if ((check & NEON_CHECK_ARCH8)
14902 && !mark_feature_used (&fpu_neon_ext_armv8))
037e8744
JB
14903 {
14904 first_error (_(BAD_FPU));
14905 return FAIL;
14906 }
5f4273c7 14907
037e8744
JB
14908 return SUCCESS;
14909}
14910
5287ad62
JB
14911static void
14912do_neon_addsub_if_i (void)
14913{
037e8744
JB
14914 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
14915 return;
14916
14917 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14918 return;
14919
5287ad62
JB
14920 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14921 affected if we specify unsigned args. */
dcbf9037 14922 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
14923}
14924
14925/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
14926 result to be:
14927 V<op> A,B (A is operand 0, B is operand 2)
14928 to mean:
14929 V<op> A,B,A
14930 not:
14931 V<op> A,B,B
14932 so handle that case specially. */
14933
14934static void
14935neon_exchange_operands (void)
14936{
5287ad62
JB
14937 if (inst.operands[1].present)
14938 {
e1fa0163
NC
14939 void *scratch = xmalloc (sizeof (inst.operands[0]));
14940
5287ad62
JB
14941 /* Swap operands[1] and operands[2]. */
14942 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
14943 inst.operands[1] = inst.operands[2];
14944 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
e1fa0163 14945 free (scratch);
5287ad62
JB
14946 }
14947 else
14948 {
14949 inst.operands[1] = inst.operands[2];
14950 inst.operands[2] = inst.operands[0];
14951 }
14952}
14953
14954static void
14955neon_compare (unsigned regtypes, unsigned immtypes, int invert)
14956{
14957 if (inst.operands[2].isreg)
14958 {
14959 if (invert)
477330fc 14960 neon_exchange_operands ();
dcbf9037 14961 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
14962 }
14963 else
14964 {
037e8744 14965 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037 14966 struct neon_type_el et = neon_check_type (2, rs,
477330fc 14967 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62 14968
88714cb8 14969 NEON_ENCODE (IMMED, inst);
5287ad62
JB
14970 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14971 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14972 inst.instruction |= LOW4 (inst.operands[1].reg);
14973 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 14974 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14975 inst.instruction |= (et.type == NT_float) << 10;
14976 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 14977
88714cb8 14978 neon_dp_fixup (&inst);
5287ad62
JB
14979 }
14980}
14981
14982static void
14983do_neon_cmp (void)
14984{
cc933301 14985 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
5287ad62
JB
14986}
14987
14988static void
14989do_neon_cmp_inv (void)
14990{
cc933301 14991 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
5287ad62
JB
14992}
14993
14994static void
14995do_neon_ceq (void)
14996{
14997 neon_compare (N_IF_32, N_IF_32, FALSE);
14998}
14999
15000/* For multiply instructions, we have the possibility of 16-bit or 32-bit
15001 scalars, which are encoded in 5 bits, M : Rm.
15002 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
15003 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
15004 index in M. */
15005
15006static unsigned
15007neon_scalar_for_mul (unsigned scalar, unsigned elsize)
15008{
dcbf9037
JB
15009 unsigned regno = NEON_SCALAR_REG (scalar);
15010 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
15011
15012 switch (elsize)
15013 {
15014 case 16:
15015 if (regno > 7 || elno > 3)
477330fc 15016 goto bad_scalar;
5287ad62 15017 return regno | (elno << 3);
5f4273c7 15018
5287ad62
JB
15019 case 32:
15020 if (regno > 15 || elno > 1)
477330fc 15021 goto bad_scalar;
5287ad62
JB
15022 return regno | (elno << 4);
15023
15024 default:
15025 bad_scalar:
dcbf9037 15026 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
15027 }
15028
15029 return 0;
15030}
15031
15032/* Encode multiply / multiply-accumulate scalar instructions. */
15033
15034static void
15035neon_mul_mac (struct neon_type_el et, int ubit)
15036{
dcbf9037
JB
15037 unsigned scalar;
15038
15039 /* Give a more helpful error message if we have an invalid type. */
15040 if (et.type == NT_invtype)
15041 return;
5f4273c7 15042
dcbf9037 15043 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
15044 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15045 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15046 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15047 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15048 inst.instruction |= LOW4 (scalar);
15049 inst.instruction |= HI1 (scalar) << 5;
15050 inst.instruction |= (et.type == NT_float) << 8;
15051 inst.instruction |= neon_logbits (et.size) << 20;
15052 inst.instruction |= (ubit != 0) << 24;
15053
88714cb8 15054 neon_dp_fixup (&inst);
5287ad62
JB
15055}
15056
15057static void
15058do_neon_mac_maybe_scalar (void)
15059{
037e8744
JB
15060 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
15061 return;
15062
15063 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15064 return;
15065
5287ad62
JB
15066 if (inst.operands[2].isscalar)
15067 {
037e8744 15068 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15069 struct neon_type_el et = neon_check_type (3, rs,
589a7d88 15070 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
88714cb8 15071 NEON_ENCODE (SCALAR, inst);
037e8744 15072 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15073 }
15074 else
428e3f1f
PB
15075 {
15076 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15077 affected if we specify unsigned args. */
15078 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15079 }
5287ad62
JB
15080}
15081
62f3b8c8
PB
15082static void
15083do_neon_fmac (void)
15084{
15085 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15086 return;
15087
15088 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15089 return;
15090
15091 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15092}
15093
5287ad62
JB
15094static void
15095do_neon_tst (void)
15096{
037e8744 15097 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
15098 struct neon_type_el et = neon_check_type (3, rs,
15099 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 15100 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15101}
15102
15103/* VMUL with 3 registers allows the P8 type. The scalar version supports the
15104 same types as the MAC equivalents. The polynomial type for this instruction
15105 is encoded the same as the integer type. */
15106
15107static void
15108do_neon_mul (void)
15109{
037e8744
JB
15110 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
15111 return;
15112
15113 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15114 return;
15115
5287ad62
JB
15116 if (inst.operands[2].isscalar)
15117 do_neon_mac_maybe_scalar ();
15118 else
cc933301 15119 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
5287ad62
JB
15120}
15121
15122static void
15123do_neon_qdmulh (void)
15124{
15125 if (inst.operands[2].isscalar)
15126 {
037e8744 15127 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62 15128 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15129 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15130 NEON_ENCODE (SCALAR, inst);
037e8744 15131 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
15132 }
15133 else
15134 {
037e8744 15135 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 15136 struct neon_type_el et = neon_check_type (3, rs,
477330fc 15137 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
88714cb8 15138 NEON_ENCODE (INTEGER, inst);
5287ad62 15139 /* The U bit (rounding) comes from bit mask. */
037e8744 15140 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
15141 }
15142}
15143
643afb90
MW
15144static void
15145do_neon_qrdmlah (void)
15146{
15147 /* Check we're on the correct architecture. */
15148 if (!mark_feature_used (&fpu_neon_ext_armv8))
15149 inst.error =
15150 _("instruction form not available on this architecture.");
15151 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15152 {
15153 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15154 record_feature_use (&fpu_neon_ext_v8_1);
15155 }
15156
15157 if (inst.operands[2].isscalar)
15158 {
15159 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15160 struct neon_type_el et = neon_check_type (3, rs,
15161 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15162 NEON_ENCODE (SCALAR, inst);
15163 neon_mul_mac (et, neon_quad (rs));
15164 }
15165 else
15166 {
15167 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15168 struct neon_type_el et = neon_check_type (3, rs,
15169 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15170 NEON_ENCODE (INTEGER, inst);
15171 /* The U bit (rounding) comes from bit mask. */
15172 neon_three_same (neon_quad (rs), 0, et.size);
15173 }
15174}
15175
5287ad62
JB
15176static void
15177do_neon_fcmp_absolute (void)
15178{
037e8744 15179 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15180 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15181 N_F_16_32 | N_KEY);
5287ad62 15182 /* Size field comes from bit mask. */
cc933301 15183 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15184}
15185
15186static void
15187do_neon_fcmp_absolute_inv (void)
15188{
15189 neon_exchange_operands ();
15190 do_neon_fcmp_absolute ();
15191}
15192
15193static void
15194do_neon_step (void)
15195{
037e8744 15196 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
cc933301
JW
15197 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15198 N_F_16_32 | N_KEY);
15199 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
5287ad62
JB
15200}
15201
15202static void
15203do_neon_abs_neg (void)
15204{
037e8744
JB
15205 enum neon_shape rs;
15206 struct neon_type_el et;
5f4273c7 15207
037e8744
JB
15208 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15209 return;
15210
15211 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15212 return;
15213
15214 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
cc933301 15215 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
5f4273c7 15216
5287ad62
JB
15217 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15218 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15219 inst.instruction |= LOW4 (inst.operands[1].reg);
15220 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 15221 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15222 inst.instruction |= (et.type == NT_float) << 10;
15223 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15224
88714cb8 15225 neon_dp_fixup (&inst);
5287ad62
JB
15226}
15227
15228static void
15229do_neon_sli (void)
15230{
037e8744 15231 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15232 struct neon_type_el et = neon_check_type (2, rs,
15233 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15234 int imm = inst.operands[2].imm;
15235 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15236 _("immediate out of range for insert"));
037e8744 15237 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15238}
15239
15240static void
15241do_neon_sri (void)
15242{
037e8744 15243 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15244 struct neon_type_el et = neon_check_type (2, rs,
15245 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15246 int imm = inst.operands[2].imm;
15247 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15248 _("immediate out of range for insert"));
037e8744 15249 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
15250}
15251
15252static void
15253do_neon_qshlu_imm (void)
15254{
037e8744 15255 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
15256 struct neon_type_el et = neon_check_type (2, rs,
15257 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15258 int imm = inst.operands[2].imm;
15259 constraint (imm < 0 || (unsigned)imm >= et.size,
477330fc 15260 _("immediate out of range for shift"));
5287ad62
JB
15261 /* Only encodes the 'U present' variant of the instruction.
15262 In this case, signed types have OP (bit 8) set to 0.
15263 Unsigned types have OP set to 1. */
15264 inst.instruction |= (et.type == NT_unsigned) << 8;
15265 /* The rest of the bits are the same as other immediate shifts. */
037e8744 15266 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
15267}
15268
15269static void
15270do_neon_qmovn (void)
15271{
15272 struct neon_type_el et = neon_check_type (2, NS_DQ,
15273 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15274 /* Saturating move where operands can be signed or unsigned, and the
15275 destination has the same signedness. */
88714cb8 15276 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15277 if (et.type == NT_unsigned)
15278 inst.instruction |= 0xc0;
15279 else
15280 inst.instruction |= 0x80;
15281 neon_two_same (0, 1, et.size / 2);
15282}
15283
15284static void
15285do_neon_qmovun (void)
15286{
15287 struct neon_type_el et = neon_check_type (2, NS_DQ,
15288 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15289 /* Saturating move with unsigned results. Operands must be signed. */
88714cb8 15290 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15291 neon_two_same (0, 1, et.size / 2);
15292}
15293
15294static void
15295do_neon_rshift_sat_narrow (void)
15296{
15297 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15298 or unsigned. If operands are unsigned, results must also be unsigned. */
15299 struct neon_type_el et = neon_check_type (2, NS_DQI,
15300 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15301 int imm = inst.operands[2].imm;
15302 /* This gets the bounds check, size encoding and immediate bits calculation
15303 right. */
15304 et.size /= 2;
5f4273c7 15305
5287ad62
JB
15306 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15307 VQMOVN.I<size> <Dd>, <Qm>. */
15308 if (imm == 0)
15309 {
15310 inst.operands[2].present = 0;
15311 inst.instruction = N_MNEM_vqmovn;
15312 do_neon_qmovn ();
15313 return;
15314 }
5f4273c7 15315
5287ad62 15316 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15317 _("immediate out of range"));
5287ad62
JB
15318 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15319}
15320
15321static void
15322do_neon_rshift_sat_narrow_u (void)
15323{
15324 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15325 or unsigned. If operands are unsigned, results must also be unsigned. */
15326 struct neon_type_el et = neon_check_type (2, NS_DQI,
15327 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15328 int imm = inst.operands[2].imm;
15329 /* This gets the bounds check, size encoding and immediate bits calculation
15330 right. */
15331 et.size /= 2;
15332
15333 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15334 VQMOVUN.I<size> <Dd>, <Qm>. */
15335 if (imm == 0)
15336 {
15337 inst.operands[2].present = 0;
15338 inst.instruction = N_MNEM_vqmovun;
15339 do_neon_qmovun ();
15340 return;
15341 }
15342
15343 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15344 _("immediate out of range"));
5287ad62
JB
15345 /* FIXME: The manual is kind of unclear about what value U should have in
15346 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15347 must be 1. */
15348 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15349}
15350
15351static void
15352do_neon_movn (void)
15353{
15354 struct neon_type_el et = neon_check_type (2, NS_DQ,
15355 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
88714cb8 15356 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15357 neon_two_same (0, 1, et.size / 2);
15358}
15359
15360static void
15361do_neon_rshift_narrow (void)
15362{
15363 struct neon_type_el et = neon_check_type (2, NS_DQI,
15364 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15365 int imm = inst.operands[2].imm;
15366 /* This gets the bounds check, size encoding and immediate bits calculation
15367 right. */
15368 et.size /= 2;
5f4273c7 15369
5287ad62
JB
15370 /* If immediate is zero then we are a pseudo-instruction for
15371 VMOVN.I<size> <Dd>, <Qm> */
15372 if (imm == 0)
15373 {
15374 inst.operands[2].present = 0;
15375 inst.instruction = N_MNEM_vmovn;
15376 do_neon_movn ();
15377 return;
15378 }
5f4273c7 15379
5287ad62 15380 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 15381 _("immediate out of range for narrowing operation"));
5287ad62
JB
15382 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15383}
15384
15385static void
15386do_neon_shll (void)
15387{
15388 /* FIXME: Type checking when lengthening. */
15389 struct neon_type_el et = neon_check_type (2, NS_QDI,
15390 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15391 unsigned imm = inst.operands[2].imm;
15392
15393 if (imm == et.size)
15394 {
15395 /* Maximum shift variant. */
88714cb8 15396 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
15397 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15398 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15399 inst.instruction |= LOW4 (inst.operands[1].reg);
15400 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15401 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 15402
88714cb8 15403 neon_dp_fixup (&inst);
5287ad62
JB
15404 }
15405 else
15406 {
15407 /* A more-specific type check for non-max versions. */
15408 et = neon_check_type (2, NS_QDI,
477330fc 15409 N_EQK | N_DBL, N_SU_32 | N_KEY);
88714cb8 15410 NEON_ENCODE (IMMED, inst);
5287ad62
JB
15411 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15412 }
15413}
15414
037e8744 15415/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
15416 the current instruction is. */
15417
6b9a8b67
MGD
15418#define CVT_FLAVOUR_VAR \
15419 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15420 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15421 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15422 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15423 /* Half-precision conversions. */ \
cc933301
JW
15424 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15425 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15426 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
15427 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
6b9a8b67
MGD
15428 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15429 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
9db2f6b4
RL
15430 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15431 Compared with single/double precision variants, only the co-processor \
15432 field is different, so the encoding flow is reused here. */ \
15433 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15434 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15435 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15436 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
6b9a8b67
MGD
15437 /* VFP instructions. */ \
15438 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15439 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15440 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15441 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15442 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15443 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15444 /* VFP instructions with bitshift. */ \
15445 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15446 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15447 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15448 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15449 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15450 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15451 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15452 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15453
15454#define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15455 neon_cvt_flavour_##C,
15456
15457/* The different types of conversions we can do. */
15458enum neon_cvt_flavour
15459{
15460 CVT_FLAVOUR_VAR
15461 neon_cvt_flavour_invalid,
15462 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15463};
15464
15465#undef CVT_VAR
15466
15467static enum neon_cvt_flavour
15468get_neon_cvt_flavour (enum neon_shape rs)
5287ad62 15469{
6b9a8b67
MGD
15470#define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15471 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15472 if (et.type != NT_invtype) \
15473 { \
15474 inst.error = NULL; \
15475 return (neon_cvt_flavour_##C); \
5287ad62 15476 }
6b9a8b67 15477
5287ad62 15478 struct neon_type_el et;
037e8744 15479 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
477330fc 15480 || rs == NS_FF) ? N_VFP : 0;
037e8744
JB
15481 /* The instruction versions which take an immediate take one register
15482 argument, which is extended to the width of the full register. Thus the
15483 "source" and "destination" registers must have the same width. Hack that
15484 here by making the size equal to the key (wider, in this case) operand. */
15485 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 15486
6b9a8b67
MGD
15487 CVT_FLAVOUR_VAR;
15488
15489 return neon_cvt_flavour_invalid;
5287ad62
JB
15490#undef CVT_VAR
15491}
15492
7e8e6784
MGD
15493enum neon_cvt_mode
15494{
15495 neon_cvt_mode_a,
15496 neon_cvt_mode_n,
15497 neon_cvt_mode_p,
15498 neon_cvt_mode_m,
15499 neon_cvt_mode_z,
30bdf752
MGD
15500 neon_cvt_mode_x,
15501 neon_cvt_mode_r
7e8e6784
MGD
15502};
15503
037e8744
JB
15504/* Neon-syntax VFP conversions. */
15505
5287ad62 15506static void
6b9a8b67 15507do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
5287ad62 15508{
037e8744 15509 const char *opname = 0;
5f4273c7 15510
d54af2d0
RL
15511 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15512 || rs == NS_FHI || rs == NS_HFI)
5287ad62 15513 {
037e8744
JB
15514 /* Conversions with immediate bitshift. */
15515 const char *enc[] =
477330fc 15516 {
6b9a8b67
MGD
15517#define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15518 CVT_FLAVOUR_VAR
15519 NULL
15520#undef CVT_VAR
477330fc 15521 };
037e8744 15522
6b9a8b67 15523 if (flavour < (int) ARRAY_SIZE (enc))
477330fc
RM
15524 {
15525 opname = enc[flavour];
15526 constraint (inst.operands[0].reg != inst.operands[1].reg,
15527 _("operands 0 and 1 must be the same register"));
15528 inst.operands[1] = inst.operands[2];
15529 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15530 }
5287ad62
JB
15531 }
15532 else
15533 {
037e8744
JB
15534 /* Conversions without bitshift. */
15535 const char *enc[] =
477330fc 15536 {
6b9a8b67
MGD
15537#define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15538 CVT_FLAVOUR_VAR
15539 NULL
15540#undef CVT_VAR
477330fc 15541 };
037e8744 15542
6b9a8b67 15543 if (flavour < (int) ARRAY_SIZE (enc))
477330fc 15544 opname = enc[flavour];
037e8744
JB
15545 }
15546
15547 if (opname)
15548 do_vfp_nsyn_opcode (opname);
9db2f6b4
RL
15549
15550 /* ARMv8.2 fp16 VCVT instruction. */
15551 if (flavour == neon_cvt_flavour_s32_f16
15552 || flavour == neon_cvt_flavour_u32_f16
15553 || flavour == neon_cvt_flavour_f16_u32
15554 || flavour == neon_cvt_flavour_f16_s32)
15555 do_scalar_fp16_v82_encode ();
037e8744
JB
15556}
15557
15558static void
15559do_vfp_nsyn_cvtz (void)
15560{
d54af2d0 15561 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
6b9a8b67 15562 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744
JB
15563 const char *enc[] =
15564 {
6b9a8b67
MGD
15565#define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15566 CVT_FLAVOUR_VAR
15567 NULL
15568#undef CVT_VAR
037e8744
JB
15569 };
15570
6b9a8b67 15571 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
037e8744
JB
15572 do_vfp_nsyn_opcode (enc[flavour]);
15573}
f31fef98 15574
037e8744 15575static void
bacebabc 15576do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
7e8e6784
MGD
15577 enum neon_cvt_mode mode)
15578{
15579 int sz, op;
15580 int rm;
15581
a715796b
TG
15582 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15583 D register operands. */
15584 if (flavour == neon_cvt_flavour_s32_f64
15585 || flavour == neon_cvt_flavour_u32_f64)
15586 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15587 _(BAD_FPU));
15588
9db2f6b4
RL
15589 if (flavour == neon_cvt_flavour_s32_f16
15590 || flavour == neon_cvt_flavour_u32_f16)
15591 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15592 _(BAD_FP16));
15593
7e8e6784
MGD
15594 set_it_insn_type (OUTSIDE_IT_INSN);
15595
15596 switch (flavour)
15597 {
15598 case neon_cvt_flavour_s32_f64:
15599 sz = 1;
827f64ff 15600 op = 1;
7e8e6784
MGD
15601 break;
15602 case neon_cvt_flavour_s32_f32:
15603 sz = 0;
15604 op = 1;
15605 break;
9db2f6b4
RL
15606 case neon_cvt_flavour_s32_f16:
15607 sz = 0;
15608 op = 1;
15609 break;
7e8e6784
MGD
15610 case neon_cvt_flavour_u32_f64:
15611 sz = 1;
15612 op = 0;
15613 break;
15614 case neon_cvt_flavour_u32_f32:
15615 sz = 0;
15616 op = 0;
15617 break;
9db2f6b4
RL
15618 case neon_cvt_flavour_u32_f16:
15619 sz = 0;
15620 op = 0;
15621 break;
7e8e6784
MGD
15622 default:
15623 first_error (_("invalid instruction shape"));
15624 return;
15625 }
15626
15627 switch (mode)
15628 {
15629 case neon_cvt_mode_a: rm = 0; break;
15630 case neon_cvt_mode_n: rm = 1; break;
15631 case neon_cvt_mode_p: rm = 2; break;
15632 case neon_cvt_mode_m: rm = 3; break;
15633 default: first_error (_("invalid rounding mode")); return;
15634 }
15635
15636 NEON_ENCODE (FPV8, inst);
15637 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15638 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15639 inst.instruction |= sz << 8;
9db2f6b4
RL
15640
15641 /* ARMv8.2 fp16 VCVT instruction. */
15642 if (flavour == neon_cvt_flavour_s32_f16
15643 ||flavour == neon_cvt_flavour_u32_f16)
15644 do_scalar_fp16_v82_encode ();
7e8e6784
MGD
15645 inst.instruction |= op << 7;
15646 inst.instruction |= rm << 16;
15647 inst.instruction |= 0xf0000000;
15648 inst.is_neon = TRUE;
15649}
15650
15651static void
15652do_neon_cvt_1 (enum neon_cvt_mode mode)
037e8744
JB
15653{
15654 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
d54af2d0
RL
15655 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
15656 NS_FH, NS_HF, NS_FHI, NS_HFI,
15657 NS_NULL);
6b9a8b67 15658 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
037e8744 15659
cc933301
JW
15660 if (flavour == neon_cvt_flavour_invalid)
15661 return;
15662
e3e535bc 15663 /* PR11109: Handle round-to-zero for VCVT conversions. */
7e8e6784 15664 if (mode == neon_cvt_mode_z
e3e535bc 15665 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
cc933301
JW
15666 && (flavour == neon_cvt_flavour_s16_f16
15667 || flavour == neon_cvt_flavour_u16_f16
15668 || flavour == neon_cvt_flavour_s32_f32
bacebabc
RM
15669 || flavour == neon_cvt_flavour_u32_f32
15670 || flavour == neon_cvt_flavour_s32_f64
6b9a8b67 15671 || flavour == neon_cvt_flavour_u32_f64)
e3e535bc
NC
15672 && (rs == NS_FD || rs == NS_FF))
15673 {
15674 do_vfp_nsyn_cvtz ();
15675 return;
15676 }
15677
9db2f6b4
RL
15678 /* ARMv8.2 fp16 VCVT conversions. */
15679 if (mode == neon_cvt_mode_z
15680 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
15681 && (flavour == neon_cvt_flavour_s32_f16
15682 || flavour == neon_cvt_flavour_u32_f16)
15683 && (rs == NS_FH))
15684 {
15685 do_vfp_nsyn_cvtz ();
15686 do_scalar_fp16_v82_encode ();
15687 return;
15688 }
15689
037e8744 15690 /* VFP rather than Neon conversions. */
6b9a8b67 15691 if (flavour >= neon_cvt_flavour_first_fp)
037e8744 15692 {
7e8e6784
MGD
15693 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15694 do_vfp_nsyn_cvt (rs, flavour);
15695 else
15696 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15697
037e8744
JB
15698 return;
15699 }
15700
15701 switch (rs)
15702 {
15703 case NS_DDI:
15704 case NS_QQI:
15705 {
477330fc 15706 unsigned immbits;
cc933301
JW
15707 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
15708 0x0000100, 0x1000100, 0x0, 0x1000000};
35997600 15709
477330fc
RM
15710 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15711 return;
037e8744 15712
477330fc
RM
15713 /* Fixed-point conversion with #0 immediate is encoded as an
15714 integer conversion. */
15715 if (inst.operands[2].present && inst.operands[2].imm == 0)
15716 goto int_encode;
477330fc
RM
15717 NEON_ENCODE (IMMED, inst);
15718 if (flavour != neon_cvt_flavour_invalid)
15719 inst.instruction |= enctab[flavour];
15720 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15721 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15722 inst.instruction |= LOW4 (inst.operands[1].reg);
15723 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15724 inst.instruction |= neon_quad (rs) << 6;
15725 inst.instruction |= 1 << 21;
cc933301
JW
15726 if (flavour < neon_cvt_flavour_s16_f16)
15727 {
15728 inst.instruction |= 1 << 21;
15729 immbits = 32 - inst.operands[2].imm;
15730 inst.instruction |= immbits << 16;
15731 }
15732 else
15733 {
15734 inst.instruction |= 3 << 20;
15735 immbits = 16 - inst.operands[2].imm;
15736 inst.instruction |= immbits << 16;
15737 inst.instruction &= ~(1 << 9);
15738 }
477330fc
RM
15739
15740 neon_dp_fixup (&inst);
037e8744
JB
15741 }
15742 break;
15743
15744 case NS_DD:
15745 case NS_QQ:
7e8e6784
MGD
15746 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15747 {
15748 NEON_ENCODE (FLOAT, inst);
15749 set_it_insn_type (OUTSIDE_IT_INSN);
15750
15751 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15752 return;
15753
15754 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15755 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15756 inst.instruction |= LOW4 (inst.operands[1].reg);
15757 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15758 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15759 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
15760 || flavour == neon_cvt_flavour_u32_f32) << 7;
7e8e6784 15761 inst.instruction |= mode << 8;
cc933301
JW
15762 if (flavour == neon_cvt_flavour_u16_f16
15763 || flavour == neon_cvt_flavour_s16_f16)
15764 /* Mask off the original size bits and reencode them. */
15765 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
15766
7e8e6784
MGD
15767 if (thumb_mode)
15768 inst.instruction |= 0xfc000000;
15769 else
15770 inst.instruction |= 0xf0000000;
15771 }
15772 else
15773 {
037e8744 15774 int_encode:
7e8e6784 15775 {
cc933301
JW
15776 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
15777 0x100, 0x180, 0x0, 0x080};
037e8744 15778
7e8e6784 15779 NEON_ENCODE (INTEGER, inst);
037e8744 15780
7e8e6784
MGD
15781 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15782 return;
037e8744 15783
7e8e6784
MGD
15784 if (flavour != neon_cvt_flavour_invalid)
15785 inst.instruction |= enctab[flavour];
037e8744 15786
7e8e6784
MGD
15787 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15788 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15789 inst.instruction |= LOW4 (inst.operands[1].reg);
15790 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15791 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
15792 if (flavour >= neon_cvt_flavour_s16_f16
15793 && flavour <= neon_cvt_flavour_f16_u16)
15794 /* Half precision. */
15795 inst.instruction |= 1 << 18;
15796 else
15797 inst.instruction |= 2 << 18;
037e8744 15798
7e8e6784
MGD
15799 neon_dp_fixup (&inst);
15800 }
15801 }
15802 break;
037e8744 15803
8e79c3df
CM
15804 /* Half-precision conversions for Advanced SIMD -- neon. */
15805 case NS_QD:
15806 case NS_DQ:
15807
15808 if ((rs == NS_DQ)
15809 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15810 {
15811 as_bad (_("operand size must match register width"));
15812 break;
15813 }
15814
15815 if ((rs == NS_QD)
15816 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15817 {
15818 as_bad (_("operand size must match register width"));
15819 break;
15820 }
15821
15822 if (rs == NS_DQ)
477330fc 15823 inst.instruction = 0x3b60600;
8e79c3df
CM
15824 else
15825 inst.instruction = 0x3b60700;
15826
15827 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15828 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15829 inst.instruction |= LOW4 (inst.operands[1].reg);
15830 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
88714cb8 15831 neon_dp_fixup (&inst);
8e79c3df
CM
15832 break;
15833
037e8744
JB
15834 default:
15835 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
7e8e6784
MGD
15836 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15837 do_vfp_nsyn_cvt (rs, flavour);
15838 else
15839 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
5287ad62 15840 }
5287ad62
JB
15841}
15842
e3e535bc
NC
15843static void
15844do_neon_cvtr (void)
15845{
7e8e6784 15846 do_neon_cvt_1 (neon_cvt_mode_x);
e3e535bc
NC
15847}
15848
15849static void
15850do_neon_cvt (void)
15851{
7e8e6784
MGD
15852 do_neon_cvt_1 (neon_cvt_mode_z);
15853}
15854
15855static void
15856do_neon_cvta (void)
15857{
15858 do_neon_cvt_1 (neon_cvt_mode_a);
15859}
15860
15861static void
15862do_neon_cvtn (void)
15863{
15864 do_neon_cvt_1 (neon_cvt_mode_n);
15865}
15866
15867static void
15868do_neon_cvtp (void)
15869{
15870 do_neon_cvt_1 (neon_cvt_mode_p);
15871}
15872
15873static void
15874do_neon_cvtm (void)
15875{
15876 do_neon_cvt_1 (neon_cvt_mode_m);
e3e535bc
NC
15877}
15878
8e79c3df 15879static void
c70a8987 15880do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
8e79c3df 15881{
c70a8987
MGD
15882 if (is_double)
15883 mark_feature_used (&fpu_vfp_ext_armv8);
8e79c3df 15884
c70a8987
MGD
15885 encode_arm_vfp_reg (inst.operands[0].reg,
15886 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15887 encode_arm_vfp_reg (inst.operands[1].reg,
15888 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15889 inst.instruction |= to ? 0x10000 : 0;
15890 inst.instruction |= t ? 0x80 : 0;
15891 inst.instruction |= is_double ? 0x100 : 0;
15892 do_vfp_cond_or_thumb ();
15893}
8e79c3df 15894
c70a8987
MGD
15895static void
15896do_neon_cvttb_1 (bfd_boolean t)
15897{
d54af2d0
RL
15898 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
15899 NS_DF, NS_DH, NS_NULL);
8e79c3df 15900
c70a8987
MGD
15901 if (rs == NS_NULL)
15902 return;
15903 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
15904 {
15905 inst.error = NULL;
15906 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
15907 }
15908 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
15909 {
15910 inst.error = NULL;
15911 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
15912 }
15913 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
15914 {
a715796b
TG
15915 /* The VCVTB and VCVTT instructions with D-register operands
15916 don't work for SP only targets. */
15917 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15918 _(BAD_FPU));
15919
c70a8987
MGD
15920 inst.error = NULL;
15921 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
15922 }
15923 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
15924 {
a715796b
TG
15925 /* The VCVTB and VCVTT instructions with D-register operands
15926 don't work for SP only targets. */
15927 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15928 _(BAD_FPU));
15929
c70a8987
MGD
15930 inst.error = NULL;
15931 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
15932 }
15933 else
15934 return;
15935}
15936
15937static void
15938do_neon_cvtb (void)
15939{
15940 do_neon_cvttb_1 (FALSE);
8e79c3df
CM
15941}
15942
15943
15944static void
15945do_neon_cvtt (void)
15946{
c70a8987 15947 do_neon_cvttb_1 (TRUE);
8e79c3df
CM
15948}
15949
5287ad62
JB
15950static void
15951neon_move_immediate (void)
15952{
037e8744
JB
15953 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
15954 struct neon_type_el et = neon_check_type (2, rs,
15955 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 15956 unsigned immlo, immhi = 0, immbits;
c96612cc 15957 int op, cmode, float_p;
5287ad62 15958
037e8744 15959 constraint (et.type == NT_invtype,
477330fc 15960 _("operand size must be specified for immediate VMOV"));
037e8744 15961
5287ad62
JB
15962 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
15963 op = (inst.instruction & (1 << 5)) != 0;
15964
15965 immlo = inst.operands[1].imm;
15966 if (inst.operands[1].regisimm)
15967 immhi = inst.operands[1].reg;
15968
15969 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
477330fc 15970 _("immediate has bits set outside the operand size"));
5287ad62 15971
c96612cc
JB
15972 float_p = inst.operands[1].immisfloat;
15973
15974 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
477330fc 15975 et.size, et.type)) == FAIL)
5287ad62
JB
15976 {
15977 /* Invert relevant bits only. */
15978 neon_invert_size (&immlo, &immhi, et.size);
15979 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
477330fc
RM
15980 with one or the other; those cases are caught by
15981 neon_cmode_for_move_imm. */
5287ad62 15982 op = !op;
c96612cc
JB
15983 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
15984 &op, et.size, et.type)) == FAIL)
477330fc
RM
15985 {
15986 first_error (_("immediate out of range"));
15987 return;
15988 }
5287ad62
JB
15989 }
15990
15991 inst.instruction &= ~(1 << 5);
15992 inst.instruction |= op << 5;
15993
15994 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15995 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 15996 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
15997 inst.instruction |= cmode << 8;
15998
15999 neon_write_immbits (immbits);
16000}
16001
16002static void
16003do_neon_mvn (void)
16004{
16005 if (inst.operands[1].isreg)
16006 {
037e8744 16007 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 16008
88714cb8 16009 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16010 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16011 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16012 inst.instruction |= LOW4 (inst.operands[1].reg);
16013 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 16014 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16015 }
16016 else
16017 {
88714cb8 16018 NEON_ENCODE (IMMED, inst);
5287ad62
JB
16019 neon_move_immediate ();
16020 }
16021
88714cb8 16022 neon_dp_fixup (&inst);
5287ad62
JB
16023}
16024
16025/* Encode instructions of form:
16026
16027 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 16028 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
16029
16030static void
16031neon_mixed_length (struct neon_type_el et, unsigned size)
16032{
16033 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16034 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16035 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16036 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16037 inst.instruction |= LOW4 (inst.operands[2].reg);
16038 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16039 inst.instruction |= (et.type == NT_unsigned) << 24;
16040 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 16041
88714cb8 16042 neon_dp_fixup (&inst);
5287ad62
JB
16043}
16044
16045static void
16046do_neon_dyadic_long (void)
16047{
16048 /* FIXME: Type checking for lengthening op. */
16049 struct neon_type_el et = neon_check_type (3, NS_QDD,
16050 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
16051 neon_mixed_length (et, et.size);
16052}
16053
16054static void
16055do_neon_abal (void)
16056{
16057 struct neon_type_el et = neon_check_type (3, NS_QDD,
16058 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16059 neon_mixed_length (et, et.size);
16060}
16061
16062static void
16063neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16064{
16065 if (inst.operands[2].isscalar)
16066 {
dcbf9037 16067 struct neon_type_el et = neon_check_type (3, NS_QDS,
477330fc 16068 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
88714cb8 16069 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16070 neon_mul_mac (et, et.type == NT_unsigned);
16071 }
16072 else
16073 {
16074 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16075 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
88714cb8 16076 NEON_ENCODE (INTEGER, inst);
5287ad62
JB
16077 neon_mixed_length (et, et.size);
16078 }
16079}
16080
16081static void
16082do_neon_mac_maybe_scalar_long (void)
16083{
16084 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16085}
16086
16087static void
16088do_neon_dyadic_wide (void)
16089{
16090 struct neon_type_el et = neon_check_type (3, NS_QQD,
16091 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
16092 neon_mixed_length (et, et.size);
16093}
16094
16095static void
16096do_neon_dyadic_narrow (void)
16097{
16098 struct neon_type_el et = neon_check_type (3, NS_QDD,
16099 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
16100 /* Operand sign is unimportant, and the U bit is part of the opcode,
16101 so force the operand type to integer. */
16102 et.type = NT_integer;
5287ad62
JB
16103 neon_mixed_length (et, et.size / 2);
16104}
16105
16106static void
16107do_neon_mul_sat_scalar_long (void)
16108{
16109 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
16110}
16111
16112static void
16113do_neon_vmull (void)
16114{
16115 if (inst.operands[2].isscalar)
16116 do_neon_mac_maybe_scalar_long ();
16117 else
16118 {
16119 struct neon_type_el et = neon_check_type (3, NS_QDD,
477330fc 16120 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
4f51b4bd 16121
5287ad62 16122 if (et.type == NT_poly)
477330fc 16123 NEON_ENCODE (POLY, inst);
5287ad62 16124 else
477330fc 16125 NEON_ENCODE (INTEGER, inst);
4f51b4bd
MGD
16126
16127 /* For polynomial encoding the U bit must be zero, and the size must
16128 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
16129 obviously, as 0b10). */
16130 if (et.size == 64)
16131 {
16132 /* Check we're on the correct architecture. */
16133 if (!mark_feature_used (&fpu_crypto_ext_armv8))
16134 inst.error =
16135 _("Instruction form not available on this architecture.");
16136
16137 et.size = 32;
16138 }
16139
5287ad62
JB
16140 neon_mixed_length (et, et.size);
16141 }
16142}
16143
16144static void
16145do_neon_ext (void)
16146{
037e8744 16147 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
16148 struct neon_type_el et = neon_check_type (3, rs,
16149 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16150 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
16151
16152 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
16153 _("shift out of range"));
5287ad62
JB
16154 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16155 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16156 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16157 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16158 inst.instruction |= LOW4 (inst.operands[2].reg);
16159 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 16160 inst.instruction |= neon_quad (rs) << 6;
5287ad62 16161 inst.instruction |= imm << 8;
5f4273c7 16162
88714cb8 16163 neon_dp_fixup (&inst);
5287ad62
JB
16164}
16165
16166static void
16167do_neon_rev (void)
16168{
037e8744 16169 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16170 struct neon_type_el et = neon_check_type (2, rs,
16171 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16172 unsigned op = (inst.instruction >> 7) & 3;
16173 /* N (width of reversed regions) is encoded as part of the bitmask. We
16174 extract it here to check the elements to be reversed are smaller.
16175 Otherwise we'd get a reserved instruction. */
16176 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 16177 gas_assert (elsize != 0);
5287ad62 16178 constraint (et.size >= elsize,
477330fc 16179 _("elements must be smaller than reversal region"));
037e8744 16180 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16181}
16182
16183static void
16184do_neon_dup (void)
16185{
16186 if (inst.operands[1].isscalar)
16187 {
037e8744 16188 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037 16189 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16190 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 16191 unsigned sizebits = et.size >> 3;
dcbf9037 16192 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 16193 int logsize = neon_logbits (et.size);
dcbf9037 16194 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
16195
16196 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
477330fc 16197 return;
037e8744 16198
88714cb8 16199 NEON_ENCODE (SCALAR, inst);
5287ad62
JB
16200 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16201 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16202 inst.instruction |= LOW4 (dm);
16203 inst.instruction |= HI1 (dm) << 5;
037e8744 16204 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
16205 inst.instruction |= x << 17;
16206 inst.instruction |= sizebits << 16;
5f4273c7 16207
88714cb8 16208 neon_dp_fixup (&inst);
5287ad62
JB
16209 }
16210 else
16211 {
037e8744
JB
16212 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16213 struct neon_type_el et = neon_check_type (2, rs,
477330fc 16214 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62 16215 /* Duplicate ARM register to lanes of vector. */
88714cb8 16216 NEON_ENCODE (ARMREG, inst);
5287ad62 16217 switch (et.size)
477330fc
RM
16218 {
16219 case 8: inst.instruction |= 0x400000; break;
16220 case 16: inst.instruction |= 0x000020; break;
16221 case 32: inst.instruction |= 0x000000; break;
16222 default: break;
16223 }
5287ad62
JB
16224 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16225 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16226 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 16227 inst.instruction |= neon_quad (rs) << 21;
5287ad62 16228 /* The encoding for this instruction is identical for the ARM and Thumb
477330fc 16229 variants, except for the condition field. */
037e8744 16230 do_vfp_cond_or_thumb ();
5287ad62
JB
16231 }
16232}
16233
16234/* VMOV has particularly many variations. It can be one of:
16235 0. VMOV<c><q> <Qd>, <Qm>
16236 1. VMOV<c><q> <Dd>, <Dm>
16237 (Register operations, which are VORR with Rm = Rn.)
16238 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16239 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16240 (Immediate loads.)
16241 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16242 (ARM register to scalar.)
16243 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16244 (Two ARM registers to vector.)
16245 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16246 (Scalar to ARM register.)
16247 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16248 (Vector to two ARM registers.)
037e8744
JB
16249 8. VMOV.F32 <Sd>, <Sm>
16250 9. VMOV.F64 <Dd>, <Dm>
16251 (VFP register moves.)
16252 10. VMOV.F32 <Sd>, #imm
16253 11. VMOV.F64 <Dd>, #imm
16254 (VFP float immediate load.)
16255 12. VMOV <Rd>, <Sm>
16256 (VFP single to ARM reg.)
16257 13. VMOV <Sd>, <Rm>
16258 (ARM reg to VFP single.)
16259 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16260 (Two ARM regs to two VFP singles.)
16261 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16262 (Two VFP singles to two ARM regs.)
5f4273c7 16263
037e8744
JB
16264 These cases can be disambiguated using neon_select_shape, except cases 1/9
16265 and 3/11 which depend on the operand type too.
5f4273c7 16266
5287ad62 16267 All the encoded bits are hardcoded by this function.
5f4273c7 16268
b7fc2769
JB
16269 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16270 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 16271
5287ad62 16272 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 16273 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
16274
16275static void
16276do_neon_mov (void)
16277{
037e8744 16278 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
9db2f6b4
RL
16279 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16280 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16281 NS_HR, NS_RH, NS_HI, NS_NULL);
037e8744
JB
16282 struct neon_type_el et;
16283 const char *ldconst = 0;
5287ad62 16284
037e8744 16285 switch (rs)
5287ad62 16286 {
037e8744
JB
16287 case NS_DD: /* case 1/9. */
16288 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16289 /* It is not an error here if no type is given. */
16290 inst.error = NULL;
16291 if (et.type == NT_float && et.size == 64)
477330fc
RM
16292 {
16293 do_vfp_nsyn_opcode ("fcpyd");
16294 break;
16295 }
037e8744 16296 /* fall through. */
5287ad62 16297
037e8744
JB
16298 case NS_QQ: /* case 0/1. */
16299 {
477330fc
RM
16300 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16301 return;
16302 /* The architecture manual I have doesn't explicitly state which
16303 value the U bit should have for register->register moves, but
16304 the equivalent VORR instruction has U = 0, so do that. */
16305 inst.instruction = 0x0200110;
16306 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16307 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16308 inst.instruction |= LOW4 (inst.operands[1].reg);
16309 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16310 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16311 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16312 inst.instruction |= neon_quad (rs) << 6;
16313
16314 neon_dp_fixup (&inst);
037e8744
JB
16315 }
16316 break;
5f4273c7 16317
037e8744
JB
16318 case NS_DI: /* case 3/11. */
16319 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16320 inst.error = NULL;
16321 if (et.type == NT_float && et.size == 64)
477330fc
RM
16322 {
16323 /* case 11 (fconstd). */
16324 ldconst = "fconstd";
16325 goto encode_fconstd;
16326 }
037e8744
JB
16327 /* fall through. */
16328
16329 case NS_QI: /* case 2/3. */
16330 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
477330fc 16331 return;
037e8744
JB
16332 inst.instruction = 0x0800010;
16333 neon_move_immediate ();
88714cb8 16334 neon_dp_fixup (&inst);
5287ad62 16335 break;
5f4273c7 16336
037e8744
JB
16337 case NS_SR: /* case 4. */
16338 {
477330fc
RM
16339 unsigned bcdebits = 0;
16340 int logsize;
16341 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16342 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
037e8744 16343
05ac0ffb
JB
16344 /* .<size> is optional here, defaulting to .32. */
16345 if (inst.vectype.elems == 0
16346 && inst.operands[0].vectype.type == NT_invtype
16347 && inst.operands[1].vectype.type == NT_invtype)
16348 {
16349 inst.vectype.el[0].type = NT_untyped;
16350 inst.vectype.el[0].size = 32;
16351 inst.vectype.elems = 1;
16352 }
16353
477330fc
RM
16354 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16355 logsize = neon_logbits (et.size);
16356
16357 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16358 _(BAD_FPU));
16359 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16360 && et.size != 32, _(BAD_FPU));
16361 constraint (et.type == NT_invtype, _("bad type for scalar"));
16362 constraint (x >= 64 / et.size, _("scalar index out of range"));
16363
16364 switch (et.size)
16365 {
16366 case 8: bcdebits = 0x8; break;
16367 case 16: bcdebits = 0x1; break;
16368 case 32: bcdebits = 0x0; break;
16369 default: ;
16370 }
16371
16372 bcdebits |= x << logsize;
16373
16374 inst.instruction = 0xe000b10;
16375 do_vfp_cond_or_thumb ();
16376 inst.instruction |= LOW4 (dn) << 16;
16377 inst.instruction |= HI1 (dn) << 7;
16378 inst.instruction |= inst.operands[1].reg << 12;
16379 inst.instruction |= (bcdebits & 3) << 5;
16380 inst.instruction |= (bcdebits >> 2) << 21;
037e8744
JB
16381 }
16382 break;
5f4273c7 16383
037e8744 16384 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 16385 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16386 _(BAD_FPU));
b7fc2769 16387
037e8744
JB
16388 inst.instruction = 0xc400b10;
16389 do_vfp_cond_or_thumb ();
16390 inst.instruction |= LOW4 (inst.operands[0].reg);
16391 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16392 inst.instruction |= inst.operands[1].reg << 12;
16393 inst.instruction |= inst.operands[2].reg << 16;
16394 break;
5f4273c7 16395
037e8744
JB
16396 case NS_RS: /* case 6. */
16397 {
477330fc
RM
16398 unsigned logsize;
16399 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16400 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16401 unsigned abcdebits = 0;
037e8744 16402
05ac0ffb
JB
16403 /* .<dt> is optional here, defaulting to .32. */
16404 if (inst.vectype.elems == 0
16405 && inst.operands[0].vectype.type == NT_invtype
16406 && inst.operands[1].vectype.type == NT_invtype)
16407 {
16408 inst.vectype.el[0].type = NT_untyped;
16409 inst.vectype.el[0].size = 32;
16410 inst.vectype.elems = 1;
16411 }
16412
91d6fa6a
NC
16413 et = neon_check_type (2, NS_NULL,
16414 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
477330fc
RM
16415 logsize = neon_logbits (et.size);
16416
16417 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16418 _(BAD_FPU));
16419 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16420 && et.size != 32, _(BAD_FPU));
16421 constraint (et.type == NT_invtype, _("bad type for scalar"));
16422 constraint (x >= 64 / et.size, _("scalar index out of range"));
16423
16424 switch (et.size)
16425 {
16426 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16427 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16428 case 32: abcdebits = 0x00; break;
16429 default: ;
16430 }
16431
16432 abcdebits |= x << logsize;
16433 inst.instruction = 0xe100b10;
16434 do_vfp_cond_or_thumb ();
16435 inst.instruction |= LOW4 (dn) << 16;
16436 inst.instruction |= HI1 (dn) << 7;
16437 inst.instruction |= inst.operands[0].reg << 12;
16438 inst.instruction |= (abcdebits & 3) << 5;
16439 inst.instruction |= (abcdebits >> 2) << 21;
037e8744
JB
16440 }
16441 break;
5f4273c7 16442
037e8744
JB
16443 case NS_RRD: /* case 7 (fmrrd). */
16444 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
477330fc 16445 _(BAD_FPU));
037e8744
JB
16446
16447 inst.instruction = 0xc500b10;
16448 do_vfp_cond_or_thumb ();
16449 inst.instruction |= inst.operands[0].reg << 12;
16450 inst.instruction |= inst.operands[1].reg << 16;
16451 inst.instruction |= LOW4 (inst.operands[2].reg);
16452 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16453 break;
5f4273c7 16454
037e8744
JB
16455 case NS_FF: /* case 8 (fcpys). */
16456 do_vfp_nsyn_opcode ("fcpys");
16457 break;
5f4273c7 16458
9db2f6b4 16459 case NS_HI:
037e8744
JB
16460 case NS_FI: /* case 10 (fconsts). */
16461 ldconst = "fconsts";
16462 encode_fconstd:
16463 if (is_quarter_float (inst.operands[1].imm))
477330fc
RM
16464 {
16465 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16466 do_vfp_nsyn_opcode (ldconst);
9db2f6b4
RL
16467
16468 /* ARMv8.2 fp16 vmov.f16 instruction. */
16469 if (rs == NS_HI)
16470 do_scalar_fp16_v82_encode ();
477330fc 16471 }
5287ad62 16472 else
477330fc 16473 first_error (_("immediate out of range"));
037e8744 16474 break;
5f4273c7 16475
9db2f6b4 16476 case NS_RH:
037e8744
JB
16477 case NS_RF: /* case 12 (fmrs). */
16478 do_vfp_nsyn_opcode ("fmrs");
9db2f6b4
RL
16479 /* ARMv8.2 fp16 vmov.f16 instruction. */
16480 if (rs == NS_RH)
16481 do_scalar_fp16_v82_encode ();
037e8744 16482 break;
5f4273c7 16483
9db2f6b4 16484 case NS_HR:
037e8744
JB
16485 case NS_FR: /* case 13 (fmsr). */
16486 do_vfp_nsyn_opcode ("fmsr");
9db2f6b4
RL
16487 /* ARMv8.2 fp16 vmov.f16 instruction. */
16488 if (rs == NS_HR)
16489 do_scalar_fp16_v82_encode ();
037e8744 16490 break;
5f4273c7 16491
037e8744
JB
16492 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16493 (one of which is a list), but we have parsed four. Do some fiddling to
16494 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16495 expect. */
16496 case NS_RRFF: /* case 14 (fmrrs). */
16497 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
477330fc 16498 _("VFP registers must be adjacent"));
037e8744
JB
16499 inst.operands[2].imm = 2;
16500 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16501 do_vfp_nsyn_opcode ("fmrrs");
16502 break;
5f4273c7 16503
037e8744
JB
16504 case NS_FFRR: /* case 15 (fmsrr). */
16505 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
477330fc 16506 _("VFP registers must be adjacent"));
037e8744
JB
16507 inst.operands[1] = inst.operands[2];
16508 inst.operands[2] = inst.operands[3];
16509 inst.operands[0].imm = 2;
16510 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16511 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 16512 break;
5f4273c7 16513
4c261dff
NC
16514 case NS_NULL:
16515 /* neon_select_shape has determined that the instruction
16516 shape is wrong and has already set the error message. */
16517 break;
16518
5287ad62
JB
16519 default:
16520 abort ();
16521 }
16522}
16523
16524static void
16525do_neon_rshift_round_imm (void)
16526{
037e8744 16527 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
16528 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16529 int imm = inst.operands[2].imm;
16530
16531 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16532 if (imm == 0)
16533 {
16534 inst.operands[2].present = 0;
16535 do_neon_mov ();
16536 return;
16537 }
16538
16539 constraint (imm < 1 || (unsigned)imm > et.size,
477330fc 16540 _("immediate out of range for shift"));
037e8744 16541 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
477330fc 16542 et.size - imm);
5287ad62
JB
16543}
16544
9db2f6b4
RL
16545static void
16546do_neon_movhf (void)
16547{
16548 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
16549 constraint (rs != NS_HH, _("invalid suffix"));
16550
16551 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16552 _(BAD_FPU));
16553
16554 do_vfp_sp_monadic ();
16555
16556 inst.is_neon = 1;
16557 inst.instruction |= 0xf0000000;
16558}
16559
5287ad62
JB
16560static void
16561do_neon_movl (void)
16562{
16563 struct neon_type_el et = neon_check_type (2, NS_QD,
16564 N_EQK | N_DBL, N_SU_32 | N_KEY);
16565 unsigned sizebits = et.size >> 3;
16566 inst.instruction |= sizebits << 19;
16567 neon_two_same (0, et.type == NT_unsigned, -1);
16568}
16569
16570static void
16571do_neon_trn (void)
16572{
037e8744 16573 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16574 struct neon_type_el et = neon_check_type (2, rs,
16575 N_EQK, N_8 | N_16 | N_32 | N_KEY);
88714cb8 16576 NEON_ENCODE (INTEGER, inst);
037e8744 16577 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16578}
16579
16580static void
16581do_neon_zip_uzp (void)
16582{
037e8744 16583 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16584 struct neon_type_el et = neon_check_type (2, rs,
16585 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16586 if (rs == NS_DD && et.size == 32)
16587 {
16588 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16589 inst.instruction = N_MNEM_vtrn;
16590 do_neon_trn ();
16591 return;
16592 }
037e8744 16593 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16594}
16595
16596static void
16597do_neon_sat_abs_neg (void)
16598{
037e8744 16599 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16600 struct neon_type_el et = neon_check_type (2, rs,
16601 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16602 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16603}
16604
16605static void
16606do_neon_pair_long (void)
16607{
037e8744 16608 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16609 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16610 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16611 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 16612 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16613}
16614
16615static void
16616do_neon_recip_est (void)
16617{
037e8744 16618 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62 16619 struct neon_type_el et = neon_check_type (2, rs,
cc933301 16620 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
5287ad62 16621 inst.instruction |= (et.type == NT_float) << 8;
037e8744 16622 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16623}
16624
16625static void
16626do_neon_cls (void)
16627{
037e8744 16628 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16629 struct neon_type_el et = neon_check_type (2, rs,
16630 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 16631 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16632}
16633
16634static void
16635do_neon_clz (void)
16636{
037e8744 16637 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16638 struct neon_type_el et = neon_check_type (2, rs,
16639 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 16640 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16641}
16642
16643static void
16644do_neon_cnt (void)
16645{
037e8744 16646 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
16647 struct neon_type_el et = neon_check_type (2, rs,
16648 N_EQK | N_INT, N_8 | N_KEY);
037e8744 16649 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
16650}
16651
16652static void
16653do_neon_swp (void)
16654{
037e8744
JB
16655 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16656 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
16657}
16658
16659static void
16660do_neon_tbl_tbx (void)
16661{
16662 unsigned listlenbits;
dcbf9037 16663 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 16664
5287ad62
JB
16665 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16666 {
dcbf9037 16667 first_error (_("bad list length for table lookup"));
5287ad62
JB
16668 return;
16669 }
5f4273c7 16670
5287ad62
JB
16671 listlenbits = inst.operands[1].imm - 1;
16672 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16673 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16674 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16675 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16676 inst.instruction |= LOW4 (inst.operands[2].reg);
16677 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16678 inst.instruction |= listlenbits << 8;
5f4273c7 16679
88714cb8 16680 neon_dp_fixup (&inst);
5287ad62
JB
16681}
16682
16683static void
16684do_neon_ldm_stm (void)
16685{
16686 /* P, U and L bits are part of bitmask. */
16687 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16688 unsigned offsetbits = inst.operands[1].imm * 2;
16689
037e8744
JB
16690 if (inst.operands[1].issingle)
16691 {
16692 do_vfp_nsyn_ldm_stm (is_dbmode);
16693 return;
16694 }
16695
5287ad62 16696 constraint (is_dbmode && !inst.operands[0].writeback,
477330fc 16697 _("writeback (!) must be used for VLDMDB and VSTMDB"));
5287ad62
JB
16698
16699 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
477330fc
RM
16700 _("register list must contain at least 1 and at most 16 "
16701 "registers"));
5287ad62
JB
16702
16703 inst.instruction |= inst.operands[0].reg << 16;
16704 inst.instruction |= inst.operands[0].writeback << 21;
16705 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16706 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16707
16708 inst.instruction |= offsetbits;
5f4273c7 16709
037e8744 16710 do_vfp_cond_or_thumb ();
5287ad62
JB
16711}
16712
16713static void
16714do_neon_ldr_str (void)
16715{
5287ad62 16716 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 16717
6844b2c2
MGD
16718 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16719 And is UNPREDICTABLE in thumb mode. */
fa94de6b 16720 if (!is_ldr
6844b2c2 16721 && inst.operands[1].reg == REG_PC
ba86b375 16722 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
6844b2c2 16723 {
94dcf8bf 16724 if (thumb_mode)
6844b2c2 16725 inst.error = _("Use of PC here is UNPREDICTABLE");
94dcf8bf 16726 else if (warn_on_deprecated)
5c3696f8 16727 as_tsktsk (_("Use of PC here is deprecated"));
6844b2c2
MGD
16728 }
16729
037e8744
JB
16730 if (inst.operands[0].issingle)
16731 {
cd2f129f 16732 if (is_ldr)
477330fc 16733 do_vfp_nsyn_opcode ("flds");
cd2f129f 16734 else
477330fc 16735 do_vfp_nsyn_opcode ("fsts");
9db2f6b4
RL
16736
16737 /* ARMv8.2 vldr.16/vstr.16 instruction. */
16738 if (inst.vectype.el[0].size == 16)
16739 do_scalar_fp16_v82_encode ();
5287ad62
JB
16740 }
16741 else
5287ad62 16742 {
cd2f129f 16743 if (is_ldr)
477330fc 16744 do_vfp_nsyn_opcode ("fldd");
5287ad62 16745 else
477330fc 16746 do_vfp_nsyn_opcode ("fstd");
5287ad62 16747 }
5287ad62
JB
16748}
16749
16750/* "interleave" version also handles non-interleaving register VLD1/VST1
16751 instructions. */
16752
16753static void
16754do_neon_ld_st_interleave (void)
16755{
037e8744 16756 struct neon_type_el et = neon_check_type (1, NS_NULL,
477330fc 16757 N_8 | N_16 | N_32 | N_64);
5287ad62
JB
16758 unsigned alignbits = 0;
16759 unsigned idx;
16760 /* The bits in this table go:
16761 0: register stride of one (0) or two (1)
16762 1,2: register list length, minus one (1, 2, 3, 4).
16763 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
16764 We use -1 for invalid entries. */
16765 const int typetable[] =
16766 {
16767 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
16768 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
16769 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
16770 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
16771 };
16772 int typebits;
16773
dcbf9037
JB
16774 if (et.type == NT_invtype)
16775 return;
16776
5287ad62
JB
16777 if (inst.operands[1].immisalign)
16778 switch (inst.operands[1].imm >> 8)
16779 {
16780 case 64: alignbits = 1; break;
16781 case 128:
477330fc 16782 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
e23c0ad8 16783 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
477330fc
RM
16784 goto bad_alignment;
16785 alignbits = 2;
16786 break;
5287ad62 16787 case 256:
477330fc
RM
16788 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
16789 goto bad_alignment;
16790 alignbits = 3;
16791 break;
5287ad62
JB
16792 default:
16793 bad_alignment:
477330fc
RM
16794 first_error (_("bad alignment"));
16795 return;
5287ad62
JB
16796 }
16797
16798 inst.instruction |= alignbits << 4;
16799 inst.instruction |= neon_logbits (et.size) << 6;
16800
16801 /* Bits [4:6] of the immediate in a list specifier encode register stride
16802 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
16803 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
16804 up the right value for "type" in a table based on this value and the given
16805 list style, then stick it back. */
16806 idx = ((inst.operands[0].imm >> 4) & 7)
477330fc 16807 | (((inst.instruction >> 8) & 3) << 3);
5287ad62
JB
16808
16809 typebits = typetable[idx];
5f4273c7 16810
5287ad62 16811 constraint (typebits == -1, _("bad list type for instruction"));
1d50d57c
WN
16812 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
16813 _("bad element type for instruction"));
5287ad62
JB
16814
16815 inst.instruction &= ~0xf00;
16816 inst.instruction |= typebits << 8;
16817}
16818
16819/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
16820 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
16821 otherwise. The variable arguments are a list of pairs of legal (size, align)
16822 values, terminated with -1. */
16823
16824static int
aa8a0863 16825neon_alignment_bit (int size, int align, int *do_alignment, ...)
5287ad62
JB
16826{
16827 va_list ap;
16828 int result = FAIL, thissize, thisalign;
5f4273c7 16829
5287ad62
JB
16830 if (!inst.operands[1].immisalign)
16831 {
aa8a0863 16832 *do_alignment = 0;
5287ad62
JB
16833 return SUCCESS;
16834 }
5f4273c7 16835
aa8a0863 16836 va_start (ap, do_alignment);
5287ad62
JB
16837
16838 do
16839 {
16840 thissize = va_arg (ap, int);
16841 if (thissize == -1)
477330fc 16842 break;
5287ad62
JB
16843 thisalign = va_arg (ap, int);
16844
16845 if (size == thissize && align == thisalign)
477330fc 16846 result = SUCCESS;
5287ad62
JB
16847 }
16848 while (result != SUCCESS);
16849
16850 va_end (ap);
16851
16852 if (result == SUCCESS)
aa8a0863 16853 *do_alignment = 1;
5287ad62 16854 else
dcbf9037 16855 first_error (_("unsupported alignment for instruction"));
5f4273c7 16856
5287ad62
JB
16857 return result;
16858}
16859
16860static void
16861do_neon_ld_st_lane (void)
16862{
037e8744 16863 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16864 int align_good, do_alignment = 0;
5287ad62
JB
16865 int logsize = neon_logbits (et.size);
16866 int align = inst.operands[1].imm >> 8;
16867 int n = (inst.instruction >> 8) & 3;
16868 int max_el = 64 / et.size;
5f4273c7 16869
dcbf9037
JB
16870 if (et.type == NT_invtype)
16871 return;
5f4273c7 16872
5287ad62 16873 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
477330fc 16874 _("bad list length"));
5287ad62 16875 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
477330fc 16876 _("scalar index out of range"));
5287ad62 16877 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
477330fc
RM
16878 && et.size == 8,
16879 _("stride of 2 unavailable when element size is 8"));
5f4273c7 16880
5287ad62
JB
16881 switch (n)
16882 {
16883 case 0: /* VLD1 / VST1. */
aa8a0863 16884 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
477330fc 16885 32, 32, -1);
5287ad62 16886 if (align_good == FAIL)
477330fc 16887 return;
aa8a0863 16888 if (do_alignment)
477330fc
RM
16889 {
16890 unsigned alignbits = 0;
16891 switch (et.size)
16892 {
16893 case 16: alignbits = 0x1; break;
16894 case 32: alignbits = 0x3; break;
16895 default: ;
16896 }
16897 inst.instruction |= alignbits << 4;
16898 }
5287ad62
JB
16899 break;
16900
16901 case 1: /* VLD2 / VST2. */
aa8a0863
TS
16902 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
16903 16, 32, 32, 64, -1);
5287ad62 16904 if (align_good == FAIL)
477330fc 16905 return;
aa8a0863 16906 if (do_alignment)
477330fc 16907 inst.instruction |= 1 << 4;
5287ad62
JB
16908 break;
16909
16910 case 2: /* VLD3 / VST3. */
16911 constraint (inst.operands[1].immisalign,
477330fc 16912 _("can't use alignment with this instruction"));
5287ad62
JB
16913 break;
16914
16915 case 3: /* VLD4 / VST4. */
aa8a0863 16916 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc 16917 16, 64, 32, 64, 32, 128, -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 8: alignbits = 0x1; break;
16926 case 16: alignbits = 0x1; break;
16927 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
16928 default: ;
16929 }
16930 inst.instruction |= alignbits << 4;
16931 }
5287ad62
JB
16932 break;
16933
16934 default: ;
16935 }
16936
16937 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
16938 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
16939 inst.instruction |= 1 << (4 + logsize);
5f4273c7 16940
5287ad62
JB
16941 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
16942 inst.instruction |= logsize << 10;
16943}
16944
16945/* Encode single n-element structure to all lanes VLD<n> instructions. */
16946
16947static void
16948do_neon_ld_dup (void)
16949{
037e8744 16950 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
aa8a0863 16951 int align_good, do_alignment = 0;
5287ad62 16952
dcbf9037
JB
16953 if (et.type == NT_invtype)
16954 return;
16955
5287ad62
JB
16956 switch ((inst.instruction >> 8) & 3)
16957 {
16958 case 0: /* VLD1. */
9c2799c2 16959 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62 16960 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863 16961 &do_alignment, 16, 16, 32, 32, -1);
5287ad62 16962 if (align_good == FAIL)
477330fc 16963 return;
5287ad62 16964 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
477330fc
RM
16965 {
16966 case 1: break;
16967 case 2: inst.instruction |= 1 << 5; break;
16968 default: first_error (_("bad list length")); return;
16969 }
5287ad62
JB
16970 inst.instruction |= neon_logbits (et.size) << 6;
16971 break;
16972
16973 case 1: /* VLD2. */
16974 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
aa8a0863
TS
16975 &do_alignment, 8, 16, 16, 32, 32, 64,
16976 -1);
5287ad62 16977 if (align_good == FAIL)
477330fc 16978 return;
5287ad62 16979 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
477330fc 16980 _("bad list length"));
5287ad62 16981 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16982 inst.instruction |= 1 << 5;
5287ad62
JB
16983 inst.instruction |= neon_logbits (et.size) << 6;
16984 break;
16985
16986 case 2: /* VLD3. */
16987 constraint (inst.operands[1].immisalign,
477330fc 16988 _("can't use alignment with this instruction"));
5287ad62 16989 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
477330fc 16990 _("bad list length"));
5287ad62 16991 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
477330fc 16992 inst.instruction |= 1 << 5;
5287ad62
JB
16993 inst.instruction |= neon_logbits (et.size) << 6;
16994 break;
16995
16996 case 3: /* VLD4. */
16997 {
477330fc 16998 int align = inst.operands[1].imm >> 8;
aa8a0863 16999 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
477330fc
RM
17000 16, 64, 32, 64, 32, 128, -1);
17001 if (align_good == FAIL)
17002 return;
17003 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
17004 _("bad list length"));
17005 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17006 inst.instruction |= 1 << 5;
17007 if (et.size == 32 && align == 128)
17008 inst.instruction |= 0x3 << 6;
17009 else
17010 inst.instruction |= neon_logbits (et.size) << 6;
5287ad62
JB
17011 }
17012 break;
17013
17014 default: ;
17015 }
17016
aa8a0863 17017 inst.instruction |= do_alignment << 4;
5287ad62
JB
17018}
17019
17020/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
17021 apart from bits [11:4]. */
17022
17023static void
17024do_neon_ldx_stx (void)
17025{
b1a769ed
DG
17026 if (inst.operands[1].isreg)
17027 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
17028
5287ad62
JB
17029 switch (NEON_LANE (inst.operands[0].imm))
17030 {
17031 case NEON_INTERLEAVE_LANES:
88714cb8 17032 NEON_ENCODE (INTERLV, inst);
5287ad62
JB
17033 do_neon_ld_st_interleave ();
17034 break;
5f4273c7 17035
5287ad62 17036 case NEON_ALL_LANES:
88714cb8 17037 NEON_ENCODE (DUP, inst);
2d51fb74
JB
17038 if (inst.instruction == N_INV)
17039 {
17040 first_error ("only loads support such operands");
17041 break;
17042 }
5287ad62
JB
17043 do_neon_ld_dup ();
17044 break;
5f4273c7 17045
5287ad62 17046 default:
88714cb8 17047 NEON_ENCODE (LANE, inst);
5287ad62
JB
17048 do_neon_ld_st_lane ();
17049 }
17050
17051 /* L bit comes from bit mask. */
17052 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17053 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17054 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 17055
5287ad62
JB
17056 if (inst.operands[1].postind)
17057 {
17058 int postreg = inst.operands[1].imm & 0xf;
17059 constraint (!inst.operands[1].immisreg,
477330fc 17060 _("post-index must be a register"));
5287ad62 17061 constraint (postreg == 0xd || postreg == 0xf,
477330fc 17062 _("bad register for post-index"));
5287ad62
JB
17063 inst.instruction |= postreg;
17064 }
4f2374c7 17065 else
5287ad62 17066 {
4f2374c7
WN
17067 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17068 constraint (inst.reloc.exp.X_op != O_constant
17069 || inst.reloc.exp.X_add_number != 0,
17070 BAD_ADDR_MODE);
17071
17072 if (inst.operands[1].writeback)
17073 {
17074 inst.instruction |= 0xd;
17075 }
17076 else
17077 inst.instruction |= 0xf;
5287ad62 17078 }
5f4273c7 17079
5287ad62
JB
17080 if (thumb_mode)
17081 inst.instruction |= 0xf9000000;
17082 else
17083 inst.instruction |= 0xf4000000;
17084}
33399f07
MGD
17085
17086/* FP v8. */
17087static void
17088do_vfp_nsyn_fpv8 (enum neon_shape rs)
17089{
a715796b
TG
17090 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17091 D register operands. */
17092 if (neon_shape_class[rs] == SC_DOUBLE)
17093 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17094 _(BAD_FPU));
17095
33399f07
MGD
17096 NEON_ENCODE (FPV8, inst);
17097
9db2f6b4
RL
17098 if (rs == NS_FFF || rs == NS_HHH)
17099 {
17100 do_vfp_sp_dyadic ();
17101
17102 /* ARMv8.2 fp16 instruction. */
17103 if (rs == NS_HHH)
17104 do_scalar_fp16_v82_encode ();
17105 }
33399f07
MGD
17106 else
17107 do_vfp_dp_rd_rn_rm ();
17108
17109 if (rs == NS_DDD)
17110 inst.instruction |= 0x100;
17111
17112 inst.instruction |= 0xf0000000;
17113}
17114
17115static void
17116do_vsel (void)
17117{
17118 set_it_insn_type (OUTSIDE_IT_INSN);
17119
17120 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
17121 first_error (_("invalid instruction shape"));
17122}
17123
73924fbc
MGD
17124static void
17125do_vmaxnm (void)
17126{
17127 set_it_insn_type (OUTSIDE_IT_INSN);
17128
17129 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
17130 return;
17131
17132 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17133 return;
17134
cc933301 17135 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
73924fbc
MGD
17136}
17137
30bdf752
MGD
17138static void
17139do_vrint_1 (enum neon_cvt_mode mode)
17140{
9db2f6b4 17141 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
30bdf752
MGD
17142 struct neon_type_el et;
17143
17144 if (rs == NS_NULL)
17145 return;
17146
a715796b
TG
17147 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17148 D register operands. */
17149 if (neon_shape_class[rs] == SC_DOUBLE)
17150 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17151 _(BAD_FPU));
17152
9db2f6b4
RL
17153 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
17154 | N_VFP);
30bdf752
MGD
17155 if (et.type != NT_invtype)
17156 {
17157 /* VFP encodings. */
17158 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
17159 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
17160 set_it_insn_type (OUTSIDE_IT_INSN);
17161
17162 NEON_ENCODE (FPV8, inst);
9db2f6b4 17163 if (rs == NS_FF || rs == NS_HH)
30bdf752
MGD
17164 do_vfp_sp_monadic ();
17165 else
17166 do_vfp_dp_rd_rm ();
17167
17168 switch (mode)
17169 {
17170 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
17171 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
17172 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
17173 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
17174 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
17175 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
17176 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
17177 default: abort ();
17178 }
17179
17180 inst.instruction |= (rs == NS_DD) << 8;
17181 do_vfp_cond_or_thumb ();
9db2f6b4
RL
17182
17183 /* ARMv8.2 fp16 vrint instruction. */
17184 if (rs == NS_HH)
17185 do_scalar_fp16_v82_encode ();
30bdf752
MGD
17186 }
17187 else
17188 {
17189 /* Neon encodings (or something broken...). */
17190 inst.error = NULL;
cc933301 17191 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
30bdf752
MGD
17192
17193 if (et.type == NT_invtype)
17194 return;
17195
17196 set_it_insn_type (OUTSIDE_IT_INSN);
17197 NEON_ENCODE (FLOAT, inst);
17198
17199 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17200 return;
17201
17202 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17203 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17204 inst.instruction |= LOW4 (inst.operands[1].reg);
17205 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17206 inst.instruction |= neon_quad (rs) << 6;
cc933301
JW
17207 /* Mask off the original size bits and reencode them. */
17208 inst.instruction = ((inst.instruction & 0xfff3ffff)
17209 | neon_logbits (et.size) << 18);
17210
30bdf752
MGD
17211 switch (mode)
17212 {
17213 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17214 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17215 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17216 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17217 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17218 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17219 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17220 default: abort ();
17221 }
17222
17223 if (thumb_mode)
17224 inst.instruction |= 0xfc000000;
17225 else
17226 inst.instruction |= 0xf0000000;
17227 }
17228}
17229
17230static void
17231do_vrintx (void)
17232{
17233 do_vrint_1 (neon_cvt_mode_x);
17234}
17235
17236static void
17237do_vrintz (void)
17238{
17239 do_vrint_1 (neon_cvt_mode_z);
17240}
17241
17242static void
17243do_vrintr (void)
17244{
17245 do_vrint_1 (neon_cvt_mode_r);
17246}
17247
17248static void
17249do_vrinta (void)
17250{
17251 do_vrint_1 (neon_cvt_mode_a);
17252}
17253
17254static void
17255do_vrintn (void)
17256{
17257 do_vrint_1 (neon_cvt_mode_n);
17258}
17259
17260static void
17261do_vrintp (void)
17262{
17263 do_vrint_1 (neon_cvt_mode_p);
17264}
17265
17266static void
17267do_vrintm (void)
17268{
17269 do_vrint_1 (neon_cvt_mode_m);
17270}
17271
c28eeff2
SN
17272static unsigned
17273neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
17274{
17275 unsigned regno = NEON_SCALAR_REG (opnd);
17276 unsigned elno = NEON_SCALAR_INDEX (opnd);
17277
17278 if (elsize == 16 && elno < 2 && regno < 16)
17279 return regno | (elno << 4);
17280 else if (elsize == 32 && elno == 0)
17281 return regno;
17282
17283 first_error (_("scalar out of range"));
17284 return 0;
17285}
17286
17287static void
17288do_vcmla (void)
17289{
17290 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17291 _(BAD_FPU));
17292 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17293 unsigned rot = inst.reloc.exp.X_add_number;
17294 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
17295 _("immediate out of range"));
17296 rot /= 90;
17297 if (inst.operands[2].isscalar)
17298 {
17299 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
17300 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17301 N_KEY | N_F16 | N_F32).size;
17302 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
17303 inst.is_neon = 1;
17304 inst.instruction = 0xfe000800;
17305 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17306 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17307 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17308 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17309 inst.instruction |= LOW4 (m);
17310 inst.instruction |= HI1 (m) << 5;
17311 inst.instruction |= neon_quad (rs) << 6;
17312 inst.instruction |= rot << 20;
17313 inst.instruction |= (size == 32) << 23;
17314 }
17315 else
17316 {
17317 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17318 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17319 N_KEY | N_F16 | N_F32).size;
17320 neon_three_same (neon_quad (rs), 0, -1);
17321 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17322 inst.instruction |= 0xfc200800;
17323 inst.instruction |= rot << 23;
17324 inst.instruction |= (size == 32) << 20;
17325 }
17326}
17327
17328static void
17329do_vcadd (void)
17330{
17331 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17332 _(BAD_FPU));
17333 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17334 unsigned rot = inst.reloc.exp.X_add_number;
17335 constraint (rot != 90 && rot != 270, _("immediate out of range"));
17336 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17337 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17338 N_KEY | N_F16 | N_F32).size;
17339 neon_three_same (neon_quad (rs), 0, -1);
17340 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17341 inst.instruction |= 0xfc800800;
17342 inst.instruction |= (rot == 270) << 24;
17343 inst.instruction |= (size == 32) << 20;
17344}
17345
91ff7894
MGD
17346/* Crypto v1 instructions. */
17347static void
17348do_crypto_2op_1 (unsigned elttype, int op)
17349{
17350 set_it_insn_type (OUTSIDE_IT_INSN);
17351
17352 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17353 == NT_invtype)
17354 return;
17355
17356 inst.error = NULL;
17357
17358 NEON_ENCODE (INTEGER, inst);
17359 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17360 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17361 inst.instruction |= LOW4 (inst.operands[1].reg);
17362 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17363 if (op != -1)
17364 inst.instruction |= op << 6;
17365
17366 if (thumb_mode)
17367 inst.instruction |= 0xfc000000;
17368 else
17369 inst.instruction |= 0xf0000000;
17370}
17371
48adcd8e
MGD
17372static void
17373do_crypto_3op_1 (int u, int op)
17374{
17375 set_it_insn_type (OUTSIDE_IT_INSN);
17376
17377 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17378 N_32 | N_UNT | N_KEY).type == NT_invtype)
17379 return;
17380
17381 inst.error = NULL;
17382
17383 NEON_ENCODE (INTEGER, inst);
17384 neon_three_same (1, u, 8 << op);
17385}
17386
91ff7894
MGD
17387static void
17388do_aese (void)
17389{
17390 do_crypto_2op_1 (N_8, 0);
17391}
17392
17393static void
17394do_aesd (void)
17395{
17396 do_crypto_2op_1 (N_8, 1);
17397}
17398
17399static void
17400do_aesmc (void)
17401{
17402 do_crypto_2op_1 (N_8, 2);
17403}
17404
17405static void
17406do_aesimc (void)
17407{
17408 do_crypto_2op_1 (N_8, 3);
17409}
17410
48adcd8e
MGD
17411static void
17412do_sha1c (void)
17413{
17414 do_crypto_3op_1 (0, 0);
17415}
17416
17417static void
17418do_sha1p (void)
17419{
17420 do_crypto_3op_1 (0, 1);
17421}
17422
17423static void
17424do_sha1m (void)
17425{
17426 do_crypto_3op_1 (0, 2);
17427}
17428
17429static void
17430do_sha1su0 (void)
17431{
17432 do_crypto_3op_1 (0, 3);
17433}
91ff7894 17434
48adcd8e
MGD
17435static void
17436do_sha256h (void)
17437{
17438 do_crypto_3op_1 (1, 0);
17439}
17440
17441static void
17442do_sha256h2 (void)
17443{
17444 do_crypto_3op_1 (1, 1);
17445}
17446
17447static void
17448do_sha256su1 (void)
17449{
17450 do_crypto_3op_1 (1, 2);
17451}
3c9017d2
MGD
17452
17453static void
17454do_sha1h (void)
17455{
17456 do_crypto_2op_1 (N_32, -1);
17457}
17458
17459static void
17460do_sha1su1 (void)
17461{
17462 do_crypto_2op_1 (N_32, 0);
17463}
17464
17465static void
17466do_sha256su0 (void)
17467{
17468 do_crypto_2op_1 (N_32, 1);
17469}
dd5181d5
KT
17470
17471static void
17472do_crc32_1 (unsigned int poly, unsigned int sz)
17473{
17474 unsigned int Rd = inst.operands[0].reg;
17475 unsigned int Rn = inst.operands[1].reg;
17476 unsigned int Rm = inst.operands[2].reg;
17477
17478 set_it_insn_type (OUTSIDE_IT_INSN);
17479 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
17480 inst.instruction |= LOW4 (Rn) << 16;
17481 inst.instruction |= LOW4 (Rm);
17482 inst.instruction |= sz << (thumb_mode ? 4 : 21);
17483 inst.instruction |= poly << (thumb_mode ? 20 : 9);
17484
17485 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
17486 as_warn (UNPRED_REG ("r15"));
17487 if (thumb_mode && (Rd == REG_SP || Rn == REG_SP || Rm == REG_SP))
17488 as_warn (UNPRED_REG ("r13"));
17489}
17490
17491static void
17492do_crc32b (void)
17493{
17494 do_crc32_1 (0, 0);
17495}
17496
17497static void
17498do_crc32h (void)
17499{
17500 do_crc32_1 (0, 1);
17501}
17502
17503static void
17504do_crc32w (void)
17505{
17506 do_crc32_1 (0, 2);
17507}
17508
17509static void
17510do_crc32cb (void)
17511{
17512 do_crc32_1 (1, 0);
17513}
17514
17515static void
17516do_crc32ch (void)
17517{
17518 do_crc32_1 (1, 1);
17519}
17520
17521static void
17522do_crc32cw (void)
17523{
17524 do_crc32_1 (1, 2);
17525}
17526
49e8a725
SN
17527static void
17528do_vjcvt (void)
17529{
17530 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17531 _(BAD_FPU));
17532 neon_check_type (2, NS_FD, N_S32, N_F64);
17533 do_vfp_sp_dp_cvt ();
17534 do_vfp_cond_or_thumb ();
17535}
17536
5287ad62
JB
17537\f
17538/* Overall per-instruction processing. */
17539
17540/* We need to be able to fix up arbitrary expressions in some statements.
17541 This is so that we can handle symbols that are an arbitrary distance from
17542 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17543 which returns part of an address in a form which will be valid for
17544 a data instruction. We do this by pushing the expression into a symbol
17545 in the expr_section, and creating a fix for that. */
17546
17547static void
17548fix_new_arm (fragS * frag,
17549 int where,
17550 short int size,
17551 expressionS * exp,
17552 int pc_rel,
17553 int reloc)
17554{
17555 fixS * new_fix;
17556
17557 switch (exp->X_op)
17558 {
17559 case O_constant:
6e7ce2cd
PB
17560 if (pc_rel)
17561 {
17562 /* Create an absolute valued symbol, so we have something to
477330fc
RM
17563 refer to in the object file. Unfortunately for us, gas's
17564 generic expression parsing will already have folded out
17565 any use of .set foo/.type foo %function that may have
17566 been used to set type information of the target location,
17567 that's being specified symbolically. We have to presume
17568 the user knows what they are doing. */
6e7ce2cd
PB
17569 char name[16 + 8];
17570 symbolS *symbol;
17571
17572 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17573
17574 symbol = symbol_find_or_make (name);
17575 S_SET_SEGMENT (symbol, absolute_section);
17576 symbol_set_frag (symbol, &zero_address_frag);
17577 S_SET_VALUE (symbol, exp->X_add_number);
17578 exp->X_op = O_symbol;
17579 exp->X_add_symbol = symbol;
17580 exp->X_add_number = 0;
17581 }
17582 /* FALLTHROUGH */
5287ad62
JB
17583 case O_symbol:
17584 case O_add:
17585 case O_subtract:
21d799b5 17586 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
477330fc 17587 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17588 break;
17589
17590 default:
21d799b5 17591 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
477330fc 17592 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
17593 break;
17594 }
17595
17596 /* Mark whether the fix is to a THUMB instruction, or an ARM
17597 instruction. */
17598 new_fix->tc_fix_data = thumb_mode;
17599}
17600
17601/* Create a frg for an instruction requiring relaxation. */
17602static void
17603output_relax_insn (void)
17604{
17605 char * to;
17606 symbolS *sym;
0110f2b8
PB
17607 int offset;
17608
6e1cb1a6
PB
17609 /* The size of the instruction is unknown, so tie the debug info to the
17610 start of the instruction. */
17611 dwarf2_emit_insn (0);
6e1cb1a6 17612
0110f2b8
PB
17613 switch (inst.reloc.exp.X_op)
17614 {
17615 case O_symbol:
17616 sym = inst.reloc.exp.X_add_symbol;
17617 offset = inst.reloc.exp.X_add_number;
17618 break;
17619 case O_constant:
17620 sym = NULL;
17621 offset = inst.reloc.exp.X_add_number;
17622 break;
17623 default:
17624 sym = make_expr_symbol (&inst.reloc.exp);
17625 offset = 0;
17626 break;
17627 }
17628 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17629 inst.relax, sym, offset, NULL/*offset, opcode*/);
17630 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
17631}
17632
17633/* Write a 32-bit thumb instruction to buf. */
17634static void
17635put_thumb32_insn (char * buf, unsigned long insn)
17636{
17637 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17638 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17639}
17640
b99bd4ef 17641static void
c19d1205 17642output_inst (const char * str)
b99bd4ef 17643{
c19d1205 17644 char * to = NULL;
b99bd4ef 17645
c19d1205 17646 if (inst.error)
b99bd4ef 17647 {
c19d1205 17648 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
17649 return;
17650 }
5f4273c7
NC
17651 if (inst.relax)
17652 {
17653 output_relax_insn ();
0110f2b8 17654 return;
5f4273c7 17655 }
c19d1205
ZW
17656 if (inst.size == 0)
17657 return;
b99bd4ef 17658
c19d1205 17659 to = frag_more (inst.size);
8dc2430f
NC
17660 /* PR 9814: Record the thumb mode into the current frag so that we know
17661 what type of NOP padding to use, if necessary. We override any previous
17662 setting so that if the mode has changed then the NOPS that we use will
17663 match the encoding of the last instruction in the frag. */
cd000bff 17664 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
17665
17666 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 17667 {
9c2799c2 17668 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 17669 put_thumb32_insn (to, inst.instruction);
b99bd4ef 17670 }
c19d1205 17671 else if (inst.size > INSN_SIZE)
b99bd4ef 17672 {
9c2799c2 17673 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
17674 md_number_to_chars (to, inst.instruction, INSN_SIZE);
17675 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 17676 }
c19d1205
ZW
17677 else
17678 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 17679
c19d1205
ZW
17680 if (inst.reloc.type != BFD_RELOC_UNUSED)
17681 fix_new_arm (frag_now, to - frag_now->fr_literal,
17682 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
17683 inst.reloc.type);
b99bd4ef 17684
c19d1205 17685 dwarf2_emit_insn (inst.size);
c19d1205 17686}
b99bd4ef 17687
e07e6e58
NC
17688static char *
17689output_it_inst (int cond, int mask, char * to)
17690{
17691 unsigned long instruction = 0xbf00;
17692
17693 mask &= 0xf;
17694 instruction |= mask;
17695 instruction |= cond << 4;
17696
17697 if (to == NULL)
17698 {
17699 to = frag_more (2);
17700#ifdef OBJ_ELF
17701 dwarf2_emit_insn (2);
17702#endif
17703 }
17704
17705 md_number_to_chars (to, instruction, 2);
17706
17707 return to;
17708}
17709
c19d1205
ZW
17710/* Tag values used in struct asm_opcode's tag field. */
17711enum opcode_tag
17712{
17713 OT_unconditional, /* Instruction cannot be conditionalized.
17714 The ARM condition field is still 0xE. */
17715 OT_unconditionalF, /* Instruction cannot be conditionalized
17716 and carries 0xF in its ARM condition field. */
17717 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744 17718 OT_csuffixF, /* Some forms of the instruction take a conditional
477330fc
RM
17719 suffix, others place 0xF where the condition field
17720 would be. */
c19d1205
ZW
17721 OT_cinfix3, /* Instruction takes a conditional infix,
17722 beginning at character index 3. (In
17723 unified mode, it becomes a suffix.) */
088fa78e
KH
17724 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
17725 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
17726 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
17727 character index 3, even in unified mode. Used for
17728 legacy instructions where suffix and infix forms
17729 may be ambiguous. */
c19d1205 17730 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 17731 suffix or an infix at character index 3. */
c19d1205
ZW
17732 OT_odd_infix_unc, /* This is the unconditional variant of an
17733 instruction that takes a conditional infix
17734 at an unusual position. In unified mode,
17735 this variant will accept a suffix. */
17736 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
17737 are the conditional variants of instructions that
17738 take conditional infixes in unusual positions.
17739 The infix appears at character index
17740 (tag - OT_odd_infix_0). These are not accepted
17741 in unified mode. */
17742};
b99bd4ef 17743
c19d1205
ZW
17744/* Subroutine of md_assemble, responsible for looking up the primary
17745 opcode from the mnemonic the user wrote. STR points to the
17746 beginning of the mnemonic.
17747
17748 This is not simply a hash table lookup, because of conditional
17749 variants. Most instructions have conditional variants, which are
17750 expressed with a _conditional affix_ to the mnemonic. If we were
17751 to encode each conditional variant as a literal string in the opcode
17752 table, it would have approximately 20,000 entries.
17753
17754 Most mnemonics take this affix as a suffix, and in unified syntax,
17755 'most' is upgraded to 'all'. However, in the divided syntax, some
17756 instructions take the affix as an infix, notably the s-variants of
17757 the arithmetic instructions. Of those instructions, all but six
17758 have the infix appear after the third character of the mnemonic.
17759
17760 Accordingly, the algorithm for looking up primary opcodes given
17761 an identifier is:
17762
17763 1. Look up the identifier in the opcode table.
17764 If we find a match, go to step U.
17765
17766 2. Look up the last two characters of the identifier in the
17767 conditions table. If we find a match, look up the first N-2
17768 characters of the identifier in the opcode table. If we
17769 find a match, go to step CE.
17770
17771 3. Look up the fourth and fifth characters of the identifier in
17772 the conditions table. If we find a match, extract those
17773 characters from the identifier, and look up the remaining
17774 characters in the opcode table. If we find a match, go
17775 to step CM.
17776
17777 4. Fail.
17778
17779 U. Examine the tag field of the opcode structure, in case this is
17780 one of the six instructions with its conditional infix in an
17781 unusual place. If it is, the tag tells us where to find the
17782 infix; look it up in the conditions table and set inst.cond
17783 accordingly. Otherwise, this is an unconditional instruction.
17784 Again set inst.cond accordingly. Return the opcode structure.
17785
17786 CE. Examine the tag field to make sure this is an instruction that
17787 should receive a conditional suffix. If it is not, fail.
17788 Otherwise, set inst.cond from the suffix we already looked up,
17789 and return the opcode structure.
17790
17791 CM. Examine the tag field to make sure this is an instruction that
17792 should receive a conditional infix after the third character.
17793 If it is not, fail. Otherwise, undo the edits to the current
17794 line of input and proceed as for case CE. */
17795
17796static const struct asm_opcode *
17797opcode_lookup (char **str)
17798{
17799 char *end, *base;
17800 char *affix;
17801 const struct asm_opcode *opcode;
17802 const struct asm_cond *cond;
e3cb604e 17803 char save[2];
c19d1205
ZW
17804
17805 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 17806 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 17807 for (base = end = *str; *end != '\0'; end++)
721a8186 17808 if (*end == ' ' || *end == '.')
c19d1205 17809 break;
b99bd4ef 17810
c19d1205 17811 if (end == base)
c921be7d 17812 return NULL;
b99bd4ef 17813
5287ad62 17814 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 17815 if (end[0] == '.')
b99bd4ef 17816 {
5287ad62 17817 int offset = 2;
5f4273c7 17818
267d2029 17819 /* The .w and .n suffixes are only valid if the unified syntax is in
477330fc 17820 use. */
267d2029 17821 if (unified_syntax && end[1] == 'w')
c19d1205 17822 inst.size_req = 4;
267d2029 17823 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
17824 inst.size_req = 2;
17825 else
477330fc 17826 offset = 0;
5287ad62
JB
17827
17828 inst.vectype.elems = 0;
17829
17830 *str = end + offset;
b99bd4ef 17831
5f4273c7 17832 if (end[offset] == '.')
5287ad62 17833 {
267d2029 17834 /* See if we have a Neon type suffix (possible in either unified or
477330fc
RM
17835 non-unified ARM syntax mode). */
17836 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 17837 return NULL;
477330fc 17838 }
5287ad62 17839 else if (end[offset] != '\0' && end[offset] != ' ')
477330fc 17840 return NULL;
b99bd4ef 17841 }
c19d1205
ZW
17842 else
17843 *str = end;
b99bd4ef 17844
c19d1205 17845 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5 17846 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17847 end - base);
c19d1205 17848 if (opcode)
b99bd4ef 17849 {
c19d1205
ZW
17850 /* step U */
17851 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 17852 {
c19d1205
ZW
17853 inst.cond = COND_ALWAYS;
17854 return opcode;
b99bd4ef 17855 }
b99bd4ef 17856
278df34e 17857 if (warn_on_deprecated && unified_syntax)
5c3696f8 17858 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205 17859 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 17860 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 17861 gas_assert (cond);
b99bd4ef 17862
c19d1205
ZW
17863 inst.cond = cond->value;
17864 return opcode;
17865 }
b99bd4ef 17866
c19d1205
ZW
17867 /* Cannot have a conditional suffix on a mnemonic of less than two
17868 characters. */
17869 if (end - base < 3)
c921be7d 17870 return NULL;
b99bd4ef 17871
c19d1205
ZW
17872 /* Look for suffixed mnemonic. */
17873 affix = end - 2;
21d799b5
NC
17874 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
17875 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17876 affix - base);
c19d1205
ZW
17877 if (opcode && cond)
17878 {
17879 /* step CE */
17880 switch (opcode->tag)
17881 {
e3cb604e
PB
17882 case OT_cinfix3_legacy:
17883 /* Ignore conditional suffixes matched on infix only mnemonics. */
17884 break;
17885
c19d1205 17886 case OT_cinfix3:
088fa78e 17887 case OT_cinfix3_deprecated:
c19d1205
ZW
17888 case OT_odd_infix_unc:
17889 if (!unified_syntax)
e3cb604e 17890 return 0;
1a0670f3 17891 /* Fall through. */
c19d1205
ZW
17892
17893 case OT_csuffix:
477330fc 17894 case OT_csuffixF:
c19d1205
ZW
17895 case OT_csuf_or_in3:
17896 inst.cond = cond->value;
17897 return opcode;
17898
17899 case OT_unconditional:
17900 case OT_unconditionalF:
dfa9f0d5 17901 if (thumb_mode)
c921be7d 17902 inst.cond = cond->value;
dfa9f0d5
PB
17903 else
17904 {
c921be7d 17905 /* Delayed diagnostic. */
dfa9f0d5
PB
17906 inst.error = BAD_COND;
17907 inst.cond = COND_ALWAYS;
17908 }
c19d1205 17909 return opcode;
b99bd4ef 17910
c19d1205 17911 default:
c921be7d 17912 return NULL;
c19d1205
ZW
17913 }
17914 }
b99bd4ef 17915
c19d1205
ZW
17916 /* Cannot have a usual-position infix on a mnemonic of less than
17917 six characters (five would be a suffix). */
17918 if (end - base < 6)
c921be7d 17919 return NULL;
b99bd4ef 17920
c19d1205
ZW
17921 /* Look for infixed mnemonic in the usual position. */
17922 affix = base + 3;
21d799b5 17923 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 17924 if (!cond)
c921be7d 17925 return NULL;
e3cb604e
PB
17926
17927 memcpy (save, affix, 2);
17928 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5 17929 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
477330fc 17930 (end - base) - 2);
e3cb604e
PB
17931 memmove (affix + 2, affix, (end - affix) - 2);
17932 memcpy (affix, save, 2);
17933
088fa78e
KH
17934 if (opcode
17935 && (opcode->tag == OT_cinfix3
17936 || opcode->tag == OT_cinfix3_deprecated
17937 || opcode->tag == OT_csuf_or_in3
17938 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 17939 {
c921be7d 17940 /* Step CM. */
278df34e 17941 if (warn_on_deprecated && unified_syntax
088fa78e
KH
17942 && (opcode->tag == OT_cinfix3
17943 || opcode->tag == OT_cinfix3_deprecated))
5c3696f8 17944 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
c19d1205
ZW
17945
17946 inst.cond = cond->value;
17947 return opcode;
b99bd4ef
NC
17948 }
17949
c921be7d 17950 return NULL;
b99bd4ef
NC
17951}
17952
e07e6e58
NC
17953/* This function generates an initial IT instruction, leaving its block
17954 virtually open for the new instructions. Eventually,
17955 the mask will be updated by now_it_add_mask () each time
17956 a new instruction needs to be included in the IT block.
17957 Finally, the block is closed with close_automatic_it_block ().
17958 The block closure can be requested either from md_assemble (),
17959 a tencode (), or due to a label hook. */
17960
17961static void
17962new_automatic_it_block (int cond)
17963{
17964 now_it.state = AUTOMATIC_IT_BLOCK;
17965 now_it.mask = 0x18;
17966 now_it.cc = cond;
17967 now_it.block_length = 1;
cd000bff 17968 mapping_state (MAP_THUMB);
e07e6e58 17969 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
5a01bb1d
MGD
17970 now_it.warn_deprecated = FALSE;
17971 now_it.insn_cond = TRUE;
e07e6e58
NC
17972}
17973
17974/* Close an automatic IT block.
17975 See comments in new_automatic_it_block (). */
17976
17977static void
17978close_automatic_it_block (void)
17979{
17980 now_it.mask = 0x10;
17981 now_it.block_length = 0;
17982}
17983
17984/* Update the mask of the current automatically-generated IT
17985 instruction. See comments in new_automatic_it_block (). */
17986
17987static void
17988now_it_add_mask (int cond)
17989{
17990#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
17991#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
477330fc 17992 | ((bitvalue) << (nbit)))
e07e6e58 17993 const int resulting_bit = (cond & 1);
c921be7d 17994
e07e6e58
NC
17995 now_it.mask &= 0xf;
17996 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
17997 resulting_bit,
17998 (5 - now_it.block_length));
e07e6e58 17999 now_it.mask = SET_BIT_VALUE (now_it.mask,
477330fc
RM
18000 1,
18001 ((5 - now_it.block_length) - 1) );
e07e6e58
NC
18002 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
18003
18004#undef CLEAR_BIT
18005#undef SET_BIT_VALUE
e07e6e58
NC
18006}
18007
18008/* The IT blocks handling machinery is accessed through the these functions:
18009 it_fsm_pre_encode () from md_assemble ()
18010 set_it_insn_type () optional, from the tencode functions
18011 set_it_insn_type_last () ditto
18012 in_it_block () ditto
18013 it_fsm_post_encode () from md_assemble ()
33eaf5de 18014 force_automatic_it_block_close () from label handling functions
e07e6e58
NC
18015
18016 Rationale:
18017 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
477330fc
RM
18018 initializing the IT insn type with a generic initial value depending
18019 on the inst.condition.
e07e6e58 18020 2) During the tencode function, two things may happen:
477330fc
RM
18021 a) The tencode function overrides the IT insn type by
18022 calling either set_it_insn_type (type) or set_it_insn_type_last ().
18023 b) The tencode function queries the IT block state by
18024 calling in_it_block () (i.e. to determine narrow/not narrow mode).
18025
18026 Both set_it_insn_type and in_it_block run the internal FSM state
18027 handling function (handle_it_state), because: a) setting the IT insn
18028 type may incur in an invalid state (exiting the function),
18029 and b) querying the state requires the FSM to be updated.
18030 Specifically we want to avoid creating an IT block for conditional
18031 branches, so it_fsm_pre_encode is actually a guess and we can't
18032 determine whether an IT block is required until the tencode () routine
18033 has decided what type of instruction this actually it.
18034 Because of this, if set_it_insn_type and in_it_block have to be used,
18035 set_it_insn_type has to be called first.
18036
18037 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
18038 determines the insn IT type depending on the inst.cond code.
18039 When a tencode () routine encodes an instruction that can be
18040 either outside an IT block, or, in the case of being inside, has to be
18041 the last one, set_it_insn_type_last () will determine the proper
18042 IT instruction type based on the inst.cond code. Otherwise,
18043 set_it_insn_type can be called for overriding that logic or
18044 for covering other cases.
18045
18046 Calling handle_it_state () may not transition the IT block state to
2b0f3761 18047 OUTSIDE_IT_BLOCK immediately, since the (current) state could be
477330fc
RM
18048 still queried. Instead, if the FSM determines that the state should
18049 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
18050 after the tencode () function: that's what it_fsm_post_encode () does.
18051
18052 Since in_it_block () calls the state handling function to get an
18053 updated state, an error may occur (due to invalid insns combination).
18054 In that case, inst.error is set.
18055 Therefore, inst.error has to be checked after the execution of
18056 the tencode () routine.
e07e6e58
NC
18057
18058 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
477330fc
RM
18059 any pending state change (if any) that didn't take place in
18060 handle_it_state () as explained above. */
e07e6e58
NC
18061
18062static void
18063it_fsm_pre_encode (void)
18064{
18065 if (inst.cond != COND_ALWAYS)
18066 inst.it_insn_type = INSIDE_IT_INSN;
18067 else
18068 inst.it_insn_type = OUTSIDE_IT_INSN;
18069
18070 now_it.state_handled = 0;
18071}
18072
18073/* IT state FSM handling function. */
18074
18075static int
18076handle_it_state (void)
18077{
18078 now_it.state_handled = 1;
5a01bb1d 18079 now_it.insn_cond = FALSE;
e07e6e58
NC
18080
18081 switch (now_it.state)
18082 {
18083 case OUTSIDE_IT_BLOCK:
18084 switch (inst.it_insn_type)
18085 {
18086 case OUTSIDE_IT_INSN:
18087 break;
18088
18089 case INSIDE_IT_INSN:
18090 case INSIDE_IT_LAST_INSN:
18091 if (thumb_mode == 0)
18092 {
c921be7d 18093 if (unified_syntax
e07e6e58
NC
18094 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
18095 as_tsktsk (_("Warning: conditional outside an IT block"\
18096 " for Thumb."));
18097 }
18098 else
18099 {
18100 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
fc289b0a 18101 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
e07e6e58
NC
18102 {
18103 /* Automatically generate the IT instruction. */
18104 new_automatic_it_block (inst.cond);
18105 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
18106 close_automatic_it_block ();
18107 }
18108 else
18109 {
18110 inst.error = BAD_OUT_IT;
18111 return FAIL;
18112 }
18113 }
18114 break;
18115
18116 case IF_INSIDE_IT_LAST_INSN:
18117 case NEUTRAL_IT_INSN:
18118 break;
18119
18120 case IT_INSN:
18121 now_it.state = MANUAL_IT_BLOCK;
18122 now_it.block_length = 0;
18123 break;
18124 }
18125 break;
18126
18127 case AUTOMATIC_IT_BLOCK:
18128 /* Three things may happen now:
18129 a) We should increment current it block size;
18130 b) We should close current it block (closing insn or 4 insns);
18131 c) We should close current it block and start a new one (due
18132 to incompatible conditions or
18133 4 insns-length block reached). */
18134
18135 switch (inst.it_insn_type)
18136 {
18137 case OUTSIDE_IT_INSN:
2b0f3761 18138 /* The closure of the block shall happen immediately,
e07e6e58
NC
18139 so any in_it_block () call reports the block as closed. */
18140 force_automatic_it_block_close ();
18141 break;
18142
18143 case INSIDE_IT_INSN:
18144 case INSIDE_IT_LAST_INSN:
18145 case IF_INSIDE_IT_LAST_INSN:
18146 now_it.block_length++;
18147
18148 if (now_it.block_length > 4
18149 || !now_it_compatible (inst.cond))
18150 {
18151 force_automatic_it_block_close ();
18152 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
18153 new_automatic_it_block (inst.cond);
18154 }
18155 else
18156 {
5a01bb1d 18157 now_it.insn_cond = TRUE;
e07e6e58
NC
18158 now_it_add_mask (inst.cond);
18159 }
18160
18161 if (now_it.state == AUTOMATIC_IT_BLOCK
18162 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
18163 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
18164 close_automatic_it_block ();
18165 break;
18166
18167 case NEUTRAL_IT_INSN:
18168 now_it.block_length++;
5a01bb1d 18169 now_it.insn_cond = TRUE;
e07e6e58
NC
18170
18171 if (now_it.block_length > 4)
18172 force_automatic_it_block_close ();
18173 else
18174 now_it_add_mask (now_it.cc & 1);
18175 break;
18176
18177 case IT_INSN:
18178 close_automatic_it_block ();
18179 now_it.state = MANUAL_IT_BLOCK;
18180 break;
18181 }
18182 break;
18183
18184 case MANUAL_IT_BLOCK:
18185 {
18186 /* Check conditional suffixes. */
18187 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
18188 int is_last;
18189 now_it.mask <<= 1;
18190 now_it.mask &= 0x1f;
18191 is_last = (now_it.mask == 0x10);
5a01bb1d 18192 now_it.insn_cond = TRUE;
e07e6e58
NC
18193
18194 switch (inst.it_insn_type)
18195 {
18196 case OUTSIDE_IT_INSN:
18197 inst.error = BAD_NOT_IT;
18198 return FAIL;
18199
18200 case INSIDE_IT_INSN:
18201 if (cond != inst.cond)
18202 {
18203 inst.error = BAD_IT_COND;
18204 return FAIL;
18205 }
18206 break;
18207
18208 case INSIDE_IT_LAST_INSN:
18209 case IF_INSIDE_IT_LAST_INSN:
18210 if (cond != inst.cond)
18211 {
18212 inst.error = BAD_IT_COND;
18213 return FAIL;
18214 }
18215 if (!is_last)
18216 {
18217 inst.error = BAD_BRANCH;
18218 return FAIL;
18219 }
18220 break;
18221
18222 case NEUTRAL_IT_INSN:
18223 /* The BKPT instruction is unconditional even in an IT block. */
18224 break;
18225
18226 case IT_INSN:
18227 inst.error = BAD_IT_IT;
18228 return FAIL;
18229 }
18230 }
18231 break;
18232 }
18233
18234 return SUCCESS;
18235}
18236
5a01bb1d
MGD
18237struct depr_insn_mask
18238{
18239 unsigned long pattern;
18240 unsigned long mask;
18241 const char* description;
18242};
18243
18244/* List of 16-bit instruction patterns deprecated in an IT block in
18245 ARMv8. */
18246static const struct depr_insn_mask depr_it_insns[] = {
18247 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
18248 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
18249 { 0xa000, 0xb800, N_("ADR") },
18250 { 0x4800, 0xf800, N_("Literal loads") },
18251 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
18252 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
c8de034b
JW
18253 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
18254 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
18255 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
5a01bb1d
MGD
18256 { 0, 0, NULL }
18257};
18258
e07e6e58
NC
18259static void
18260it_fsm_post_encode (void)
18261{
18262 int is_last;
18263
18264 if (!now_it.state_handled)
18265 handle_it_state ();
18266
5a01bb1d
MGD
18267 if (now_it.insn_cond
18268 && !now_it.warn_deprecated
18269 && warn_on_deprecated
18270 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
18271 {
18272 if (inst.instruction >= 0x10000)
18273 {
5c3696f8 18274 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
5a01bb1d
MGD
18275 "deprecated in ARMv8"));
18276 now_it.warn_deprecated = TRUE;
18277 }
18278 else
18279 {
18280 const struct depr_insn_mask *p = depr_it_insns;
18281
18282 while (p->mask != 0)
18283 {
18284 if ((inst.instruction & p->mask) == p->pattern)
18285 {
5c3696f8 18286 as_tsktsk (_("IT blocks containing 16-bit Thumb instructions "
5a01bb1d
MGD
18287 "of the following class are deprecated in ARMv8: "
18288 "%s"), p->description);
18289 now_it.warn_deprecated = TRUE;
18290 break;
18291 }
18292
18293 ++p;
18294 }
18295 }
18296
18297 if (now_it.block_length > 1)
18298 {
5c3696f8 18299 as_tsktsk (_("IT blocks containing more than one conditional "
0a8897c7 18300 "instruction are deprecated in ARMv8"));
5a01bb1d
MGD
18301 now_it.warn_deprecated = TRUE;
18302 }
18303 }
18304
e07e6e58
NC
18305 is_last = (now_it.mask == 0x10);
18306 if (is_last)
18307 {
18308 now_it.state = OUTSIDE_IT_BLOCK;
18309 now_it.mask = 0;
18310 }
18311}
18312
18313static void
18314force_automatic_it_block_close (void)
18315{
18316 if (now_it.state == AUTOMATIC_IT_BLOCK)
18317 {
18318 close_automatic_it_block ();
18319 now_it.state = OUTSIDE_IT_BLOCK;
18320 now_it.mask = 0;
18321 }
18322}
18323
18324static int
18325in_it_block (void)
18326{
18327 if (!now_it.state_handled)
18328 handle_it_state ();
18329
18330 return now_it.state != OUTSIDE_IT_BLOCK;
18331}
18332
ff8646ee
TP
18333/* Whether OPCODE only has T32 encoding. Since this function is only used by
18334 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18335 here, hence the "known" in the function name. */
fc289b0a
TP
18336
18337static bfd_boolean
ff8646ee 18338known_t32_only_insn (const struct asm_opcode *opcode)
fc289b0a
TP
18339{
18340 /* Original Thumb-1 wide instruction. */
18341 if (opcode->tencode == do_t_blx
18342 || opcode->tencode == do_t_branch23
18343 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18344 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18345 return TRUE;
18346
16a1fa25
TP
18347 /* Wide-only instruction added to ARMv8-M Baseline. */
18348 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
ff8646ee
TP
18349 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18350 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18351 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18352 return TRUE;
18353
18354 return FALSE;
18355}
18356
18357/* Whether wide instruction variant can be used if available for a valid OPCODE
18358 in ARCH. */
18359
18360static bfd_boolean
18361t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18362{
18363 if (known_t32_only_insn (opcode))
18364 return TRUE;
18365
18366 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18367 of variant T3 of B.W is checked in do_t_branch. */
18368 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18369 && opcode->tencode == do_t_branch)
18370 return TRUE;
18371
bada4342
JW
18372 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
18373 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18374 && opcode->tencode == do_t_mov_cmp
18375 /* Make sure CMP instruction is not affected. */
18376 && opcode->aencode == do_mov)
18377 return TRUE;
18378
ff8646ee
TP
18379 /* Wide instruction variants of all instructions with narrow *and* wide
18380 variants become available with ARMv6t2. Other opcodes are either
18381 narrow-only or wide-only and are thus available if OPCODE is valid. */
18382 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18383 return TRUE;
18384
18385 /* OPCODE with narrow only instruction variant or wide variant not
18386 available. */
fc289b0a
TP
18387 return FALSE;
18388}
18389
c19d1205
ZW
18390void
18391md_assemble (char *str)
b99bd4ef 18392{
c19d1205
ZW
18393 char *p = str;
18394 const struct asm_opcode * opcode;
b99bd4ef 18395
c19d1205
ZW
18396 /* Align the previous label if needed. */
18397 if (last_label_seen != NULL)
b99bd4ef 18398 {
c19d1205
ZW
18399 symbol_set_frag (last_label_seen, frag_now);
18400 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18401 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
18402 }
18403
c19d1205
ZW
18404 memset (&inst, '\0', sizeof (inst));
18405 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 18406
c19d1205
ZW
18407 opcode = opcode_lookup (&p);
18408 if (!opcode)
b99bd4ef 18409 {
c19d1205 18410 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 18411 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d 18412 if (! create_register_alias (str, p)
477330fc 18413 && ! create_neon_reg_alias (str, p))
c19d1205 18414 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 18415
b99bd4ef
NC
18416 return;
18417 }
18418
278df34e 18419 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
5c3696f8 18420 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
088fa78e 18421
037e8744
JB
18422 /* The value which unconditional instructions should have in place of the
18423 condition field. */
18424 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
18425
c19d1205 18426 if (thumb_mode)
b99bd4ef 18427 {
e74cfd16 18428 arm_feature_set variant;
8f06b2d8
PB
18429
18430 variant = cpu_variant;
18431 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
18432 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
18433 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 18434 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
18435 if (!opcode->tvariant
18436 || (thumb_mode == 1
18437 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 18438 {
84b52b66 18439 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
b99bd4ef
NC
18440 return;
18441 }
c19d1205
ZW
18442 if (inst.cond != COND_ALWAYS && !unified_syntax
18443 && opcode->tencode != do_t_branch)
b99bd4ef 18444 {
c19d1205 18445 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
18446 return;
18447 }
18448
fc289b0a
TP
18449 /* Two things are addressed here:
18450 1) Implicit require narrow instructions on Thumb-1.
18451 This avoids relaxation accidentally introducing Thumb-2
18452 instructions.
18453 2) Reject wide instructions in non Thumb-2 cores.
18454
18455 Only instructions with narrow and wide variants need to be handled
18456 but selecting all non wide-only instructions is easier. */
18457 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
ff8646ee 18458 && !t32_insn_ok (variant, opcode))
076d447c 18459 {
fc289b0a
TP
18460 if (inst.size_req == 0)
18461 inst.size_req = 2;
18462 else if (inst.size_req == 4)
752d5da4 18463 {
ff8646ee
TP
18464 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
18465 as_bad (_("selected processor does not support 32bit wide "
18466 "variant of instruction `%s'"), str);
18467 else
18468 as_bad (_("selected processor does not support `%s' in "
18469 "Thumb-2 mode"), str);
fc289b0a 18470 return;
752d5da4 18471 }
076d447c
PB
18472 }
18473
c19d1205
ZW
18474 inst.instruction = opcode->tvalue;
18475
5be8be5d 18476 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
477330fc
RM
18477 {
18478 /* Prepare the it_insn_type for those encodings that don't set
18479 it. */
18480 it_fsm_pre_encode ();
c19d1205 18481
477330fc 18482 opcode->tencode ();
e07e6e58 18483
477330fc
RM
18484 it_fsm_post_encode ();
18485 }
e27ec89e 18486
0110f2b8 18487 if (!(inst.error || inst.relax))
b99bd4ef 18488 {
9c2799c2 18489 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
18490 inst.size = (inst.instruction > 0xffff ? 4 : 2);
18491 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 18492 {
c19d1205 18493 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
18494 return;
18495 }
18496 }
076d447c
PB
18497
18498 /* Something has gone badly wrong if we try to relax a fixed size
477330fc 18499 instruction. */
9c2799c2 18500 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 18501
e74cfd16
PB
18502 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18503 *opcode->tvariant);
ee065d83 18504 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
fc289b0a
TP
18505 set those bits when Thumb-2 32-bit instructions are seen. The impact
18506 of relaxable instructions will be considered later after we finish all
18507 relaxation. */
ff8646ee
TP
18508 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
18509 variant = arm_arch_none;
18510 else
18511 variant = cpu_variant;
18512 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
e74cfd16
PB
18513 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18514 arm_ext_v6t2);
cd000bff 18515
88714cb8
DG
18516 check_neon_suffixes;
18517
cd000bff 18518 if (!inst.error)
c877a2f2
NC
18519 {
18520 mapping_state (MAP_THUMB);
18521 }
c19d1205 18522 }
3e9e4fcf 18523 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 18524 {
845b51d6
PB
18525 bfd_boolean is_bx;
18526
18527 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
18528 is_bx = (opcode->aencode == do_bx);
18529
c19d1205 18530 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
18531 if (!(is_bx && fix_v4bx)
18532 && !(opcode->avariant &&
18533 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 18534 {
84b52b66 18535 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
c19d1205 18536 return;
b99bd4ef 18537 }
c19d1205 18538 if (inst.size_req)
b99bd4ef 18539 {
c19d1205
ZW
18540 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
18541 return;
b99bd4ef
NC
18542 }
18543
c19d1205
ZW
18544 inst.instruction = opcode->avalue;
18545 if (opcode->tag == OT_unconditionalF)
eff0bc54 18546 inst.instruction |= 0xFU << 28;
c19d1205
ZW
18547 else
18548 inst.instruction |= inst.cond << 28;
18549 inst.size = INSN_SIZE;
5be8be5d 18550 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
477330fc
RM
18551 {
18552 it_fsm_pre_encode ();
18553 opcode->aencode ();
18554 it_fsm_post_encode ();
18555 }
ee065d83 18556 /* Arm mode bx is marked as both v4T and v5 because it's still required
477330fc 18557 on a hypothetical non-thumb v5 core. */
845b51d6 18558 if (is_bx)
e74cfd16 18559 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 18560 else
e74cfd16
PB
18561 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
18562 *opcode->avariant);
88714cb8
DG
18563
18564 check_neon_suffixes;
18565
cd000bff 18566 if (!inst.error)
c877a2f2
NC
18567 {
18568 mapping_state (MAP_ARM);
18569 }
b99bd4ef 18570 }
3e9e4fcf
JB
18571 else
18572 {
18573 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
18574 "-- `%s'"), str);
18575 return;
18576 }
c19d1205
ZW
18577 output_inst (str);
18578}
b99bd4ef 18579
e07e6e58
NC
18580static void
18581check_it_blocks_finished (void)
18582{
18583#ifdef OBJ_ELF
18584 asection *sect;
18585
18586 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
18587 if (seg_info (sect)->tc_segment_info_data.current_it.state
18588 == MANUAL_IT_BLOCK)
18589 {
18590 as_warn (_("section '%s' finished with an open IT block."),
18591 sect->name);
18592 }
18593#else
18594 if (now_it.state == MANUAL_IT_BLOCK)
18595 as_warn (_("file finished with an open IT block."));
18596#endif
18597}
18598
c19d1205
ZW
18599/* Various frobbings of labels and their addresses. */
18600
18601void
18602arm_start_line_hook (void)
18603{
18604 last_label_seen = NULL;
b99bd4ef
NC
18605}
18606
c19d1205
ZW
18607void
18608arm_frob_label (symbolS * sym)
b99bd4ef 18609{
c19d1205 18610 last_label_seen = sym;
b99bd4ef 18611
c19d1205 18612 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 18613
c19d1205
ZW
18614#if defined OBJ_COFF || defined OBJ_ELF
18615 ARM_SET_INTERWORK (sym, support_interwork);
18616#endif
b99bd4ef 18617
e07e6e58
NC
18618 force_automatic_it_block_close ();
18619
5f4273c7 18620 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
18621 as Thumb functions. This is because these labels, whilst
18622 they exist inside Thumb code, are not the entry points for
18623 possible ARM->Thumb calls. Also, these labels can be used
18624 as part of a computed goto or switch statement. eg gcc
18625 can generate code that looks like this:
b99bd4ef 18626
c19d1205
ZW
18627 ldr r2, [pc, .Laaa]
18628 lsl r3, r3, #2
18629 ldr r2, [r3, r2]
18630 mov pc, r2
b99bd4ef 18631
c19d1205
ZW
18632 .Lbbb: .word .Lxxx
18633 .Lccc: .word .Lyyy
18634 ..etc...
18635 .Laaa: .word Lbbb
b99bd4ef 18636
c19d1205
ZW
18637 The first instruction loads the address of the jump table.
18638 The second instruction converts a table index into a byte offset.
18639 The third instruction gets the jump address out of the table.
18640 The fourth instruction performs the jump.
b99bd4ef 18641
c19d1205
ZW
18642 If the address stored at .Laaa is that of a symbol which has the
18643 Thumb_Func bit set, then the linker will arrange for this address
18644 to have the bottom bit set, which in turn would mean that the
18645 address computation performed by the third instruction would end
18646 up with the bottom bit set. Since the ARM is capable of unaligned
18647 word loads, the instruction would then load the incorrect address
18648 out of the jump table, and chaos would ensue. */
18649 if (label_is_thumb_function_name
18650 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18651 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 18652 {
c19d1205
ZW
18653 /* When the address of a Thumb function is taken the bottom
18654 bit of that address should be set. This will allow
18655 interworking between Arm and Thumb functions to work
18656 correctly. */
b99bd4ef 18657
c19d1205 18658 THUMB_SET_FUNC (sym, 1);
b99bd4ef 18659
c19d1205 18660 label_is_thumb_function_name = FALSE;
b99bd4ef 18661 }
07a53e5c 18662
07a53e5c 18663 dwarf2_emit_label (sym);
b99bd4ef
NC
18664}
18665
c921be7d 18666bfd_boolean
c19d1205 18667arm_data_in_code (void)
b99bd4ef 18668{
c19d1205 18669 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 18670 {
c19d1205
ZW
18671 *input_line_pointer = '/';
18672 input_line_pointer += 5;
18673 *input_line_pointer = 0;
c921be7d 18674 return TRUE;
b99bd4ef
NC
18675 }
18676
c921be7d 18677 return FALSE;
b99bd4ef
NC
18678}
18679
c19d1205
ZW
18680char *
18681arm_canonicalize_symbol_name (char * name)
b99bd4ef 18682{
c19d1205 18683 int len;
b99bd4ef 18684
c19d1205
ZW
18685 if (thumb_mode && (len = strlen (name)) > 5
18686 && streq (name + len - 5, "/data"))
18687 *(name + len - 5) = 0;
b99bd4ef 18688
c19d1205 18689 return name;
b99bd4ef 18690}
c19d1205
ZW
18691\f
18692/* Table of all register names defined by default. The user can
18693 define additional names with .req. Note that all register names
18694 should appear in both upper and lowercase variants. Some registers
18695 also have mixed-case names. */
b99bd4ef 18696
dcbf9037 18697#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 18698#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 18699#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
18700#define REGSET(p,t) \
18701 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
18702 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
18703 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
18704 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
18705#define REGSETH(p,t) \
18706 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
18707 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
18708 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
18709 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
18710#define REGSET2(p,t) \
18711 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
18712 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
18713 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
18714 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
90ec0d68
MGD
18715#define SPLRBANK(base,bank,t) \
18716 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
18717 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
18718 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
18719 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
18720 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
18721 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
7ed4c4c5 18722
c19d1205 18723static const struct reg_entry reg_names[] =
7ed4c4c5 18724{
c19d1205
ZW
18725 /* ARM integer registers. */
18726 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 18727
c19d1205
ZW
18728 /* ATPCS synonyms. */
18729 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
18730 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
18731 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 18732
c19d1205
ZW
18733 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
18734 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
18735 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 18736
c19d1205
ZW
18737 /* Well-known aliases. */
18738 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
18739 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
18740
18741 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
18742 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
18743
18744 /* Coprocessor numbers. */
18745 REGSET(p, CP), REGSET(P, CP),
18746
18747 /* Coprocessor register numbers. The "cr" variants are for backward
18748 compatibility. */
18749 REGSET(c, CN), REGSET(C, CN),
18750 REGSET(cr, CN), REGSET(CR, CN),
18751
90ec0d68
MGD
18752 /* ARM banked registers. */
18753 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
18754 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
18755 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
18756 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
18757 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
18758 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
18759 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
18760
18761 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
18762 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
18763 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
18764 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
18765 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
1472d06f 18766 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
90ec0d68
MGD
18767 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
18768 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
18769
18770 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
18771 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
18772 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
18773 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
18774 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
18775 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
18776 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
fa94de6b 18777 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
90ec0d68
MGD
18778 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
18779
c19d1205
ZW
18780 /* FPA registers. */
18781 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
18782 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
18783
18784 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
18785 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
18786
18787 /* VFP SP registers. */
5287ad62
JB
18788 REGSET(s,VFS), REGSET(S,VFS),
18789 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
18790
18791 /* VFP DP Registers. */
5287ad62
JB
18792 REGSET(d,VFD), REGSET(D,VFD),
18793 /* Extra Neon DP registers. */
18794 REGSETH(d,VFD), REGSETH(D,VFD),
18795
18796 /* Neon QP registers. */
18797 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
18798
18799 /* VFP control registers. */
18800 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
18801 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
18802 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
18803 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
18804 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
18805 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
18806
18807 /* Maverick DSP coprocessor registers. */
18808 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
18809 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
18810
18811 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
18812 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
18813 REGDEF(dspsc,0,DSPSC),
18814
18815 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
18816 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
18817 REGDEF(DSPSC,0,DSPSC),
18818
18819 /* iWMMXt data registers - p0, c0-15. */
18820 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
18821
18822 /* iWMMXt control registers - p1, c0-3. */
18823 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
18824 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
18825 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
18826 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
18827
18828 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
18829 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
18830 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
18831 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
18832 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
18833
18834 /* XScale accumulator registers. */
18835 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
18836};
18837#undef REGDEF
18838#undef REGNUM
18839#undef REGSET
7ed4c4c5 18840
c19d1205
ZW
18841/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
18842 within psr_required_here. */
18843static const struct asm_psr psrs[] =
18844{
18845 /* Backward compatibility notation. Note that "all" is no longer
18846 truly all possible PSR bits. */
18847 {"all", PSR_c | PSR_f},
18848 {"flg", PSR_f},
18849 {"ctl", PSR_c},
18850
18851 /* Individual flags. */
18852 {"f", PSR_f},
18853 {"c", PSR_c},
18854 {"x", PSR_x},
18855 {"s", PSR_s},
59b42a0d 18856
c19d1205
ZW
18857 /* Combinations of flags. */
18858 {"fs", PSR_f | PSR_s},
18859 {"fx", PSR_f | PSR_x},
18860 {"fc", PSR_f | PSR_c},
18861 {"sf", PSR_s | PSR_f},
18862 {"sx", PSR_s | PSR_x},
18863 {"sc", PSR_s | PSR_c},
18864 {"xf", PSR_x | PSR_f},
18865 {"xs", PSR_x | PSR_s},
18866 {"xc", PSR_x | PSR_c},
18867 {"cf", PSR_c | PSR_f},
18868 {"cs", PSR_c | PSR_s},
18869 {"cx", PSR_c | PSR_x},
18870 {"fsx", PSR_f | PSR_s | PSR_x},
18871 {"fsc", PSR_f | PSR_s | PSR_c},
18872 {"fxs", PSR_f | PSR_x | PSR_s},
18873 {"fxc", PSR_f | PSR_x | PSR_c},
18874 {"fcs", PSR_f | PSR_c | PSR_s},
18875 {"fcx", PSR_f | PSR_c | PSR_x},
18876 {"sfx", PSR_s | PSR_f | PSR_x},
18877 {"sfc", PSR_s | PSR_f | PSR_c},
18878 {"sxf", PSR_s | PSR_x | PSR_f},
18879 {"sxc", PSR_s | PSR_x | PSR_c},
18880 {"scf", PSR_s | PSR_c | PSR_f},
18881 {"scx", PSR_s | PSR_c | PSR_x},
18882 {"xfs", PSR_x | PSR_f | PSR_s},
18883 {"xfc", PSR_x | PSR_f | PSR_c},
18884 {"xsf", PSR_x | PSR_s | PSR_f},
18885 {"xsc", PSR_x | PSR_s | PSR_c},
18886 {"xcf", PSR_x | PSR_c | PSR_f},
18887 {"xcs", PSR_x | PSR_c | PSR_s},
18888 {"cfs", PSR_c | PSR_f | PSR_s},
18889 {"cfx", PSR_c | PSR_f | PSR_x},
18890 {"csf", PSR_c | PSR_s | PSR_f},
18891 {"csx", PSR_c | PSR_s | PSR_x},
18892 {"cxf", PSR_c | PSR_x | PSR_f},
18893 {"cxs", PSR_c | PSR_x | PSR_s},
18894 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
18895 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
18896 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
18897 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
18898 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
18899 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
18900 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
18901 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
18902 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
18903 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
18904 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
18905 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
18906 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
18907 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
18908 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
18909 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
18910 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
18911 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
18912 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
18913 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
18914 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
18915 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
18916 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
18917 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
18918};
18919
62b3e311
PB
18920/* Table of V7M psr names. */
18921static const struct asm_psr v7m_psrs[] =
18922{
1a336194
TP
18923 {"apsr", 0x0 }, {"APSR", 0x0 },
18924 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
18925 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
18926 {"psr", 0x3 }, {"PSR", 0x3 },
18927 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
18928 {"ipsr", 0x5 }, {"IPSR", 0x5 },
18929 {"epsr", 0x6 }, {"EPSR", 0x6 },
18930 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
18931 {"msp", 0x8 }, {"MSP", 0x8 },
18932 {"psp", 0x9 }, {"PSP", 0x9 },
18933 {"msplim", 0xa }, {"MSPLIM", 0xa },
18934 {"psplim", 0xb }, {"PSPLIM", 0xb },
18935 {"primask", 0x10}, {"PRIMASK", 0x10},
18936 {"basepri", 0x11}, {"BASEPRI", 0x11},
18937 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
1a336194
TP
18938 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
18939 {"control", 0x14}, {"CONTROL", 0x14},
18940 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
18941 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
18942 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
18943 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
18944 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
18945 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
18946 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
18947 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
18948 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
62b3e311
PB
18949};
18950
c19d1205
ZW
18951/* Table of all shift-in-operand names. */
18952static const struct asm_shift_name shift_names [] =
b99bd4ef 18953{
c19d1205
ZW
18954 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
18955 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
18956 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
18957 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
18958 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
18959 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
18960};
b99bd4ef 18961
c19d1205
ZW
18962/* Table of all explicit relocation names. */
18963#ifdef OBJ_ELF
18964static struct reloc_entry reloc_names[] =
18965{
18966 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
18967 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
18968 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
18969 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
18970 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
18971 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
18972 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
18973 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
18974 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
18975 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
b43420e6 18976 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
0855e32b
NS
18977 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
18978 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
477330fc 18979 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
0855e32b 18980 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
477330fc 18981 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
0855e32b 18982 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
477330fc 18983 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
c19d1205
ZW
18984};
18985#endif
b99bd4ef 18986
c19d1205
ZW
18987/* Table of all conditional affixes. 0xF is not defined as a condition code. */
18988static const struct asm_cond conds[] =
18989{
18990 {"eq", 0x0},
18991 {"ne", 0x1},
18992 {"cs", 0x2}, {"hs", 0x2},
18993 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
18994 {"mi", 0x4},
18995 {"pl", 0x5},
18996 {"vs", 0x6},
18997 {"vc", 0x7},
18998 {"hi", 0x8},
18999 {"ls", 0x9},
19000 {"ge", 0xa},
19001 {"lt", 0xb},
19002 {"gt", 0xc},
19003 {"le", 0xd},
19004 {"al", 0xe}
19005};
bfae80f2 19006
e797f7e0 19007#define UL_BARRIER(L,U,CODE,FEAT) \
823d2571
TG
19008 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
19009 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
e797f7e0 19010
62b3e311
PB
19011static struct asm_barrier_opt barrier_opt_names[] =
19012{
e797f7e0
MGD
19013 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
19014 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
19015 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
19016 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
19017 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
19018 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
19019 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
19020 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
19021 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
19022 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
19023 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
19024 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
19025 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
19026 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
19027 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
19028 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
62b3e311
PB
19029};
19030
e797f7e0
MGD
19031#undef UL_BARRIER
19032
c19d1205
ZW
19033/* Table of ARM-format instructions. */
19034
19035/* Macros for gluing together operand strings. N.B. In all cases
19036 other than OPS0, the trailing OP_stop comes from default
19037 zero-initialization of the unspecified elements of the array. */
19038#define OPS0() { OP_stop, }
19039#define OPS1(a) { OP_##a, }
19040#define OPS2(a,b) { OP_##a,OP_##b, }
19041#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
19042#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
19043#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
19044#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
19045
5be8be5d
DG
19046/* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
19047 This is useful when mixing operands for ARM and THUMB, i.e. using the
19048 MIX_ARM_THUMB_OPERANDS macro.
19049 In order to use these macros, prefix the number of operands with _
19050 e.g. _3. */
19051#define OPS_1(a) { a, }
19052#define OPS_2(a,b) { a,b, }
19053#define OPS_3(a,b,c) { a,b,c, }
19054#define OPS_4(a,b,c,d) { a,b,c,d, }
19055#define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
19056#define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
19057
c19d1205
ZW
19058/* These macros abstract out the exact format of the mnemonic table and
19059 save some repeated characters. */
19060
19061/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
19062#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19063 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 19064 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19065
19066/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
19067 a T_MNEM_xyz enumerator. */
19068#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19069 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19070#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19071 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
19072
19073/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
19074 infix after the third character. */
19075#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 19076 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 19077 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 19078#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 19079 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 19080 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19081#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19082 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 19083#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 19084 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 19085#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19086 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 19087#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 19088 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205 19089
c19d1205 19090/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
19091 field is still 0xE. Many of the Thumb variants can be executed
19092 conditionally, so this is checked separately. */
c19d1205 19093#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 19094 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19095 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 19096
dd5181d5
KT
19097/* Same as TUE but the encoding function for ARM and Thumb modes is the same.
19098 Used by mnemonics that have very minimal differences in the encoding for
19099 ARM and Thumb variants and can be handled in a common function. */
19100#define TUEc(mnem, op, top, nops, ops, en) \
19101 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
19102 THUMB_VARIANT, do_##en, do_##en }
19103
c19d1205
ZW
19104/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
19105 condition code field. */
19106#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 19107 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 19108 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
19109
19110/* ARM-only variants of all the above. */
6a86118a 19111#define CE(mnem, op, nops, ops, ae) \
21d799b5 19112 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
19113
19114#define C3(mnem, op, nops, ops, ae) \
19115 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19116
e3cb604e
PB
19117/* Legacy mnemonics that always have conditional infix after the third
19118 character. */
19119#define CL(mnem, op, nops, ops, ae) \
21d799b5 19120 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19121 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19122
8f06b2d8
PB
19123/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
19124#define cCE(mnem, op, nops, ops, ae) \
21d799b5 19125 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19126
e3cb604e
PB
19127/* Legacy coprocessor instructions where conditional infix and conditional
19128 suffix are ambiguous. For consistency this includes all FPA instructions,
19129 not just the potentially ambiguous ones. */
19130#define cCL(mnem, op, nops, ops, ae) \
21d799b5 19131 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
19132 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
19133
19134/* Coprocessor, takes either a suffix or a position-3 infix
19135 (for an FPA corner case). */
19136#define C3E(mnem, op, nops, ops, ae) \
21d799b5 19137 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 19138 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 19139
6a86118a 19140#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
19141 { m1 #m2 m3, OPS##nops ops, \
19142 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
19143 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19144
19145#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
19146 xCM_ (m1, , m2, op, nops, ops, ae), \
19147 xCM_ (m1, eq, m2, op, nops, ops, ae), \
19148 xCM_ (m1, ne, m2, op, nops, ops, ae), \
19149 xCM_ (m1, cs, m2, op, nops, ops, ae), \
19150 xCM_ (m1, hs, m2, op, nops, ops, ae), \
19151 xCM_ (m1, cc, m2, op, nops, ops, ae), \
19152 xCM_ (m1, ul, m2, op, nops, ops, ae), \
19153 xCM_ (m1, lo, m2, op, nops, ops, ae), \
19154 xCM_ (m1, mi, m2, op, nops, ops, ae), \
19155 xCM_ (m1, pl, m2, op, nops, ops, ae), \
19156 xCM_ (m1, vs, m2, op, nops, ops, ae), \
19157 xCM_ (m1, vc, m2, op, nops, ops, ae), \
19158 xCM_ (m1, hi, m2, op, nops, ops, ae), \
19159 xCM_ (m1, ls, m2, op, nops, ops, ae), \
19160 xCM_ (m1, ge, m2, op, nops, ops, ae), \
19161 xCM_ (m1, lt, m2, op, nops, ops, ae), \
19162 xCM_ (m1, gt, m2, op, nops, ops, ae), \
19163 xCM_ (m1, le, m2, op, nops, ops, ae), \
19164 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
19165
19166#define UE(mnem, op, nops, ops, ae) \
19167 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19168
19169#define UF(mnem, op, nops, ops, ae) \
19170 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19171
5287ad62
JB
19172/* Neon data-processing. ARM versions are unconditional with cond=0xf.
19173 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
19174 use the same encoding function for each. */
19175#define NUF(mnem, op, nops, ops, enc) \
19176 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
19177 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19178
19179/* Neon data processing, version which indirects through neon_enc_tab for
19180 the various overloaded versions of opcodes. */
19181#define nUF(mnem, op, nops, ops, enc) \
21d799b5 19182 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19183 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19184
19185/* Neon insn with conditional suffix for the ARM version, non-overloaded
19186 version. */
037e8744
JB
19187#define NCE_tag(mnem, op, nops, ops, enc, tag) \
19188 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
19189 THUMB_VARIANT, do_##enc, do_##enc }
19190
037e8744 19191#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 19192 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19193
19194#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 19195 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19196
5287ad62 19197/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 19198#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 19199 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
19200 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19201
037e8744 19202#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 19203 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
19204
19205#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 19206 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 19207
c19d1205
ZW
19208#define do_0 0
19209
c19d1205 19210static const struct asm_opcode insns[] =
bfae80f2 19211{
74db7efb
NC
19212#define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
19213#define THUMB_VARIANT & arm_ext_v4t
21d799b5
NC
19214 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
19215 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
19216 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
19217 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
19218 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
19219 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
19220 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
19221 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
19222 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
19223 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
19224 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
19225 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
19226 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
19227 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
19228 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
19229 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
19230
19231 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
19232 for setting PSR flag bits. They are obsolete in V6 and do not
19233 have Thumb equivalents. */
21d799b5
NC
19234 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19235 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19236 CL("tstp", 110f000, 2, (RR, SH), cmp),
19237 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19238 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19239 CL("cmpp", 150f000, 2, (RR, SH), cmp),
19240 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19241 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19242 CL("cmnp", 170f000, 2, (RR, SH), cmp),
19243
19244 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
72d98d16 19245 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
21d799b5
NC
19246 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
19247 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
19248
19249 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
5be8be5d
DG
19250 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19251 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
19252 OP_RRnpc),
19253 OP_ADDRGLDR),ldst, t_ldst),
19254 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
21d799b5
NC
19255
19256 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19257 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19258 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19259 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19260 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19261 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19262
19263 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
19264 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
19265 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
19266 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 19267
c19d1205 19268 /* Pseudo ops. */
21d799b5 19269 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 19270 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 19271 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
74db7efb 19272 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
c19d1205
ZW
19273
19274 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
19275 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
19276 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
19277 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
19278 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
19279 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
19280 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
19281 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
19282 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
19283 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
19284 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
19285 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
19286 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 19287
16a4cf17 19288 /* These may simplify to neg. */
21d799b5
NC
19289 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
19290 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 19291
c921be7d
NC
19292#undef THUMB_VARIANT
19293#define THUMB_VARIANT & arm_ext_v6
19294
21d799b5 19295 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
19296
19297 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
19298#undef THUMB_VARIANT
19299#define THUMB_VARIANT & arm_ext_v6t2
19300
21d799b5
NC
19301 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19302 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19303 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 19304
5be8be5d
DG
19305 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19306 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19307 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19308 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
c19d1205 19309
21d799b5
NC
19310 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19311 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 19312
21d799b5
NC
19313 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19314 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
19315
19316 /* V1 instructions with no Thumb analogue at all. */
21d799b5 19317 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
19318 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19319
19320 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19321 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19322 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19323 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19324 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19325 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19326 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19327 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19328
c921be7d
NC
19329#undef ARM_VARIANT
19330#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19331#undef THUMB_VARIANT
19332#define THUMB_VARIANT & arm_ext_v4t
19333
21d799b5
NC
19334 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19335 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 19336
c921be7d
NC
19337#undef THUMB_VARIANT
19338#define THUMB_VARIANT & arm_ext_v6t2
19339
21d799b5 19340 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
19341 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19342
19343 /* Generic coprocessor instructions. */
21d799b5
NC
19344 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19345 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19346 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19347 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19348 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19349 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
db472d6f 19350 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19351
c921be7d
NC
19352#undef ARM_VARIANT
19353#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19354
21d799b5 19355 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
19356 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19357
c921be7d
NC
19358#undef ARM_VARIANT
19359#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19360#undef THUMB_VARIANT
19361#define THUMB_VARIANT & arm_ext_msr
19362
d2cd1205
JB
19363 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19364 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
c19d1205 19365
c921be7d
NC
19366#undef ARM_VARIANT
19367#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19368#undef THUMB_VARIANT
19369#define THUMB_VARIANT & arm_ext_v6t2
19370
21d799b5
NC
19371 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19372 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19373 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19374 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19375 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19376 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19377 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19378 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 19379
c921be7d
NC
19380#undef ARM_VARIANT
19381#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
19382#undef THUMB_VARIANT
19383#define THUMB_VARIANT & arm_ext_v4t
19384
5be8be5d
DG
19385 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19386 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19387 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19388 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
56c0a61f
RE
19389 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19390 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 19391
c921be7d
NC
19392#undef ARM_VARIANT
19393#define ARM_VARIANT & arm_ext_v4t_5
19394
c19d1205
ZW
19395 /* ARM Architecture 4T. */
19396 /* Note: bx (and blx) are required on V5, even if the processor does
19397 not support Thumb. */
21d799b5 19398 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 19399
c921be7d
NC
19400#undef ARM_VARIANT
19401#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
19402#undef THUMB_VARIANT
19403#define THUMB_VARIANT & arm_ext_v5t
19404
c19d1205
ZW
19405 /* Note: blx has 2 variants; the .value coded here is for
19406 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
19407 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
19408 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 19409
c921be7d
NC
19410#undef THUMB_VARIANT
19411#define THUMB_VARIANT & arm_ext_v6t2
19412
21d799b5
NC
19413 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
19414 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19415 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19416 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19417 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19418 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19419 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19420 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 19421
c921be7d 19422#undef ARM_VARIANT
74db7efb
NC
19423#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
19424#undef THUMB_VARIANT
19425#define THUMB_VARIANT & arm_ext_v5exp
c921be7d 19426
21d799b5
NC
19427 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19428 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19429 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19430 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19431
21d799b5
NC
19432 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19433 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 19434
21d799b5
NC
19435 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19436 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19437 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19438 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 19439
21d799b5
NC
19440 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19441 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19442 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19443 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19444
21d799b5
NC
19445 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19446 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 19447
03ee1b7f
NC
19448 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19449 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19450 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19451 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
c19d1205 19452
c921be7d 19453#undef ARM_VARIANT
74db7efb
NC
19454#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
19455#undef THUMB_VARIANT
19456#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19457
21d799b5 19458 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
5be8be5d
DG
19459 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
19460 ldrd, t_ldstd),
19461 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
19462 ADDRGLDRS), ldrd, t_ldstd),
c19d1205 19463
21d799b5
NC
19464 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19465 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 19466
c921be7d
NC
19467#undef ARM_VARIANT
19468#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
19469
21d799b5 19470 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 19471
c921be7d
NC
19472#undef ARM_VARIANT
19473#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
19474#undef THUMB_VARIANT
19475#define THUMB_VARIANT & arm_ext_v6
19476
21d799b5
NC
19477 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
19478 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
19479 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19480 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19481 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19482 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19483 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19484 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19485 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19486 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 19487
c921be7d 19488#undef THUMB_VARIANT
ff8646ee 19489#define THUMB_VARIANT & arm_ext_v6t2_v8m
c921be7d 19490
5be8be5d
DG
19491 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
19492 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19493 strex, t_strex),
ff8646ee
TP
19494#undef THUMB_VARIANT
19495#define THUMB_VARIANT & arm_ext_v6t2
19496
21d799b5
NC
19497 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19498 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 19499
21d799b5
NC
19500 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
19501 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 19502
9e3c6df6 19503/* ARM V6 not included in V7M. */
c921be7d
NC
19504#undef THUMB_VARIANT
19505#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6 19506 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6 19507 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
9e3c6df6
PB
19508 UF(rfeib, 9900a00, 1, (RRw), rfe),
19509 UF(rfeda, 8100a00, 1, (RRw), rfe),
19510 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19511 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
d709e4e6
RE
19512 UF(rfefa, 8100a00, 1, (RRw), rfe),
19513 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19514 UF(rfeed, 9900a00, 1, (RRw), rfe),
9e3c6df6 19515 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
d709e4e6
RE
19516 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19517 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
9e3c6df6 19518 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
d709e4e6 19519 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
9e3c6df6 19520 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
d709e4e6 19521 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
9e3c6df6 19522 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
d709e4e6 19523 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
941c9cad 19524 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c921be7d 19525
9e3c6df6
PB
19526/* ARM V6 not included in V7M (eg. integer SIMD). */
19527#undef THUMB_VARIANT
19528#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
19529 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
19530 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
19531 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19532 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19533 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19534 /* Old name for QASX. */
74db7efb 19535 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19536 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19537 /* Old name for QSAX. */
74db7efb 19538 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19539 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19540 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19541 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19542 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19543 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19544 /* Old name for SASX. */
74db7efb 19545 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19546 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19547 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19548 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19549 /* Old name for SHASX. */
21d799b5 19550 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19551 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19552 /* Old name for SHSAX. */
21d799b5
NC
19553 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19554 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19555 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19556 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19557 /* Old name for SSAX. */
74db7efb 19558 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19559 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19560 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19561 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19562 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19563 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19564 /* Old name for UASX. */
74db7efb 19565 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19566 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19567 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19568 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19569 /* Old name for UHASX. */
21d799b5
NC
19570 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19571 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19572 /* Old name for UHSAX. */
21d799b5
NC
19573 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19574 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19575 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19576 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19577 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
74db7efb 19578 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19579 /* Old name for UQASX. */
21d799b5
NC
19580 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19581 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19582 /* Old name for UQSAX. */
21d799b5
NC
19583 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19584 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19585 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19586 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19587 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 19588 /* Old name for USAX. */
74db7efb 19589 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5 19590 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
19591 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19592 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19593 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19594 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19595 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19596 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19597 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19598 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19599 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19600 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19601 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19602 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19603 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19604 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19605 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19606 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19607 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19608 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19609 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19610 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19611 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19612 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19613 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19614 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19615 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19616 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19617 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
19618 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
19619 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
19620 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19621 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19622 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 19623
c921be7d
NC
19624#undef ARM_VARIANT
19625#define ARM_VARIANT & arm_ext_v6k
19626#undef THUMB_VARIANT
19627#define THUMB_VARIANT & arm_ext_v6k
19628
21d799b5
NC
19629 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
19630 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
19631 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
19632 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 19633
c921be7d
NC
19634#undef THUMB_VARIANT
19635#define THUMB_VARIANT & arm_ext_v6_notm
5be8be5d
DG
19636 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
19637 ldrexd, t_ldrexd),
19638 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
19639 RRnpcb), strexd, t_strexd),
ebdca51a 19640
c921be7d 19641#undef THUMB_VARIANT
ff8646ee 19642#define THUMB_VARIANT & arm_ext_v6t2_v8m
5be8be5d
DG
19643 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
19644 rd_rn, rd_rn),
19645 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
19646 rd_rn, rd_rn),
19647 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19648 strex, t_strexbh),
5be8be5d 19649 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
877807f8 19650 strex, t_strexbh),
21d799b5 19651 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 19652
c921be7d 19653#undef ARM_VARIANT
f4c65163 19654#define ARM_VARIANT & arm_ext_sec
74db7efb 19655#undef THUMB_VARIANT
f4c65163 19656#define THUMB_VARIANT & arm_ext_sec
c921be7d 19657
21d799b5 19658 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 19659
90ec0d68
MGD
19660#undef ARM_VARIANT
19661#define ARM_VARIANT & arm_ext_virt
19662#undef THUMB_VARIANT
19663#define THUMB_VARIANT & arm_ext_virt
19664
19665 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
19666 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
19667
ddfded2f
MW
19668#undef ARM_VARIANT
19669#define ARM_VARIANT & arm_ext_pan
19670#undef THUMB_VARIANT
19671#define THUMB_VARIANT & arm_ext_pan
19672
19673 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
19674
c921be7d 19675#undef ARM_VARIANT
74db7efb 19676#define ARM_VARIANT & arm_ext_v6t2
f4c65163
MGD
19677#undef THUMB_VARIANT
19678#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19679
21d799b5
NC
19680 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
19681 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
19682 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
19683 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 19684
21d799b5 19685 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
21d799b5 19686 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 19687
5be8be5d
DG
19688 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19689 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19690 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
19691 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
c19d1205 19692
ff8646ee
TP
19693#undef THUMB_VARIANT
19694#define THUMB_VARIANT & arm_ext_v6t2_v8m
19695 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
19696 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
19697
bf3eeda7 19698 /* Thumb-only instructions. */
74db7efb 19699#undef ARM_VARIANT
bf3eeda7
NS
19700#define ARM_VARIANT NULL
19701 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
19702 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
c921be7d
NC
19703
19704 /* ARM does not really have an IT instruction, so always allow it.
19705 The opcode is copied from Thumb in order to allow warnings in
19706 -mimplicit-it=[never | arm] modes. */
19707#undef ARM_VARIANT
19708#define ARM_VARIANT & arm_ext_v1
ff8646ee
TP
19709#undef THUMB_VARIANT
19710#define THUMB_VARIANT & arm_ext_v6t2
c921be7d 19711
21d799b5
NC
19712 TUE("it", bf08, bf08, 1, (COND), it, t_it),
19713 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
19714 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
19715 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
19716 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
19717 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
19718 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
19719 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
19720 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
19721 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
19722 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
19723 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
19724 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
19725 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
19726 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 19727 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
19728 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
19729 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 19730
92e90b6e 19731 /* Thumb2 only instructions. */
c921be7d
NC
19732#undef ARM_VARIANT
19733#define ARM_VARIANT NULL
92e90b6e 19734
21d799b5
NC
19735 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19736 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
19737 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
19738 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
19739 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
19740 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 19741
eea54501
MGD
19742 /* Hardware division instructions. */
19743#undef ARM_VARIANT
19744#define ARM_VARIANT & arm_ext_adiv
c921be7d
NC
19745#undef THUMB_VARIANT
19746#define THUMB_VARIANT & arm_ext_div
19747
eea54501
MGD
19748 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
19749 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
62b3e311 19750
7e806470 19751 /* ARM V6M/V7 instructions. */
c921be7d
NC
19752#undef ARM_VARIANT
19753#define ARM_VARIANT & arm_ext_barrier
19754#undef THUMB_VARIANT
19755#define THUMB_VARIANT & arm_ext_barrier
19756
ccb84d65
JB
19757 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
19758 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
19759 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
7e806470 19760
62b3e311 19761 /* ARM V7 instructions. */
c921be7d
NC
19762#undef ARM_VARIANT
19763#define ARM_VARIANT & arm_ext_v7
19764#undef THUMB_VARIANT
19765#define THUMB_VARIANT & arm_ext_v7
19766
21d799b5
NC
19767 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
19768 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 19769
74db7efb 19770#undef ARM_VARIANT
60e5ef9f 19771#define ARM_VARIANT & arm_ext_mp
74db7efb 19772#undef THUMB_VARIANT
60e5ef9f
MGD
19773#define THUMB_VARIANT & arm_ext_mp
19774
19775 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
19776
53c4b28b
MGD
19777 /* AArchv8 instructions. */
19778#undef ARM_VARIANT
19779#define ARM_VARIANT & arm_ext_v8
4ed7ed8d
TP
19780
19781/* Instructions shared between armv8-a and armv8-m. */
53c4b28b 19782#undef THUMB_VARIANT
4ed7ed8d 19783#define THUMB_VARIANT & arm_ext_atomics
53c4b28b 19784
4ed7ed8d
TP
19785 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19786 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19787 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19788 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19789 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
19790 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
4b8c8c02 19791 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
4b8c8c02
RE
19792 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
19793 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
19794 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
19795 stlex, t_stlex),
4b8c8c02
RE
19796 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
19797 stlex, t_stlex),
19798 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
19799 stlex, t_stlex),
4ed7ed8d
TP
19800#undef THUMB_VARIANT
19801#define THUMB_VARIANT & arm_ext_v8
53c4b28b 19802
4ed7ed8d
TP
19803 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
19804 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
19805 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
19806 ldrexd, t_ldrexd),
19807 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
19808 strexd, t_strexd),
8884b720 19809 /* ARMv8 T32 only. */
74db7efb 19810#undef ARM_VARIANT
b79f7053
MGD
19811#define ARM_VARIANT NULL
19812 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
19813 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
19814 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
19815
33399f07
MGD
19816 /* FP for ARMv8. */
19817#undef ARM_VARIANT
a715796b 19818#define ARM_VARIANT & fpu_vfp_ext_armv8xd
33399f07 19819#undef THUMB_VARIANT
a715796b 19820#define THUMB_VARIANT & fpu_vfp_ext_armv8xd
33399f07
MGD
19821
19822 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
19823 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
19824 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
19825 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
73924fbc
MGD
19826 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
19827 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
7e8e6784
MGD
19828 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
19829 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
19830 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
19831 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
30bdf752
MGD
19832 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
19833 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
19834 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
19835 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
19836 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
19837 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
19838 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
33399f07 19839
91ff7894
MGD
19840 /* Crypto v1 extensions. */
19841#undef ARM_VARIANT
19842#define ARM_VARIANT & fpu_crypto_ext_armv8
19843#undef THUMB_VARIANT
19844#define THUMB_VARIANT & fpu_crypto_ext_armv8
19845
19846 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
19847 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
19848 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
19849 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
48adcd8e
MGD
19850 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
19851 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
19852 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
19853 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
19854 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
19855 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
19856 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
3c9017d2
MGD
19857 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
19858 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
19859 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
91ff7894 19860
dd5181d5 19861#undef ARM_VARIANT
74db7efb 19862#define ARM_VARIANT & crc_ext_armv8
dd5181d5
KT
19863#undef THUMB_VARIANT
19864#define THUMB_VARIANT & crc_ext_armv8
19865 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
19866 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
19867 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
19868 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
19869 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
19870 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
19871
105bde57
MW
19872 /* ARMv8.2 RAS extension. */
19873#undef ARM_VARIANT
4d1464f2 19874#define ARM_VARIANT & arm_ext_ras
105bde57 19875#undef THUMB_VARIANT
4d1464f2 19876#define THUMB_VARIANT & arm_ext_ras
105bde57
MW
19877 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
19878
49e8a725
SN
19879#undef ARM_VARIANT
19880#define ARM_VARIANT & arm_ext_v8_3
19881#undef THUMB_VARIANT
19882#define THUMB_VARIANT & arm_ext_v8_3
19883 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
c28eeff2
SN
19884 NUF (vcmla, 0, 4, (RNDQ, RNDQ, RNDQ_RNSC, EXPi), vcmla),
19885 NUF (vcadd, 0, 4, (RNDQ, RNDQ, RNDQ, EXPi), vcadd),
49e8a725 19886
c921be7d
NC
19887#undef ARM_VARIANT
19888#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
53c4b28b
MGD
19889#undef THUMB_VARIANT
19890#define THUMB_VARIANT NULL
c921be7d 19891
21d799b5
NC
19892 cCE("wfs", e200110, 1, (RR), rd),
19893 cCE("rfs", e300110, 1, (RR), rd),
19894 cCE("wfc", e400110, 1, (RR), rd),
19895 cCE("rfc", e500110, 1, (RR), rd),
19896
19897 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
19898 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
19899 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
19900 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
19901
19902 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
19903 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
19904 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
19905 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
19906
19907 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
19908 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
19909 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
19910 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
19911 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
19912 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
19913 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
19914 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
19915 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
19916 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
19917 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
19918 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
19919
19920 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
19921 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
19922 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
19923 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
19924 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
19925 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
19926 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
19927 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
19928 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
19929 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
19930 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
19931 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
19932
19933 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
19934 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
19935 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
19936 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
19937 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
19938 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
19939 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
19940 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
19941 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
19942 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
19943 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
19944 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
19945
19946 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
19947 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
19948 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
19949 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
19950 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
19951 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
19952 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
19953 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
19954 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
19955 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
19956 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
19957 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
19958
19959 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
19960 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
19961 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
19962 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
19963 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
19964 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
19965 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
19966 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
19967 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
19968 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
19969 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
19970 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
19971
19972 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
19973 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
19974 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
19975 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
19976 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
19977 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
19978 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
19979 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
19980 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
19981 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
19982 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
19983 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
19984
19985 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
19986 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
19987 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
19988 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
19989 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
19990 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
19991 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
19992 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
19993 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
19994 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
19995 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
19996 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
19997
19998 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
19999 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
20000 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
20001 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
20002 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
20003 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
20004 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
20005 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
20006 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
20007 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
20008 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
20009 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
20010
20011 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
20012 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
20013 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
20014 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
20015 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
20016 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
20017 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
20018 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
20019 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
20020 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
20021 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
20022 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
20023
20024 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
20025 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
20026 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
20027 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
20028 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
20029 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
20030 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
20031 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
20032 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
20033 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
20034 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
20035 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
20036
20037 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
20038 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
20039 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
20040 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
20041 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
20042 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
20043 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
20044 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
20045 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
20046 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
20047 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
20048 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
20049
20050 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
20051 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
20052 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
20053 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
20054 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
20055 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
20056 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
20057 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
20058 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
20059 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
20060 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
20061 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
20062
20063 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
20064 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
20065 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
20066 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
20067 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
20068 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
20069 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
20070 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
20071 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
20072 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
20073 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
20074 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
20075
20076 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
20077 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
20078 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
20079 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
20080 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
20081 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
20082 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
20083 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
20084 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
20085 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
20086 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
20087 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
20088
20089 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
20090 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
20091 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
20092 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
20093 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
20094 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
20095 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
20096 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
20097 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
20098 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
20099 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
20100 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
20101
20102 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
20103 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
20104 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
20105 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
20106 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
20107 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
20108 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
20109 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
20110 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
20111 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
20112 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
20113 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
20114
20115 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
20116 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
20117 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
20118 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
20119 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
20120 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20121 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20122 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20123 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
20124 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
20125 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
20126 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
20127
20128 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
20129 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
20130 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
20131 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
20132 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
20133 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20134 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20135 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20136 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
20137 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
20138 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
20139 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
20140
20141 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
20142 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
20143 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
20144 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
20145 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
20146 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20147 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20148 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20149 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
20150 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
20151 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
20152 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
20153
20154 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
20155 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
20156 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
20157 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
20158 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
20159 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20160 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20161 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20162 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
20163 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
20164 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
20165 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
20166
20167 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
20168 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
20169 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
20170 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
20171 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
20172 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20173 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20174 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20175 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
20176 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
20177 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
20178 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
20179
20180 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
20181 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
20182 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
20183 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
20184 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
20185 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20186 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20187 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20188 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
20189 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
20190 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
20191 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
20192
20193 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
20194 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
20195 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
20196 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
20197 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
20198 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20199 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20200 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20201 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
20202 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
20203 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
20204 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
20205
20206 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
20207 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
20208 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
20209 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
20210 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
20211 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20212 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20213 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20214 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
20215 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
20216 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
20217 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
20218
20219 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
20220 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
20221 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
20222 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
20223 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
20224 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20225 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20226 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20227 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
20228 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
20229 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
20230 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
20231
20232 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
20233 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
20234 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
20235 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
20236 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
20237 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20238 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20239 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20240 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
20241 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
20242 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
20243 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
20244
20245 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20246 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20247 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20248 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20249 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20250 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20251 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20252 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20253 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20254 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20255 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20256 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20257
20258 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20259 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20260 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20261 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20262 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20263 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20264 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20265 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20266 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20267 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20268 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20269 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20270
20271 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20272 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20273 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20274 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20275 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20276 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20277 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20278 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20279 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20280 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20281 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20282 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20283
20284 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
20285 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
20286 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
20287 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
20288
20289 cCL("flts", e000110, 2, (RF, RR), rn_rd),
20290 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
20291 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
20292 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
20293 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
20294 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
20295 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
20296 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
20297 cCL("flte", e080110, 2, (RF, RR), rn_rd),
20298 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
20299 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20300 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 20301
c19d1205
ZW
20302 /* The implementation of the FIX instruction is broken on some
20303 assemblers, in that it accepts a precision specifier as well as a
20304 rounding specifier, despite the fact that this is meaningless.
20305 To be more compatible, we accept it as well, though of course it
20306 does not set any bits. */
21d799b5
NC
20307 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20308 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20309 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20310 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20311 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20312 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20313 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20314 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20315 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20316 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20317 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20318 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20319 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 20320
c19d1205 20321 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
20322#undef ARM_VARIANT
20323#define ARM_VARIANT & fpu_fpa_ext_v2
20324
21d799b5
NC
20325 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20326 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20327 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20328 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20329 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20330 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 20331
c921be7d
NC
20332#undef ARM_VARIANT
20333#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20334
c19d1205 20335 /* Moves and type conversions. */
21d799b5
NC
20336 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20337 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20338 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20339 cCE("fmstat", ef1fa10, 0, (), noargs),
7465e07a
NC
20340 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20341 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
21d799b5
NC
20342 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20343 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20344 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
20345 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20346 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
20347 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20348 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
20349 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
20350
20351 /* Memory operations. */
21d799b5
NC
20352 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20353 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
55881a11
MGD
20354 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20355 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20356 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20357 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20358 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20359 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20360 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20361 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20362 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20363 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20364 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20365 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20366 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20367 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20368 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20369 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 20370
c19d1205 20371 /* Monadic operations. */
21d799b5
NC
20372 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
20373 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
20374 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
20375
20376 /* Dyadic operations. */
21d799b5
NC
20377 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20378 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20379 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20380 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20381 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20382 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20383 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20384 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20385 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 20386
c19d1205 20387 /* Comparisons. */
21d799b5
NC
20388 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
20389 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
20390 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
20391 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 20392
62f3b8c8
PB
20393 /* Double precision load/store are still present on single precision
20394 implementations. */
20395 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20396 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
55881a11
MGD
20397 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20398 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20399 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20400 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20401 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20402 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20403 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20404 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
62f3b8c8 20405
c921be7d
NC
20406#undef ARM_VARIANT
20407#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
20408
c19d1205 20409 /* Moves and type conversions. */
21d799b5
NC
20410 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20411 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20412 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20413 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
20414 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
20415 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
20416 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
20417 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20418 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
20419 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20420 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20421 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20422 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 20423
c19d1205 20424 /* Monadic operations. */
21d799b5
NC
20425 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20426 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20427 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
20428
20429 /* Dyadic operations. */
21d799b5
NC
20430 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20431 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20432 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20433 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20434 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20435 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20436 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20437 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20438 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 20439
c19d1205 20440 /* Comparisons. */
21d799b5
NC
20441 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20442 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
20443 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20444 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 20445
c921be7d
NC
20446#undef ARM_VARIANT
20447#define ARM_VARIANT & fpu_vfp_ext_v2
20448
21d799b5
NC
20449 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
20450 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
20451 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
20452 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 20453
037e8744
JB
20454/* Instructions which may belong to either the Neon or VFP instruction sets.
20455 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
20456#undef ARM_VARIANT
20457#define ARM_VARIANT & fpu_vfp_ext_v1xd
20458#undef THUMB_VARIANT
20459#define THUMB_VARIANT & fpu_vfp_ext_v1xd
20460
037e8744
JB
20461 /* These mnemonics are unique to VFP. */
20462 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
20463 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
20464 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20465 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20466 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
aacf0b33
KT
20467 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20468 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
037e8744
JB
20469 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
20470 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
20471 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
20472
20473 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
20474 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
20475 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20476 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 20477
21d799b5
NC
20478 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20479 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
20480
20481 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20482 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20483
55881a11
MGD
20484 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20485 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20486 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20487 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20488 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20489 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
4962c51a
MS
20490 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20491 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 20492
5f1af56b 20493 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
e3e535bc 20494 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
c70a8987
MGD
20495 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
20496 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
f31fef98 20497
037e8744
JB
20498
20499 /* NOTE: All VMOV encoding is special-cased! */
20500 NCE(vmov, 0, 1, (VMOV), neon_mov),
20501 NCE(vmovq, 0, 1, (VMOV), neon_mov),
20502
9db2f6b4
RL
20503#undef ARM_VARIANT
20504#define ARM_VARIANT & arm_ext_fp16
20505#undef THUMB_VARIANT
20506#define THUMB_VARIANT & arm_ext_fp16
20507 /* New instructions added from v8.2, allowing the extraction and insertion of
20508 the upper 16 bits of a 32-bit vector register. */
20509 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
20510 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
20511
c921be7d
NC
20512#undef THUMB_VARIANT
20513#define THUMB_VARIANT & fpu_neon_ext_v1
20514#undef ARM_VARIANT
20515#define ARM_VARIANT & fpu_neon_ext_v1
20516
5287ad62
JB
20517 /* Data processing with three registers of the same length. */
20518 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
20519 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
20520 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
20521 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20522 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20523 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20524 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20525 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20526 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20527 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
20528 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20529 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20530 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20531 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
20532 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20533 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20534 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20535 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
20536 /* If not immediate, fall back to neon_dyadic_i64_su.
20537 shl_imm should accept I8 I16 I32 I64,
20538 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
20539 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
20540 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
20541 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
20542 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 20543 /* Logic ops, types optional & ignored. */
4316f0d2
DG
20544 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20545 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20546 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20547 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20548 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20549 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20550 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20551 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20552 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
20553 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
20554 /* Bitfield ops, untyped. */
20555 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20556 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20557 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20558 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20559 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20560 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
cc933301 20561 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21d799b5
NC
20562 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20563 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20564 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20565 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20566 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20567 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
20568 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
20569 back to neon_dyadic_if_su. */
21d799b5
NC
20570 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20571 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20572 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20573 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20574 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20575 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
20576 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20577 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 20578 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
20579 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
20580 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 20581 /* As above, D registers only. */
21d799b5
NC
20582 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
20583 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 20584 /* Int and float variants, signedness unimportant. */
21d799b5
NC
20585 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20586 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20587 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 20588 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
20589 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
20590 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
20591 /* vtst takes sizes 8, 16, 32. */
20592 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
20593 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
20594 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 20595 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 20596 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
20597 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20598 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
20599 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20600 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
20601 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20602 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
20603 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20604 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
20605 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20606 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
20607 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20608 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
20609 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20610 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
20611 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20612 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
d6b4b13e 20613 /* ARM v8.1 extension. */
643afb90
MW
20614 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20615 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
20616 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20617 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
5287ad62
JB
20618
20619 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 20620 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
20621 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
20622
20623 /* Data processing with two registers and a shift amount. */
20624 /* Right shifts, and variants with rounding.
20625 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
20626 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20627 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20628 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
20629 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
20630 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20631 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20632 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
20633 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
20634 /* Shift and insert. Sizes accepted 8 16 32 64. */
20635 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
20636 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
20637 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
20638 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
20639 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
20640 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
20641 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
20642 /* Right shift immediate, saturating & narrowing, with rounding variants.
20643 Types accepted S16 S32 S64 U16 U32 U64. */
20644 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20645 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
20646 /* As above, unsigned. Types accepted S16 S32 S64. */
20647 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20648 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
20649 /* Right shift narrowing. Types accepted I16 I32 I64. */
20650 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20651 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
20652 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 20653 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 20654 /* CVT with optional immediate for fixed-point variant. */
21d799b5 20655 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 20656
4316f0d2
DG
20657 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
20658 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
5287ad62
JB
20659
20660 /* Data processing, three registers of different lengths. */
20661 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
20662 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
20663 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
20664 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
20665 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
20666 /* If not scalar, fall back to neon_dyadic_long.
20667 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
20668 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
20669 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
20670 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
20671 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20672 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
20673 /* Dyadic, narrowing insns. Types I16 I32 I64. */
20674 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20675 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20676 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20677 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
20678 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
20679 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20680 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
20681 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
20682 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
20683 S16 S32 U16 U32. */
21d799b5 20684 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
20685
20686 /* Extract. Size 8. */
3b8d421e
PB
20687 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
20688 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
20689
20690 /* Two registers, miscellaneous. */
20691 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
20692 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
20693 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
20694 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
20695 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
20696 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
20697 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
20698 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
20699 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
20700 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
20701 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
20702 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
20703 /* VMOVN. Types I16 I32 I64. */
21d799b5 20704 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 20705 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 20706 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 20707 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 20708 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
20709 /* VZIP / VUZP. Sizes 8 16 32. */
20710 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
20711 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
20712 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
20713 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
20714 /* VQABS / VQNEG. Types S8 S16 S32. */
20715 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20716 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
20717 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
20718 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
20719 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
20720 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
20721 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
20722 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
20723 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
cc933301 20724 /* Reciprocal estimates. Types U32 F16 F32. */
5287ad62
JB
20725 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
20726 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
20727 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
20728 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
20729 /* VCLS. Types S8 S16 S32. */
20730 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
20731 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
20732 /* VCLZ. Types I8 I16 I32. */
20733 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
20734 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
20735 /* VCNT. Size 8. */
20736 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
20737 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
20738 /* Two address, untyped. */
20739 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
20740 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
20741 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
20742 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
20743 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
20744
20745 /* Table lookup. Size 8. */
20746 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20747 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
20748
c921be7d
NC
20749#undef THUMB_VARIANT
20750#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
20751#undef ARM_VARIANT
20752#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
20753
5287ad62 20754 /* Neon element/structure load/store. */
21d799b5
NC
20755 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20756 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
20757 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20758 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
20759 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20760 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
20761 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
20762 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 20763
c921be7d 20764#undef THUMB_VARIANT
74db7efb
NC
20765#define THUMB_VARIANT & fpu_vfp_ext_v3xd
20766#undef ARM_VARIANT
20767#define ARM_VARIANT & fpu_vfp_ext_v3xd
62f3b8c8
PB
20768 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
20769 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20770 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20771 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20772 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20773 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20774 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20775 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
20776 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
20777
74db7efb 20778#undef THUMB_VARIANT
c921be7d
NC
20779#define THUMB_VARIANT & fpu_vfp_ext_v3
20780#undef ARM_VARIANT
20781#define ARM_VARIANT & fpu_vfp_ext_v3
20782
21d799b5 20783 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 20784 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20785 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20786 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20787 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20788 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20789 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 20790 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 20791 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 20792
74db7efb
NC
20793#undef ARM_VARIANT
20794#define ARM_VARIANT & fpu_vfp_ext_fma
20795#undef THUMB_VARIANT
20796#define THUMB_VARIANT & fpu_vfp_ext_fma
62f3b8c8
PB
20797 /* Mnemonics shared by Neon and VFP. These are included in the
20798 VFP FMA variant; NEON and VFP FMA always includes the NEON
20799 FMA instructions. */
20800 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20801 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
20802 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
20803 the v form should always be used. */
20804 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20805 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20806 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20807 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20808 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20809 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20810
5287ad62 20811#undef THUMB_VARIANT
c921be7d
NC
20812#undef ARM_VARIANT
20813#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
20814
21d799b5
NC
20815 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20816 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20817 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20818 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20819 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20820 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
20821 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
20822 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 20823
c921be7d
NC
20824#undef ARM_VARIANT
20825#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
20826
21d799b5
NC
20827 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
20828 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
20829 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
20830 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
20831 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
20832 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
20833 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
20834 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
20835 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
74db7efb
NC
20836 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20837 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20838 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
20839 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20840 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
20841 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21d799b5
NC
20842 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20843 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20844 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
20845 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
20846 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
20847 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20848 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20849 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20850 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20851 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
20852 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
74db7efb
NC
20853 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
20854 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
20855 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21d799b5
NC
20856 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
20857 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
20858 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
20859 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
20860 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
20861 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
20862 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
20863 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
20864 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20865 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20866 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20867 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20868 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20869 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20870 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20871 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20872 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20873 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
74db7efb
NC
20874 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20875 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20876 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20877 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20878 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20879 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20880 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20881 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20882 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20883 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20884 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20885 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20886 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20887 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20888 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20889 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20890 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20891 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20892 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20893 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20894 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20895 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20896 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20897 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20898 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20899 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20900 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20901 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20902 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20903 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20904 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20905 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20906 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20907 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20908 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20909 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20910 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20911 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20912 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20913 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20914 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20915 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
20916 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20917 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20918 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20919 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20920 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
74db7efb
NC
20921 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20922 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20923 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20924 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20925 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20926 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21d799b5
NC
20927 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20928 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20929 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20930 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20931 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20932 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20933 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20934 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20935 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20936 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20937 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
20938 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20939 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20940 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20941 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20942 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20943 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20944 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20945 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20946 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20947 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20948 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20949 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20950 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20951 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20952 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20953 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20954 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
20955 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
20956 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20957 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
20958 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
20959 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
20960 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20961 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20962 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20963 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20964 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20965 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20966 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20967 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20968 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20969 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
20970 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
20971 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
20972 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
20973 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
20974 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
20975 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20976 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20977 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20978 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
20979 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
20980 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
20981 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
20982 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
20983 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
20984 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20985 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20986 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20987 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
20988 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 20989
c921be7d
NC
20990#undef ARM_VARIANT
20991#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
20992
21d799b5
NC
20993 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
20994 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
20995 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
20996 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
20997 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
20998 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
20999 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21000 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21001 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21002 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21003 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21004 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21005 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21006 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21007 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21008 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21009 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21010 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21011 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21012 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21013 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
21014 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21015 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21016 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21017 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21018 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21019 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21020 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21021 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21022 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21023 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21024 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21025 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21026 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21027 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21028 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21029 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21030 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21031 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21032 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21033 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21034 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21035 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21036 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21037 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21038 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21039 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21040 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21041 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21042 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21043 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21044 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21045 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21046 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21047 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21048 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21049 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 21050
c921be7d
NC
21051#undef ARM_VARIANT
21052#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
21053
21d799b5
NC
21054 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21055 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21056 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21057 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21058 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21059 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21060 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21061 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21062 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
21063 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
21064 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
21065 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
21066 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
21067 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
74db7efb
NC
21068 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
21069 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
21070 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
21071 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
21072 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
21073 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
21074 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
21075 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
21076 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
21077 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21d799b5
NC
21078 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
21079 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
21080 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
21081 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
74db7efb
NC
21082 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
21083 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21d799b5
NC
21084 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
21085 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
21086 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
21087 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
74db7efb
NC
21088 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
21089 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
21090 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
21091 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
21092 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
21093 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21d799b5
NC
21094 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
21095 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
74db7efb
NC
21096 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
21097 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21d799b5
NC
21098 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
21099 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
21100 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
21101 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
21102 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
21103 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
21104 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
21105 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
21106 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
21107 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
21108 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
21109 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
21110 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
21111 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
21112 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
21113 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
21114 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
21115 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
21116 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
21117 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
21118 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21119 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21120 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21121 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21122 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21123 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21124 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21125 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
74db7efb
NC
21126 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21127 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21d799b5
NC
21128 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
21129 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
4ed7ed8d 21130
16a1fa25 21131 /* ARMv8-M instructions. */
4ed7ed8d
TP
21132#undef ARM_VARIANT
21133#define ARM_VARIANT NULL
21134#undef THUMB_VARIANT
21135#define THUMB_VARIANT & arm_ext_v8m
16a1fa25
TP
21136 TUE("sg", 0, e97fe97f, 0, (), 0, noargs),
21137 TUE("blxns", 0, 4784, 1, (RRnpc), 0, t_blx),
21138 TUE("bxns", 0, 4704, 1, (RRnpc), 0, t_bx),
4ed7ed8d
TP
21139 TUE("tt", 0, e840f000, 2, (RRnpc, RRnpc), 0, tt),
21140 TUE("ttt", 0, e840f040, 2, (RRnpc, RRnpc), 0, tt),
16a1fa25
TP
21141 TUE("tta", 0, e840f080, 2, (RRnpc, RRnpc), 0, tt),
21142 TUE("ttat", 0, e840f0c0, 2, (RRnpc, RRnpc), 0, tt),
21143
21144 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
21145 instructions behave as nop if no VFP is present. */
21146#undef THUMB_VARIANT
21147#define THUMB_VARIANT & arm_ext_v8m_main
21148 TUEc("vlldm", 0, ec300a00, 1, (RRnpc), rn),
21149 TUEc("vlstm", 0, ec200a00, 1, (RRnpc), rn),
c19d1205
ZW
21150};
21151#undef ARM_VARIANT
21152#undef THUMB_VARIANT
21153#undef TCE
c19d1205
ZW
21154#undef TUE
21155#undef TUF
21156#undef TCC
8f06b2d8 21157#undef cCE
e3cb604e
PB
21158#undef cCL
21159#undef C3E
c19d1205
ZW
21160#undef CE
21161#undef CM
21162#undef UE
21163#undef UF
21164#undef UT
5287ad62
JB
21165#undef NUF
21166#undef nUF
21167#undef NCE
21168#undef nCE
c19d1205
ZW
21169#undef OPS0
21170#undef OPS1
21171#undef OPS2
21172#undef OPS3
21173#undef OPS4
21174#undef OPS5
21175#undef OPS6
21176#undef do_0
21177\f
21178/* MD interface: bits in the object file. */
bfae80f2 21179
c19d1205
ZW
21180/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
21181 for use in the a.out file, and stores them in the array pointed to by buf.
21182 This knows about the endian-ness of the target machine and does
21183 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
21184 2 (short) and 4 (long) Floating numbers are put out as a series of
21185 LITTLENUMS (shorts, here at least). */
b99bd4ef 21186
c19d1205
ZW
21187void
21188md_number_to_chars (char * buf, valueT val, int n)
21189{
21190 if (target_big_endian)
21191 number_to_chars_bigendian (buf, val, n);
21192 else
21193 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
21194}
21195
c19d1205
ZW
21196static valueT
21197md_chars_to_number (char * buf, int n)
bfae80f2 21198{
c19d1205
ZW
21199 valueT result = 0;
21200 unsigned char * where = (unsigned char *) buf;
bfae80f2 21201
c19d1205 21202 if (target_big_endian)
b99bd4ef 21203 {
c19d1205
ZW
21204 while (n--)
21205 {
21206 result <<= 8;
21207 result |= (*where++ & 255);
21208 }
b99bd4ef 21209 }
c19d1205 21210 else
b99bd4ef 21211 {
c19d1205
ZW
21212 while (n--)
21213 {
21214 result <<= 8;
21215 result |= (where[n] & 255);
21216 }
bfae80f2 21217 }
b99bd4ef 21218
c19d1205 21219 return result;
bfae80f2 21220}
b99bd4ef 21221
c19d1205 21222/* MD interface: Sections. */
b99bd4ef 21223
fa94de6b
RM
21224/* Calculate the maximum variable size (i.e., excluding fr_fix)
21225 that an rs_machine_dependent frag may reach. */
21226
21227unsigned int
21228arm_frag_max_var (fragS *fragp)
21229{
21230 /* We only use rs_machine_dependent for variable-size Thumb instructions,
21231 which are either THUMB_SIZE (2) or INSN_SIZE (4).
21232
21233 Note that we generate relaxable instructions even for cases that don't
21234 really need it, like an immediate that's a trivial constant. So we're
21235 overestimating the instruction size for some of those cases. Rather
21236 than putting more intelligence here, it would probably be better to
21237 avoid generating a relaxation frag in the first place when it can be
21238 determined up front that a short instruction will suffice. */
21239
21240 gas_assert (fragp->fr_type == rs_machine_dependent);
21241 return INSN_SIZE;
21242}
21243
0110f2b8
PB
21244/* Estimate the size of a frag before relaxing. Assume everything fits in
21245 2 bytes. */
21246
c19d1205 21247int
0110f2b8 21248md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
21249 segT segtype ATTRIBUTE_UNUSED)
21250{
0110f2b8
PB
21251 fragp->fr_var = 2;
21252 return 2;
21253}
21254
21255/* Convert a machine dependent frag. */
21256
21257void
21258md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
21259{
21260 unsigned long insn;
21261 unsigned long old_op;
21262 char *buf;
21263 expressionS exp;
21264 fixS *fixp;
21265 int reloc_type;
21266 int pc_rel;
21267 int opcode;
21268
21269 buf = fragp->fr_literal + fragp->fr_fix;
21270
21271 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
21272 if (fragp->fr_symbol)
21273 {
0110f2b8
PB
21274 exp.X_op = O_symbol;
21275 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
21276 }
21277 else
21278 {
0110f2b8 21279 exp.X_op = O_constant;
5f4273c7 21280 }
0110f2b8
PB
21281 exp.X_add_number = fragp->fr_offset;
21282 opcode = fragp->fr_subtype;
21283 switch (opcode)
21284 {
21285 case T_MNEM_ldr_pc:
21286 case T_MNEM_ldr_pc2:
21287 case T_MNEM_ldr_sp:
21288 case T_MNEM_str_sp:
21289 case T_MNEM_ldr:
21290 case T_MNEM_ldrb:
21291 case T_MNEM_ldrh:
21292 case T_MNEM_str:
21293 case T_MNEM_strb:
21294 case T_MNEM_strh:
21295 if (fragp->fr_var == 4)
21296 {
5f4273c7 21297 insn = THUMB_OP32 (opcode);
0110f2b8
PB
21298 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
21299 {
21300 insn |= (old_op & 0x700) << 4;
21301 }
21302 else
21303 {
21304 insn |= (old_op & 7) << 12;
21305 insn |= (old_op & 0x38) << 13;
21306 }
21307 insn |= 0x00000c00;
21308 put_thumb32_insn (buf, insn);
21309 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
21310 }
21311 else
21312 {
21313 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
21314 }
21315 pc_rel = (opcode == T_MNEM_ldr_pc2);
21316 break;
21317 case T_MNEM_adr:
21318 if (fragp->fr_var == 4)
21319 {
21320 insn = THUMB_OP32 (opcode);
21321 insn |= (old_op & 0xf0) << 4;
21322 put_thumb32_insn (buf, insn);
21323 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
21324 }
21325 else
21326 {
21327 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21328 exp.X_add_number -= 4;
21329 }
21330 pc_rel = 1;
21331 break;
21332 case T_MNEM_mov:
21333 case T_MNEM_movs:
21334 case T_MNEM_cmp:
21335 case T_MNEM_cmn:
21336 if (fragp->fr_var == 4)
21337 {
21338 int r0off = (opcode == T_MNEM_mov
21339 || opcode == T_MNEM_movs) ? 0 : 8;
21340 insn = THUMB_OP32 (opcode);
21341 insn = (insn & 0xe1ffffff) | 0x10000000;
21342 insn |= (old_op & 0x700) << r0off;
21343 put_thumb32_insn (buf, insn);
21344 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21345 }
21346 else
21347 {
21348 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
21349 }
21350 pc_rel = 0;
21351 break;
21352 case T_MNEM_b:
21353 if (fragp->fr_var == 4)
21354 {
21355 insn = THUMB_OP32(opcode);
21356 put_thumb32_insn (buf, insn);
21357 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
21358 }
21359 else
21360 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
21361 pc_rel = 1;
21362 break;
21363 case T_MNEM_bcond:
21364 if (fragp->fr_var == 4)
21365 {
21366 insn = THUMB_OP32(opcode);
21367 insn |= (old_op & 0xf00) << 14;
21368 put_thumb32_insn (buf, insn);
21369 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
21370 }
21371 else
21372 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
21373 pc_rel = 1;
21374 break;
21375 case T_MNEM_add_sp:
21376 case T_MNEM_add_pc:
21377 case T_MNEM_inc_sp:
21378 case T_MNEM_dec_sp:
21379 if (fragp->fr_var == 4)
21380 {
21381 /* ??? Choose between add and addw. */
21382 insn = THUMB_OP32 (opcode);
21383 insn |= (old_op & 0xf0) << 4;
21384 put_thumb32_insn (buf, insn);
16805f35
PB
21385 if (opcode == T_MNEM_add_pc)
21386 reloc_type = BFD_RELOC_ARM_T32_IMM12;
21387 else
21388 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
21389 }
21390 else
21391 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21392 pc_rel = 0;
21393 break;
21394
21395 case T_MNEM_addi:
21396 case T_MNEM_addis:
21397 case T_MNEM_subi:
21398 case T_MNEM_subis:
21399 if (fragp->fr_var == 4)
21400 {
21401 insn = THUMB_OP32 (opcode);
21402 insn |= (old_op & 0xf0) << 4;
21403 insn |= (old_op & 0xf) << 16;
21404 put_thumb32_insn (buf, insn);
16805f35
PB
21405 if (insn & (1 << 20))
21406 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21407 else
21408 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
21409 }
21410 else
21411 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21412 pc_rel = 0;
21413 break;
21414 default:
5f4273c7 21415 abort ();
0110f2b8
PB
21416 }
21417 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 21418 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
21419 fixp->fx_file = fragp->fr_file;
21420 fixp->fx_line = fragp->fr_line;
21421 fragp->fr_fix += fragp->fr_var;
3cfdb781
TG
21422
21423 /* Set whether we use thumb-2 ISA based on final relaxation results. */
21424 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
21425 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
21426 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
0110f2b8
PB
21427}
21428
21429/* Return the size of a relaxable immediate operand instruction.
21430 SHIFT and SIZE specify the form of the allowable immediate. */
21431static int
21432relax_immediate (fragS *fragp, int size, int shift)
21433{
21434 offsetT offset;
21435 offsetT mask;
21436 offsetT low;
21437
21438 /* ??? Should be able to do better than this. */
21439 if (fragp->fr_symbol)
21440 return 4;
21441
21442 low = (1 << shift) - 1;
21443 mask = (1 << (shift + size)) - (1 << shift);
21444 offset = fragp->fr_offset;
21445 /* Force misaligned offsets to 32-bit variant. */
21446 if (offset & low)
5e77afaa 21447 return 4;
0110f2b8
PB
21448 if (offset & ~mask)
21449 return 4;
21450 return 2;
21451}
21452
5e77afaa
PB
21453/* Get the address of a symbol during relaxation. */
21454static addressT
5f4273c7 21455relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
21456{
21457 fragS *sym_frag;
21458 addressT addr;
21459 symbolS *sym;
21460
21461 sym = fragp->fr_symbol;
21462 sym_frag = symbol_get_frag (sym);
21463 know (S_GET_SEGMENT (sym) != absolute_section
21464 || sym_frag == &zero_address_frag);
21465 addr = S_GET_VALUE (sym) + fragp->fr_offset;
21466
21467 /* If frag has yet to be reached on this pass, assume it will
21468 move by STRETCH just as we did. If this is not so, it will
21469 be because some frag between grows, and that will force
21470 another pass. */
21471
21472 if (stretch != 0
21473 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
21474 {
21475 fragS *f;
21476
21477 /* Adjust stretch for any alignment frag. Note that if have
21478 been expanding the earlier code, the symbol may be
21479 defined in what appears to be an earlier frag. FIXME:
21480 This doesn't handle the fr_subtype field, which specifies
21481 a maximum number of bytes to skip when doing an
21482 alignment. */
21483 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
21484 {
21485 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
21486 {
21487 if (stretch < 0)
21488 stretch = - ((- stretch)
21489 & ~ ((1 << (int) f->fr_offset) - 1));
21490 else
21491 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
21492 if (stretch == 0)
21493 break;
21494 }
21495 }
21496 if (f != NULL)
21497 addr += stretch;
21498 }
5e77afaa
PB
21499
21500 return addr;
21501}
21502
0110f2b8
PB
21503/* Return the size of a relaxable adr pseudo-instruction or PC-relative
21504 load. */
21505static int
5e77afaa 21506relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
21507{
21508 addressT addr;
21509 offsetT val;
21510
21511 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
21512 if (fragp->fr_symbol == NULL
21513 || !S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21514 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21515 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21516 return 4;
21517
5f4273c7 21518 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21519 addr = fragp->fr_address + fragp->fr_fix;
21520 addr = (addr + 4) & ~3;
5e77afaa 21521 /* Force misaligned targets to 32-bit variant. */
0110f2b8 21522 if (val & 3)
5e77afaa 21523 return 4;
0110f2b8
PB
21524 val -= addr;
21525 if (val < 0 || val > 1020)
21526 return 4;
21527 return 2;
21528}
21529
21530/* Return the size of a relaxable add/sub immediate instruction. */
21531static int
21532relax_addsub (fragS *fragp, asection *sec)
21533{
21534 char *buf;
21535 int op;
21536
21537 buf = fragp->fr_literal + fragp->fr_fix;
21538 op = bfd_get_16(sec->owner, buf);
21539 if ((op & 0xf) == ((op >> 4) & 0xf))
21540 return relax_immediate (fragp, 8, 0);
21541 else
21542 return relax_immediate (fragp, 3, 0);
21543}
21544
e83a675f
RE
21545/* Return TRUE iff the definition of symbol S could be pre-empted
21546 (overridden) at link or load time. */
21547static bfd_boolean
21548symbol_preemptible (symbolS *s)
21549{
21550 /* Weak symbols can always be pre-empted. */
21551 if (S_IS_WEAK (s))
21552 return TRUE;
21553
21554 /* Non-global symbols cannot be pre-empted. */
21555 if (! S_IS_EXTERNAL (s))
21556 return FALSE;
21557
21558#ifdef OBJ_ELF
21559 /* In ELF, a global symbol can be marked protected, or private. In that
21560 case it can't be pre-empted (other definitions in the same link unit
21561 would violate the ODR). */
21562 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
21563 return FALSE;
21564#endif
21565
21566 /* Other global symbols might be pre-empted. */
21567 return TRUE;
21568}
0110f2b8
PB
21569
21570/* Return the size of a relaxable branch instruction. BITS is the
21571 size of the offset field in the narrow instruction. */
21572
21573static int
5e77afaa 21574relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
21575{
21576 addressT addr;
21577 offsetT val;
21578 offsetT limit;
21579
21580 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 21581 if (!S_IS_DEFINED (fragp->fr_symbol)
77db8e2e
NC
21582 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21583 || S_IS_WEAK (fragp->fr_symbol))
0110f2b8
PB
21584 return 4;
21585
267bf995 21586#ifdef OBJ_ELF
e83a675f 21587 /* A branch to a function in ARM state will require interworking. */
267bf995
RR
21588 if (S_IS_DEFINED (fragp->fr_symbol)
21589 && ARM_IS_FUNC (fragp->fr_symbol))
21590 return 4;
e83a675f 21591#endif
0d9b4b55 21592
e83a675f 21593 if (symbol_preemptible (fragp->fr_symbol))
0d9b4b55 21594 return 4;
267bf995 21595
5f4273c7 21596 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
21597 addr = fragp->fr_address + fragp->fr_fix + 4;
21598 val -= addr;
21599
21600 /* Offset is a signed value *2 */
21601 limit = 1 << bits;
21602 if (val >= limit || val < -limit)
21603 return 4;
21604 return 2;
21605}
21606
21607
21608/* Relax a machine dependent frag. This returns the amount by which
21609 the current size of the frag should change. */
21610
21611int
5e77afaa 21612arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
21613{
21614 int oldsize;
21615 int newsize;
21616
21617 oldsize = fragp->fr_var;
21618 switch (fragp->fr_subtype)
21619 {
21620 case T_MNEM_ldr_pc2:
5f4273c7 21621 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21622 break;
21623 case T_MNEM_ldr_pc:
21624 case T_MNEM_ldr_sp:
21625 case T_MNEM_str_sp:
5f4273c7 21626 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
21627 break;
21628 case T_MNEM_ldr:
21629 case T_MNEM_str:
5f4273c7 21630 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
21631 break;
21632 case T_MNEM_ldrh:
21633 case T_MNEM_strh:
5f4273c7 21634 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
21635 break;
21636 case T_MNEM_ldrb:
21637 case T_MNEM_strb:
5f4273c7 21638 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
21639 break;
21640 case T_MNEM_adr:
5f4273c7 21641 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
21642 break;
21643 case T_MNEM_mov:
21644 case T_MNEM_movs:
21645 case T_MNEM_cmp:
21646 case T_MNEM_cmn:
5f4273c7 21647 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
21648 break;
21649 case T_MNEM_b:
5f4273c7 21650 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
21651 break;
21652 case T_MNEM_bcond:
5f4273c7 21653 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
21654 break;
21655 case T_MNEM_add_sp:
21656 case T_MNEM_add_pc:
21657 newsize = relax_immediate (fragp, 8, 2);
21658 break;
21659 case T_MNEM_inc_sp:
21660 case T_MNEM_dec_sp:
21661 newsize = relax_immediate (fragp, 7, 2);
21662 break;
21663 case T_MNEM_addi:
21664 case T_MNEM_addis:
21665 case T_MNEM_subi:
21666 case T_MNEM_subis:
21667 newsize = relax_addsub (fragp, sec);
21668 break;
21669 default:
5f4273c7 21670 abort ();
0110f2b8 21671 }
5e77afaa
PB
21672
21673 fragp->fr_var = newsize;
21674 /* Freeze wide instructions that are at or before the same location as
21675 in the previous pass. This avoids infinite loops.
5f4273c7
NC
21676 Don't freeze them unconditionally because targets may be artificially
21677 misaligned by the expansion of preceding frags. */
5e77afaa 21678 if (stretch <= 0 && newsize > 2)
0110f2b8 21679 {
0110f2b8 21680 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 21681 frag_wane (fragp);
0110f2b8 21682 }
5e77afaa 21683
0110f2b8 21684 return newsize - oldsize;
c19d1205 21685}
b99bd4ef 21686
c19d1205 21687/* Round up a section size to the appropriate boundary. */
b99bd4ef 21688
c19d1205
ZW
21689valueT
21690md_section_align (segT segment ATTRIBUTE_UNUSED,
21691 valueT size)
21692{
f0927246
NC
21693#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
21694 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
21695 {
21696 /* For a.out, force the section size to be aligned. If we don't do
21697 this, BFD will align it for us, but it will not write out the
21698 final bytes of the section. This may be a bug in BFD, but it is
21699 easier to fix it here since that is how the other a.out targets
21700 work. */
21701 int align;
21702
21703 align = bfd_get_section_alignment (stdoutput, segment);
8d3842cd 21704 size = ((size + (1 << align) - 1) & (-((valueT) 1 << align)));
f0927246 21705 }
c19d1205 21706#endif
f0927246 21707
6844c0cc 21708 return size;
bfae80f2 21709}
b99bd4ef 21710
c19d1205
ZW
21711/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
21712 of an rs_align_code fragment. */
21713
21714void
21715arm_handle_align (fragS * fragP)
bfae80f2 21716{
d9235011 21717 static unsigned char const arm_noop[2][2][4] =
e7495e45
NS
21718 {
21719 { /* ARMv1 */
21720 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
21721 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
21722 },
21723 { /* ARMv6k */
21724 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
21725 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
21726 },
21727 };
d9235011 21728 static unsigned char const thumb_noop[2][2][2] =
e7495e45
NS
21729 {
21730 { /* Thumb-1 */
21731 {0xc0, 0x46}, /* LE */
21732 {0x46, 0xc0}, /* BE */
21733 },
21734 { /* Thumb-2 */
21735 {0x00, 0xbf}, /* LE */
21736 {0xbf, 0x00} /* BE */
21737 }
21738 };
d9235011 21739 static unsigned char const wide_thumb_noop[2][4] =
e7495e45
NS
21740 { /* Wide Thumb-2 */
21741 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
21742 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
21743 };
c921be7d 21744
e7495e45 21745 unsigned bytes, fix, noop_size;
c19d1205 21746 char * p;
d9235011
TS
21747 const unsigned char * noop;
21748 const unsigned char *narrow_noop = NULL;
cd000bff
DJ
21749#ifdef OBJ_ELF
21750 enum mstate state;
21751#endif
bfae80f2 21752
c19d1205 21753 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
21754 return;
21755
c19d1205
ZW
21756 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
21757 p = fragP->fr_literal + fragP->fr_fix;
21758 fix = 0;
bfae80f2 21759
c19d1205
ZW
21760 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
21761 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 21762
cd000bff 21763 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
8dc2430f 21764
cd000bff 21765 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 21766 {
7f78eb34
JW
21767 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21768 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
e7495e45
NS
21769 {
21770 narrow_noop = thumb_noop[1][target_big_endian];
21771 noop = wide_thumb_noop[target_big_endian];
21772 }
c19d1205 21773 else
e7495e45
NS
21774 noop = thumb_noop[0][target_big_endian];
21775 noop_size = 2;
cd000bff
DJ
21776#ifdef OBJ_ELF
21777 state = MAP_THUMB;
21778#endif
7ed4c4c5
NC
21779 }
21780 else
21781 {
7f78eb34
JW
21782 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
21783 ? selected_cpu : arm_arch_none,
21784 arm_ext_v6k) != 0]
e7495e45
NS
21785 [target_big_endian];
21786 noop_size = 4;
cd000bff
DJ
21787#ifdef OBJ_ELF
21788 state = MAP_ARM;
21789#endif
7ed4c4c5 21790 }
c921be7d 21791
e7495e45 21792 fragP->fr_var = noop_size;
c921be7d 21793
c19d1205 21794 if (bytes & (noop_size - 1))
7ed4c4c5 21795 {
c19d1205 21796 fix = bytes & (noop_size - 1);
cd000bff
DJ
21797#ifdef OBJ_ELF
21798 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
21799#endif
c19d1205
ZW
21800 memset (p, 0, fix);
21801 p += fix;
21802 bytes -= fix;
a737bd4d 21803 }
a737bd4d 21804
e7495e45
NS
21805 if (narrow_noop)
21806 {
21807 if (bytes & noop_size)
21808 {
21809 /* Insert a narrow noop. */
21810 memcpy (p, narrow_noop, noop_size);
21811 p += noop_size;
21812 bytes -= noop_size;
21813 fix += noop_size;
21814 }
21815
21816 /* Use wide noops for the remainder */
21817 noop_size = 4;
21818 }
21819
c19d1205 21820 while (bytes >= noop_size)
a737bd4d 21821 {
c19d1205
ZW
21822 memcpy (p, noop, noop_size);
21823 p += noop_size;
21824 bytes -= noop_size;
21825 fix += noop_size;
a737bd4d
NC
21826 }
21827
c19d1205 21828 fragP->fr_fix += fix;
a737bd4d
NC
21829}
21830
c19d1205
ZW
21831/* Called from md_do_align. Used to create an alignment
21832 frag in a code section. */
21833
21834void
21835arm_frag_align_code (int n, int max)
bfae80f2 21836{
c19d1205 21837 char * p;
7ed4c4c5 21838
c19d1205 21839 /* We assume that there will never be a requirement
6ec8e702 21840 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 21841 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
21842 {
21843 char err_msg[128];
21844
fa94de6b 21845 sprintf (err_msg,
477330fc
RM
21846 _("alignments greater than %d bytes not supported in .text sections."),
21847 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 21848 as_fatal ("%s", err_msg);
6ec8e702 21849 }
bfae80f2 21850
c19d1205
ZW
21851 p = frag_var (rs_align_code,
21852 MAX_MEM_FOR_RS_ALIGN_CODE,
21853 1,
21854 (relax_substateT) max,
21855 (symbolS *) NULL,
21856 (offsetT) n,
21857 (char *) NULL);
21858 *p = 0;
21859}
bfae80f2 21860
8dc2430f
NC
21861/* Perform target specific initialisation of a frag.
21862 Note - despite the name this initialisation is not done when the frag
21863 is created, but only when its type is assigned. A frag can be created
21864 and used a long time before its type is set, so beware of assuming that
33eaf5de 21865 this initialisation is performed first. */
bfae80f2 21866
cd000bff
DJ
21867#ifndef OBJ_ELF
21868void
21869arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
21870{
21871 /* Record whether this frag is in an ARM or a THUMB area. */
2e98972e 21872 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
cd000bff
DJ
21873}
21874
21875#else /* OBJ_ELF is defined. */
c19d1205 21876void
cd000bff 21877arm_init_frag (fragS * fragP, int max_chars)
c19d1205 21878{
b968d18a
JW
21879 int frag_thumb_mode;
21880
8dc2430f
NC
21881 /* If the current ARM vs THUMB mode has not already
21882 been recorded into this frag then do so now. */
cd000bff 21883 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
b968d18a
JW
21884 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
21885
21886 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
cd000bff 21887
f9c1b181
RL
21888 /* Record a mapping symbol for alignment frags. We will delete this
21889 later if the alignment ends up empty. */
21890 switch (fragP->fr_type)
21891 {
21892 case rs_align:
21893 case rs_align_test:
21894 case rs_fill:
21895 mapping_state_2 (MAP_DATA, max_chars);
21896 break;
21897 case rs_align_code:
b968d18a 21898 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
f9c1b181
RL
21899 break;
21900 default:
21901 break;
cd000bff 21902 }
bfae80f2
RE
21903}
21904
c19d1205
ZW
21905/* When we change sections we need to issue a new mapping symbol. */
21906
21907void
21908arm_elf_change_section (void)
bfae80f2 21909{
c19d1205
ZW
21910 /* Link an unlinked unwind index table section to the .text section. */
21911 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
21912 && elf_linked_to_section (now_seg) == NULL)
21913 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
21914}
21915
c19d1205
ZW
21916int
21917arm_elf_section_type (const char * str, size_t len)
e45d0630 21918{
c19d1205
ZW
21919 if (len == 5 && strncmp (str, "exidx", 5) == 0)
21920 return SHT_ARM_EXIDX;
e45d0630 21921
c19d1205
ZW
21922 return -1;
21923}
21924\f
21925/* Code to deal with unwinding tables. */
e45d0630 21926
c19d1205 21927static void add_unwind_adjustsp (offsetT);
e45d0630 21928
5f4273c7 21929/* Generate any deferred unwind frame offset. */
e45d0630 21930
bfae80f2 21931static void
c19d1205 21932flush_pending_unwind (void)
bfae80f2 21933{
c19d1205 21934 offsetT offset;
bfae80f2 21935
c19d1205
ZW
21936 offset = unwind.pending_offset;
21937 unwind.pending_offset = 0;
21938 if (offset != 0)
21939 add_unwind_adjustsp (offset);
bfae80f2
RE
21940}
21941
c19d1205
ZW
21942/* Add an opcode to this list for this function. Two-byte opcodes should
21943 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
21944 order. */
21945
bfae80f2 21946static void
c19d1205 21947add_unwind_opcode (valueT op, int length)
bfae80f2 21948{
c19d1205
ZW
21949 /* Add any deferred stack adjustment. */
21950 if (unwind.pending_offset)
21951 flush_pending_unwind ();
bfae80f2 21952
c19d1205 21953 unwind.sp_restored = 0;
bfae80f2 21954
c19d1205 21955 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 21956 {
c19d1205
ZW
21957 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
21958 if (unwind.opcodes)
325801bd
TS
21959 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
21960 unwind.opcode_alloc);
c19d1205 21961 else
325801bd 21962 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
bfae80f2 21963 }
c19d1205 21964 while (length > 0)
bfae80f2 21965 {
c19d1205
ZW
21966 length--;
21967 unwind.opcodes[unwind.opcode_count] = op & 0xff;
21968 op >>= 8;
21969 unwind.opcode_count++;
bfae80f2 21970 }
bfae80f2
RE
21971}
21972
c19d1205
ZW
21973/* Add unwind opcodes to adjust the stack pointer. */
21974
bfae80f2 21975static void
c19d1205 21976add_unwind_adjustsp (offsetT offset)
bfae80f2 21977{
c19d1205 21978 valueT op;
bfae80f2 21979
c19d1205 21980 if (offset > 0x200)
bfae80f2 21981 {
c19d1205
ZW
21982 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
21983 char bytes[5];
21984 int n;
21985 valueT o;
bfae80f2 21986
c19d1205
ZW
21987 /* Long form: 0xb2, uleb128. */
21988 /* This might not fit in a word so add the individual bytes,
21989 remembering the list is built in reverse order. */
21990 o = (valueT) ((offset - 0x204) >> 2);
21991 if (o == 0)
21992 add_unwind_opcode (0, 1);
bfae80f2 21993
c19d1205
ZW
21994 /* Calculate the uleb128 encoding of the offset. */
21995 n = 0;
21996 while (o)
21997 {
21998 bytes[n] = o & 0x7f;
21999 o >>= 7;
22000 if (o)
22001 bytes[n] |= 0x80;
22002 n++;
22003 }
22004 /* Add the insn. */
22005 for (; n; n--)
22006 add_unwind_opcode (bytes[n - 1], 1);
22007 add_unwind_opcode (0xb2, 1);
22008 }
22009 else if (offset > 0x100)
bfae80f2 22010 {
c19d1205
ZW
22011 /* Two short opcodes. */
22012 add_unwind_opcode (0x3f, 1);
22013 op = (offset - 0x104) >> 2;
22014 add_unwind_opcode (op, 1);
bfae80f2 22015 }
c19d1205
ZW
22016 else if (offset > 0)
22017 {
22018 /* Short opcode. */
22019 op = (offset - 4) >> 2;
22020 add_unwind_opcode (op, 1);
22021 }
22022 else if (offset < 0)
bfae80f2 22023 {
c19d1205
ZW
22024 offset = -offset;
22025 while (offset > 0x100)
bfae80f2 22026 {
c19d1205
ZW
22027 add_unwind_opcode (0x7f, 1);
22028 offset -= 0x100;
bfae80f2 22029 }
c19d1205
ZW
22030 op = ((offset - 4) >> 2) | 0x40;
22031 add_unwind_opcode (op, 1);
bfae80f2 22032 }
bfae80f2
RE
22033}
22034
c19d1205
ZW
22035/* Finish the list of unwind opcodes for this function. */
22036static void
22037finish_unwind_opcodes (void)
bfae80f2 22038{
c19d1205 22039 valueT op;
bfae80f2 22040
c19d1205 22041 if (unwind.fp_used)
bfae80f2 22042 {
708587a4 22043 /* Adjust sp as necessary. */
c19d1205
ZW
22044 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
22045 flush_pending_unwind ();
bfae80f2 22046
c19d1205
ZW
22047 /* After restoring sp from the frame pointer. */
22048 op = 0x90 | unwind.fp_reg;
22049 add_unwind_opcode (op, 1);
22050 }
22051 else
22052 flush_pending_unwind ();
bfae80f2
RE
22053}
22054
bfae80f2 22055
c19d1205
ZW
22056/* Start an exception table entry. If idx is nonzero this is an index table
22057 entry. */
bfae80f2
RE
22058
22059static void
c19d1205 22060start_unwind_section (const segT text_seg, int idx)
bfae80f2 22061{
c19d1205
ZW
22062 const char * text_name;
22063 const char * prefix;
22064 const char * prefix_once;
22065 const char * group_name;
c19d1205 22066 char * sec_name;
c19d1205
ZW
22067 int type;
22068 int flags;
22069 int linkonce;
bfae80f2 22070
c19d1205 22071 if (idx)
bfae80f2 22072 {
c19d1205
ZW
22073 prefix = ELF_STRING_ARM_unwind;
22074 prefix_once = ELF_STRING_ARM_unwind_once;
22075 type = SHT_ARM_EXIDX;
bfae80f2 22076 }
c19d1205 22077 else
bfae80f2 22078 {
c19d1205
ZW
22079 prefix = ELF_STRING_ARM_unwind_info;
22080 prefix_once = ELF_STRING_ARM_unwind_info_once;
22081 type = SHT_PROGBITS;
bfae80f2
RE
22082 }
22083
c19d1205
ZW
22084 text_name = segment_name (text_seg);
22085 if (streq (text_name, ".text"))
22086 text_name = "";
22087
22088 if (strncmp (text_name, ".gnu.linkonce.t.",
22089 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 22090 {
c19d1205
ZW
22091 prefix = prefix_once;
22092 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
22093 }
22094
29a2809e 22095 sec_name = concat (prefix, text_name, (char *) NULL);
bfae80f2 22096
c19d1205
ZW
22097 flags = SHF_ALLOC;
22098 linkonce = 0;
22099 group_name = 0;
bfae80f2 22100
c19d1205
ZW
22101 /* Handle COMDAT group. */
22102 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 22103 {
c19d1205
ZW
22104 group_name = elf_group_name (text_seg);
22105 if (group_name == NULL)
22106 {
bd3ba5d1 22107 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
22108 segment_name (text_seg));
22109 ignore_rest_of_line ();
22110 return;
22111 }
22112 flags |= SHF_GROUP;
22113 linkonce = 1;
bfae80f2
RE
22114 }
22115
c19d1205 22116 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 22117
5f4273c7 22118 /* Set the section link for index tables. */
c19d1205
ZW
22119 if (idx)
22120 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
22121}
22122
bfae80f2 22123
c19d1205
ZW
22124/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
22125 personality routine data. Returns zero, or the index table value for
cad0da33 22126 an inline entry. */
c19d1205
ZW
22127
22128static valueT
22129create_unwind_entry (int have_data)
bfae80f2 22130{
c19d1205
ZW
22131 int size;
22132 addressT where;
22133 char *ptr;
22134 /* The current word of data. */
22135 valueT data;
22136 /* The number of bytes left in this word. */
22137 int n;
bfae80f2 22138
c19d1205 22139 finish_unwind_opcodes ();
bfae80f2 22140
c19d1205
ZW
22141 /* Remember the current text section. */
22142 unwind.saved_seg = now_seg;
22143 unwind.saved_subseg = now_subseg;
bfae80f2 22144
c19d1205 22145 start_unwind_section (now_seg, 0);
bfae80f2 22146
c19d1205 22147 if (unwind.personality_routine == NULL)
bfae80f2 22148 {
c19d1205
ZW
22149 if (unwind.personality_index == -2)
22150 {
22151 if (have_data)
5f4273c7 22152 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
22153 return 1; /* EXIDX_CANTUNWIND. */
22154 }
bfae80f2 22155
c19d1205
ZW
22156 /* Use a default personality routine if none is specified. */
22157 if (unwind.personality_index == -1)
22158 {
22159 if (unwind.opcode_count > 3)
22160 unwind.personality_index = 1;
22161 else
22162 unwind.personality_index = 0;
22163 }
bfae80f2 22164
c19d1205
ZW
22165 /* Space for the personality routine entry. */
22166 if (unwind.personality_index == 0)
22167 {
22168 if (unwind.opcode_count > 3)
22169 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 22170
c19d1205
ZW
22171 if (!have_data)
22172 {
22173 /* All the data is inline in the index table. */
22174 data = 0x80;
22175 n = 3;
22176 while (unwind.opcode_count > 0)
22177 {
22178 unwind.opcode_count--;
22179 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22180 n--;
22181 }
bfae80f2 22182
c19d1205
ZW
22183 /* Pad with "finish" opcodes. */
22184 while (n--)
22185 data = (data << 8) | 0xb0;
bfae80f2 22186
c19d1205
ZW
22187 return data;
22188 }
22189 size = 0;
22190 }
22191 else
22192 /* We get two opcodes "free" in the first word. */
22193 size = unwind.opcode_count - 2;
22194 }
22195 else
5011093d 22196 {
cad0da33
NC
22197 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
22198 if (unwind.personality_index != -1)
22199 {
22200 as_bad (_("attempt to recreate an unwind entry"));
22201 return 1;
22202 }
5011093d
NC
22203
22204 /* An extra byte is required for the opcode count. */
22205 size = unwind.opcode_count + 1;
22206 }
bfae80f2 22207
c19d1205
ZW
22208 size = (size + 3) >> 2;
22209 if (size > 0xff)
22210 as_bad (_("too many unwind opcodes"));
bfae80f2 22211
c19d1205
ZW
22212 frag_align (2, 0, 0);
22213 record_alignment (now_seg, 2);
22214 unwind.table_entry = expr_build_dot ();
22215
22216 /* Allocate the table entry. */
22217 ptr = frag_more ((size << 2) + 4);
74929e7b
NC
22218 /* PR 13449: Zero the table entries in case some of them are not used. */
22219 memset (ptr, 0, (size << 2) + 4);
c19d1205 22220 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 22221
c19d1205 22222 switch (unwind.personality_index)
bfae80f2 22223 {
c19d1205
ZW
22224 case -1:
22225 /* ??? Should this be a PLT generating relocation? */
22226 /* Custom personality routine. */
22227 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
22228 BFD_RELOC_ARM_PREL31);
bfae80f2 22229
c19d1205
ZW
22230 where += 4;
22231 ptr += 4;
bfae80f2 22232
c19d1205 22233 /* Set the first byte to the number of additional words. */
5011093d 22234 data = size > 0 ? size - 1 : 0;
c19d1205
ZW
22235 n = 3;
22236 break;
bfae80f2 22237
c19d1205
ZW
22238 /* ABI defined personality routines. */
22239 case 0:
22240 /* Three opcodes bytes are packed into the first word. */
22241 data = 0x80;
22242 n = 3;
22243 break;
bfae80f2 22244
c19d1205
ZW
22245 case 1:
22246 case 2:
22247 /* The size and first two opcode bytes go in the first word. */
22248 data = ((0x80 + unwind.personality_index) << 8) | size;
22249 n = 2;
22250 break;
bfae80f2 22251
c19d1205
ZW
22252 default:
22253 /* Should never happen. */
22254 abort ();
22255 }
bfae80f2 22256
c19d1205
ZW
22257 /* Pack the opcodes into words (MSB first), reversing the list at the same
22258 time. */
22259 while (unwind.opcode_count > 0)
22260 {
22261 if (n == 0)
22262 {
22263 md_number_to_chars (ptr, data, 4);
22264 ptr += 4;
22265 n = 4;
22266 data = 0;
22267 }
22268 unwind.opcode_count--;
22269 n--;
22270 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22271 }
22272
22273 /* Finish off the last word. */
22274 if (n < 4)
22275 {
22276 /* Pad with "finish" opcodes. */
22277 while (n--)
22278 data = (data << 8) | 0xb0;
22279
22280 md_number_to_chars (ptr, data, 4);
22281 }
22282
22283 if (!have_data)
22284 {
22285 /* Add an empty descriptor if there is no user-specified data. */
22286 ptr = frag_more (4);
22287 md_number_to_chars (ptr, 0, 4);
22288 }
22289
22290 return 0;
bfae80f2
RE
22291}
22292
f0927246
NC
22293
22294/* Initialize the DWARF-2 unwind information for this procedure. */
22295
22296void
22297tc_arm_frame_initial_instructions (void)
22298{
22299 cfi_add_CFA_def_cfa (REG_SP, 0);
22300}
22301#endif /* OBJ_ELF */
22302
c19d1205
ZW
22303/* Convert REGNAME to a DWARF-2 register number. */
22304
22305int
1df69f4f 22306tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 22307{
1df69f4f 22308 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
1f5afe1c
NC
22309 if (reg != FAIL)
22310 return reg;
c19d1205 22311
1f5afe1c
NC
22312 /* PR 16694: Allow VFP registers as well. */
22313 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22314 if (reg != FAIL)
22315 return 64 + reg;
c19d1205 22316
1f5afe1c
NC
22317 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
22318 if (reg != FAIL)
22319 return reg + 256;
22320
22321 return -1;
bfae80f2
RE
22322}
22323
f0927246 22324#ifdef TE_PE
c19d1205 22325void
f0927246 22326tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 22327{
91d6fa6a 22328 expressionS exp;
bfae80f2 22329
91d6fa6a
NC
22330 exp.X_op = O_secrel;
22331 exp.X_add_symbol = symbol;
22332 exp.X_add_number = 0;
22333 emit_expr (&exp, size);
f0927246
NC
22334}
22335#endif
bfae80f2 22336
c19d1205 22337/* MD interface: Symbol and relocation handling. */
bfae80f2 22338
2fc8bdac
ZW
22339/* Return the address within the segment that a PC-relative fixup is
22340 relative to. For ARM, PC-relative fixups applied to instructions
22341 are generally relative to the location of the fixup plus 8 bytes.
22342 Thumb branches are offset by 4, and Thumb loads relative to PC
22343 require special handling. */
bfae80f2 22344
c19d1205 22345long
2fc8bdac 22346md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 22347{
2fc8bdac
ZW
22348 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
22349
22350 /* If this is pc-relative and we are going to emit a relocation
22351 then we just want to put out any pipeline compensation that the linker
53baae48
NC
22352 will need. Otherwise we want to use the calculated base.
22353 For WinCE we skip the bias for externals as well, since this
22354 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 22355 if (fixP->fx_pcrel
2fc8bdac 22356 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
22357 || (arm_force_relocation (fixP)
22358#ifdef TE_WINCE
22359 && !S_IS_EXTERNAL (fixP->fx_addsy)
22360#endif
22361 )))
2fc8bdac 22362 base = 0;
bfae80f2 22363
267bf995 22364
c19d1205 22365 switch (fixP->fx_r_type)
bfae80f2 22366 {
2fc8bdac
ZW
22367 /* PC relative addressing on the Thumb is slightly odd as the
22368 bottom two bits of the PC are forced to zero for the
22369 calculation. This happens *after* application of the
22370 pipeline offset. However, Thumb adrl already adjusts for
22371 this, so we need not do it again. */
c19d1205 22372 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 22373 return base & ~3;
c19d1205
ZW
22374
22375 case BFD_RELOC_ARM_THUMB_OFFSET:
22376 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 22377 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 22378 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 22379 return (base + 4) & ~3;
c19d1205 22380
2fc8bdac
ZW
22381 /* Thumb branches are simply offset by +4. */
22382 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22383 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22384 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22385 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 22386 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 22387 return base + 4;
bfae80f2 22388
267bf995 22389 case BFD_RELOC_THUMB_PCREL_BRANCH23:
486499d0
CL
22390 if (fixP->fx_addsy
22391 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22392 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995 22393 && ARM_IS_FUNC (fixP->fx_addsy)
477330fc
RM
22394 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22395 base = fixP->fx_where + fixP->fx_frag->fr_address;
267bf995
RR
22396 return base + 4;
22397
00adf2d4
JB
22398 /* BLX is like branches above, but forces the low two bits of PC to
22399 zero. */
486499d0
CL
22400 case BFD_RELOC_THUMB_PCREL_BLX:
22401 if (fixP->fx_addsy
22402 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22403 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22404 && THUMB_IS_FUNC (fixP->fx_addsy)
22405 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22406 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
22407 return (base + 4) & ~3;
22408
2fc8bdac
ZW
22409 /* ARM mode branches are offset by +8. However, the Windows CE
22410 loader expects the relocation not to take this into account. */
267bf995 22411 case BFD_RELOC_ARM_PCREL_BLX:
486499d0
CL
22412 if (fixP->fx_addsy
22413 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22414 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22415 && ARM_IS_FUNC (fixP->fx_addsy)
22416 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22417 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22418 return base + 8;
267bf995 22419
486499d0
CL
22420 case BFD_RELOC_ARM_PCREL_CALL:
22421 if (fixP->fx_addsy
22422 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 22423 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
477330fc
RM
22424 && THUMB_IS_FUNC (fixP->fx_addsy)
22425 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22426 base = fixP->fx_where + fixP->fx_frag->fr_address;
486499d0 22427 return base + 8;
267bf995 22428
2fc8bdac 22429 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 22430 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 22431 case BFD_RELOC_ARM_PLT32:
c19d1205 22432#ifdef TE_WINCE
5f4273c7 22433 /* When handling fixups immediately, because we have already
477330fc 22434 discovered the value of a symbol, or the address of the frag involved
53baae48 22435 we must account for the offset by +8, as the OS loader will never see the reloc.
477330fc
RM
22436 see fixup_segment() in write.c
22437 The S_IS_EXTERNAL test handles the case of global symbols.
22438 Those need the calculated base, not just the pipe compensation the linker will need. */
53baae48
NC
22439 if (fixP->fx_pcrel
22440 && fixP->fx_addsy != NULL
22441 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22442 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
22443 return base + 8;
2fc8bdac 22444 return base;
c19d1205 22445#else
2fc8bdac 22446 return base + 8;
c19d1205 22447#endif
2fc8bdac 22448
267bf995 22449
2fc8bdac
ZW
22450 /* ARM mode loads relative to PC are also offset by +8. Unlike
22451 branches, the Windows CE loader *does* expect the relocation
22452 to take this into account. */
22453 case BFD_RELOC_ARM_OFFSET_IMM:
22454 case BFD_RELOC_ARM_OFFSET_IMM8:
22455 case BFD_RELOC_ARM_HWLITERAL:
22456 case BFD_RELOC_ARM_LITERAL:
22457 case BFD_RELOC_ARM_CP_OFF_IMM:
22458 return base + 8;
22459
22460
22461 /* Other PC-relative relocations are un-offset. */
22462 default:
22463 return base;
22464 }
bfae80f2
RE
22465}
22466
8b2d793c
NC
22467static bfd_boolean flag_warn_syms = TRUE;
22468
ae8714c2
NC
22469bfd_boolean
22470arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
bfae80f2 22471{
8b2d793c
NC
22472 /* PR 18347 - Warn if the user attempts to create a symbol with the same
22473 name as an ARM instruction. Whilst strictly speaking it is allowed, it
22474 does mean that the resulting code might be very confusing to the reader.
22475 Also this warning can be triggered if the user omits an operand before
22476 an immediate address, eg:
22477
22478 LDR =foo
22479
22480 GAS treats this as an assignment of the value of the symbol foo to a
22481 symbol LDR, and so (without this code) it will not issue any kind of
22482 warning or error message.
22483
22484 Note - ARM instructions are case-insensitive but the strings in the hash
22485 table are all stored in lower case, so we must first ensure that name is
ae8714c2
NC
22486 lower case too. */
22487 if (flag_warn_syms && arm_ops_hsh)
8b2d793c
NC
22488 {
22489 char * nbuf = strdup (name);
22490 char * p;
22491
22492 for (p = nbuf; *p; p++)
22493 *p = TOLOWER (*p);
22494 if (hash_find (arm_ops_hsh, nbuf) != NULL)
22495 {
22496 static struct hash_control * already_warned = NULL;
22497
22498 if (already_warned == NULL)
22499 already_warned = hash_new ();
22500 /* Only warn about the symbol once. To keep the code
22501 simple we let hash_insert do the lookup for us. */
22502 if (hash_insert (already_warned, name, NULL) == NULL)
ae8714c2 22503 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
8b2d793c
NC
22504 }
22505 else
22506 free (nbuf);
22507 }
3739860c 22508
ae8714c2
NC
22509 return FALSE;
22510}
22511
22512/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
22513 Otherwise we have no need to default values of symbols. */
22514
22515symbolS *
22516md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
22517{
22518#ifdef OBJ_ELF
22519 if (name[0] == '_' && name[1] == 'G'
22520 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
22521 {
22522 if (!GOT_symbol)
22523 {
22524 if (symbol_find (name))
22525 as_bad (_("GOT already in the symbol table"));
22526
22527 GOT_symbol = symbol_new (name, undefined_section,
22528 (valueT) 0, & zero_address_frag);
22529 }
22530
22531 return GOT_symbol;
22532 }
22533#endif
22534
c921be7d 22535 return NULL;
bfae80f2
RE
22536}
22537
55cf6793 22538/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
22539 computed as two separate immediate values, added together. We
22540 already know that this value cannot be computed by just one ARM
22541 instruction. */
22542
22543static unsigned int
22544validate_immediate_twopart (unsigned int val,
22545 unsigned int * highpart)
bfae80f2 22546{
c19d1205
ZW
22547 unsigned int a;
22548 unsigned int i;
bfae80f2 22549
c19d1205
ZW
22550 for (i = 0; i < 32; i += 2)
22551 if (((a = rotate_left (val, i)) & 0xff) != 0)
22552 {
22553 if (a & 0xff00)
22554 {
22555 if (a & ~ 0xffff)
22556 continue;
22557 * highpart = (a >> 8) | ((i + 24) << 7);
22558 }
22559 else if (a & 0xff0000)
22560 {
22561 if (a & 0xff000000)
22562 continue;
22563 * highpart = (a >> 16) | ((i + 16) << 7);
22564 }
22565 else
22566 {
9c2799c2 22567 gas_assert (a & 0xff000000);
c19d1205
ZW
22568 * highpart = (a >> 24) | ((i + 8) << 7);
22569 }
bfae80f2 22570
c19d1205
ZW
22571 return (a & 0xff) | (i << 7);
22572 }
bfae80f2 22573
c19d1205 22574 return FAIL;
bfae80f2
RE
22575}
22576
c19d1205
ZW
22577static int
22578validate_offset_imm (unsigned int val, int hwse)
22579{
22580 if ((hwse && val > 255) || val > 4095)
22581 return FAIL;
22582 return val;
22583}
bfae80f2 22584
55cf6793 22585/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
22586 negative immediate constant by altering the instruction. A bit of
22587 a hack really.
22588 MOV <-> MVN
22589 AND <-> BIC
22590 ADC <-> SBC
22591 by inverting the second operand, and
22592 ADD <-> SUB
22593 CMP <-> CMN
22594 by negating the second operand. */
bfae80f2 22595
c19d1205
ZW
22596static int
22597negate_data_op (unsigned long * instruction,
22598 unsigned long value)
bfae80f2 22599{
c19d1205
ZW
22600 int op, new_inst;
22601 unsigned long negated, inverted;
bfae80f2 22602
c19d1205
ZW
22603 negated = encode_arm_immediate (-value);
22604 inverted = encode_arm_immediate (~value);
bfae80f2 22605
c19d1205
ZW
22606 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
22607 switch (op)
bfae80f2 22608 {
c19d1205
ZW
22609 /* First negates. */
22610 case OPCODE_SUB: /* ADD <-> SUB */
22611 new_inst = OPCODE_ADD;
22612 value = negated;
22613 break;
bfae80f2 22614
c19d1205
ZW
22615 case OPCODE_ADD:
22616 new_inst = OPCODE_SUB;
22617 value = negated;
22618 break;
bfae80f2 22619
c19d1205
ZW
22620 case OPCODE_CMP: /* CMP <-> CMN */
22621 new_inst = OPCODE_CMN;
22622 value = negated;
22623 break;
bfae80f2 22624
c19d1205
ZW
22625 case OPCODE_CMN:
22626 new_inst = OPCODE_CMP;
22627 value = negated;
22628 break;
bfae80f2 22629
c19d1205
ZW
22630 /* Now Inverted ops. */
22631 case OPCODE_MOV: /* MOV <-> MVN */
22632 new_inst = OPCODE_MVN;
22633 value = inverted;
22634 break;
bfae80f2 22635
c19d1205
ZW
22636 case OPCODE_MVN:
22637 new_inst = OPCODE_MOV;
22638 value = inverted;
22639 break;
bfae80f2 22640
c19d1205
ZW
22641 case OPCODE_AND: /* AND <-> BIC */
22642 new_inst = OPCODE_BIC;
22643 value = inverted;
22644 break;
bfae80f2 22645
c19d1205
ZW
22646 case OPCODE_BIC:
22647 new_inst = OPCODE_AND;
22648 value = inverted;
22649 break;
bfae80f2 22650
c19d1205
ZW
22651 case OPCODE_ADC: /* ADC <-> SBC */
22652 new_inst = OPCODE_SBC;
22653 value = inverted;
22654 break;
bfae80f2 22655
c19d1205
ZW
22656 case OPCODE_SBC:
22657 new_inst = OPCODE_ADC;
22658 value = inverted;
22659 break;
bfae80f2 22660
c19d1205
ZW
22661 /* We cannot do anything. */
22662 default:
22663 return FAIL;
b99bd4ef
NC
22664 }
22665
c19d1205
ZW
22666 if (value == (unsigned) FAIL)
22667 return FAIL;
22668
22669 *instruction &= OPCODE_MASK;
22670 *instruction |= new_inst << DATA_OP_SHIFT;
22671 return value;
b99bd4ef
NC
22672}
22673
ef8d22e6
PB
22674/* Like negate_data_op, but for Thumb-2. */
22675
22676static unsigned int
16dd5e42 22677thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
22678{
22679 int op, new_inst;
22680 int rd;
16dd5e42 22681 unsigned int negated, inverted;
ef8d22e6
PB
22682
22683 negated = encode_thumb32_immediate (-value);
22684 inverted = encode_thumb32_immediate (~value);
22685
22686 rd = (*instruction >> 8) & 0xf;
22687 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
22688 switch (op)
22689 {
22690 /* ADD <-> SUB. Includes CMP <-> CMN. */
22691 case T2_OPCODE_SUB:
22692 new_inst = T2_OPCODE_ADD;
22693 value = negated;
22694 break;
22695
22696 case T2_OPCODE_ADD:
22697 new_inst = T2_OPCODE_SUB;
22698 value = negated;
22699 break;
22700
22701 /* ORR <-> ORN. Includes MOV <-> MVN. */
22702 case T2_OPCODE_ORR:
22703 new_inst = T2_OPCODE_ORN;
22704 value = inverted;
22705 break;
22706
22707 case T2_OPCODE_ORN:
22708 new_inst = T2_OPCODE_ORR;
22709 value = inverted;
22710 break;
22711
22712 /* AND <-> BIC. TST has no inverted equivalent. */
22713 case T2_OPCODE_AND:
22714 new_inst = T2_OPCODE_BIC;
22715 if (rd == 15)
22716 value = FAIL;
22717 else
22718 value = inverted;
22719 break;
22720
22721 case T2_OPCODE_BIC:
22722 new_inst = T2_OPCODE_AND;
22723 value = inverted;
22724 break;
22725
22726 /* ADC <-> SBC */
22727 case T2_OPCODE_ADC:
22728 new_inst = T2_OPCODE_SBC;
22729 value = inverted;
22730 break;
22731
22732 case T2_OPCODE_SBC:
22733 new_inst = T2_OPCODE_ADC;
22734 value = inverted;
22735 break;
22736
22737 /* We cannot do anything. */
22738 default:
22739 return FAIL;
22740 }
22741
16dd5e42 22742 if (value == (unsigned int)FAIL)
ef8d22e6
PB
22743 return FAIL;
22744
22745 *instruction &= T2_OPCODE_MASK;
22746 *instruction |= new_inst << T2_DATA_OP_SHIFT;
22747 return value;
22748}
22749
8f06b2d8
PB
22750/* Read a 32-bit thumb instruction from buf. */
22751static unsigned long
22752get_thumb32_insn (char * buf)
22753{
22754 unsigned long insn;
22755 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
22756 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22757
22758 return insn;
22759}
22760
a8bc6c78
PB
22761
22762/* We usually want to set the low bit on the address of thumb function
22763 symbols. In particular .word foo - . should have the low bit set.
22764 Generic code tries to fold the difference of two symbols to
22765 a constant. Prevent this and force a relocation when the first symbols
22766 is a thumb function. */
c921be7d
NC
22767
22768bfd_boolean
a8bc6c78
PB
22769arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
22770{
22771 if (op == O_subtract
22772 && l->X_op == O_symbol
22773 && r->X_op == O_symbol
22774 && THUMB_IS_FUNC (l->X_add_symbol))
22775 {
22776 l->X_op = O_subtract;
22777 l->X_op_symbol = r->X_add_symbol;
22778 l->X_add_number -= r->X_add_number;
c921be7d 22779 return TRUE;
a8bc6c78 22780 }
c921be7d 22781
a8bc6c78 22782 /* Process as normal. */
c921be7d 22783 return FALSE;
a8bc6c78
PB
22784}
22785
4a42ebbc
RR
22786/* Encode Thumb2 unconditional branches and calls. The encoding
22787 for the 2 are identical for the immediate values. */
22788
22789static void
22790encode_thumb2_b_bl_offset (char * buf, offsetT value)
22791{
22792#define T2I1I2MASK ((1 << 13) | (1 << 11))
22793 offsetT newval;
22794 offsetT newval2;
22795 addressT S, I1, I2, lo, hi;
22796
22797 S = (value >> 24) & 0x01;
22798 I1 = (value >> 23) & 0x01;
22799 I2 = (value >> 22) & 0x01;
22800 hi = (value >> 12) & 0x3ff;
fa94de6b 22801 lo = (value >> 1) & 0x7ff;
4a42ebbc
RR
22802 newval = md_chars_to_number (buf, THUMB_SIZE);
22803 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
22804 newval |= (S << 10) | hi;
22805 newval2 &= ~T2I1I2MASK;
22806 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
22807 md_number_to_chars (buf, newval, THUMB_SIZE);
22808 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
22809}
22810
c19d1205 22811void
55cf6793 22812md_apply_fix (fixS * fixP,
c19d1205
ZW
22813 valueT * valP,
22814 segT seg)
22815{
22816 offsetT value = * valP;
22817 offsetT newval;
22818 unsigned int newimm;
22819 unsigned long temp;
22820 int sign;
22821 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 22822
9c2799c2 22823 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 22824
c19d1205 22825 /* Note whether this will delete the relocation. */
4962c51a 22826
c19d1205
ZW
22827 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
22828 fixP->fx_done = 1;
b99bd4ef 22829
adbaf948 22830 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 22831 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
22832 for emit_reloc. */
22833 value &= 0xffffffff;
22834 value ^= 0x80000000;
5f4273c7 22835 value -= 0x80000000;
adbaf948
ZW
22836
22837 *valP = value;
c19d1205 22838 fixP->fx_addnumber = value;
b99bd4ef 22839
adbaf948
ZW
22840 /* Same treatment for fixP->fx_offset. */
22841 fixP->fx_offset &= 0xffffffff;
22842 fixP->fx_offset ^= 0x80000000;
22843 fixP->fx_offset -= 0x80000000;
22844
c19d1205 22845 switch (fixP->fx_r_type)
b99bd4ef 22846 {
c19d1205
ZW
22847 case BFD_RELOC_NONE:
22848 /* This will need to go in the object file. */
22849 fixP->fx_done = 0;
22850 break;
b99bd4ef 22851
c19d1205
ZW
22852 case BFD_RELOC_ARM_IMMEDIATE:
22853 /* We claim that this fixup has been processed here,
22854 even if in fact we generate an error because we do
22855 not have a reloc for it, so tc_gen_reloc will reject it. */
22856 fixP->fx_done = 1;
b99bd4ef 22857
77db8e2e 22858 if (fixP->fx_addsy)
b99bd4ef 22859 {
77db8e2e 22860 const char *msg = 0;
b99bd4ef 22861
77db8e2e
NC
22862 if (! S_IS_DEFINED (fixP->fx_addsy))
22863 msg = _("undefined symbol %s used as an immediate value");
22864 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22865 msg = _("symbol %s is in a different section");
22866 else if (S_IS_WEAK (fixP->fx_addsy))
22867 msg = _("symbol %s is weak and may be overridden later");
22868
22869 if (msg)
22870 {
22871 as_bad_where (fixP->fx_file, fixP->fx_line,
22872 msg, S_GET_NAME (fixP->fx_addsy));
22873 break;
22874 }
42e5fcbf
AS
22875 }
22876
c19d1205
ZW
22877 temp = md_chars_to_number (buf, INSN_SIZE);
22878
5e73442d
SL
22879 /* If the offset is negative, we should use encoding A2 for ADR. */
22880 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
22881 newimm = negate_data_op (&temp, value);
22882 else
22883 {
22884 newimm = encode_arm_immediate (value);
22885
22886 /* If the instruction will fail, see if we can fix things up by
22887 changing the opcode. */
22888 if (newimm == (unsigned int) FAIL)
22889 newimm = negate_data_op (&temp, value);
bada4342
JW
22890 /* MOV accepts both ARM modified immediate (A1 encoding) and
22891 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
22892 When disassembling, MOV is preferred when there is no encoding
22893 overlap. */
22894 if (newimm == (unsigned int) FAIL
22895 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
22896 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
22897 && !((temp >> SBIT_SHIFT) & 0x1)
22898 && value >= 0 && value <= 0xffff)
22899 {
22900 /* Clear bits[23:20] to change encoding from A1 to A2. */
22901 temp &= 0xff0fffff;
22902 /* Encoding high 4bits imm. Code below will encode the remaining
22903 low 12bits. */
22904 temp |= (value & 0x0000f000) << 4;
22905 newimm = value & 0x00000fff;
22906 }
5e73442d
SL
22907 }
22908
22909 if (newimm == (unsigned int) FAIL)
b99bd4ef 22910 {
c19d1205
ZW
22911 as_bad_where (fixP->fx_file, fixP->fx_line,
22912 _("invalid constant (%lx) after fixup"),
22913 (unsigned long) value);
22914 break;
b99bd4ef 22915 }
b99bd4ef 22916
c19d1205
ZW
22917 newimm |= (temp & 0xfffff000);
22918 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
22919 break;
b99bd4ef 22920
c19d1205
ZW
22921 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22922 {
22923 unsigned int highpart = 0;
22924 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 22925
77db8e2e 22926 if (fixP->fx_addsy)
42e5fcbf 22927 {
77db8e2e 22928 const char *msg = 0;
42e5fcbf 22929
77db8e2e
NC
22930 if (! S_IS_DEFINED (fixP->fx_addsy))
22931 msg = _("undefined symbol %s used as an immediate value");
22932 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
22933 msg = _("symbol %s is in a different section");
22934 else if (S_IS_WEAK (fixP->fx_addsy))
22935 msg = _("symbol %s is weak and may be overridden later");
42e5fcbf 22936
77db8e2e
NC
22937 if (msg)
22938 {
22939 as_bad_where (fixP->fx_file, fixP->fx_line,
22940 msg, S_GET_NAME (fixP->fx_addsy));
22941 break;
22942 }
22943 }
fa94de6b 22944
c19d1205
ZW
22945 newimm = encode_arm_immediate (value);
22946 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 22947
c19d1205
ZW
22948 /* If the instruction will fail, see if we can fix things up by
22949 changing the opcode. */
22950 if (newimm == (unsigned int) FAIL
22951 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
22952 {
22953 /* No ? OK - try using two ADD instructions to generate
22954 the value. */
22955 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 22956
c19d1205
ZW
22957 /* Yes - then make sure that the second instruction is
22958 also an add. */
22959 if (newimm != (unsigned int) FAIL)
22960 newinsn = temp;
22961 /* Still No ? Try using a negated value. */
22962 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
22963 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
22964 /* Otherwise - give up. */
22965 else
22966 {
22967 as_bad_where (fixP->fx_file, fixP->fx_line,
22968 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
22969 (long) value);
22970 break;
22971 }
b99bd4ef 22972
c19d1205
ZW
22973 /* Replace the first operand in the 2nd instruction (which
22974 is the PC) with the destination register. We have
22975 already added in the PC in the first instruction and we
22976 do not want to do it again. */
22977 newinsn &= ~ 0xf0000;
22978 newinsn |= ((newinsn & 0x0f000) << 4);
22979 }
b99bd4ef 22980
c19d1205
ZW
22981 newimm |= (temp & 0xfffff000);
22982 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 22983
c19d1205
ZW
22984 highpart |= (newinsn & 0xfffff000);
22985 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
22986 }
22987 break;
b99bd4ef 22988
c19d1205 22989 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
22990 if (!fixP->fx_done && seg->use_rela_p)
22991 value = 0;
1a0670f3 22992 /* Fall through. */
00a97672 22993
c19d1205 22994 case BFD_RELOC_ARM_LITERAL:
26d97720 22995 sign = value > 0;
b99bd4ef 22996
c19d1205
ZW
22997 if (value < 0)
22998 value = - value;
b99bd4ef 22999
c19d1205 23000 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 23001 {
c19d1205
ZW
23002 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
23003 as_bad_where (fixP->fx_file, fixP->fx_line,
23004 _("invalid literal constant: pool needs to be closer"));
23005 else
23006 as_bad_where (fixP->fx_file, fixP->fx_line,
23007 _("bad immediate value for offset (%ld)"),
23008 (long) value);
23009 break;
f03698e6
RE
23010 }
23011
c19d1205 23012 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23013 if (value == 0)
23014 newval &= 0xfffff000;
23015 else
23016 {
23017 newval &= 0xff7ff000;
23018 newval |= value | (sign ? INDEX_UP : 0);
23019 }
c19d1205
ZW
23020 md_number_to_chars (buf, newval, INSN_SIZE);
23021 break;
b99bd4ef 23022
c19d1205
ZW
23023 case BFD_RELOC_ARM_OFFSET_IMM8:
23024 case BFD_RELOC_ARM_HWLITERAL:
26d97720 23025 sign = value > 0;
b99bd4ef 23026
c19d1205
ZW
23027 if (value < 0)
23028 value = - value;
b99bd4ef 23029
c19d1205 23030 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 23031 {
c19d1205
ZW
23032 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
23033 as_bad_where (fixP->fx_file, fixP->fx_line,
23034 _("invalid literal constant: pool needs to be closer"));
23035 else
427d0db6
RM
23036 as_bad_where (fixP->fx_file, fixP->fx_line,
23037 _("bad immediate value for 8-bit offset (%ld)"),
23038 (long) value);
c19d1205 23039 break;
b99bd4ef
NC
23040 }
23041
c19d1205 23042 newval = md_chars_to_number (buf, INSN_SIZE);
26d97720
NS
23043 if (value == 0)
23044 newval &= 0xfffff0f0;
23045 else
23046 {
23047 newval &= 0xff7ff0f0;
23048 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
23049 }
c19d1205
ZW
23050 md_number_to_chars (buf, newval, INSN_SIZE);
23051 break;
b99bd4ef 23052
c19d1205
ZW
23053 case BFD_RELOC_ARM_T32_OFFSET_U8:
23054 if (value < 0 || value > 1020 || value % 4 != 0)
23055 as_bad_where (fixP->fx_file, fixP->fx_line,
23056 _("bad immediate value for offset (%ld)"), (long) value);
23057 value /= 4;
b99bd4ef 23058
c19d1205 23059 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
23060 newval |= value;
23061 md_number_to_chars (buf+2, newval, THUMB_SIZE);
23062 break;
b99bd4ef 23063
c19d1205
ZW
23064 case BFD_RELOC_ARM_T32_OFFSET_IMM:
23065 /* This is a complicated relocation used for all varieties of Thumb32
23066 load/store instruction with immediate offset:
23067
23068 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
477330fc 23069 *4, optional writeback(W)
c19d1205
ZW
23070 (doubleword load/store)
23071
23072 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
23073 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
23074 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
23075 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
23076 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
23077
23078 Uppercase letters indicate bits that are already encoded at
23079 this point. Lowercase letters are our problem. For the
23080 second block of instructions, the secondary opcode nybble
23081 (bits 8..11) is present, and bit 23 is zero, even if this is
23082 a PC-relative operation. */
23083 newval = md_chars_to_number (buf, THUMB_SIZE);
23084 newval <<= 16;
23085 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 23086
c19d1205 23087 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 23088 {
c19d1205
ZW
23089 /* Doubleword load/store: 8-bit offset, scaled by 4. */
23090 if (value >= 0)
23091 newval |= (1 << 23);
23092 else
23093 value = -value;
23094 if (value % 4 != 0)
23095 {
23096 as_bad_where (fixP->fx_file, fixP->fx_line,
23097 _("offset not a multiple of 4"));
23098 break;
23099 }
23100 value /= 4;
216d22bc 23101 if (value > 0xff)
c19d1205
ZW
23102 {
23103 as_bad_where (fixP->fx_file, fixP->fx_line,
23104 _("offset out of range"));
23105 break;
23106 }
23107 newval &= ~0xff;
b99bd4ef 23108 }
c19d1205 23109 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 23110 {
c19d1205
ZW
23111 /* PC-relative, 12-bit offset. */
23112 if (value >= 0)
23113 newval |= (1 << 23);
23114 else
23115 value = -value;
216d22bc 23116 if (value > 0xfff)
c19d1205
ZW
23117 {
23118 as_bad_where (fixP->fx_file, fixP->fx_line,
23119 _("offset out of range"));
23120 break;
23121 }
23122 newval &= ~0xfff;
b99bd4ef 23123 }
c19d1205 23124 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 23125 {
c19d1205
ZW
23126 /* Writeback: 8-bit, +/- offset. */
23127 if (value >= 0)
23128 newval |= (1 << 9);
23129 else
23130 value = -value;
216d22bc 23131 if (value > 0xff)
c19d1205
ZW
23132 {
23133 as_bad_where (fixP->fx_file, fixP->fx_line,
23134 _("offset out of range"));
23135 break;
23136 }
23137 newval &= ~0xff;
b99bd4ef 23138 }
c19d1205 23139 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 23140 {
c19d1205 23141 /* T-instruction: positive 8-bit offset. */
216d22bc 23142 if (value < 0 || value > 0xff)
b99bd4ef 23143 {
c19d1205
ZW
23144 as_bad_where (fixP->fx_file, fixP->fx_line,
23145 _("offset out of range"));
23146 break;
b99bd4ef 23147 }
c19d1205
ZW
23148 newval &= ~0xff;
23149 newval |= value;
b99bd4ef
NC
23150 }
23151 else
b99bd4ef 23152 {
c19d1205
ZW
23153 /* Positive 12-bit or negative 8-bit offset. */
23154 int limit;
23155 if (value >= 0)
b99bd4ef 23156 {
c19d1205
ZW
23157 newval |= (1 << 23);
23158 limit = 0xfff;
23159 }
23160 else
23161 {
23162 value = -value;
23163 limit = 0xff;
23164 }
23165 if (value > limit)
23166 {
23167 as_bad_where (fixP->fx_file, fixP->fx_line,
23168 _("offset out of range"));
23169 break;
b99bd4ef 23170 }
c19d1205 23171 newval &= ~limit;
b99bd4ef 23172 }
b99bd4ef 23173
c19d1205
ZW
23174 newval |= value;
23175 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
23176 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
23177 break;
404ff6b5 23178
c19d1205
ZW
23179 case BFD_RELOC_ARM_SHIFT_IMM:
23180 newval = md_chars_to_number (buf, INSN_SIZE);
23181 if (((unsigned long) value) > 32
23182 || (value == 32
23183 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
23184 {
23185 as_bad_where (fixP->fx_file, fixP->fx_line,
23186 _("shift expression is too large"));
23187 break;
23188 }
404ff6b5 23189
c19d1205
ZW
23190 if (value == 0)
23191 /* Shifts of zero must be done as lsl. */
23192 newval &= ~0x60;
23193 else if (value == 32)
23194 value = 0;
23195 newval &= 0xfffff07f;
23196 newval |= (value & 0x1f) << 7;
23197 md_number_to_chars (buf, newval, INSN_SIZE);
23198 break;
404ff6b5 23199
c19d1205 23200 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 23201 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 23202 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 23203 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
23204 /* We claim that this fixup has been processed here,
23205 even if in fact we generate an error because we do
23206 not have a reloc for it, so tc_gen_reloc will reject it. */
23207 fixP->fx_done = 1;
404ff6b5 23208
c19d1205
ZW
23209 if (fixP->fx_addsy
23210 && ! S_IS_DEFINED (fixP->fx_addsy))
23211 {
23212 as_bad_where (fixP->fx_file, fixP->fx_line,
23213 _("undefined symbol %s used as an immediate value"),
23214 S_GET_NAME (fixP->fx_addsy));
23215 break;
23216 }
404ff6b5 23217
c19d1205
ZW
23218 newval = md_chars_to_number (buf, THUMB_SIZE);
23219 newval <<= 16;
23220 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 23221
16805f35 23222 newimm = FAIL;
bada4342
JW
23223 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23224 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
23225 Thumb2 modified immediate encoding (T2). */
23226 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
16805f35 23227 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
23228 {
23229 newimm = encode_thumb32_immediate (value);
23230 if (newimm == (unsigned int) FAIL)
23231 newimm = thumb32_negate_data_op (&newval, value);
23232 }
bada4342 23233 if (newimm == (unsigned int) FAIL)
92e90b6e 23234 {
bada4342 23235 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
e9f89963 23236 {
bada4342
JW
23237 /* Turn add/sum into addw/subw. */
23238 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23239 newval = (newval & 0xfeffffff) | 0x02000000;
23240 /* No flat 12-bit imm encoding for addsw/subsw. */
23241 if ((newval & 0x00100000) == 0)
40f246e3 23242 {
bada4342
JW
23243 /* 12 bit immediate for addw/subw. */
23244 if (value < 0)
23245 {
23246 value = -value;
23247 newval ^= 0x00a00000;
23248 }
23249 if (value > 0xfff)
23250 newimm = (unsigned int) FAIL;
23251 else
23252 newimm = value;
23253 }
23254 }
23255 else
23256 {
23257 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
23258 UINT16 (T3 encoding), MOVW only accepts UINT16. When
23259 disassembling, MOV is preferred when there is no encoding
23260 overlap.
23261 NOTE: MOV is using ORR opcode under Thumb 2 mode. */
23262 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
23263 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
23264 && !((newval >> T2_SBIT_SHIFT) & 0x1)
23265 && value >= 0 && value <=0xffff)
23266 {
23267 /* Toggle bit[25] to change encoding from T2 to T3. */
23268 newval ^= 1 << 25;
23269 /* Clear bits[19:16]. */
23270 newval &= 0xfff0ffff;
23271 /* Encoding high 4bits imm. Code below will encode the
23272 remaining low 12bits. */
23273 newval |= (value & 0x0000f000) << 4;
23274 newimm = value & 0x00000fff;
40f246e3 23275 }
e9f89963 23276 }
92e90b6e 23277 }
cc8a6dd0 23278
c19d1205 23279 if (newimm == (unsigned int)FAIL)
3631a3c8 23280 {
c19d1205
ZW
23281 as_bad_where (fixP->fx_file, fixP->fx_line,
23282 _("invalid constant (%lx) after fixup"),
23283 (unsigned long) value);
23284 break;
3631a3c8
NC
23285 }
23286
c19d1205
ZW
23287 newval |= (newimm & 0x800) << 15;
23288 newval |= (newimm & 0x700) << 4;
23289 newval |= (newimm & 0x0ff);
cc8a6dd0 23290
c19d1205
ZW
23291 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
23292 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
23293 break;
a737bd4d 23294
3eb17e6b 23295 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
23296 if (((unsigned long) value) > 0xffff)
23297 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 23298 _("invalid smc expression"));
2fc8bdac 23299 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23300 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23301 md_number_to_chars (buf, newval, INSN_SIZE);
23302 break;
a737bd4d 23303
90ec0d68
MGD
23304 case BFD_RELOC_ARM_HVC:
23305 if (((unsigned long) value) > 0xffff)
23306 as_bad_where (fixP->fx_file, fixP->fx_line,
23307 _("invalid hvc expression"));
23308 newval = md_chars_to_number (buf, INSN_SIZE);
23309 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23310 md_number_to_chars (buf, newval, INSN_SIZE);
23311 break;
23312
c19d1205 23313 case BFD_RELOC_ARM_SWI:
adbaf948 23314 if (fixP->tc_fix_data != 0)
c19d1205
ZW
23315 {
23316 if (((unsigned long) value) > 0xff)
23317 as_bad_where (fixP->fx_file, fixP->fx_line,
23318 _("invalid swi expression"));
2fc8bdac 23319 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
23320 newval |= value;
23321 md_number_to_chars (buf, newval, THUMB_SIZE);
23322 }
23323 else
23324 {
23325 if (((unsigned long) value) > 0x00ffffff)
23326 as_bad_where (fixP->fx_file, fixP->fx_line,
23327 _("invalid swi expression"));
2fc8bdac 23328 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
23329 newval |= value;
23330 md_number_to_chars (buf, newval, INSN_SIZE);
23331 }
23332 break;
a737bd4d 23333
c19d1205
ZW
23334 case BFD_RELOC_ARM_MULTI:
23335 if (((unsigned long) value) > 0xffff)
23336 as_bad_where (fixP->fx_file, fixP->fx_line,
23337 _("invalid expression in load/store multiple"));
23338 newval = value | md_chars_to_number (buf, INSN_SIZE);
23339 md_number_to_chars (buf, newval, INSN_SIZE);
23340 break;
a737bd4d 23341
c19d1205 23342#ifdef OBJ_ELF
39b41c9c 23343 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
23344
23345 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23346 && fixP->fx_addsy
34e77a92 23347 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23348 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23349 && THUMB_IS_FUNC (fixP->fx_addsy))
23350 /* Flip the bl to blx. This is a simple flip
23351 bit here because we generate PCREL_CALL for
23352 unconditional bls. */
23353 {
23354 newval = md_chars_to_number (buf, INSN_SIZE);
23355 newval = newval | 0x10000000;
23356 md_number_to_chars (buf, newval, INSN_SIZE);
23357 temp = 1;
23358 fixP->fx_done = 1;
23359 }
39b41c9c
PB
23360 else
23361 temp = 3;
23362 goto arm_branch_common;
23363
23364 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
23365 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23366 && fixP->fx_addsy
34e77a92 23367 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23368 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23369 && THUMB_IS_FUNC (fixP->fx_addsy))
23370 {
23371 /* This would map to a bl<cond>, b<cond>,
23372 b<always> to a Thumb function. We
23373 need to force a relocation for this particular
23374 case. */
23375 newval = md_chars_to_number (buf, INSN_SIZE);
23376 fixP->fx_done = 0;
23377 }
1a0670f3 23378 /* Fall through. */
267bf995 23379
2fc8bdac 23380 case BFD_RELOC_ARM_PLT32:
c19d1205 23381#endif
39b41c9c
PB
23382 case BFD_RELOC_ARM_PCREL_BRANCH:
23383 temp = 3;
23384 goto arm_branch_common;
a737bd4d 23385
39b41c9c 23386 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 23387
39b41c9c 23388 temp = 1;
267bf995
RR
23389 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23390 && fixP->fx_addsy
34e77a92 23391 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23392 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23393 && ARM_IS_FUNC (fixP->fx_addsy))
23394 {
23395 /* Flip the blx to a bl and warn. */
23396 const char *name = S_GET_NAME (fixP->fx_addsy);
23397 newval = 0xeb000000;
23398 as_warn_where (fixP->fx_file, fixP->fx_line,
23399 _("blx to '%s' an ARM ISA state function changed to bl"),
23400 name);
23401 md_number_to_chars (buf, newval, INSN_SIZE);
23402 temp = 3;
23403 fixP->fx_done = 1;
23404 }
23405
23406#ifdef OBJ_ELF
23407 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
477330fc 23408 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
267bf995
RR
23409#endif
23410
39b41c9c 23411 arm_branch_common:
c19d1205 23412 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
23413 instruction, in a 24 bit, signed field. Bits 26 through 32 either
23414 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
23415 also be be clear. */
23416 if (value & temp)
c19d1205 23417 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
23418 _("misaligned branch destination"));
23419 if ((value & (offsetT)0xfe000000) != (offsetT)0
23420 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
08f10d51 23421 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23422
2fc8bdac 23423 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23424 {
2fc8bdac
ZW
23425 newval = md_chars_to_number (buf, INSN_SIZE);
23426 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
23427 /* Set the H bit on BLX instructions. */
23428 if (temp == 1)
23429 {
23430 if (value & 2)
23431 newval |= 0x01000000;
23432 else
23433 newval &= ~0x01000000;
23434 }
2fc8bdac 23435 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 23436 }
c19d1205 23437 break;
a737bd4d 23438
25fe350b
MS
23439 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
23440 /* CBZ can only branch forward. */
a737bd4d 23441
738755b0 23442 /* Attempts to use CBZ to branch to the next instruction
477330fc
RM
23443 (which, strictly speaking, are prohibited) will be turned into
23444 no-ops.
738755b0
MS
23445
23446 FIXME: It may be better to remove the instruction completely and
23447 perform relaxation. */
23448 if (value == -2)
2fc8bdac
ZW
23449 {
23450 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 23451 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
23452 md_number_to_chars (buf, newval, THUMB_SIZE);
23453 }
738755b0
MS
23454 else
23455 {
23456 if (value & ~0x7e)
08f10d51 23457 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
738755b0 23458
477330fc 23459 if (fixP->fx_done || !seg->use_rela_p)
738755b0
MS
23460 {
23461 newval = md_chars_to_number (buf, THUMB_SIZE);
23462 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
23463 md_number_to_chars (buf, newval, THUMB_SIZE);
23464 }
23465 }
c19d1205 23466 break;
a737bd4d 23467
c19d1205 23468 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac 23469 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
08f10d51 23470 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23471
2fc8bdac
ZW
23472 if (fixP->fx_done || !seg->use_rela_p)
23473 {
23474 newval = md_chars_to_number (buf, THUMB_SIZE);
23475 newval |= (value & 0x1ff) >> 1;
23476 md_number_to_chars (buf, newval, THUMB_SIZE);
23477 }
c19d1205 23478 break;
a737bd4d 23479
c19d1205 23480 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac 23481 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
08f10d51 23482 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
a737bd4d 23483
2fc8bdac
ZW
23484 if (fixP->fx_done || !seg->use_rela_p)
23485 {
23486 newval = md_chars_to_number (buf, THUMB_SIZE);
23487 newval |= (value & 0xfff) >> 1;
23488 md_number_to_chars (buf, newval, THUMB_SIZE);
23489 }
c19d1205 23490 break;
a737bd4d 23491
c19d1205 23492 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
23493 if (fixP->fx_addsy
23494 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23495 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23496 && ARM_IS_FUNC (fixP->fx_addsy)
23497 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23498 {
23499 /* Force a relocation for a branch 20 bits wide. */
23500 fixP->fx_done = 0;
23501 }
08f10d51 23502 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
2fc8bdac
ZW
23503 as_bad_where (fixP->fx_file, fixP->fx_line,
23504 _("conditional branch out of range"));
404ff6b5 23505
2fc8bdac
ZW
23506 if (fixP->fx_done || !seg->use_rela_p)
23507 {
23508 offsetT newval2;
23509 addressT S, J1, J2, lo, hi;
404ff6b5 23510
2fc8bdac
ZW
23511 S = (value & 0x00100000) >> 20;
23512 J2 = (value & 0x00080000) >> 19;
23513 J1 = (value & 0x00040000) >> 18;
23514 hi = (value & 0x0003f000) >> 12;
23515 lo = (value & 0x00000ffe) >> 1;
6c43fab6 23516
2fc8bdac
ZW
23517 newval = md_chars_to_number (buf, THUMB_SIZE);
23518 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23519 newval |= (S << 10) | hi;
23520 newval2 |= (J1 << 13) | (J2 << 11) | lo;
23521 md_number_to_chars (buf, newval, THUMB_SIZE);
23522 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23523 }
c19d1205 23524 break;
6c43fab6 23525
c19d1205 23526 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
23527 /* If there is a blx from a thumb state function to
23528 another thumb function flip this to a bl and warn
23529 about it. */
23530
23531 if (fixP->fx_addsy
34e77a92 23532 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23533 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23534 && THUMB_IS_FUNC (fixP->fx_addsy))
23535 {
23536 const char *name = S_GET_NAME (fixP->fx_addsy);
23537 as_warn_where (fixP->fx_file, fixP->fx_line,
23538 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
23539 name);
23540 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23541 newval = newval | 0x1000;
23542 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23543 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23544 fixP->fx_done = 1;
23545 }
23546
23547
23548 goto thumb_bl_common;
23549
c19d1205 23550 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
23551 /* A bl from Thumb state ISA to an internal ARM state function
23552 is converted to a blx. */
23553 if (fixP->fx_addsy
23554 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
34e77a92 23555 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
267bf995
RR
23556 && ARM_IS_FUNC (fixP->fx_addsy)
23557 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23558 {
23559 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23560 newval = newval & ~0x1000;
23561 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23562 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
23563 fixP->fx_done = 1;
23564 }
23565
23566 thumb_bl_common:
23567
2fc8bdac
ZW
23568 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23569 /* For a BLX instruction, make sure that the relocation is rounded up
23570 to a word boundary. This follows the semantics of the instruction
23571 which specifies that bit 1 of the target address will come from bit
23572 1 of the base address. */
d406f3e4
JB
23573 value = (value + 3) & ~ 3;
23574
23575#ifdef OBJ_ELF
23576 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
23577 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23578 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23579#endif
404ff6b5 23580
2b2f5df9
NC
23581 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
23582 {
fc289b0a 23583 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
2b2f5df9
NC
23584 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23585 else if ((value & ~0x1ffffff)
23586 && ((value & ~0x1ffffff) != ~0x1ffffff))
23587 as_bad_where (fixP->fx_file, fixP->fx_line,
23588 _("Thumb2 branch out of range"));
23589 }
4a42ebbc
RR
23590
23591 if (fixP->fx_done || !seg->use_rela_p)
23592 encode_thumb2_b_bl_offset (buf, value);
23593
c19d1205 23594 break;
404ff6b5 23595
c19d1205 23596 case BFD_RELOC_THUMB_PCREL_BRANCH25:
08f10d51
NC
23597 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
23598 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
6c43fab6 23599
2fc8bdac 23600 if (fixP->fx_done || !seg->use_rela_p)
4a42ebbc 23601 encode_thumb2_b_bl_offset (buf, value);
6c43fab6 23602
2fc8bdac 23603 break;
a737bd4d 23604
2fc8bdac
ZW
23605 case BFD_RELOC_8:
23606 if (fixP->fx_done || !seg->use_rela_p)
4b1a927e 23607 *buf = value;
c19d1205 23608 break;
a737bd4d 23609
c19d1205 23610 case BFD_RELOC_16:
2fc8bdac 23611 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 23612 md_number_to_chars (buf, value, 2);
c19d1205 23613 break;
a737bd4d 23614
c19d1205 23615#ifdef OBJ_ELF
0855e32b
NS
23616 case BFD_RELOC_ARM_TLS_CALL:
23617 case BFD_RELOC_ARM_THM_TLS_CALL:
23618 case BFD_RELOC_ARM_TLS_DESCSEQ:
23619 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
0855e32b 23620 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205
ZW
23621 case BFD_RELOC_ARM_TLS_GD32:
23622 case BFD_RELOC_ARM_TLS_LE32:
23623 case BFD_RELOC_ARM_TLS_IE32:
23624 case BFD_RELOC_ARM_TLS_LDM32:
23625 case BFD_RELOC_ARM_TLS_LDO32:
23626 S_SET_THREAD_LOCAL (fixP->fx_addsy);
4b1a927e 23627 break;
6c43fab6 23628
c19d1205
ZW
23629 case BFD_RELOC_ARM_GOT32:
23630 case BFD_RELOC_ARM_GOTOFF:
c19d1205 23631 break;
b43420e6
NC
23632
23633 case BFD_RELOC_ARM_GOT_PREL:
23634 if (fixP->fx_done || !seg->use_rela_p)
477330fc 23635 md_number_to_chars (buf, value, 4);
b43420e6
NC
23636 break;
23637
9a6f4e97
NS
23638 case BFD_RELOC_ARM_TARGET2:
23639 /* TARGET2 is not partial-inplace, so we need to write the
477330fc
RM
23640 addend here for REL targets, because it won't be written out
23641 during reloc processing later. */
9a6f4e97
NS
23642 if (fixP->fx_done || !seg->use_rela_p)
23643 md_number_to_chars (buf, fixP->fx_offset, 4);
23644 break;
c19d1205 23645#endif
6c43fab6 23646
c19d1205
ZW
23647 case BFD_RELOC_RVA:
23648 case BFD_RELOC_32:
23649 case BFD_RELOC_ARM_TARGET1:
23650 case BFD_RELOC_ARM_ROSEGREL32:
23651 case BFD_RELOC_ARM_SBREL32:
23652 case BFD_RELOC_32_PCREL:
f0927246
NC
23653#ifdef TE_PE
23654 case BFD_RELOC_32_SECREL:
23655#endif
2fc8bdac 23656 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
23657#ifdef TE_WINCE
23658 /* For WinCE we only do this for pcrel fixups. */
23659 if (fixP->fx_done || fixP->fx_pcrel)
23660#endif
23661 md_number_to_chars (buf, value, 4);
c19d1205 23662 break;
6c43fab6 23663
c19d1205
ZW
23664#ifdef OBJ_ELF
23665 case BFD_RELOC_ARM_PREL31:
2fc8bdac 23666 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
23667 {
23668 newval = md_chars_to_number (buf, 4) & 0x80000000;
23669 if ((value ^ (value >> 1)) & 0x40000000)
23670 {
23671 as_bad_where (fixP->fx_file, fixP->fx_line,
23672 _("rel31 relocation overflow"));
23673 }
23674 newval |= value & 0x7fffffff;
23675 md_number_to_chars (buf, newval, 4);
23676 }
23677 break;
c19d1205 23678#endif
a737bd4d 23679
c19d1205 23680 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 23681 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
9db2f6b4
RL
23682 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
23683 newval = md_chars_to_number (buf, INSN_SIZE);
23684 else
23685 newval = get_thumb32_insn (buf);
23686 if ((newval & 0x0f200f00) == 0x0d000900)
23687 {
23688 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
23689 has permitted values that are multiples of 2, in the range 0
23690 to 510. */
23691 if (value < -510 || value > 510 || (value & 1))
23692 as_bad_where (fixP->fx_file, fixP->fx_line,
23693 _("co-processor offset out of range"));
23694 }
23695 else if (value < -1023 || value > 1023 || (value & 3))
c19d1205
ZW
23696 as_bad_where (fixP->fx_file, fixP->fx_line,
23697 _("co-processor offset out of range"));
23698 cp_off_common:
26d97720 23699 sign = value > 0;
c19d1205
ZW
23700 if (value < 0)
23701 value = -value;
8f06b2d8
PB
23702 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23703 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23704 newval = md_chars_to_number (buf, INSN_SIZE);
23705 else
23706 newval = get_thumb32_insn (buf);
26d97720
NS
23707 if (value == 0)
23708 newval &= 0xffffff00;
23709 else
23710 {
23711 newval &= 0xff7fff00;
9db2f6b4
RL
23712 if ((newval & 0x0f200f00) == 0x0d000900)
23713 {
23714 /* This is a fp16 vstr/vldr.
23715
23716 It requires the immediate offset in the instruction is shifted
23717 left by 1 to be a half-word offset.
23718
23719 Here, left shift by 1 first, and later right shift by 2
23720 should get the right offset. */
23721 value <<= 1;
23722 }
26d97720
NS
23723 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
23724 }
8f06b2d8
PB
23725 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
23726 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
23727 md_number_to_chars (buf, newval, INSN_SIZE);
23728 else
23729 put_thumb32_insn (buf, newval);
c19d1205 23730 break;
a737bd4d 23731
c19d1205 23732 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 23733 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
23734 if (value < -255 || value > 255)
23735 as_bad_where (fixP->fx_file, fixP->fx_line,
23736 _("co-processor offset out of range"));
df7849c5 23737 value *= 4;
c19d1205 23738 goto cp_off_common;
6c43fab6 23739
c19d1205
ZW
23740 case BFD_RELOC_ARM_THUMB_OFFSET:
23741 newval = md_chars_to_number (buf, THUMB_SIZE);
23742 /* Exactly what ranges, and where the offset is inserted depends
23743 on the type of instruction, we can establish this from the
23744 top 4 bits. */
23745 switch (newval >> 12)
23746 {
23747 case 4: /* PC load. */
23748 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
23749 forced to zero for these loads; md_pcrel_from has already
23750 compensated for this. */
23751 if (value & 3)
23752 as_bad_where (fixP->fx_file, fixP->fx_line,
23753 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
23754 (((unsigned long) fixP->fx_frag->fr_address
23755 + (unsigned long) fixP->fx_where) & ~3)
23756 + (unsigned long) value);
a737bd4d 23757
c19d1205
ZW
23758 if (value & ~0x3fc)
23759 as_bad_where (fixP->fx_file, fixP->fx_line,
23760 _("invalid offset, value too big (0x%08lX)"),
23761 (long) value);
a737bd4d 23762
c19d1205
ZW
23763 newval |= value >> 2;
23764 break;
a737bd4d 23765
c19d1205
ZW
23766 case 9: /* SP load/store. */
23767 if (value & ~0x3fc)
23768 as_bad_where (fixP->fx_file, fixP->fx_line,
23769 _("invalid offset, value too big (0x%08lX)"),
23770 (long) value);
23771 newval |= value >> 2;
23772 break;
6c43fab6 23773
c19d1205
ZW
23774 case 6: /* Word load/store. */
23775 if (value & ~0x7c)
23776 as_bad_where (fixP->fx_file, fixP->fx_line,
23777 _("invalid offset, value too big (0x%08lX)"),
23778 (long) value);
23779 newval |= value << 4; /* 6 - 2. */
23780 break;
a737bd4d 23781
c19d1205
ZW
23782 case 7: /* Byte load/store. */
23783 if (value & ~0x1f)
23784 as_bad_where (fixP->fx_file, fixP->fx_line,
23785 _("invalid offset, value too big (0x%08lX)"),
23786 (long) value);
23787 newval |= value << 6;
23788 break;
a737bd4d 23789
c19d1205
ZW
23790 case 8: /* Halfword load/store. */
23791 if (value & ~0x3e)
23792 as_bad_where (fixP->fx_file, fixP->fx_line,
23793 _("invalid offset, value too big (0x%08lX)"),
23794 (long) value);
23795 newval |= value << 5; /* 6 - 1. */
23796 break;
a737bd4d 23797
c19d1205
ZW
23798 default:
23799 as_bad_where (fixP->fx_file, fixP->fx_line,
23800 "Unable to process relocation for thumb opcode: %lx",
23801 (unsigned long) newval);
23802 break;
23803 }
23804 md_number_to_chars (buf, newval, THUMB_SIZE);
23805 break;
a737bd4d 23806
c19d1205
ZW
23807 case BFD_RELOC_ARM_THUMB_ADD:
23808 /* This is a complicated relocation, since we use it for all of
23809 the following immediate relocations:
a737bd4d 23810
c19d1205
ZW
23811 3bit ADD/SUB
23812 8bit ADD/SUB
23813 9bit ADD/SUB SP word-aligned
23814 10bit ADD PC/SP word-aligned
a737bd4d 23815
c19d1205
ZW
23816 The type of instruction being processed is encoded in the
23817 instruction field:
a737bd4d 23818
c19d1205
ZW
23819 0x8000 SUB
23820 0x00F0 Rd
23821 0x000F Rs
23822 */
23823 newval = md_chars_to_number (buf, THUMB_SIZE);
23824 {
23825 int rd = (newval >> 4) & 0xf;
23826 int rs = newval & 0xf;
23827 int subtract = !!(newval & 0x8000);
a737bd4d 23828
c19d1205
ZW
23829 /* Check for HI regs, only very restricted cases allowed:
23830 Adjusting SP, and using PC or SP to get an address. */
23831 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
23832 || (rs > 7 && rs != REG_SP && rs != REG_PC))
23833 as_bad_where (fixP->fx_file, fixP->fx_line,
23834 _("invalid Hi register with immediate"));
a737bd4d 23835
c19d1205
ZW
23836 /* If value is negative, choose the opposite instruction. */
23837 if (value < 0)
23838 {
23839 value = -value;
23840 subtract = !subtract;
23841 if (value < 0)
23842 as_bad_where (fixP->fx_file, fixP->fx_line,
23843 _("immediate value out of range"));
23844 }
a737bd4d 23845
c19d1205
ZW
23846 if (rd == REG_SP)
23847 {
75c11999 23848 if (value & ~0x1fc)
c19d1205
ZW
23849 as_bad_where (fixP->fx_file, fixP->fx_line,
23850 _("invalid immediate for stack address calculation"));
23851 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
23852 newval |= value >> 2;
23853 }
23854 else if (rs == REG_PC || rs == REG_SP)
23855 {
c12d2c9d
NC
23856 /* PR gas/18541. If the addition is for a defined symbol
23857 within range of an ADR instruction then accept it. */
23858 if (subtract
23859 && value == 4
23860 && fixP->fx_addsy != NULL)
23861 {
23862 subtract = 0;
23863
23864 if (! S_IS_DEFINED (fixP->fx_addsy)
23865 || S_GET_SEGMENT (fixP->fx_addsy) != seg
23866 || S_IS_WEAK (fixP->fx_addsy))
23867 {
23868 as_bad_where (fixP->fx_file, fixP->fx_line,
23869 _("address calculation needs a strongly defined nearby symbol"));
23870 }
23871 else
23872 {
23873 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
23874
23875 /* Round up to the next 4-byte boundary. */
23876 if (v & 3)
23877 v = (v + 3) & ~ 3;
23878 else
23879 v += 4;
23880 v = S_GET_VALUE (fixP->fx_addsy) - v;
23881
23882 if (v & ~0x3fc)
23883 {
23884 as_bad_where (fixP->fx_file, fixP->fx_line,
23885 _("symbol too far away"));
23886 }
23887 else
23888 {
23889 fixP->fx_done = 1;
23890 value = v;
23891 }
23892 }
23893 }
23894
c19d1205
ZW
23895 if (subtract || value & ~0x3fc)
23896 as_bad_where (fixP->fx_file, fixP->fx_line,
23897 _("invalid immediate for address calculation (value = 0x%08lX)"),
5fc177c8 23898 (unsigned long) (subtract ? - value : value));
c19d1205
ZW
23899 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
23900 newval |= rd << 8;
23901 newval |= value >> 2;
23902 }
23903 else if (rs == rd)
23904 {
23905 if (value & ~0xff)
23906 as_bad_where (fixP->fx_file, fixP->fx_line,
23907 _("immediate value out of range"));
23908 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
23909 newval |= (rd << 8) | value;
23910 }
23911 else
23912 {
23913 if (value & ~0x7)
23914 as_bad_where (fixP->fx_file, fixP->fx_line,
23915 _("immediate value out of range"));
23916 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
23917 newval |= rd | (rs << 3) | (value << 6);
23918 }
23919 }
23920 md_number_to_chars (buf, newval, THUMB_SIZE);
23921 break;
a737bd4d 23922
c19d1205
ZW
23923 case BFD_RELOC_ARM_THUMB_IMM:
23924 newval = md_chars_to_number (buf, THUMB_SIZE);
23925 if (value < 0 || value > 255)
23926 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 23927 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
23928 (long) value);
23929 newval |= value;
23930 md_number_to_chars (buf, newval, THUMB_SIZE);
23931 break;
a737bd4d 23932
c19d1205
ZW
23933 case BFD_RELOC_ARM_THUMB_SHIFT:
23934 /* 5bit shift value (0..32). LSL cannot take 32. */
23935 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
23936 temp = newval & 0xf800;
23937 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
23938 as_bad_where (fixP->fx_file, fixP->fx_line,
23939 _("invalid shift value: %ld"), (long) value);
23940 /* Shifts of zero must be encoded as LSL. */
23941 if (value == 0)
23942 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
23943 /* Shifts of 32 are encoded as zero. */
23944 else if (value == 32)
23945 value = 0;
23946 newval |= value << 6;
23947 md_number_to_chars (buf, newval, THUMB_SIZE);
23948 break;
a737bd4d 23949
c19d1205
ZW
23950 case BFD_RELOC_VTABLE_INHERIT:
23951 case BFD_RELOC_VTABLE_ENTRY:
23952 fixP->fx_done = 0;
23953 return;
6c43fab6 23954
b6895b4f
PB
23955 case BFD_RELOC_ARM_MOVW:
23956 case BFD_RELOC_ARM_MOVT:
23957 case BFD_RELOC_ARM_THUMB_MOVW:
23958 case BFD_RELOC_ARM_THUMB_MOVT:
23959 if (fixP->fx_done || !seg->use_rela_p)
23960 {
23961 /* REL format relocations are limited to a 16-bit addend. */
23962 if (!fixP->fx_done)
23963 {
39623e12 23964 if (value < -0x8000 || value > 0x7fff)
b6895b4f 23965 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 23966 _("offset out of range"));
b6895b4f
PB
23967 }
23968 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
23969 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23970 {
23971 value >>= 16;
23972 }
23973
23974 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
23975 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
23976 {
23977 newval = get_thumb32_insn (buf);
23978 newval &= 0xfbf08f00;
23979 newval |= (value & 0xf000) << 4;
23980 newval |= (value & 0x0800) << 15;
23981 newval |= (value & 0x0700) << 4;
23982 newval |= (value & 0x00ff);
23983 put_thumb32_insn (buf, newval);
23984 }
23985 else
23986 {
23987 newval = md_chars_to_number (buf, 4);
23988 newval &= 0xfff0f000;
23989 newval |= value & 0x0fff;
23990 newval |= (value & 0xf000) << 4;
23991 md_number_to_chars (buf, newval, 4);
23992 }
23993 }
23994 return;
23995
72d98d16
MG
23996 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
23997 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
23998 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
23999 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
24000 gas_assert (!fixP->fx_done);
24001 {
24002 bfd_vma insn;
24003 bfd_boolean is_mov;
24004 bfd_vma encoded_addend = value;
24005
24006 /* Check that addend can be encoded in instruction. */
24007 if (!seg->use_rela_p && (value < 0 || value > 255))
24008 as_bad_where (fixP->fx_file, fixP->fx_line,
24009 _("the offset 0x%08lX is not representable"),
24010 (unsigned long) encoded_addend);
24011
24012 /* Extract the instruction. */
24013 insn = md_chars_to_number (buf, THUMB_SIZE);
24014 is_mov = (insn & 0xf800) == 0x2000;
24015
24016 /* Encode insn. */
24017 if (is_mov)
24018 {
24019 if (!seg->use_rela_p)
24020 insn |= encoded_addend;
24021 }
24022 else
24023 {
24024 int rd, rs;
24025
24026 /* Extract the instruction. */
24027 /* Encoding is the following
24028 0x8000 SUB
24029 0x00F0 Rd
24030 0x000F Rs
24031 */
24032 /* The following conditions must be true :
24033 - ADD
24034 - Rd == Rs
24035 - Rd <= 7
24036 */
24037 rd = (insn >> 4) & 0xf;
24038 rs = insn & 0xf;
24039 if ((insn & 0x8000) || (rd != rs) || rd > 7)
24040 as_bad_where (fixP->fx_file, fixP->fx_line,
24041 _("Unable to process relocation for thumb opcode: %lx"),
24042 (unsigned long) insn);
24043
24044 /* Encode as ADD immediate8 thumb 1 code. */
24045 insn = 0x3000 | (rd << 8);
24046
24047 /* Place the encoded addend into the first 8 bits of the
24048 instruction. */
24049 if (!seg->use_rela_p)
24050 insn |= encoded_addend;
24051 }
24052
24053 /* Update the instruction. */
24054 md_number_to_chars (buf, insn, THUMB_SIZE);
24055 }
24056 break;
24057
4962c51a
MS
24058 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24059 case BFD_RELOC_ARM_ALU_PC_G0:
24060 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24061 case BFD_RELOC_ARM_ALU_PC_G1:
24062 case BFD_RELOC_ARM_ALU_PC_G2:
24063 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24064 case BFD_RELOC_ARM_ALU_SB_G0:
24065 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24066 case BFD_RELOC_ARM_ALU_SB_G1:
24067 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 24068 gas_assert (!fixP->fx_done);
4962c51a
MS
24069 if (!seg->use_rela_p)
24070 {
477330fc
RM
24071 bfd_vma insn;
24072 bfd_vma encoded_addend;
24073 bfd_vma addend_abs = abs (value);
24074
24075 /* Check that the absolute value of the addend can be
24076 expressed as an 8-bit constant plus a rotation. */
24077 encoded_addend = encode_arm_immediate (addend_abs);
24078 if (encoded_addend == (unsigned int) FAIL)
4962c51a 24079 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24080 _("the offset 0x%08lX is not representable"),
24081 (unsigned long) addend_abs);
24082
24083 /* Extract the instruction. */
24084 insn = md_chars_to_number (buf, INSN_SIZE);
24085
24086 /* If the addend is positive, use an ADD instruction.
24087 Otherwise use a SUB. Take care not to destroy the S bit. */
24088 insn &= 0xff1fffff;
24089 if (value < 0)
24090 insn |= 1 << 22;
24091 else
24092 insn |= 1 << 23;
24093
24094 /* Place the encoded addend into the first 12 bits of the
24095 instruction. */
24096 insn &= 0xfffff000;
24097 insn |= encoded_addend;
24098
24099 /* Update the instruction. */
24100 md_number_to_chars (buf, insn, INSN_SIZE);
4962c51a
MS
24101 }
24102 break;
24103
24104 case BFD_RELOC_ARM_LDR_PC_G0:
24105 case BFD_RELOC_ARM_LDR_PC_G1:
24106 case BFD_RELOC_ARM_LDR_PC_G2:
24107 case BFD_RELOC_ARM_LDR_SB_G0:
24108 case BFD_RELOC_ARM_LDR_SB_G1:
24109 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 24110 gas_assert (!fixP->fx_done);
4962c51a 24111 if (!seg->use_rela_p)
477330fc
RM
24112 {
24113 bfd_vma insn;
24114 bfd_vma addend_abs = abs (value);
4962c51a 24115
477330fc
RM
24116 /* Check that the absolute value of the addend can be
24117 encoded in 12 bits. */
24118 if (addend_abs >= 0x1000)
4962c51a 24119 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24120 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
24121 (unsigned long) addend_abs);
24122
24123 /* Extract the instruction. */
24124 insn = md_chars_to_number (buf, INSN_SIZE);
24125
24126 /* If the addend is negative, clear bit 23 of the instruction.
24127 Otherwise set it. */
24128 if (value < 0)
24129 insn &= ~(1 << 23);
24130 else
24131 insn |= 1 << 23;
24132
24133 /* Place the absolute value of the addend into the first 12 bits
24134 of the instruction. */
24135 insn &= 0xfffff000;
24136 insn |= addend_abs;
24137
24138 /* Update the instruction. */
24139 md_number_to_chars (buf, insn, INSN_SIZE);
24140 }
4962c51a
MS
24141 break;
24142
24143 case BFD_RELOC_ARM_LDRS_PC_G0:
24144 case BFD_RELOC_ARM_LDRS_PC_G1:
24145 case BFD_RELOC_ARM_LDRS_PC_G2:
24146 case BFD_RELOC_ARM_LDRS_SB_G0:
24147 case BFD_RELOC_ARM_LDRS_SB_G1:
24148 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 24149 gas_assert (!fixP->fx_done);
4962c51a 24150 if (!seg->use_rela_p)
477330fc
RM
24151 {
24152 bfd_vma insn;
24153 bfd_vma addend_abs = abs (value);
4962c51a 24154
477330fc
RM
24155 /* Check that the absolute value of the addend can be
24156 encoded in 8 bits. */
24157 if (addend_abs >= 0x100)
4962c51a 24158 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24159 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
24160 (unsigned long) addend_abs);
24161
24162 /* Extract the instruction. */
24163 insn = md_chars_to_number (buf, INSN_SIZE);
24164
24165 /* If the addend is negative, clear bit 23 of the instruction.
24166 Otherwise set it. */
24167 if (value < 0)
24168 insn &= ~(1 << 23);
24169 else
24170 insn |= 1 << 23;
24171
24172 /* Place the first four bits of the absolute value of the addend
24173 into the first 4 bits of the instruction, and the remaining
24174 four into bits 8 .. 11. */
24175 insn &= 0xfffff0f0;
24176 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
24177
24178 /* Update the instruction. */
24179 md_number_to_chars (buf, insn, INSN_SIZE);
24180 }
4962c51a
MS
24181 break;
24182
24183 case BFD_RELOC_ARM_LDC_PC_G0:
24184 case BFD_RELOC_ARM_LDC_PC_G1:
24185 case BFD_RELOC_ARM_LDC_PC_G2:
24186 case BFD_RELOC_ARM_LDC_SB_G0:
24187 case BFD_RELOC_ARM_LDC_SB_G1:
24188 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 24189 gas_assert (!fixP->fx_done);
4962c51a 24190 if (!seg->use_rela_p)
477330fc
RM
24191 {
24192 bfd_vma insn;
24193 bfd_vma addend_abs = abs (value);
4962c51a 24194
477330fc
RM
24195 /* Check that the absolute value of the addend is a multiple of
24196 four and, when divided by four, fits in 8 bits. */
24197 if (addend_abs & 0x3)
4962c51a 24198 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24199 _("bad offset 0x%08lX (must be word-aligned)"),
24200 (unsigned long) addend_abs);
4962c51a 24201
477330fc 24202 if ((addend_abs >> 2) > 0xff)
4962c51a 24203 as_bad_where (fixP->fx_file, fixP->fx_line,
477330fc
RM
24204 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
24205 (unsigned long) addend_abs);
24206
24207 /* Extract the instruction. */
24208 insn = md_chars_to_number (buf, INSN_SIZE);
24209
24210 /* If the addend is negative, clear bit 23 of the instruction.
24211 Otherwise set it. */
24212 if (value < 0)
24213 insn &= ~(1 << 23);
24214 else
24215 insn |= 1 << 23;
24216
24217 /* Place the addend (divided by four) into the first eight
24218 bits of the instruction. */
24219 insn &= 0xfffffff0;
24220 insn |= addend_abs >> 2;
24221
24222 /* Update the instruction. */
24223 md_number_to_chars (buf, insn, INSN_SIZE);
24224 }
4962c51a
MS
24225 break;
24226
845b51d6
PB
24227 case BFD_RELOC_ARM_V4BX:
24228 /* This will need to go in the object file. */
24229 fixP->fx_done = 0;
24230 break;
24231
c19d1205
ZW
24232 case BFD_RELOC_UNUSED:
24233 default:
24234 as_bad_where (fixP->fx_file, fixP->fx_line,
24235 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
24236 }
6c43fab6
RE
24237}
24238
c19d1205
ZW
24239/* Translate internal representation of relocation info to BFD target
24240 format. */
a737bd4d 24241
c19d1205 24242arelent *
00a97672 24243tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 24244{
c19d1205
ZW
24245 arelent * reloc;
24246 bfd_reloc_code_real_type code;
a737bd4d 24247
325801bd 24248 reloc = XNEW (arelent);
a737bd4d 24249
325801bd 24250 reloc->sym_ptr_ptr = XNEW (asymbol *);
c19d1205
ZW
24251 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
24252 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 24253
2fc8bdac 24254 if (fixp->fx_pcrel)
00a97672
RS
24255 {
24256 if (section->use_rela_p)
24257 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
24258 else
24259 fixp->fx_offset = reloc->address;
24260 }
c19d1205 24261 reloc->addend = fixp->fx_offset;
a737bd4d 24262
c19d1205 24263 switch (fixp->fx_r_type)
a737bd4d 24264 {
c19d1205
ZW
24265 case BFD_RELOC_8:
24266 if (fixp->fx_pcrel)
24267 {
24268 code = BFD_RELOC_8_PCREL;
24269 break;
24270 }
1a0670f3 24271 /* Fall through. */
a737bd4d 24272
c19d1205
ZW
24273 case BFD_RELOC_16:
24274 if (fixp->fx_pcrel)
24275 {
24276 code = BFD_RELOC_16_PCREL;
24277 break;
24278 }
1a0670f3 24279 /* Fall through. */
6c43fab6 24280
c19d1205
ZW
24281 case BFD_RELOC_32:
24282 if (fixp->fx_pcrel)
24283 {
24284 code = BFD_RELOC_32_PCREL;
24285 break;
24286 }
1a0670f3 24287 /* Fall through. */
a737bd4d 24288
b6895b4f
PB
24289 case BFD_RELOC_ARM_MOVW:
24290 if (fixp->fx_pcrel)
24291 {
24292 code = BFD_RELOC_ARM_MOVW_PCREL;
24293 break;
24294 }
1a0670f3 24295 /* Fall through. */
b6895b4f
PB
24296
24297 case BFD_RELOC_ARM_MOVT:
24298 if (fixp->fx_pcrel)
24299 {
24300 code = BFD_RELOC_ARM_MOVT_PCREL;
24301 break;
24302 }
1a0670f3 24303 /* Fall through. */
b6895b4f
PB
24304
24305 case BFD_RELOC_ARM_THUMB_MOVW:
24306 if (fixp->fx_pcrel)
24307 {
24308 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
24309 break;
24310 }
1a0670f3 24311 /* Fall through. */
b6895b4f
PB
24312
24313 case BFD_RELOC_ARM_THUMB_MOVT:
24314 if (fixp->fx_pcrel)
24315 {
24316 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
24317 break;
24318 }
1a0670f3 24319 /* Fall through. */
b6895b4f 24320
c19d1205
ZW
24321 case BFD_RELOC_NONE:
24322 case BFD_RELOC_ARM_PCREL_BRANCH:
24323 case BFD_RELOC_ARM_PCREL_BLX:
24324 case BFD_RELOC_RVA:
24325 case BFD_RELOC_THUMB_PCREL_BRANCH7:
24326 case BFD_RELOC_THUMB_PCREL_BRANCH9:
24327 case BFD_RELOC_THUMB_PCREL_BRANCH12:
24328 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24329 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24330 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
24331 case BFD_RELOC_VTABLE_ENTRY:
24332 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
24333#ifdef TE_PE
24334 case BFD_RELOC_32_SECREL:
24335#endif
c19d1205
ZW
24336 code = fixp->fx_r_type;
24337 break;
a737bd4d 24338
00adf2d4
JB
24339 case BFD_RELOC_THUMB_PCREL_BLX:
24340#ifdef OBJ_ELF
24341 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
24342 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
24343 else
24344#endif
24345 code = BFD_RELOC_THUMB_PCREL_BLX;
24346 break;
24347
c19d1205
ZW
24348 case BFD_RELOC_ARM_LITERAL:
24349 case BFD_RELOC_ARM_HWLITERAL:
24350 /* If this is called then the a literal has
24351 been referenced across a section boundary. */
24352 as_bad_where (fixp->fx_file, fixp->fx_line,
24353 _("literal referenced across section boundary"));
24354 return NULL;
a737bd4d 24355
c19d1205 24356#ifdef OBJ_ELF
0855e32b
NS
24357 case BFD_RELOC_ARM_TLS_CALL:
24358 case BFD_RELOC_ARM_THM_TLS_CALL:
24359 case BFD_RELOC_ARM_TLS_DESCSEQ:
24360 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
c19d1205
ZW
24361 case BFD_RELOC_ARM_GOT32:
24362 case BFD_RELOC_ARM_GOTOFF:
b43420e6 24363 case BFD_RELOC_ARM_GOT_PREL:
c19d1205
ZW
24364 case BFD_RELOC_ARM_PLT32:
24365 case BFD_RELOC_ARM_TARGET1:
24366 case BFD_RELOC_ARM_ROSEGREL32:
24367 case BFD_RELOC_ARM_SBREL32:
24368 case BFD_RELOC_ARM_PREL31:
24369 case BFD_RELOC_ARM_TARGET2:
c19d1205 24370 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
24371 case BFD_RELOC_ARM_PCREL_CALL:
24372 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
24373 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24374 case BFD_RELOC_ARM_ALU_PC_G0:
24375 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24376 case BFD_RELOC_ARM_ALU_PC_G1:
24377 case BFD_RELOC_ARM_ALU_PC_G2:
24378 case BFD_RELOC_ARM_LDR_PC_G0:
24379 case BFD_RELOC_ARM_LDR_PC_G1:
24380 case BFD_RELOC_ARM_LDR_PC_G2:
24381 case BFD_RELOC_ARM_LDRS_PC_G0:
24382 case BFD_RELOC_ARM_LDRS_PC_G1:
24383 case BFD_RELOC_ARM_LDRS_PC_G2:
24384 case BFD_RELOC_ARM_LDC_PC_G0:
24385 case BFD_RELOC_ARM_LDC_PC_G1:
24386 case BFD_RELOC_ARM_LDC_PC_G2:
24387 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24388 case BFD_RELOC_ARM_ALU_SB_G0:
24389 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24390 case BFD_RELOC_ARM_ALU_SB_G1:
24391 case BFD_RELOC_ARM_ALU_SB_G2:
24392 case BFD_RELOC_ARM_LDR_SB_G0:
24393 case BFD_RELOC_ARM_LDR_SB_G1:
24394 case BFD_RELOC_ARM_LDR_SB_G2:
24395 case BFD_RELOC_ARM_LDRS_SB_G0:
24396 case BFD_RELOC_ARM_LDRS_SB_G1:
24397 case BFD_RELOC_ARM_LDRS_SB_G2:
24398 case BFD_RELOC_ARM_LDC_SB_G0:
24399 case BFD_RELOC_ARM_LDC_SB_G1:
24400 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 24401 case BFD_RELOC_ARM_V4BX:
72d98d16
MG
24402 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24403 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24404 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24405 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
c19d1205
ZW
24406 code = fixp->fx_r_type;
24407 break;
a737bd4d 24408
0855e32b 24409 case BFD_RELOC_ARM_TLS_GOTDESC:
c19d1205 24410 case BFD_RELOC_ARM_TLS_GD32:
75c11999 24411 case BFD_RELOC_ARM_TLS_LE32:
c19d1205
ZW
24412 case BFD_RELOC_ARM_TLS_IE32:
24413 case BFD_RELOC_ARM_TLS_LDM32:
24414 /* BFD will include the symbol's address in the addend.
24415 But we don't want that, so subtract it out again here. */
24416 if (!S_IS_COMMON (fixp->fx_addsy))
24417 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
24418 code = fixp->fx_r_type;
24419 break;
24420#endif
a737bd4d 24421
c19d1205
ZW
24422 case BFD_RELOC_ARM_IMMEDIATE:
24423 as_bad_where (fixp->fx_file, fixp->fx_line,
24424 _("internal relocation (type: IMMEDIATE) not fixed up"));
24425 return NULL;
a737bd4d 24426
c19d1205
ZW
24427 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24428 as_bad_where (fixp->fx_file, fixp->fx_line,
24429 _("ADRL used for a symbol not defined in the same file"));
24430 return NULL;
a737bd4d 24431
c19d1205 24432 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
24433 if (section->use_rela_p)
24434 {
24435 code = fixp->fx_r_type;
24436 break;
24437 }
24438
c19d1205
ZW
24439 if (fixp->fx_addsy != NULL
24440 && !S_IS_DEFINED (fixp->fx_addsy)
24441 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 24442 {
c19d1205
ZW
24443 as_bad_where (fixp->fx_file, fixp->fx_line,
24444 _("undefined local label `%s'"),
24445 S_GET_NAME (fixp->fx_addsy));
24446 return NULL;
a737bd4d
NC
24447 }
24448
c19d1205
ZW
24449 as_bad_where (fixp->fx_file, fixp->fx_line,
24450 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
24451 return NULL;
a737bd4d 24452
c19d1205
ZW
24453 default:
24454 {
e0471c16 24455 const char * type;
6c43fab6 24456
c19d1205
ZW
24457 switch (fixp->fx_r_type)
24458 {
24459 case BFD_RELOC_NONE: type = "NONE"; break;
24460 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
24461 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 24462 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
24463 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
24464 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
24465 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
db187cb9 24466 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
8f06b2d8 24467 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
24468 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
24469 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
24470 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
24471 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
24472 default: type = _("<unknown>"); break;
24473 }
24474 as_bad_where (fixp->fx_file, fixp->fx_line,
24475 _("cannot represent %s relocation in this object file format"),
24476 type);
24477 return NULL;
24478 }
a737bd4d 24479 }
6c43fab6 24480
c19d1205
ZW
24481#ifdef OBJ_ELF
24482 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
24483 && GOT_symbol
24484 && fixp->fx_addsy == GOT_symbol)
24485 {
24486 code = BFD_RELOC_ARM_GOTPC;
24487 reloc->addend = fixp->fx_offset = reloc->address;
24488 }
24489#endif
6c43fab6 24490
c19d1205 24491 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 24492
c19d1205
ZW
24493 if (reloc->howto == NULL)
24494 {
24495 as_bad_where (fixp->fx_file, fixp->fx_line,
24496 _("cannot represent %s relocation in this object file format"),
24497 bfd_get_reloc_code_name (code));
24498 return NULL;
24499 }
6c43fab6 24500
c19d1205
ZW
24501 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
24502 vtable entry to be used in the relocation's section offset. */
24503 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
24504 reloc->address = fixp->fx_offset;
6c43fab6 24505
c19d1205 24506 return reloc;
6c43fab6
RE
24507}
24508
c19d1205 24509/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 24510
c19d1205
ZW
24511void
24512cons_fix_new_arm (fragS * frag,
24513 int where,
24514 int size,
62ebcb5c
AM
24515 expressionS * exp,
24516 bfd_reloc_code_real_type reloc)
6c43fab6 24517{
c19d1205 24518 int pcrel = 0;
6c43fab6 24519
c19d1205
ZW
24520 /* Pick a reloc.
24521 FIXME: @@ Should look at CPU word size. */
24522 switch (size)
24523 {
24524 case 1:
62ebcb5c 24525 reloc = BFD_RELOC_8;
c19d1205
ZW
24526 break;
24527 case 2:
62ebcb5c 24528 reloc = BFD_RELOC_16;
c19d1205
ZW
24529 break;
24530 case 4:
24531 default:
62ebcb5c 24532 reloc = BFD_RELOC_32;
c19d1205
ZW
24533 break;
24534 case 8:
62ebcb5c 24535 reloc = BFD_RELOC_64;
c19d1205
ZW
24536 break;
24537 }
6c43fab6 24538
f0927246
NC
24539#ifdef TE_PE
24540 if (exp->X_op == O_secrel)
24541 {
24542 exp->X_op = O_symbol;
62ebcb5c 24543 reloc = BFD_RELOC_32_SECREL;
f0927246
NC
24544 }
24545#endif
24546
62ebcb5c 24547 fix_new_exp (frag, where, size, exp, pcrel, reloc);
c19d1205 24548}
6c43fab6 24549
4343666d 24550#if defined (OBJ_COFF)
c19d1205
ZW
24551void
24552arm_validate_fix (fixS * fixP)
6c43fab6 24553{
c19d1205
ZW
24554 /* If the destination of the branch is a defined symbol which does not have
24555 the THUMB_FUNC attribute, then we must be calling a function which has
24556 the (interfacearm) attribute. We look for the Thumb entry point to that
24557 function and change the branch to refer to that function instead. */
24558 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
24559 && fixP->fx_addsy != NULL
24560 && S_IS_DEFINED (fixP->fx_addsy)
24561 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 24562 {
c19d1205 24563 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 24564 }
c19d1205
ZW
24565}
24566#endif
6c43fab6 24567
267bf995 24568
c19d1205
ZW
24569int
24570arm_force_relocation (struct fix * fixp)
24571{
24572#if defined (OBJ_COFF) && defined (TE_PE)
24573 if (fixp->fx_r_type == BFD_RELOC_RVA)
24574 return 1;
24575#endif
6c43fab6 24576
267bf995
RR
24577 /* In case we have a call or a branch to a function in ARM ISA mode from
24578 a thumb function or vice-versa force the relocation. These relocations
24579 are cleared off for some cores that might have blx and simple transformations
24580 are possible. */
24581
24582#ifdef OBJ_ELF
24583 switch (fixp->fx_r_type)
24584 {
24585 case BFD_RELOC_ARM_PCREL_JUMP:
24586 case BFD_RELOC_ARM_PCREL_CALL:
24587 case BFD_RELOC_THUMB_PCREL_BLX:
24588 if (THUMB_IS_FUNC (fixp->fx_addsy))
24589 return 1;
24590 break;
24591
24592 case BFD_RELOC_ARM_PCREL_BLX:
24593 case BFD_RELOC_THUMB_PCREL_BRANCH25:
24594 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24595 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24596 if (ARM_IS_FUNC (fixp->fx_addsy))
24597 return 1;
24598 break;
24599
24600 default:
24601 break;
24602 }
24603#endif
24604
b5884301
PB
24605 /* Resolve these relocations even if the symbol is extern or weak.
24606 Technically this is probably wrong due to symbol preemption.
24607 In practice these relocations do not have enough range to be useful
24608 at dynamic link time, and some code (e.g. in the Linux kernel)
24609 expects these references to be resolved. */
c19d1205
ZW
24610 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
24611 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
b5884301 24612 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
0110f2b8 24613 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
b5884301
PB
24614 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24615 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
24616 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
16805f35 24617 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
24618 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
24619 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
b5884301
PB
24620 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
24621 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
24622 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
24623 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
c19d1205 24624 return 0;
a737bd4d 24625
4962c51a
MS
24626 /* Always leave these relocations for the linker. */
24627 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24628 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24629 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
24630 return 1;
24631
f0291e4c
PB
24632 /* Always generate relocations against function symbols. */
24633 if (fixp->fx_r_type == BFD_RELOC_32
24634 && fixp->fx_addsy
24635 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
24636 return 1;
24637
c19d1205 24638 return generic_force_reloc (fixp);
404ff6b5
AH
24639}
24640
0ffdc86c 24641#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
24642/* Relocations against function names must be left unadjusted,
24643 so that the linker can use this information to generate interworking
24644 stubs. The MIPS version of this function
c19d1205
ZW
24645 also prevents relocations that are mips-16 specific, but I do not
24646 know why it does this.
404ff6b5 24647
c19d1205
ZW
24648 FIXME:
24649 There is one other problem that ought to be addressed here, but
24650 which currently is not: Taking the address of a label (rather
24651 than a function) and then later jumping to that address. Such
24652 addresses also ought to have their bottom bit set (assuming that
24653 they reside in Thumb code), but at the moment they will not. */
404ff6b5 24654
c19d1205
ZW
24655bfd_boolean
24656arm_fix_adjustable (fixS * fixP)
404ff6b5 24657{
c19d1205
ZW
24658 if (fixP->fx_addsy == NULL)
24659 return 1;
404ff6b5 24660
e28387c3
PB
24661 /* Preserve relocations against symbols with function type. */
24662 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 24663 return FALSE;
e28387c3 24664
c19d1205
ZW
24665 if (THUMB_IS_FUNC (fixP->fx_addsy)
24666 && fixP->fx_subsy == NULL)
c921be7d 24667 return FALSE;
a737bd4d 24668
c19d1205
ZW
24669 /* We need the symbol name for the VTABLE entries. */
24670 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
24671 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 24672 return FALSE;
404ff6b5 24673
c19d1205
ZW
24674 /* Don't allow symbols to be discarded on GOT related relocs. */
24675 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
24676 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
24677 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
24678 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
24679 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
24680 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
24681 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
24682 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
0855e32b
NS
24683 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
24684 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
24685 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
24686 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
24687 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
c19d1205 24688 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 24689 return FALSE;
a737bd4d 24690
4962c51a
MS
24691 /* Similarly for group relocations. */
24692 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
24693 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
24694 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 24695 return FALSE;
4962c51a 24696
79947c54
CD
24697 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
24698 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
24699 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24700 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
24701 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
24702 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24703 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
24704 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
24705 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 24706 return FALSE;
79947c54 24707
72d98d16
MG
24708 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
24709 offsets, so keep these symbols. */
24710 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
24711 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
24712 return FALSE;
24713
c921be7d 24714 return TRUE;
a737bd4d 24715}
0ffdc86c
NC
24716#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
24717
24718#ifdef OBJ_ELF
c19d1205
ZW
24719const char *
24720elf32_arm_target_format (void)
404ff6b5 24721{
c19d1205
ZW
24722#ifdef TE_SYMBIAN
24723 return (target_big_endian
24724 ? "elf32-bigarm-symbian"
24725 : "elf32-littlearm-symbian");
24726#elif defined (TE_VXWORKS)
24727 return (target_big_endian
24728 ? "elf32-bigarm-vxworks"
24729 : "elf32-littlearm-vxworks");
b38cadfb
NC
24730#elif defined (TE_NACL)
24731 return (target_big_endian
24732 ? "elf32-bigarm-nacl"
24733 : "elf32-littlearm-nacl");
c19d1205
ZW
24734#else
24735 if (target_big_endian)
24736 return "elf32-bigarm";
24737 else
24738 return "elf32-littlearm";
24739#endif
404ff6b5
AH
24740}
24741
c19d1205
ZW
24742void
24743armelf_frob_symbol (symbolS * symp,
24744 int * puntp)
404ff6b5 24745{
c19d1205
ZW
24746 elf_frob_symbol (symp, puntp);
24747}
24748#endif
404ff6b5 24749
c19d1205 24750/* MD interface: Finalization. */
a737bd4d 24751
c19d1205
ZW
24752void
24753arm_cleanup (void)
24754{
24755 literal_pool * pool;
a737bd4d 24756
e07e6e58
NC
24757 /* Ensure that all the IT blocks are properly closed. */
24758 check_it_blocks_finished ();
24759
c19d1205
ZW
24760 for (pool = list_of_pools; pool; pool = pool->next)
24761 {
5f4273c7 24762 /* Put it at the end of the relevant section. */
c19d1205
ZW
24763 subseg_set (pool->section, pool->sub_section);
24764#ifdef OBJ_ELF
24765 arm_elf_change_section ();
24766#endif
24767 s_ltorg (0);
24768 }
404ff6b5
AH
24769}
24770
cd000bff
DJ
24771#ifdef OBJ_ELF
24772/* Remove any excess mapping symbols generated for alignment frags in
24773 SEC. We may have created a mapping symbol before a zero byte
24774 alignment; remove it if there's a mapping symbol after the
24775 alignment. */
24776static void
24777check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
24778 void *dummy ATTRIBUTE_UNUSED)
24779{
24780 segment_info_type *seginfo = seg_info (sec);
24781 fragS *fragp;
24782
24783 if (seginfo == NULL || seginfo->frchainP == NULL)
24784 return;
24785
24786 for (fragp = seginfo->frchainP->frch_root;
24787 fragp != NULL;
24788 fragp = fragp->fr_next)
24789 {
24790 symbolS *sym = fragp->tc_frag_data.last_map;
24791 fragS *next = fragp->fr_next;
24792
24793 /* Variable-sized frags have been converted to fixed size by
24794 this point. But if this was variable-sized to start with,
24795 there will be a fixed-size frag after it. So don't handle
24796 next == NULL. */
24797 if (sym == NULL || next == NULL)
24798 continue;
24799
24800 if (S_GET_VALUE (sym) < next->fr_address)
24801 /* Not at the end of this frag. */
24802 continue;
24803 know (S_GET_VALUE (sym) == next->fr_address);
24804
24805 do
24806 {
24807 if (next->tc_frag_data.first_map != NULL)
24808 {
24809 /* Next frag starts with a mapping symbol. Discard this
24810 one. */
24811 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24812 break;
24813 }
24814
24815 if (next->fr_next == NULL)
24816 {
24817 /* This mapping symbol is at the end of the section. Discard
24818 it. */
24819 know (next->fr_fix == 0 && next->fr_var == 0);
24820 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
24821 break;
24822 }
24823
24824 /* As long as we have empty frags without any mapping symbols,
24825 keep looking. */
24826 /* If the next frag is non-empty and does not start with a
24827 mapping symbol, then this mapping symbol is required. */
24828 if (next->fr_address != next->fr_next->fr_address)
24829 break;
24830
24831 next = next->fr_next;
24832 }
24833 while (next != NULL);
24834 }
24835}
24836#endif
24837
c19d1205
ZW
24838/* Adjust the symbol table. This marks Thumb symbols as distinct from
24839 ARM ones. */
404ff6b5 24840
c19d1205
ZW
24841void
24842arm_adjust_symtab (void)
404ff6b5 24843{
c19d1205
ZW
24844#ifdef OBJ_COFF
24845 symbolS * sym;
404ff6b5 24846
c19d1205
ZW
24847 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
24848 {
24849 if (ARM_IS_THUMB (sym))
24850 {
24851 if (THUMB_IS_FUNC (sym))
24852 {
24853 /* Mark the symbol as a Thumb function. */
24854 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
24855 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
24856 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 24857
c19d1205
ZW
24858 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
24859 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
24860 else
24861 as_bad (_("%s: unexpected function type: %d"),
24862 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
24863 }
24864 else switch (S_GET_STORAGE_CLASS (sym))
24865 {
24866 case C_EXT:
24867 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
24868 break;
24869 case C_STAT:
24870 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
24871 break;
24872 case C_LABEL:
24873 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
24874 break;
24875 default:
24876 /* Do nothing. */
24877 break;
24878 }
24879 }
a737bd4d 24880
c19d1205
ZW
24881 if (ARM_IS_INTERWORK (sym))
24882 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 24883 }
c19d1205
ZW
24884#endif
24885#ifdef OBJ_ELF
24886 symbolS * sym;
24887 char bind;
404ff6b5 24888
c19d1205 24889 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 24890 {
c19d1205
ZW
24891 if (ARM_IS_THUMB (sym))
24892 {
24893 elf_symbol_type * elf_sym;
404ff6b5 24894
c19d1205
ZW
24895 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
24896 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 24897
b0796911
PB
24898 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
24899 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
24900 {
24901 /* If it's a .thumb_func, declare it as so,
24902 otherwise tag label as .code 16. */
24903 if (THUMB_IS_FUNC (sym))
39d911fc
TP
24904 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
24905 ST_BRANCH_TO_THUMB);
3ba67470 24906 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
24907 elf_sym->internal_elf_sym.st_info =
24908 ELF_ST_INFO (bind, STT_ARM_16BIT);
24909 }
24910 }
24911 }
cd000bff
DJ
24912
24913 /* Remove any overlapping mapping symbols generated by alignment frags. */
24914 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
709001e9
MM
24915 /* Now do generic ELF adjustments. */
24916 elf_adjust_symtab ();
c19d1205 24917#endif
404ff6b5
AH
24918}
24919
c19d1205 24920/* MD interface: Initialization. */
404ff6b5 24921
a737bd4d 24922static void
c19d1205 24923set_constant_flonums (void)
a737bd4d 24924{
c19d1205 24925 int i;
404ff6b5 24926
c19d1205
ZW
24927 for (i = 0; i < NUM_FLOAT_VALS; i++)
24928 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
24929 abort ();
a737bd4d 24930}
404ff6b5 24931
3e9e4fcf
JB
24932/* Auto-select Thumb mode if it's the only available instruction set for the
24933 given architecture. */
24934
24935static void
24936autoselect_thumb_from_cpu_variant (void)
24937{
24938 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
24939 opcode_select (16);
24940}
24941
c19d1205
ZW
24942void
24943md_begin (void)
a737bd4d 24944{
c19d1205
ZW
24945 unsigned mach;
24946 unsigned int i;
404ff6b5 24947
c19d1205
ZW
24948 if ( (arm_ops_hsh = hash_new ()) == NULL
24949 || (arm_cond_hsh = hash_new ()) == NULL
24950 || (arm_shift_hsh = hash_new ()) == NULL
24951 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 24952 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 24953 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
24954 || (arm_reloc_hsh = hash_new ()) == NULL
24955 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
24956 as_fatal (_("virtual memory exhausted"));
24957
24958 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 24959 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 24960 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 24961 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 24962 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 24963 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 24964 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24965 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 24966 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 24967 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
477330fc 24968 (void *) (v7m_psrs + i));
c19d1205 24969 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 24970 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
24971 for (i = 0;
24972 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
24973 i++)
d3ce72d0 24974 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 24975 (void *) (barrier_opt_names + i));
c19d1205 24976#ifdef OBJ_ELF
3da1d841
NC
24977 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
24978 {
24979 struct reloc_entry * entry = reloc_names + i;
24980
24981 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
24982 /* This makes encode_branch() use the EABI versions of this relocation. */
24983 entry->reloc = BFD_RELOC_UNUSED;
24984
24985 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
24986 }
c19d1205
ZW
24987#endif
24988
24989 set_constant_flonums ();
404ff6b5 24990
c19d1205
ZW
24991 /* Set the cpu variant based on the command-line options. We prefer
24992 -mcpu= over -march= if both are set (as for GCC); and we prefer
24993 -mfpu= over any other way of setting the floating point unit.
24994 Use of legacy options with new options are faulted. */
e74cfd16 24995 if (legacy_cpu)
404ff6b5 24996 {
e74cfd16 24997 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
24998 as_bad (_("use of old and new-style options to set CPU type"));
24999
25000 mcpu_cpu_opt = legacy_cpu;
404ff6b5 25001 }
e74cfd16 25002 else if (!mcpu_cpu_opt)
c19d1205 25003 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 25004
e74cfd16 25005 if (legacy_fpu)
c19d1205 25006 {
e74cfd16 25007 if (mfpu_opt)
c19d1205 25008 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
25009
25010 mfpu_opt = legacy_fpu;
25011 }
e74cfd16 25012 else if (!mfpu_opt)
03b1477f 25013 {
45eb4c1b
NS
25014#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
25015 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
25016 /* Some environments specify a default FPU. If they don't, infer it
25017 from the processor. */
e74cfd16 25018 if (mcpu_fpu_opt)
03b1477f
RE
25019 mfpu_opt = mcpu_fpu_opt;
25020 else
25021 mfpu_opt = march_fpu_opt;
39c2da32 25022#else
e74cfd16 25023 mfpu_opt = &fpu_default;
39c2da32 25024#endif
03b1477f
RE
25025 }
25026
e74cfd16 25027 if (!mfpu_opt)
03b1477f 25028 {
493cb6ef 25029 if (mcpu_cpu_opt != NULL)
e74cfd16 25030 mfpu_opt = &fpu_default;
493cb6ef 25031 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 25032 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 25033 else
e74cfd16 25034 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
25035 }
25036
ee065d83 25037#ifdef CPU_DEFAULT
e74cfd16 25038 if (!mcpu_cpu_opt)
ee065d83 25039 {
e74cfd16
PB
25040 mcpu_cpu_opt = &cpu_default;
25041 selected_cpu = cpu_default;
ee065d83 25042 }
73f43896
NC
25043 else if (no_cpu_selected ())
25044 selected_cpu = cpu_default;
e74cfd16
PB
25045#else
25046 if (mcpu_cpu_opt)
25047 selected_cpu = *mcpu_cpu_opt;
ee065d83 25048 else
e74cfd16 25049 mcpu_cpu_opt = &arm_arch_any;
ee065d83 25050#endif
03b1477f 25051
e74cfd16 25052 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 25053
3e9e4fcf
JB
25054 autoselect_thumb_from_cpu_variant ();
25055
e74cfd16 25056 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 25057
f17c130b 25058#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 25059 {
7cc69913
NC
25060 unsigned int flags = 0;
25061
25062#if defined OBJ_ELF
25063 flags = meabi_flags;
d507cf36
PB
25064
25065 switch (meabi_flags)
33a392fb 25066 {
d507cf36 25067 case EF_ARM_EABI_UNKNOWN:
7cc69913 25068#endif
d507cf36
PB
25069 /* Set the flags in the private structure. */
25070 if (uses_apcs_26) flags |= F_APCS26;
25071 if (support_interwork) flags |= F_INTERWORK;
25072 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 25073 if (pic_code) flags |= F_PIC;
e74cfd16 25074 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
25075 flags |= F_SOFT_FLOAT;
25076
d507cf36
PB
25077 switch (mfloat_abi_opt)
25078 {
25079 case ARM_FLOAT_ABI_SOFT:
25080 case ARM_FLOAT_ABI_SOFTFP:
25081 flags |= F_SOFT_FLOAT;
25082 break;
33a392fb 25083
d507cf36
PB
25084 case ARM_FLOAT_ABI_HARD:
25085 if (flags & F_SOFT_FLOAT)
25086 as_bad (_("hard-float conflicts with specified fpu"));
25087 break;
25088 }
03b1477f 25089
e74cfd16
PB
25090 /* Using pure-endian doubles (even if soft-float). */
25091 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 25092 flags |= F_VFP_FLOAT;
f17c130b 25093
fde78edd 25094#if defined OBJ_ELF
e74cfd16 25095 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 25096 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
25097 break;
25098
8cb51566 25099 case EF_ARM_EABI_VER4:
3a4a14e9 25100 case EF_ARM_EABI_VER5:
c19d1205 25101 /* No additional flags to set. */
d507cf36
PB
25102 break;
25103
25104 default:
25105 abort ();
25106 }
7cc69913 25107#endif
b99bd4ef
NC
25108 bfd_set_private_flags (stdoutput, flags);
25109
25110 /* We have run out flags in the COFF header to encode the
25111 status of ATPCS support, so instead we create a dummy,
c19d1205 25112 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
25113 if (atpcs)
25114 {
25115 asection * sec;
25116
25117 sec = bfd_make_section (stdoutput, ".arm.atpcs");
25118
25119 if (sec != NULL)
25120 {
25121 bfd_set_section_flags
25122 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
25123 bfd_set_section_size (stdoutput, sec, 0);
25124 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
25125 }
25126 }
7cc69913 25127 }
f17c130b 25128#endif
b99bd4ef
NC
25129
25130 /* Record the CPU type as well. */
2d447fca
JM
25131 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
25132 mach = bfd_mach_arm_iWMMXt2;
25133 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 25134 mach = bfd_mach_arm_iWMMXt;
e74cfd16 25135 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 25136 mach = bfd_mach_arm_XScale;
e74cfd16 25137 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 25138 mach = bfd_mach_arm_ep9312;
e74cfd16 25139 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 25140 mach = bfd_mach_arm_5TE;
e74cfd16 25141 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 25142 {
e74cfd16 25143 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25144 mach = bfd_mach_arm_5T;
25145 else
25146 mach = bfd_mach_arm_5;
25147 }
e74cfd16 25148 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 25149 {
e74cfd16 25150 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
25151 mach = bfd_mach_arm_4T;
25152 else
25153 mach = bfd_mach_arm_4;
25154 }
e74cfd16 25155 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 25156 mach = bfd_mach_arm_3M;
e74cfd16
PB
25157 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
25158 mach = bfd_mach_arm_3;
25159 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
25160 mach = bfd_mach_arm_2a;
25161 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
25162 mach = bfd_mach_arm_2;
25163 else
25164 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
25165
25166 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
25167}
25168
c19d1205 25169/* Command line processing. */
b99bd4ef 25170
c19d1205
ZW
25171/* md_parse_option
25172 Invocation line includes a switch not recognized by the base assembler.
25173 See if it's a processor-specific option.
b99bd4ef 25174
c19d1205
ZW
25175 This routine is somewhat complicated by the need for backwards
25176 compatibility (since older releases of gcc can't be changed).
25177 The new options try to make the interface as compatible as
25178 possible with GCC.
b99bd4ef 25179
c19d1205 25180 New options (supported) are:
b99bd4ef 25181
c19d1205
ZW
25182 -mcpu=<cpu name> Assemble for selected processor
25183 -march=<architecture name> Assemble for selected architecture
25184 -mfpu=<fpu architecture> Assemble for selected FPU.
25185 -EB/-mbig-endian Big-endian
25186 -EL/-mlittle-endian Little-endian
25187 -k Generate PIC code
25188 -mthumb Start in Thumb mode
25189 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 25190
278df34e 25191 -m[no-]warn-deprecated Warn about deprecated features
8b2d793c 25192 -m[no-]warn-syms Warn when symbols match instructions
267bf995 25193
c19d1205 25194 For now we will also provide support for:
b99bd4ef 25195
c19d1205
ZW
25196 -mapcs-32 32-bit Program counter
25197 -mapcs-26 26-bit Program counter
25198 -macps-float Floats passed in FP registers
25199 -mapcs-reentrant Reentrant code
25200 -matpcs
25201 (sometime these will probably be replaced with -mapcs=<list of options>
25202 and -matpcs=<list of options>)
b99bd4ef 25203
c19d1205
ZW
25204 The remaining options are only supported for back-wards compatibility.
25205 Cpu variants, the arm part is optional:
25206 -m[arm]1 Currently not supported.
25207 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
25208 -m[arm]3 Arm 3 processor
25209 -m[arm]6[xx], Arm 6 processors
25210 -m[arm]7[xx][t][[d]m] Arm 7 processors
25211 -m[arm]8[10] Arm 8 processors
25212 -m[arm]9[20][tdmi] Arm 9 processors
25213 -mstrongarm[110[0]] StrongARM processors
25214 -mxscale XScale processors
25215 -m[arm]v[2345[t[e]]] Arm architectures
25216 -mall All (except the ARM1)
25217 FP variants:
25218 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
25219 -mfpe-old (No float load/store multiples)
25220 -mvfpxd VFP Single precision
25221 -mvfp All VFP
25222 -mno-fpu Disable all floating point instructions
b99bd4ef 25223
c19d1205
ZW
25224 The following CPU names are recognized:
25225 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
25226 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
25227 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
25228 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
25229 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
25230 arm10t arm10e, arm1020t, arm1020e, arm10200e,
25231 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 25232
c19d1205 25233 */
b99bd4ef 25234
c19d1205 25235const char * md_shortopts = "m:k";
b99bd4ef 25236
c19d1205
ZW
25237#ifdef ARM_BI_ENDIAN
25238#define OPTION_EB (OPTION_MD_BASE + 0)
25239#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 25240#else
c19d1205
ZW
25241#if TARGET_BYTES_BIG_ENDIAN
25242#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 25243#else
c19d1205
ZW
25244#define OPTION_EL (OPTION_MD_BASE + 1)
25245#endif
b99bd4ef 25246#endif
845b51d6 25247#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 25248
c19d1205 25249struct option md_longopts[] =
b99bd4ef 25250{
c19d1205
ZW
25251#ifdef OPTION_EB
25252 {"EB", no_argument, NULL, OPTION_EB},
25253#endif
25254#ifdef OPTION_EL
25255 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 25256#endif
845b51d6 25257 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
25258 {NULL, no_argument, NULL, 0}
25259};
b99bd4ef 25260
8b2d793c 25261
c19d1205 25262size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 25263
c19d1205 25264struct arm_option_table
b99bd4ef 25265{
e0471c16
TS
25266 const char *option; /* Option name to match. */
25267 const char *help; /* Help information. */
c19d1205
ZW
25268 int *var; /* Variable to change. */
25269 int value; /* What to change it to. */
e0471c16 25270 const char *deprecated; /* If non-null, print this message. */
c19d1205 25271};
b99bd4ef 25272
c19d1205
ZW
25273struct arm_option_table arm_opts[] =
25274{
25275 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
25276 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
25277 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
25278 &support_interwork, 1, NULL},
25279 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
25280 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
25281 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
25282 1, NULL},
25283 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
25284 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
25285 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
25286 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
25287 NULL},
b99bd4ef 25288
c19d1205
ZW
25289 /* These are recognized by the assembler, but have no affect on code. */
25290 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
25291 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
25292
25293 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
25294 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
25295 &warn_on_deprecated, 0, NULL},
8b2d793c
NC
25296 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
25297 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
e74cfd16
PB
25298 {NULL, NULL, NULL, 0, NULL}
25299};
25300
25301struct arm_legacy_option_table
25302{
e0471c16 25303 const char *option; /* Option name to match. */
e74cfd16
PB
25304 const arm_feature_set **var; /* Variable to change. */
25305 const arm_feature_set value; /* What to change it to. */
e0471c16 25306 const char *deprecated; /* If non-null, print this message. */
e74cfd16 25307};
b99bd4ef 25308
e74cfd16
PB
25309const struct arm_legacy_option_table arm_legacy_opts[] =
25310{
c19d1205
ZW
25311 /* DON'T add any new processors to this list -- we want the whole list
25312 to go away... Add them to the processors table instead. */
e74cfd16
PB
25313 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25314 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25315 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25316 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25317 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25318 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25319 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25320 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25321 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25322 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25323 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25324 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25325 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25326 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25327 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25328 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25329 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25330 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25331 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25332 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25333 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25334 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25335 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25336 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25337 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25338 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25339 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25340 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25341 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25342 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25343 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25344 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25345 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25346 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25347 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25348 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25349 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25350 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25351 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25352 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25353 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25354 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25355 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25356 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25357 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25358 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25359 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25360 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25361 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25362 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25363 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25364 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25365 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25366 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25367 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25368 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25369 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25370 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25371 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25372 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25373 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25374 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25375 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25376 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25377 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25378 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25379 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25380 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25381 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
25382 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25383 N_("use -mcpu=strongarm110")},
e74cfd16 25384 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25385 N_("use -mcpu=strongarm1100")},
e74cfd16 25386 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 25387 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
25388 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
25389 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
25390 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 25391
c19d1205 25392 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
25393 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25394 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25395 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25396 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25397 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25398 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25399 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25400 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25401 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25402 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25403 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25404 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25405 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25406 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25407 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25408 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25409 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
25410 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 25411
c19d1205 25412 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
25413 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
25414 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
25415 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
25416 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 25417 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 25418
e74cfd16 25419 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 25420};
7ed4c4c5 25421
c19d1205 25422struct arm_cpu_option_table
7ed4c4c5 25423{
e0471c16 25424 const char *name;
f3bad469 25425 size_t name_len;
e74cfd16 25426 const arm_feature_set value;
c19d1205
ZW
25427 /* For some CPUs we assume an FPU unless the user explicitly sets
25428 -mfpu=... */
e74cfd16 25429 const arm_feature_set default_fpu;
ee065d83
PB
25430 /* The canonical name of the CPU, or NULL to use NAME converted to upper
25431 case. */
25432 const char *canonical_name;
c19d1205 25433};
7ed4c4c5 25434
c19d1205
ZW
25435/* This list should, at a minimum, contain all the cpu names
25436 recognized by GCC. */
f3bad469 25437#define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
e74cfd16 25438static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 25439{
f3bad469
MGD
25440 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
25441 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
25442 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
25443 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
25444 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
25445 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25446 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25447 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25448 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25449 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25450 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25451 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25452 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25453 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25454 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25455 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
25456 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25457 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25458 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25459 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25460 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25461 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25462 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25463 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25464 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25465 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25466 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25467 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
25468 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25469 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25470 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25471 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25472 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25473 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25474 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25475 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25476 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25477 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25478 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25479 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
25480 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25481 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25482 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25483 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
25484 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
25485 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
c19d1205
ZW
25486 /* For V5 or later processors we default to using VFP; but the user
25487 should really set the FPU type explicitly. */
f3bad469
MGD
25488 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25489 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25490 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
25491 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
25492 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
25493 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25494 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
25495 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25496 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
25497 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
25498 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25499 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25500 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25501 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25502 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25503 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
25504 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
25505 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25506 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25507 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
25508 "ARM1026EJ-S"),
25509 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
25510 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25511 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25512 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25513 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25514 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
25515 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
25516 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
25517 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
25518 "ARM1136JF-S"),
25519 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
25520 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
25521 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
25522 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
25523 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
f33026a9
MW
25524 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6KZ, FPU_NONE, NULL),
25525 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6KZ, FPU_ARCH_VFP_V2, NULL),
f3bad469
MGD
25526 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
25527 FPU_NONE, "Cortex-A5"),
c9fb6e58 25528 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469
MGD
25529 "Cortex-A7"),
25530 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
823d2571 25531 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 25532 | FPU_NEON_EXT_V1),
f3bad469
MGD
25533 "Cortex-A8"),
25534 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
823d2571 25535 ARM_FEATURE_COPROC (FPU_VFP_V3
477330fc 25536 | FPU_NEON_EXT_V1),
f3bad469 25537 "Cortex-A9"),
c9fb6e58 25538 ARM_CPU_OPT ("cortex-a12", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
63a4bc21 25539 "Cortex-A12"),
c9fb6e58 25540 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
f3bad469 25541 "Cortex-A15"),
d7adf960
KT
25542 ARM_CPU_OPT ("cortex-a17", ARM_ARCH_V7VE, FPU_ARCH_NEON_VFP_V4,
25543 "Cortex-A17"),
27e5a270 25544 ARM_CPU_OPT ("cortex-a32", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
6735952f 25545 "Cortex-A32"),
27e5a270 25546 ARM_CPU_OPT ("cortex-a35", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
43cdc0a8 25547 "Cortex-A35"),
27e5a270 25548 ARM_CPU_OPT ("cortex-a53", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 25549 "Cortex-A53"),
27e5a270 25550 ARM_CPU_OPT ("cortex-a57", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
477330fc 25551 "Cortex-A57"),
27e5a270 25552 ARM_CPU_OPT ("cortex-a72", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
b19f47ad 25553 "Cortex-A72"),
27e5a270 25554 ARM_CPU_OPT ("cortex-a73", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
362a3eba 25555 "Cortex-A73"),
f3bad469
MGD
25556 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
25557 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
25558 "Cortex-R4F"),
25559 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
25560 FPU_NONE, "Cortex-R5"),
70a8bc5b 25561 ARM_CPU_OPT ("cortex-r7", ARM_ARCH_V7R_IDIV,
25562 FPU_ARCH_VFP_V3D16,
25563 "Cortex-R7"),
5f474010
TP
25564 ARM_CPU_OPT ("cortex-r8", ARM_ARCH_V7R_IDIV,
25565 FPU_ARCH_VFP_V3D16,
25566 "Cortex-R8"),
b19ea8d2
TP
25567 ARM_CPU_OPT ("cortex-m33", ARM_ARCH_V8M_MAIN_DSP,
25568 FPU_NONE, "Cortex-M33"),
ce1b0a45
TP
25569 ARM_CPU_OPT ("cortex-m23", ARM_ARCH_V8M_BASE,
25570 FPU_NONE, "Cortex-M23"),
a715796b 25571 ARM_CPU_OPT ("cortex-m7", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M7"),
f3bad469
MGD
25572 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
25573 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
25574 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
25575 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
ce32bd10 25576 ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"),
27e5a270 25577 ARM_CPU_OPT ("exynos-m1", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
246496bb
EM
25578 "Samsung " \
25579 "Exynos M1"),
2fe9c2a0
SP
25580 ARM_CPU_OPT ("falkor", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25581 "Qualcomm "
25582 "Falkor"),
27e5a270 25583 ARM_CPU_OPT ("qdf24xx", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
6b21c2bf
JW
25584 "Qualcomm "
25585 "QDF24XX"),
25586
c19d1205 25587 /* ??? XSCALE is really an architecture. */
f3bad469 25588 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 25589 /* ??? iwmmxt is not a processor. */
f3bad469
MGD
25590 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
25591 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
25592 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
c19d1205 25593 /* Maverick */
823d2571 25594 ARM_CPU_OPT ("ep9312", ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
da4339ed
NC
25595 FPU_ARCH_MAVERICK, "ARM920T"),
25596 /* Marvell processors. */
ff8646ee
TP
25597 ARM_CPU_OPT ("marvell-pj4", ARM_FEATURE_CORE (ARM_AEXT_V7A | ARM_EXT_MP
25598 | ARM_EXT_SEC,
25599 ARM_EXT2_V6T2_V8M),
477330fc 25600 FPU_ARCH_VFP_V3D16, NULL),
ff8646ee
TP
25601 ARM_CPU_OPT ("marvell-whitney", ARM_FEATURE_CORE (ARM_AEXT_V7A | ARM_EXT_MP
25602 | ARM_EXT_SEC,
25603 ARM_EXT2_V6T2_V8M),
4347085a 25604 FPU_ARCH_NEON_VFP_V4, NULL),
ea0d6bb9
PT
25605 /* APM X-Gene family. */
25606 ARM_CPU_OPT ("xgene1", ARM_ARCH_V8A, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
25607 "APM X-Gene 1"),
27e5a270 25608 ARM_CPU_OPT ("xgene2", ARM_ARCH_V8A_CRC, FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
ea0d6bb9 25609 "APM X-Gene 2"),
da4339ed 25610
f3bad469 25611 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
c19d1205 25612};
f3bad469 25613#undef ARM_CPU_OPT
7ed4c4c5 25614
c19d1205 25615struct arm_arch_option_table
7ed4c4c5 25616{
e0471c16 25617 const char *name;
f3bad469 25618 size_t name_len;
e74cfd16
PB
25619 const arm_feature_set value;
25620 const arm_feature_set default_fpu;
c19d1205 25621};
7ed4c4c5 25622
c19d1205
ZW
25623/* This list should, at a minimum, contain all the architecture names
25624 recognized by GCC. */
f3bad469 25625#define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
e74cfd16 25626static const struct arm_arch_option_table arm_archs[] =
c19d1205 25627{
f3bad469
MGD
25628 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
25629 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
25630 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
25631 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
25632 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
25633 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
25634 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
25635 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
25636 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
25637 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
25638 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
25639 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
25640 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
25641 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
25642 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
25643 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
25644 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
25645 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
25646 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
25647 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
25648 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
f33026a9
MW
25649 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
25650 kept to preserve existing behaviour. */
25651 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
25652 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
f3bad469
MGD
25653 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
25654 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
25655 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
f33026a9
MW
25656 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
25657 kept to preserve existing behaviour. */
25658 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
25659 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
f3bad469
MGD
25660 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
25661 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
25662 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
c450d570
PB
25663 /* The official spelling of the ARMv7 profile variants is the dashed form.
25664 Accept the non-dashed form for compatibility with old toolchains. */
f3bad469 25665 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
c9fb6e58 25666 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
f3bad469
MGD
25667 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
25668 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
25669 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
25670 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
25671 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
25672 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
ff8646ee 25673 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
4ed7ed8d 25674 ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP),
bca38921 25675 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
a5932920 25676 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
56a1b672 25677 ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP),
a12fd8e1 25678 ARM_ARCH_OPT ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP),
f3bad469
MGD
25679 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
25680 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
25681 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
25682 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
c19d1205 25683};
f3bad469 25684#undef ARM_ARCH_OPT
7ed4c4c5 25685
69133863
MGD
25686/* ISA extensions in the co-processor and main instruction set space. */
25687struct arm_option_extension_value_table
c19d1205 25688{
e0471c16 25689 const char *name;
f3bad469 25690 size_t name_len;
5a70a223
JB
25691 const arm_feature_set merge_value;
25692 const arm_feature_set clear_value;
d942732e
TP
25693 /* List of architectures for which an extension is available. ARM_ARCH_NONE
25694 indicates that an extension is available for all architectures while
25695 ARM_ANY marks an empty entry. */
25696 const arm_feature_set allowed_archs[2];
c19d1205 25697};
7ed4c4c5 25698
69133863
MGD
25699/* The following table must be in alphabetical order with a NULL last entry.
25700 */
d942732e
TP
25701#define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
25702#define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
69133863 25703static const struct arm_option_extension_value_table arm_extensions[] =
c19d1205 25704{
823d2571
TG
25705 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
25706 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
bca38921 25707 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
823d2571
TG
25708 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
25709 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
15afaa63
TP
25710 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
25711 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
25712 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
823d2571
TG
25713 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
25714 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
b8ec4e87
JW
25715 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25716 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
25717 ARM_ARCH_V8_2A),
d942732e 25718 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
823d2571 25719 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
d942732e
TP
25720 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
25721 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571 25722 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
d942732e 25723 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
823d2571 25724 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
d942732e 25725 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
823d2571 25726 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
d942732e
TP
25727 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
25728 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
823d2571 25729 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
d942732e
TP
25730 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
25731 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
823d2571
TG
25732 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25733 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
25734 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
ddfded2f
MW
25735 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
25736 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
25737 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
4d1464f2
MW
25738 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
25739 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
25740 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
643afb90
MW
25741 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
25742 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
25743 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
d942732e 25744 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
823d2571 25745 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
d942732e
TP
25746 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
25747 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
643afb90
MW
25748 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
25749 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
25750 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
823d2571
TG
25751 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
25752 | ARM_EXT_DIV),
25753 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
25754 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
25755 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
d942732e
TP
25756 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
25757 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
69133863 25758};
f3bad469 25759#undef ARM_EXT_OPT
69133863
MGD
25760
25761/* ISA floating-point and Advanced SIMD extensions. */
25762struct arm_option_fpu_value_table
25763{
e0471c16 25764 const char *name;
69133863 25765 const arm_feature_set value;
c19d1205 25766};
7ed4c4c5 25767
c19d1205
ZW
25768/* This list should, at a minimum, contain all the fpu names
25769 recognized by GCC. */
69133863 25770static const struct arm_option_fpu_value_table arm_fpus[] =
c19d1205
ZW
25771{
25772 {"softfpa", FPU_NONE},
25773 {"fpe", FPU_ARCH_FPE},
25774 {"fpe2", FPU_ARCH_FPE},
25775 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
25776 {"fpa", FPU_ARCH_FPA},
25777 {"fpa10", FPU_ARCH_FPA},
25778 {"fpa11", FPU_ARCH_FPA},
25779 {"arm7500fe", FPU_ARCH_FPA},
25780 {"softvfp", FPU_ARCH_VFP},
25781 {"softvfp+vfp", FPU_ARCH_VFP_V2},
25782 {"vfp", FPU_ARCH_VFP_V2},
25783 {"vfp9", FPU_ARCH_VFP_V2},
33eaf5de 25784 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatibility. */
c19d1205
ZW
25785 {"vfp10", FPU_ARCH_VFP_V2},
25786 {"vfp10-r0", FPU_ARCH_VFP_V1},
25787 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
25788 {"vfpv2", FPU_ARCH_VFP_V2},
25789 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 25790 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 25791 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
25792 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
25793 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
25794 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
25795 {"arm1020t", FPU_ARCH_VFP_V1},
25796 {"arm1020e", FPU_ARCH_VFP_V2},
25797 {"arm1136jfs", FPU_ARCH_VFP_V2},
25798 {"arm1136jf-s", FPU_ARCH_VFP_V2},
25799 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 25800 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 25801 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
25802 {"vfpv4", FPU_ARCH_VFP_V4},
25803 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 25804 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
a715796b
TG
25805 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
25806 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
62f3b8c8 25807 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
bca38921
MGD
25808 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
25809 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
25810 {"crypto-neon-fp-armv8",
25811 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
d6b4b13e 25812 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
081e4c7d
MW
25813 {"crypto-neon-fp-armv8.1",
25814 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
e74cfd16
PB
25815 {NULL, ARM_ARCH_NONE}
25816};
25817
25818struct arm_option_value_table
25819{
e0471c16 25820 const char *name;
e74cfd16 25821 long value;
c19d1205 25822};
7ed4c4c5 25823
e74cfd16 25824static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
25825{
25826 {"hard", ARM_FLOAT_ABI_HARD},
25827 {"softfp", ARM_FLOAT_ABI_SOFTFP},
25828 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 25829 {NULL, 0}
c19d1205 25830};
7ed4c4c5 25831
c19d1205 25832#ifdef OBJ_ELF
3a4a14e9 25833/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 25834static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
25835{
25836 {"gnu", EF_ARM_EABI_UNKNOWN},
25837 {"4", EF_ARM_EABI_VER4},
3a4a14e9 25838 {"5", EF_ARM_EABI_VER5},
e74cfd16 25839 {NULL, 0}
c19d1205
ZW
25840};
25841#endif
7ed4c4c5 25842
c19d1205
ZW
25843struct arm_long_option_table
25844{
e0471c16
TS
25845 const char * option; /* Substring to match. */
25846 const char * help; /* Help information. */
17b9d67d 25847 int (* func) (const char * subopt); /* Function to decode sub-option. */
e0471c16 25848 const char * deprecated; /* If non-null, print this message. */
c19d1205 25849};
7ed4c4c5 25850
c921be7d 25851static bfd_boolean
82b8a785 25852arm_parse_extension (const char *str, const arm_feature_set **opt_p)
7ed4c4c5 25853{
325801bd 25854 arm_feature_set *ext_set = XNEW (arm_feature_set);
e74cfd16 25855
69133863 25856 /* We insist on extensions being specified in alphabetical order, and with
fa94de6b
RM
25857 extensions being added before being removed. We achieve this by having
25858 the global ARM_EXTENSIONS table in alphabetical order, and using the
69133863 25859 ADDING_VALUE variable to indicate whether we are adding an extension (1)
fa94de6b 25860 or removing it (0) and only allowing it to change in the order
69133863
MGD
25861 -1 -> 1 -> 0. */
25862 const struct arm_option_extension_value_table * opt = NULL;
d942732e 25863 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
25864 int adding_value = -1;
25865
e74cfd16
PB
25866 /* Copy the feature set, so that we can modify it. */
25867 *ext_set = **opt_p;
25868 *opt_p = ext_set;
25869
c19d1205 25870 while (str != NULL && *str != 0)
7ed4c4c5 25871 {
82b8a785 25872 const char *ext;
f3bad469 25873 size_t len;
7ed4c4c5 25874
c19d1205
ZW
25875 if (*str != '+')
25876 {
25877 as_bad (_("invalid architectural extension"));
c921be7d 25878 return FALSE;
c19d1205 25879 }
7ed4c4c5 25880
c19d1205
ZW
25881 str++;
25882 ext = strchr (str, '+');
7ed4c4c5 25883
c19d1205 25884 if (ext != NULL)
f3bad469 25885 len = ext - str;
c19d1205 25886 else
f3bad469 25887 len = strlen (str);
7ed4c4c5 25888
f3bad469 25889 if (len >= 2 && strncmp (str, "no", 2) == 0)
69133863
MGD
25890 {
25891 if (adding_value != 0)
25892 {
25893 adding_value = 0;
25894 opt = arm_extensions;
25895 }
25896
f3bad469 25897 len -= 2;
69133863
MGD
25898 str += 2;
25899 }
f3bad469 25900 else if (len > 0)
69133863
MGD
25901 {
25902 if (adding_value == -1)
25903 {
25904 adding_value = 1;
25905 opt = arm_extensions;
25906 }
25907 else if (adding_value != 1)
25908 {
25909 as_bad (_("must specify extensions to add before specifying "
25910 "those to remove"));
25911 return FALSE;
25912 }
25913 }
25914
f3bad469 25915 if (len == 0)
c19d1205
ZW
25916 {
25917 as_bad (_("missing architectural extension"));
c921be7d 25918 return FALSE;
c19d1205 25919 }
7ed4c4c5 25920
69133863
MGD
25921 gas_assert (adding_value != -1);
25922 gas_assert (opt != NULL);
25923
25924 /* Scan over the options table trying to find an exact match. */
25925 for (; opt->name != NULL; opt++)
f3bad469 25926 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 25927 {
d942732e
TP
25928 int i, nb_allowed_archs =
25929 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
69133863 25930 /* Check we can apply the extension to this architecture. */
d942732e
TP
25931 for (i = 0; i < nb_allowed_archs; i++)
25932 {
25933 /* Empty entry. */
25934 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
25935 continue;
25936 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *ext_set))
25937 break;
25938 }
25939 if (i == nb_allowed_archs)
69133863
MGD
25940 {
25941 as_bad (_("extension does not apply to the base architecture"));
25942 return FALSE;
25943 }
25944
25945 /* Add or remove the extension. */
25946 if (adding_value)
5a70a223 25947 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
69133863 25948 else
5a70a223 25949 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
69133863 25950
c19d1205
ZW
25951 break;
25952 }
7ed4c4c5 25953
c19d1205
ZW
25954 if (opt->name == NULL)
25955 {
69133863
MGD
25956 /* Did we fail to find an extension because it wasn't specified in
25957 alphabetical order, or because it does not exist? */
25958
25959 for (opt = arm_extensions; opt->name != NULL; opt++)
f3bad469 25960 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
69133863
MGD
25961 break;
25962
25963 if (opt->name == NULL)
25964 as_bad (_("unknown architectural extension `%s'"), str);
25965 else
25966 as_bad (_("architectural extensions must be specified in "
25967 "alphabetical order"));
25968
c921be7d 25969 return FALSE;
c19d1205 25970 }
69133863
MGD
25971 else
25972 {
25973 /* We should skip the extension we've just matched the next time
25974 round. */
25975 opt++;
25976 }
7ed4c4c5 25977
c19d1205
ZW
25978 str = ext;
25979 };
7ed4c4c5 25980
c921be7d 25981 return TRUE;
c19d1205 25982}
7ed4c4c5 25983
c921be7d 25984static bfd_boolean
17b9d67d 25985arm_parse_cpu (const char *str)
7ed4c4c5 25986{
f3bad469 25987 const struct arm_cpu_option_table *opt;
82b8a785 25988 const char *ext = strchr (str, '+');
f3bad469 25989 size_t len;
7ed4c4c5 25990
c19d1205 25991 if (ext != NULL)
f3bad469 25992 len = ext - str;
7ed4c4c5 25993 else
f3bad469 25994 len = strlen (str);
7ed4c4c5 25995
f3bad469 25996 if (len == 0)
7ed4c4c5 25997 {
c19d1205 25998 as_bad (_("missing cpu name `%s'"), str);
c921be7d 25999 return FALSE;
7ed4c4c5
NC
26000 }
26001
c19d1205 26002 for (opt = arm_cpus; opt->name != NULL; opt++)
f3bad469 26003 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26004 {
e74cfd16
PB
26005 mcpu_cpu_opt = &opt->value;
26006 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 26007 if (opt->canonical_name)
ef8e6722
JW
26008 {
26009 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
26010 strcpy (selected_cpu_name, opt->canonical_name);
26011 }
ee065d83
PB
26012 else
26013 {
f3bad469 26014 size_t i;
c921be7d 26015
ef8e6722
JW
26016 if (len >= sizeof selected_cpu_name)
26017 len = (sizeof selected_cpu_name) - 1;
26018
f3bad469 26019 for (i = 0; i < len; i++)
ee065d83
PB
26020 selected_cpu_name[i] = TOUPPER (opt->name[i]);
26021 selected_cpu_name[i] = 0;
26022 }
7ed4c4c5 26023
c19d1205
ZW
26024 if (ext != NULL)
26025 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 26026
c921be7d 26027 return TRUE;
c19d1205 26028 }
7ed4c4c5 26029
c19d1205 26030 as_bad (_("unknown cpu `%s'"), str);
c921be7d 26031 return FALSE;
7ed4c4c5
NC
26032}
26033
c921be7d 26034static bfd_boolean
17b9d67d 26035arm_parse_arch (const char *str)
7ed4c4c5 26036{
e74cfd16 26037 const struct arm_arch_option_table *opt;
82b8a785 26038 const char *ext = strchr (str, '+');
f3bad469 26039 size_t len;
7ed4c4c5 26040
c19d1205 26041 if (ext != NULL)
f3bad469 26042 len = ext - str;
7ed4c4c5 26043 else
f3bad469 26044 len = strlen (str);
7ed4c4c5 26045
f3bad469 26046 if (len == 0)
7ed4c4c5 26047 {
c19d1205 26048 as_bad (_("missing architecture name `%s'"), str);
c921be7d 26049 return FALSE;
7ed4c4c5
NC
26050 }
26051
c19d1205 26052 for (opt = arm_archs; opt->name != NULL; opt++)
f3bad469 26053 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
c19d1205 26054 {
e74cfd16
PB
26055 march_cpu_opt = &opt->value;
26056 march_fpu_opt = &opt->default_fpu;
5f4273c7 26057 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 26058
c19d1205
ZW
26059 if (ext != NULL)
26060 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 26061
c921be7d 26062 return TRUE;
c19d1205
ZW
26063 }
26064
26065 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 26066 return FALSE;
7ed4c4c5 26067}
eb043451 26068
c921be7d 26069static bfd_boolean
17b9d67d 26070arm_parse_fpu (const char * str)
c19d1205 26071{
69133863 26072 const struct arm_option_fpu_value_table * opt;
b99bd4ef 26073
c19d1205
ZW
26074 for (opt = arm_fpus; opt->name != NULL; opt++)
26075 if (streq (opt->name, str))
26076 {
e74cfd16 26077 mfpu_opt = &opt->value;
c921be7d 26078 return TRUE;
c19d1205 26079 }
b99bd4ef 26080
c19d1205 26081 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 26082 return FALSE;
c19d1205
ZW
26083}
26084
c921be7d 26085static bfd_boolean
17b9d67d 26086arm_parse_float_abi (const char * str)
b99bd4ef 26087{
e74cfd16 26088 const struct arm_option_value_table * opt;
b99bd4ef 26089
c19d1205
ZW
26090 for (opt = arm_float_abis; opt->name != NULL; opt++)
26091 if (streq (opt->name, str))
26092 {
26093 mfloat_abi_opt = opt->value;
c921be7d 26094 return TRUE;
c19d1205 26095 }
cc8a6dd0 26096
c19d1205 26097 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 26098 return FALSE;
c19d1205 26099}
b99bd4ef 26100
c19d1205 26101#ifdef OBJ_ELF
c921be7d 26102static bfd_boolean
17b9d67d 26103arm_parse_eabi (const char * str)
c19d1205 26104{
e74cfd16 26105 const struct arm_option_value_table *opt;
cc8a6dd0 26106
c19d1205
ZW
26107 for (opt = arm_eabis; opt->name != NULL; opt++)
26108 if (streq (opt->name, str))
26109 {
26110 meabi_flags = opt->value;
c921be7d 26111 return TRUE;
c19d1205
ZW
26112 }
26113 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 26114 return FALSE;
c19d1205
ZW
26115}
26116#endif
cc8a6dd0 26117
c921be7d 26118static bfd_boolean
17b9d67d 26119arm_parse_it_mode (const char * str)
e07e6e58 26120{
c921be7d 26121 bfd_boolean ret = TRUE;
e07e6e58
NC
26122
26123 if (streq ("arm", str))
26124 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
26125 else if (streq ("thumb", str))
26126 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
26127 else if (streq ("always", str))
26128 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
26129 else if (streq ("never", str))
26130 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
26131 else
26132 {
26133 as_bad (_("unknown implicit IT mode `%s', should be "\
477330fc 26134 "arm, thumb, always, or never."), str);
c921be7d 26135 ret = FALSE;
e07e6e58
NC
26136 }
26137
26138 return ret;
26139}
26140
2e6976a8 26141static bfd_boolean
17b9d67d 26142arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
2e6976a8
DG
26143{
26144 codecomposer_syntax = TRUE;
26145 arm_comment_chars[0] = ';';
26146 arm_line_separator_chars[0] = 0;
26147 return TRUE;
26148}
26149
c19d1205
ZW
26150struct arm_long_option_table arm_long_opts[] =
26151{
26152 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
26153 arm_parse_cpu, NULL},
26154 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
26155 arm_parse_arch, NULL},
26156 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
26157 arm_parse_fpu, NULL},
26158 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
26159 arm_parse_float_abi, NULL},
26160#ifdef OBJ_ELF
7fac0536 26161 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
26162 arm_parse_eabi, NULL},
26163#endif
e07e6e58
NC
26164 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
26165 arm_parse_it_mode, NULL},
2e6976a8
DG
26166 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
26167 arm_ccs_mode, NULL},
c19d1205
ZW
26168 {NULL, NULL, 0, NULL}
26169};
cc8a6dd0 26170
c19d1205 26171int
17b9d67d 26172md_parse_option (int c, const char * arg)
c19d1205
ZW
26173{
26174 struct arm_option_table *opt;
e74cfd16 26175 const struct arm_legacy_option_table *fopt;
c19d1205 26176 struct arm_long_option_table *lopt;
b99bd4ef 26177
c19d1205 26178 switch (c)
b99bd4ef 26179 {
c19d1205
ZW
26180#ifdef OPTION_EB
26181 case OPTION_EB:
26182 target_big_endian = 1;
26183 break;
26184#endif
cc8a6dd0 26185
c19d1205
ZW
26186#ifdef OPTION_EL
26187 case OPTION_EL:
26188 target_big_endian = 0;
26189 break;
26190#endif
b99bd4ef 26191
845b51d6
PB
26192 case OPTION_FIX_V4BX:
26193 fix_v4bx = TRUE;
26194 break;
26195
c19d1205
ZW
26196 case 'a':
26197 /* Listing option. Just ignore these, we don't support additional
26198 ones. */
26199 return 0;
b99bd4ef 26200
c19d1205
ZW
26201 default:
26202 for (opt = arm_opts; opt->option != NULL; opt++)
26203 {
26204 if (c == opt->option[0]
26205 && ((arg == NULL && opt->option[1] == 0)
26206 || streq (arg, opt->option + 1)))
26207 {
c19d1205 26208 /* If the option is deprecated, tell the user. */
278df34e 26209 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
26210 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26211 arg ? arg : "", _(opt->deprecated));
b99bd4ef 26212
c19d1205
ZW
26213 if (opt->var != NULL)
26214 *opt->var = opt->value;
cc8a6dd0 26215
c19d1205
ZW
26216 return 1;
26217 }
26218 }
b99bd4ef 26219
e74cfd16
PB
26220 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
26221 {
26222 if (c == fopt->option[0]
26223 && ((arg == NULL && fopt->option[1] == 0)
26224 || streq (arg, fopt->option + 1)))
26225 {
e74cfd16 26226 /* If the option is deprecated, tell the user. */
278df34e 26227 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
26228 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26229 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
26230
26231 if (fopt->var != NULL)
26232 *fopt->var = &fopt->value;
26233
26234 return 1;
26235 }
26236 }
26237
c19d1205
ZW
26238 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26239 {
26240 /* These options are expected to have an argument. */
26241 if (c == lopt->option[0]
26242 && arg != NULL
26243 && strncmp (arg, lopt->option + 1,
26244 strlen (lopt->option + 1)) == 0)
26245 {
c19d1205 26246 /* If the option is deprecated, tell the user. */
278df34e 26247 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
26248 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
26249 _(lopt->deprecated));
b99bd4ef 26250
c19d1205
ZW
26251 /* Call the sup-option parser. */
26252 return lopt->func (arg + strlen (lopt->option) - 1);
26253 }
26254 }
a737bd4d 26255
c19d1205
ZW
26256 return 0;
26257 }
a394c00f 26258
c19d1205
ZW
26259 return 1;
26260}
a394c00f 26261
c19d1205
ZW
26262void
26263md_show_usage (FILE * fp)
a394c00f 26264{
c19d1205
ZW
26265 struct arm_option_table *opt;
26266 struct arm_long_option_table *lopt;
a394c00f 26267
c19d1205 26268 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 26269
c19d1205
ZW
26270 for (opt = arm_opts; opt->option != NULL; opt++)
26271 if (opt->help != NULL)
26272 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 26273
c19d1205
ZW
26274 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26275 if (lopt->help != NULL)
26276 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 26277
c19d1205
ZW
26278#ifdef OPTION_EB
26279 fprintf (fp, _("\
26280 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
26281#endif
26282
c19d1205
ZW
26283#ifdef OPTION_EL
26284 fprintf (fp, _("\
26285 -EL assemble code for a little-endian cpu\n"));
a737bd4d 26286#endif
845b51d6
PB
26287
26288 fprintf (fp, _("\
26289 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 26290}
ee065d83
PB
26291
26292
26293#ifdef OBJ_ELF
62b3e311
PB
26294typedef struct
26295{
26296 int val;
26297 arm_feature_set flags;
26298} cpu_arch_ver_table;
26299
4ed7ed8d
TP
26300/* Mapping from CPU features to EABI CPU arch values. As a general rule, table
26301 must be sorted least features first but some reordering is needed, eg. for
26302 Thumb-2 instructions to be detected as coming from ARMv6T2. */
62b3e311
PB
26303static const cpu_arch_ver_table cpu_arch_ver[] =
26304{
26305 {1, ARM_ARCH_V4},
26306 {2, ARM_ARCH_V4T},
26307 {3, ARM_ARCH_V5},
ee3c0378 26308 {3, ARM_ARCH_V5T},
62b3e311
PB
26309 {4, ARM_ARCH_V5TE},
26310 {5, ARM_ARCH_V5TEJ},
26311 {6, ARM_ARCH_V6},
7e806470 26312 {9, ARM_ARCH_V6K},
f4c65163 26313 {7, ARM_ARCH_V6Z},
91e22acd 26314 {11, ARM_ARCH_V6M},
b2a5fbdc 26315 {12, ARM_ARCH_V6SM},
7e806470 26316 {8, ARM_ARCH_V6T2},
c9fb6e58 26317 {10, ARM_ARCH_V7VE},
62b3e311
PB
26318 {10, ARM_ARCH_V7R},
26319 {10, ARM_ARCH_V7M},
bca38921 26320 {14, ARM_ARCH_V8A},
ff8646ee 26321 {16, ARM_ARCH_V8M_BASE},
4ed7ed8d 26322 {17, ARM_ARCH_V8M_MAIN},
62b3e311
PB
26323 {0, ARM_ARCH_NONE}
26324};
26325
ee3c0378
AS
26326/* Set an attribute if it has not already been set by the user. */
26327static void
26328aeabi_set_attribute_int (int tag, int value)
26329{
26330 if (tag < 1
26331 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26332 || !attributes_set_explicitly[tag])
26333 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
26334}
26335
26336static void
26337aeabi_set_attribute_string (int tag, const char *value)
26338{
26339 if (tag < 1
26340 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
26341 || !attributes_set_explicitly[tag])
26342 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
26343}
26344
ee065d83 26345/* Set the public EABI object attributes. */
3cfdb781 26346void
ee065d83
PB
26347aeabi_set_public_attributes (void)
26348{
26349 int arch;
69239280 26350 char profile;
90ec0d68 26351 int virt_sec = 0;
bca38921 26352 int fp16_optional = 0;
15afaa63 26353 arm_feature_set arm_arch = ARM_ARCH_NONE;
e74cfd16 26354 arm_feature_set flags;
62b3e311 26355 arm_feature_set tmp;
ff8646ee 26356 arm_feature_set arm_arch_v8m_base = ARM_ARCH_V8M_BASE;
62b3e311 26357 const cpu_arch_ver_table *p;
ee065d83
PB
26358
26359 /* Choose the architecture based on the capabilities of the requested cpu
26360 (if any) and/or the instructions actually used. */
e74cfd16
PB
26361 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
26362 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
26363 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
ddd7f988
RE
26364
26365 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
26366 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
26367
26368 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
26369 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
26370
7f78eb34
JW
26371 selected_cpu = flags;
26372
ddd7f988 26373 /* Allow the user to override the reported architecture. */
7a1d4c38
PB
26374 if (object_arch)
26375 {
26376 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
26377 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
26378 }
26379
251665fc
MGD
26380 /* We need to make sure that the attributes do not identify us as v6S-M
26381 when the only v6S-M feature in use is the Operating System Extensions. */
26382 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
26383 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
477330fc 26384 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
251665fc 26385
62b3e311
PB
26386 tmp = flags;
26387 arch = 0;
26388 for (p = cpu_arch_ver; p->val; p++)
26389 {
26390 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
26391 {
26392 arch = p->val;
15afaa63 26393 arm_arch = p->flags;
62b3e311
PB
26394 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
26395 }
26396 }
ee065d83 26397
9e3c6df6
PB
26398 /* The table lookup above finds the last architecture to contribute
26399 a new feature. Unfortunately, Tag13 is a subset of the union of
26400 v6T2 and v7-M, so it is never seen as contributing a new feature.
26401 We can not search for the last entry which is entirely used,
26402 because if no CPU is specified we build up only those flags
26403 actually used. Perhaps we should separate out the specified
26404 and implicit cases. Avoid taking this path for -march=all by
26405 checking for contradictory v7-A / v7-M features. */
4ed7ed8d 26406 if (arch == TAG_CPU_ARCH_V7
9e3c6df6
PB
26407 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
26408 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
26409 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
15afaa63
TP
26410 {
26411 arch = TAG_CPU_ARCH_V7E_M;
26412 arm_arch = (arm_feature_set) ARM_ARCH_V7EM;
26413 }
4ed7ed8d 26414
ff8646ee
TP
26415 ARM_CLEAR_FEATURE (tmp, flags, arm_arch_v8m_base);
26416 if (arch == TAG_CPU_ARCH_V8M_BASE && ARM_CPU_HAS_FEATURE (tmp, arm_arch_any))
15afaa63
TP
26417 {
26418 arch = TAG_CPU_ARCH_V8M_MAIN;
26419 arm_arch = (arm_feature_set) ARM_ARCH_V8M_MAIN;
26420 }
ff8646ee 26421
4ed7ed8d
TP
26422 /* In cpu_arch_ver ARMv8-A is before ARMv8-M for atomics to be detected as
26423 coming from ARMv8-A. However, since ARMv8-A has more instructions than
26424 ARMv8-M, -march=all must be detected as ARMv8-A. */
26425 if (arch == TAG_CPU_ARCH_V8M_MAIN
26426 && ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
15afaa63
TP
26427 {
26428 arch = TAG_CPU_ARCH_V8;
26429 arm_arch = (arm_feature_set) ARM_ARCH_V8A;
26430 }
9e3c6df6 26431
ee065d83
PB
26432 /* Tag_CPU_name. */
26433 if (selected_cpu_name[0])
26434 {
91d6fa6a 26435 char *q;
ee065d83 26436
91d6fa6a
NC
26437 q = selected_cpu_name;
26438 if (strncmp (q, "armv", 4) == 0)
ee065d83
PB
26439 {
26440 int i;
5f4273c7 26441
91d6fa6a
NC
26442 q += 4;
26443 for (i = 0; q[i]; i++)
26444 q[i] = TOUPPER (q[i]);
ee065d83 26445 }
91d6fa6a 26446 aeabi_set_attribute_string (Tag_CPU_name, q);
ee065d83 26447 }
62f3b8c8 26448
ee065d83 26449 /* Tag_CPU_arch. */
ee3c0378 26450 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 26451
62b3e311 26452 /* Tag_CPU_arch_profile. */
10c9892b 26453 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
4ed7ed8d
TP
26454 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26455 || (ARM_CPU_HAS_FEATURE (flags, arm_ext_atomics)
16a1fa25 26456 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only)))
69239280 26457 profile = 'A';
62b3e311 26458 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
69239280 26459 profile = 'R';
7e806470 26460 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
69239280
MGD
26461 profile = 'M';
26462 else
26463 profile = '\0';
26464
26465 if (profile != '\0')
26466 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
62f3b8c8 26467
15afaa63
TP
26468 /* Tag_DSP_extension. */
26469 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_dsp))
26470 {
26471 arm_feature_set ext;
26472
26473 /* DSP instructions not in architecture. */
26474 ARM_CLEAR_FEATURE (ext, flags, arm_arch);
26475 if (ARM_CPU_HAS_FEATURE (ext, arm_ext_dsp))
26476 aeabi_set_attribute_int (Tag_DSP_extension, 1);
26477 }
26478
ee065d83 26479 /* Tag_ARM_ISA_use. */
ee3c0378
AS
26480 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
26481 || arch == 0)
26482 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 26483
ee065d83 26484 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
26485 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
26486 || arch == 0)
4ed7ed8d
TP
26487 {
26488 int thumb_isa_use;
26489
26490 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
16a1fa25 26491 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
4ed7ed8d
TP
26492 thumb_isa_use = 3;
26493 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
26494 thumb_isa_use = 2;
26495 else
26496 thumb_isa_use = 1;
26497 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
26498 }
62f3b8c8 26499
ee065d83 26500 /* Tag_VFP_arch. */
a715796b
TG
26501 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
26502 aeabi_set_attribute_int (Tag_VFP_arch,
26503 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
26504 ? 7 : 8);
bca38921 26505 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
62f3b8c8
PB
26506 aeabi_set_attribute_int (Tag_VFP_arch,
26507 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
26508 ? 5 : 6);
26509 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
bca38921
MGD
26510 {
26511 fp16_optional = 1;
26512 aeabi_set_attribute_int (Tag_VFP_arch, 3);
26513 }
ada65aa3 26514 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
bca38921
MGD
26515 {
26516 aeabi_set_attribute_int (Tag_VFP_arch, 4);
26517 fp16_optional = 1;
26518 }
ee3c0378
AS
26519 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
26520 aeabi_set_attribute_int (Tag_VFP_arch, 2);
26521 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
477330fc 26522 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
ee3c0378 26523 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 26524
4547cb56
NC
26525 /* Tag_ABI_HardFP_use. */
26526 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
26527 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
26528 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
26529
ee065d83 26530 /* Tag_WMMX_arch. */
ee3c0378
AS
26531 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
26532 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
26533 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
26534 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 26535
ee3c0378 26536 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
9411fd44
MW
26537 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
26538 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
26539 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
bca38921
MGD
26540 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
26541 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
26542 {
26543 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
26544 {
26545 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
26546 }
26547 else
26548 {
26549 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
26550 fp16_optional = 1;
26551 }
26552 }
fa94de6b 26553
ee3c0378 26554 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
bca38921 26555 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
ee3c0378 26556 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
4547cb56 26557
69239280
MGD
26558 /* Tag_DIV_use.
26559
26560 We set Tag_DIV_use to two when integer divide instructions have been used
26561 in ARM state, or when Thumb integer divide instructions have been used,
26562 but we have no architecture profile set, nor have we any ARM instructions.
26563
4ed7ed8d
TP
26564 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
26565 by the base architecture.
bca38921 26566
69239280 26567 For new architectures we will have to check these tests. */
ff8646ee
TP
26568 gas_assert (arch <= TAG_CPU_ARCH_V8
26569 || (arch >= TAG_CPU_ARCH_V8M_BASE
26570 && arch <= TAG_CPU_ARCH_V8M_MAIN));
4ed7ed8d
TP
26571 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
26572 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
bca38921
MGD
26573 aeabi_set_attribute_int (Tag_DIV_use, 0);
26574 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
26575 || (profile == '\0'
26576 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
26577 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
eea54501 26578 aeabi_set_attribute_int (Tag_DIV_use, 2);
60e5ef9f
MGD
26579
26580 /* Tag_MP_extension_use. */
26581 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
26582 aeabi_set_attribute_int (Tag_MPextension_use, 1);
f4c65163
MGD
26583
26584 /* Tag Virtualization_use. */
26585 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
90ec0d68
MGD
26586 virt_sec |= 1;
26587 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
26588 virt_sec |= 2;
26589 if (virt_sec != 0)
26590 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
ee065d83
PB
26591}
26592
104d59d1 26593/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
26594void
26595arm_md_end (void)
26596{
ee065d83
PB
26597 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
26598 return;
26599
26600 aeabi_set_public_attributes ();
ee065d83 26601}
8463be01 26602#endif /* OBJ_ELF */
ee065d83
PB
26603
26604
26605/* Parse a .cpu directive. */
26606
26607static void
26608s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
26609{
e74cfd16 26610 const struct arm_cpu_option_table *opt;
ee065d83
PB
26611 char *name;
26612 char saved_char;
26613
26614 name = input_line_pointer;
5f4273c7 26615 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26616 input_line_pointer++;
26617 saved_char = *input_line_pointer;
26618 *input_line_pointer = 0;
26619
26620 /* Skip the first "all" entry. */
26621 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
26622 if (streq (opt->name, name))
26623 {
e74cfd16
PB
26624 mcpu_cpu_opt = &opt->value;
26625 selected_cpu = opt->value;
ee065d83 26626 if (opt->canonical_name)
5f4273c7 26627 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
26628 else
26629 {
26630 int i;
26631 for (i = 0; opt->name[i]; i++)
26632 selected_cpu_name[i] = TOUPPER (opt->name[i]);
f3bad469 26633
ee065d83
PB
26634 selected_cpu_name[i] = 0;
26635 }
e74cfd16 26636 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26637 *input_line_pointer = saved_char;
26638 demand_empty_rest_of_line ();
26639 return;
26640 }
26641 as_bad (_("unknown cpu `%s'"), name);
26642 *input_line_pointer = saved_char;
26643 ignore_rest_of_line ();
26644}
26645
26646
26647/* Parse a .arch directive. */
26648
26649static void
26650s_arm_arch (int ignored ATTRIBUTE_UNUSED)
26651{
e74cfd16 26652 const struct arm_arch_option_table *opt;
ee065d83
PB
26653 char saved_char;
26654 char *name;
26655
26656 name = input_line_pointer;
5f4273c7 26657 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26658 input_line_pointer++;
26659 saved_char = *input_line_pointer;
26660 *input_line_pointer = 0;
26661
26662 /* Skip the first "all" entry. */
26663 for (opt = arm_archs + 1; opt->name != NULL; opt++)
26664 if (streq (opt->name, name))
26665 {
e74cfd16
PB
26666 mcpu_cpu_opt = &opt->value;
26667 selected_cpu = opt->value;
5f4273c7 26668 strcpy (selected_cpu_name, opt->name);
e74cfd16 26669 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26670 *input_line_pointer = saved_char;
26671 demand_empty_rest_of_line ();
26672 return;
26673 }
26674
26675 as_bad (_("unknown architecture `%s'\n"), name);
26676 *input_line_pointer = saved_char;
26677 ignore_rest_of_line ();
26678}
26679
26680
7a1d4c38
PB
26681/* Parse a .object_arch directive. */
26682
26683static void
26684s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
26685{
26686 const struct arm_arch_option_table *opt;
26687 char saved_char;
26688 char *name;
26689
26690 name = input_line_pointer;
5f4273c7 26691 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
26692 input_line_pointer++;
26693 saved_char = *input_line_pointer;
26694 *input_line_pointer = 0;
26695
26696 /* Skip the first "all" entry. */
26697 for (opt = arm_archs + 1; opt->name != NULL; opt++)
26698 if (streq (opt->name, name))
26699 {
26700 object_arch = &opt->value;
26701 *input_line_pointer = saved_char;
26702 demand_empty_rest_of_line ();
26703 return;
26704 }
26705
26706 as_bad (_("unknown architecture `%s'\n"), name);
26707 *input_line_pointer = saved_char;
26708 ignore_rest_of_line ();
26709}
26710
69133863
MGD
26711/* Parse a .arch_extension directive. */
26712
26713static void
26714s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
26715{
26716 const struct arm_option_extension_value_table *opt;
d942732e 26717 const arm_feature_set arm_any = ARM_ANY;
69133863
MGD
26718 char saved_char;
26719 char *name;
26720 int adding_value = 1;
26721
26722 name = input_line_pointer;
26723 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
26724 input_line_pointer++;
26725 saved_char = *input_line_pointer;
26726 *input_line_pointer = 0;
26727
26728 if (strlen (name) >= 2
26729 && strncmp (name, "no", 2) == 0)
26730 {
26731 adding_value = 0;
26732 name += 2;
26733 }
26734
26735 for (opt = arm_extensions; opt->name != NULL; opt++)
26736 if (streq (opt->name, name))
26737 {
d942732e
TP
26738 int i, nb_allowed_archs =
26739 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
26740 for (i = 0; i < nb_allowed_archs; i++)
26741 {
26742 /* Empty entry. */
26743 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
26744 continue;
26745 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *mcpu_cpu_opt))
26746 break;
26747 }
26748
26749 if (i == nb_allowed_archs)
69133863
MGD
26750 {
26751 as_bad (_("architectural extension `%s' is not allowed for the "
26752 "current base architecture"), name);
26753 break;
26754 }
26755
26756 if (adding_value)
5a70a223
JB
26757 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu,
26758 opt->merge_value);
69133863 26759 else
5a70a223 26760 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->clear_value);
69133863
MGD
26761
26762 mcpu_cpu_opt = &selected_cpu;
26763 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
26764 *input_line_pointer = saved_char;
26765 demand_empty_rest_of_line ();
26766 return;
26767 }
26768
26769 if (opt->name == NULL)
e673710a 26770 as_bad (_("unknown architecture extension `%s'\n"), name);
69133863
MGD
26771
26772 *input_line_pointer = saved_char;
26773 ignore_rest_of_line ();
26774}
26775
ee065d83
PB
26776/* Parse a .fpu directive. */
26777
26778static void
26779s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
26780{
69133863 26781 const struct arm_option_fpu_value_table *opt;
ee065d83
PB
26782 char saved_char;
26783 char *name;
26784
26785 name = input_line_pointer;
5f4273c7 26786 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
26787 input_line_pointer++;
26788 saved_char = *input_line_pointer;
26789 *input_line_pointer = 0;
5f4273c7 26790
ee065d83
PB
26791 for (opt = arm_fpus; opt->name != NULL; opt++)
26792 if (streq (opt->name, name))
26793 {
e74cfd16
PB
26794 mfpu_opt = &opt->value;
26795 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
26796 *input_line_pointer = saved_char;
26797 demand_empty_rest_of_line ();
26798 return;
26799 }
26800
26801 as_bad (_("unknown floating point format `%s'\n"), name);
26802 *input_line_pointer = saved_char;
26803 ignore_rest_of_line ();
26804}
ee065d83 26805
794ba86a 26806/* Copy symbol information. */
f31fef98 26807
794ba86a
DJ
26808void
26809arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
26810{
26811 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
26812}
e04befd0 26813
f31fef98 26814#ifdef OBJ_ELF
e04befd0
AS
26815/* Given a symbolic attribute NAME, return the proper integer value.
26816 Returns -1 if the attribute is not known. */
f31fef98 26817
e04befd0
AS
26818int
26819arm_convert_symbolic_attribute (const char *name)
26820{
f31fef98
NC
26821 static const struct
26822 {
26823 const char * name;
26824 const int tag;
26825 }
26826 attribute_table[] =
26827 {
26828 /* When you modify this table you should
26829 also modify the list in doc/c-arm.texi. */
e04befd0 26830#define T(tag) {#tag, tag}
f31fef98
NC
26831 T (Tag_CPU_raw_name),
26832 T (Tag_CPU_name),
26833 T (Tag_CPU_arch),
26834 T (Tag_CPU_arch_profile),
26835 T (Tag_ARM_ISA_use),
26836 T (Tag_THUMB_ISA_use),
75375b3e 26837 T (Tag_FP_arch),
f31fef98
NC
26838 T (Tag_VFP_arch),
26839 T (Tag_WMMX_arch),
26840 T (Tag_Advanced_SIMD_arch),
26841 T (Tag_PCS_config),
26842 T (Tag_ABI_PCS_R9_use),
26843 T (Tag_ABI_PCS_RW_data),
26844 T (Tag_ABI_PCS_RO_data),
26845 T (Tag_ABI_PCS_GOT_use),
26846 T (Tag_ABI_PCS_wchar_t),
26847 T (Tag_ABI_FP_rounding),
26848 T (Tag_ABI_FP_denormal),
26849 T (Tag_ABI_FP_exceptions),
26850 T (Tag_ABI_FP_user_exceptions),
26851 T (Tag_ABI_FP_number_model),
75375b3e 26852 T (Tag_ABI_align_needed),
f31fef98 26853 T (Tag_ABI_align8_needed),
75375b3e 26854 T (Tag_ABI_align_preserved),
f31fef98
NC
26855 T (Tag_ABI_align8_preserved),
26856 T (Tag_ABI_enum_size),
26857 T (Tag_ABI_HardFP_use),
26858 T (Tag_ABI_VFP_args),
26859 T (Tag_ABI_WMMX_args),
26860 T (Tag_ABI_optimization_goals),
26861 T (Tag_ABI_FP_optimization_goals),
26862 T (Tag_compatibility),
26863 T (Tag_CPU_unaligned_access),
75375b3e 26864 T (Tag_FP_HP_extension),
f31fef98
NC
26865 T (Tag_VFP_HP_extension),
26866 T (Tag_ABI_FP_16bit_format),
cd21e546
MGD
26867 T (Tag_MPextension_use),
26868 T (Tag_DIV_use),
f31fef98
NC
26869 T (Tag_nodefaults),
26870 T (Tag_also_compatible_with),
26871 T (Tag_conformance),
26872 T (Tag_T2EE_use),
26873 T (Tag_Virtualization_use),
15afaa63 26874 T (Tag_DSP_extension),
cd21e546 26875 /* We deliberately do not include Tag_MPextension_use_legacy. */
e04befd0 26876#undef T
f31fef98 26877 };
e04befd0
AS
26878 unsigned int i;
26879
26880 if (name == NULL)
26881 return -1;
26882
f31fef98 26883 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 26884 if (streq (name, attribute_table[i].name))
e04befd0
AS
26885 return attribute_table[i].tag;
26886
26887 return -1;
26888}
267bf995
RR
26889
26890
93ef582d
NC
26891/* Apply sym value for relocations only in the case that they are for
26892 local symbols in the same segment as the fixup and you have the
26893 respective architectural feature for blx and simple switches. */
267bf995 26894int
93ef582d 26895arm_apply_sym_value (struct fix * fixP, segT this_seg)
267bf995
RR
26896{
26897 if (fixP->fx_addsy
26898 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
93ef582d
NC
26899 /* PR 17444: If the local symbol is in a different section then a reloc
26900 will always be generated for it, so applying the symbol value now
26901 will result in a double offset being stored in the relocation. */
26902 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
34e77a92 26903 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
267bf995
RR
26904 {
26905 switch (fixP->fx_r_type)
26906 {
26907 case BFD_RELOC_ARM_PCREL_BLX:
26908 case BFD_RELOC_THUMB_PCREL_BRANCH23:
26909 if (ARM_IS_FUNC (fixP->fx_addsy))
26910 return 1;
26911 break;
26912
26913 case BFD_RELOC_ARM_PCREL_CALL:
26914 case BFD_RELOC_THUMB_PCREL_BLX:
26915 if (THUMB_IS_FUNC (fixP->fx_addsy))
93ef582d 26916 return 1;
267bf995
RR
26917 break;
26918
26919 default:
26920 break;
26921 }
26922
26923 }
26924 return 0;
26925}
f31fef98 26926#endif /* OBJ_ELF */